Android:以编程方式将apk复制到/ system / app

时间:2012-05-21 19:37:32

标签: android root android-install-apk su

我正在尝试从我的java代码安装系统应用程序,到目前为止,我没有取得任何成功。

以下是我到目前为止所做的:

  1. 我的设备已植根。
  2. 我的“安装程序”应用程序已安装为系统应用程序。 (手动将其复制到/ system / app)
  3. 我已经使用平台密钥签署了安装程序apk,并且我在清单中有android:sharedUserId="android.uid.system"
  4. 我一直在为Runtime.getRuntime.exec("su")尝试(并尝试,然后再尝试一些)。我打算将系统分区挂载为rw,为apk执行cat,然后创建系统分区ro。以下是命令列表:

    mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system<br>
    cat /sdcard/application.apk > /system/app/application.apk<br>
    mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system<br><br>The application.apk here is the app being installed from the installer app. This app is also signed with platform key, and has the sharedUserId configured.
    
  5. 我已要求提供清单中的INSTALL_PACKAGES权限。
  6. 我尝试了许多exec(“”)格式的变体,包括在每个命令中使用'su -c'。我得到了Broken Pipe异常和安全异常。有时候,我没有异常,但文件没有被复制。


    请告诉我这里缺少的东西。有人有这个工作吗?

    谢谢!

1 个答案:

答案 0 :(得分:4)

我继续挖掘,结果如下:

  • Android在su.c中检查:[“android源码根”/system/extras/su/su.c]
/* Until we have something better, only root and the shell can use su.*/
myuid = getuid();
if (myuid != AID_ROOT && myuid != AID_SHELL) {
    fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
    return 1;
}

ChainsDD(SuperUser)和cyanogen mod通过实现自己的su.c来解决这个问题:https://github.com/CyanogenMod/android_system_su/blob/master/su.c

我现在接受这个答案。

相关问题