在我的 AOSP 5.1-build 中,我正在尝试创建一个MySetupApp.apk
- 应用,根据用户执行一些设置操作。
例如。除了其他东西(大多数也需要root)之外,用户应该能够在MySetupApp.apk
中选择一个bootanimation。 bootanimation保存在/sdcard/
上,apk应该将其移动到正确的系统文件夹/system/media/bootanimation.zip
这在adb-shell上工作正常。以下命令提供了所需的结果(新的bootanimation):
adb remount
adb shell cp /sdcard/bootanimation.zip /system/media/
adb shell chmod 777 /system/media/bootanimation.zip
该应用以系统用户身份运行:
android:sharedUserId="android.uid.system"
我可以在adb-shell上验证这一点:
root@astar-yh:/system/bin # ps
system 9634 170 1242144 35536 ffffffff b6e51bf4 S com.mycompany.MySetupApp
我在AOSP-build中添加了应用程序:
/android/device/softwinner/common/prebuild/apk/Android.mk
:
include $(CLEAR_VARS)
LOCAL_MODULE := MySetupApp
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PRIVILEGED_MODULE := true
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
include $(BUILD_PREBUILT)
因此,应用程序安装在/system/priv-app
中,并使用平台密钥进行签名。
我也调整了 /android/system/extras/su/su.c
:
myuid = getuid();
// added AID_SYSTEM
if (myuid != AID_ROOT && myuid != AID_SHELL && myuid != AID_SYSTEM) {
fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
return 1;
}
// Removed this code-block
/*if(setgid(gid) || setuid(uid)) {
fprintf(stderr,"su: permission denied\n");
return 1;
}*/
这是我的Java代码。产出的背后是评论:
public void doRootStuff(){
try {
String line;
Process process = Runtime.getRuntime().exec("su");
OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
stdin.write(("getenforce\n").getBytes()); // "Permissive"
stdin.write(("mount -o rw,remount -t ext4 /system\n").getBytes()); //E/[Error]: mount: Operation not permitted
stdin.write(("ls /data/data/\n").getBytes()); // Works! Shows the directory contents
stdin.write(("touch /system/media/test\n").getBytes()); // Does nothing - no error but also no file
stdin.write(("cp -f /sdcard/bootanimation.zip /system/media/bootanimation_test.zip\n").getBytes()); // E/[Error]: cp: /system/media/bootanimation_test.zip: Read-only file system
stdin.write("exit\n".getBytes());
stdin.flush();
stdin.close();
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while ((line = br.readLine()) != null) {
Log.d("[Output]", line);
}
br.close();
br = new BufferedReader(new InputStreamReader(stderr));
while ((line = br.readLine()) != null) {
Log.e("[Error]", line);
}
br.close();
process.waitFor();
process.destroy();
} catch (Exception ex) {
Log.e(TAG, ex.toString());
ex.printStackTrace();
}
}
根据建议here,我还编辑了android_filesystem_config.h
,但没有运气
{ 06755, AID_ROOT, AID_ROOT, 0, "system/priv-app/MySetupApp/*" },
在我的应用中调用setuid(0);
也不起作用:
com.mycompany.MySetupApp W/art: Failed to find OatDexFile for DexFile /system/priv-app/MySetupApp/MySetupApp.apk ( canonical path /system/priv-app/MySetupApp/MySetupApp.apk) with checksum 0x73b2ee8d in OatFile /data/dalvik-cache/arm/system@priv-app@MySetupApp@MySetupApp.apk@classes.dex
com.mycompany.MySetupApp W/System.err: android.system.ErrnoException: setuid failed: EPERM (Operation not permitted)
因此无法从apk重新安装系统目录并在其上复制内容!
我能做些什么来使这项工作成功?我应该在Android应用程序或Android资源中更改哪些内容?
我还尝试将功能转移到脚本setup_device.sh
并将其放入/system/bin/setup_script.sh
。当我尝试在java中运行它时:
Process process = Runtime.getRuntime().exec("su");
stdin.write(("./system/bin/setup_device.sh\n").getBytes());
它说:
E/[Error]: sh: <stdin>[2]: ./system/bin/setup_device.sh: Permission denied
答案 0 :(得分:0)
我能够解决我的问题:
/sdcard/
复制到/system/media/
。将此脚本放入/system/bin/
<强> setup_device.sh
强>
#!/sbin/busybox sh
BUSYBOX="/sbin/busybox"
echo "Remount /system-partition to rw"
mount -o remount,rw /system
if [ -e /sdcard/bootanimation.zip ] ; then
echo "copy bootanimation"
$BUSYBOX cp -fp "/sdcard/bootanimation.zip" "/system/media/bootanimation.zip"
chmod 777 "/system/media/bootanimation.zip"
chown 0.0 "/system/media/bootanimation.zip"
$BUSYBOX rm "/sdcard/bootanimation.zip"
else
echo "Bootanimation not in /sdcard/-folder"
fi
init.rc
中调用此脚本并在property-change service setup_device /sbin/busybox sh /system/bin/setup_device.sh
user root
group root
disabled
oneshot
on property:start.setup=1
start setup_device
Process proc = Runtime.getRuntime().exec(new String[] { "/system/bin/sh", "-c", "setprop start.setup 1" });
proc.waitFor();
在应用设置此属性后,setup_device.sh
- 脚本将触发并执行 root-rights 的代码!
bootanimation.zip
最终将复制到/system/media/
,您可以在重新启动设备后立即看到新的引导。
-
或_