2022-03-04 adb install 安装apk的时候会调用的代码,简单分析记录。实际的需求是禁止用户通过adb install 安装第三方app

一、adb install 安装apk的时候会有下面的log,有install字样。会调用StartCommandInProcess和execCmd执行命令。system\core\adb\daemon\abb.cpp

frameworks\native\cmds\cmd\cmd.cpp

后面会在frameworks\base\services\core\java\com\android\server\pm\Installer.java里面调用 installd 执行文件安装

二、从上面的log可以知道android\system\core\adb\daemon\abb.cpp里面的bin程序一直在读命令ReadProtocolString,abb这个程序开机就在后台运行。

三、禁止用户使用adb install 命令安装app的方法(android 11 )

     1、system\core\adb\daemon\shell_service.cpp修改下面的代码

commit 59e6e59a99bbf6d774139933cfd33b7e7557bb1b
Author: 
Date:   Thu Jul 7 19:38:18 2022 +0800

    setprop topdon.thirdapp.prohibit true to prohibit user to install app by using adb install
    
    Change-Id: I284635cef80f08b4d43fa77e05db41b940bdabf3

diff --git a/adb/daemon/shell_service.cpp b/adb/daemon/shell_service.cpp
old mode 100644
new mode 100755
index fbfae1e..224bce1
--- a/adb/daemon/shell_service.cpp
+++ b/adb/daemon/shell_service.cpp
@@ -877,16 +877,43 @@ unique_fd StartSubprocess(std::string name, const char* terminal_type, Subproces
 
     return local_socket;
 }
+						  
+bool CheckThirdAppProhibit() {
+	std::string isprohibit ("true");
+	std::string value;
+	value = android::base::GetProperty("topdon.thirdapp.prohibit", "false");
+	if (!isprohibit.compare(value))
+      return true;
+	else
+	  return false;	
+}
 
 unique_fd StartCommandInProcess(std::string name, Command command, SubprocessProtocol protocol) {
-    LOG(INFO) << "StartCommandInProcess(" << dump_hex(name.data(), name.size()) << ")";
+	std::string namestring;
+	std::string install_flag="package.install";
+	std::string::size_type idx;
+	namestring = dump_hex(name.data(), name.size());
+
+	LOG(INFO) << "StartCommandInProcess(" << namestring << ")";
 
     constexpr auto terminal_type = "";
     constexpr auto type = SubprocessType::kRaw;
     constexpr auto make_pty_raw = false;
 
     auto subprocess = std::make_unique<Subprocess>(std::move(name), terminal_type, type, protocol,
-                                                   make_pty_raw);
+                                             make_pty_raw);
+	idx=namestring.find(install_flag);
+	if(idx == std::string::npos )
+	     LOG(ERROR) << "the command do not include package.install string";
+	else
+	{
+	  if(CheckThirdAppProhibit()) {
+	     LOG(ERROR) << "Prohibit to install third app" ;
+	     return ReportError(protocol, "Prohibit to install third app by adb install command");
+	  }else 
+	     LOG(ERROR) << "Allow to install third app" ;
+	}
+
     if (!subprocess) {
         LOG(ERROR) << "failed to allocate new subprocess";
         return ReportError(protocol, "failed to allocate new subprocess");

2、测试看一下效果 ,可以看到当用setprop把属性写成true,用户就没办法用adb install 安装app了。

四、静默安装文章Android Apk安装过程解析 - 简书

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`adb install`和`pm install`命令都用于在Android设备上安装应用程序,它们的安装流程如下: 1. `adb install`安装流程: - 通过USB连接将Android设备与计算机相连。 - 打开终端或命令提示符,并导航到ADB工具的目录(通常是Android SDK的`platform-tools`目录)。 - 运行命令`adb devices`,确保设备已经被检测到。 - 使用命令`adb install <path_to_apk>`,其中`<path_to_apk>`指向要安装APK文件的路径。 - ADB客户端将APK文件发送到设备,并启动设备上的ADB守护进程。 - ADB守护进程将APK文件传递给`pm install`命令进行处理。 2. `pm install`安装流程: - 接收到安装请求的`pm install`命令调用PackageManagerService中的相应方法来处理安装操作。 - 首先,进行签名验证,确保APK文件的签名与设备上已安装应用程序的签名匹配或者具备系统签名。 - 然后,检查应用程序的权限列表,并与设备的权限进行比对。 - 如果验证通过,PackageManagerService解析APK文件,提取应用程序的信息(包名、版本号等)。 - 接下来,为应用程序分配用户ID,并在系统中创建应用程序的数据目录。 - 最后,将应用程序的APK文件复制到设备的数据分区,并注册应用程序的信息到PackageManagerService中,使其成为已安装应用。 需要注意的是,`pm install`命令可以在设备上直接运行,而`adb install`命令需要通过ADB客户端与设备进行通信。这两个命令都是通过PackageManagerService来处理应用程序的安装,但`adb install`命令先将APK文件传递给设备上运行的ADB守护进程,再由守护进程调用`pm install`命令进行处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值