Android: 编程将apk文件复制到/system/app目录

7

我正在尝试从我的Java代码中安装一个系统应用程序,但迄今为止我还没有成功。

以下是我已经完成的内容:

  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.

我尝试了多种exec("")格式的变化,包括在每个命令中使用'su -c'。我遇到了Broken Pipe异常和Security异常。有时候我没有得到异常,但是文件没有被复制。


请告诉我我错过了什么。有人成功实现了吗?

谢谢!


顺便问一下,使用平台密钥签署并具有sharedUserId=system的应用程序与位于/system/app中的应用程序有什么区别? - Chaitanya
位于/system/app的应用程序可以访问权限级别2(据我所知不是1)。无论授予了哪些权限,具有共享用户ID为system的应用程序都会继承授予“父”应用程序的权限,并且还会在与其“父”相同的进程ID中运行。各种API检查应用程序的进程ID,并且如果它们不属于特定类型,则拒绝访问它们。虽然这两者大多紧密相关,但它们并不总是一致的。这是非技术性的描述方式,我相信其他人会做得更好... - slinden77
1个回答

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 /system/app有什么特殊之处?似乎非root设备上该分区是只读的,防止对放在那里的应用进行修改/卸载。https://android.stackexchange.com/questions/17871/what-are-the-differences-between-a-system-app-and-user-app 使用平台密钥签名并具有sharedUserId = system的应用程序对我的目的而言已经足够了,我不需要将其复制到/system/app。
我现在接受这个答案。

一个应用是否可以复制到系统文件夹而不是使用外部应用程序?您能否请澄清一下用于复制应用的命令?另外,我如何获取平台密钥?谢谢。 - Dania

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接