我正在尝试从我的 java 代码安装系统应用程序,到目前为止,我还没有成功。
以下是我到目前为止所做的:
- 我的设备已获得 root 权限。
- 我的“安装程序”应用程序作为系统应用程序安装。 (手动复制到/system/app)
- 我已经使用平台 key 签署了安装程序 apk,并且我在 list 中有
android:sharedUserId="android.uid.system"
。 我一直在为
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.
- 我已在 list 中请求
INSTALL_PACKAGES
权限。
我尝试了多种 exec("") 格式的变体,包括在每个命令中使用 'su -c'
。我得到了 Broken Pipe 异常和 Security 异常。有时,我没有得到异常,但文件没有被复制。
请让我知道我在这里缺少什么。有人成功了吗?
谢谢!
最佳答案
我继续挖掘,结果如下:
- Android 在 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( super 用户)和 cyanogen mod 通过实现他们自己的 su.c 来解决这个问题:https://github.com/CyanogenMod/android_system_su/blob/master/su.c
/system/app
有什么特别之处?事实似乎是该分区在非根设备上是只读的,从而防止修改/卸载放置在那里的应用程序。 https://android.stackexchange.com/questions/17871/what-are-the-differences-between-a-system-app-and-user-app使用平台 key 和
sharedUserId = system
签名的应用程序对于我的目的来说“足够好”,我不需要特别将它复制到/system/app。
我暂时接受这个作为答案。
关于安卓 : programmatically copying apk to/system/app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10691485/