Android:以编程方式将 apk 复制到/system/app [英] Android : programmatically copying apk to /system/app
问题描述
我正在尝试从我的 java 代码安装系统应用程序,到目前为止,我还没有成功.
以下是我到目前为止所做的:
- 我的设备已植根.
- 我的安装程序"应用安装为系统应用.(手动复制到/system/app)
- 我已使用平台密钥对安装程序 apk 进行了签名,并且清单中有
android:sharedUserId="android.uid.system"
. 我一直在为
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.- 我已在清单中请求
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
/system/app
有什么特别之处?似乎分区在非 root 设备上是只读的,防止修改/卸载放置在那里的应用程序.https://android.stackexchange.com/questions/17871/what-are-the-differences-between-a-system-app-and-user-app使用平台密钥和
sharedUserId = system
签名的应用程序对我来说足够好",我不需要专门将其复制到/system/app.>
我现在接受这个作为答案.
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:
- My device is rooted.
- My "installer" app is installed as a system app. (copied it manually to /system/app)
- I have signed the installer apk with platform key, and I have
android:sharedUserId="android.uid.system"
in the Manifest. I have been trying (and trying, and then some more) for
Runtime.getRuntime.exec("su")
. I intend to mount the system partition asrw
, do acat
for the apk, and then make system partitionro
. 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.
- 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
What's special about
/system/app
? It seems that it is the fact that the partition is read-only on non-rooted devices, preventing modification/uninstall of applications put there. https://android.stackexchange.com/questions/17871/what-are-the-differences-between-a-system-app-and-user-appAn app signed with platform key and with
sharedUserId = system
is 'good enough' for my purposes, I don't specifically have to copy it to /system/app.
I am accepting this as answer for now.
这篇关于Android:以编程方式将 apk 复制到/system/app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!