Android:以编程方式将apk复制到/system/app [英] Android : programmatically copying apk to /system/app
问题描述
我正在尝试从我的Java代码安装系统应用程序,到目前为止,我还没有成功.
到目前为止,我所做的是:
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:
- 我的设备已植根.
- 我的安装程序"应用安装为系统应用.(将其手动复制到/system/app)
- 我已经使用平台密钥对安装程序apk进行了签名,并且清单中具有
android:sharedUserId ="android.uid.system"
. -
我一直在尝试(然后再尝试)
Runtime.getRuntime.exec("su")
.我打算将系统分区安装为rw
,对apk做cat
,然后将系统分区设置为ro
.以下是命令列表:
- 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.
INSTALL_PACKAGES
权限.我尝试了exec(")格式的多种变体,包括对每个命令使用'su -c'
.我得到了管道破裂"异常和安全性"异常.有时候,我没有例外,但是文件没有被复制.
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在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来解决此问题:
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
-
/system/app
有什么特别之处?似乎事实是该分区在非root用户的设备上是只读的,从而阻止了修改/卸载在那里放置的应用程序. https://android.stackexchange.com/questions/17871/系统应用程序和用户应用程序之间的区别是什么
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-app
使用平台密钥和 sharedUserId = system
签名的应用程序对于我来说已经足够好了,我不必专门将其复制到/system/app.p>
An 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屋!