Android:以编程方式将 apk 复制到/system/app [英] Android : programmatically copying apk to /system/app

查看:79
本文介绍了Android:以编程方式将 apk 复制到/system/app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的 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
    cat/sdcard/application.apk >/system/app/application.apk
    mount -o remount,ro -t yaffs2/dev/block/mtdblock3/system<br><br>这里的application.apk是从安装程序安装的应用程序.此应用程序还使用平台密钥进行签名,并配置了 sharedUserId.

  5. 我已在清单中请求 INSTALL_PACKAGES 权限.

我尝试了 exec("") 格式的多种变体,包括对每个命令使用 'su -c'.我收到了 Broken Pipe 异常和 Security 异常.有时,我没有收到异常,但文件没有被复制.


请让我知道我在这里遗漏了什么.有人成功了吗?

谢谢!

解决方案

我一直在挖掘,结果如下:

  • Android 在 su.c 中有此检查:["android 源的根目录"/system/extras/su/su.c]
<块引用>

/* 在我们有更好的东西之前,只有 root 和 shell 可以使用 su.*/myuid = getuid();if (myuid != AID_ROOT && myuid != AID_SHELL) {fprintf(stderr,"su: uid %d 不允许 su\n", myuid);返回 1;}

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

我现在接受这个作为答案.

I am trying to install a system app from my java code, and so far, I haven't had any success.

Following is what I have done so far:

  1. My device is rooted.
  2. My "installer" app is installed as a system app. (copied it manually to /system/app)
  3. I have signed the installer apk with platform key, and I have android:sharedUserId="android.uid.system" in the Manifest.
  4. I have been trying (and trying, and then some more) for Runtime.getRuntime.exec("su"). I intend to mount the system partition as rw, do a cat for the apk, and then make system partition ro. Following is the list of commands:

    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. I have requested for the INSTALL_PACKAGES permission in the manifest.

I have tried a number of variations of the exec("") format, including using 'su -c' with every command. I have gotten the Broken Pipe exception and Security exception. Sometimes, I don't get an exception, but the file isn't copied.


Please let me know what I am missing here. Has anyone got this working?

Thanks!

解决方案

I kept on digging, and here are the results:

  • Android has this check in su.c: ["root of android source"/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) and cyanogen mod get around this by implementing their own su.c: https://github.com/CyanogenMod/android_system_su/blob/master/su.c

I am accepting this as answer for now.

这篇关于Android:以编程方式将 apk 复制到/system/app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆