Add and install permission file for Android 9+
Without this, installing the twrp app as system app leads to
reboot loops into recovery with log messages like:
java.lang.IllegalStateException: Signature|privileged permissions not in privapp-permissions whitelist: {me.twrp.twrpapp: android.permission.READ_PRECISE_PHONE_STATE, me.twrp.twrpapp: android.permission.BATTERY_STATS, me.twrp.twrpapp: android.permission.PACKAGE_USAGE_STATS}
Change-Id: I6156323ea0d23512b0d7eefbd03aa627f3002ae8
diff --git a/gui/action.cpp b/gui/action.cpp
old mode 100755
new mode 100644
index f955cca..b26d55b
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -2058,6 +2058,22 @@
LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno));
goto exit;
}
+
+ // System apps require their permissions to be pre-set via an XML file in /etc/permissions
+ string permission_path = base_path + "/etc/permissions/privapp-permissions-twrpapp.xml";
+ if (TWFunc::copy_file("/sbin/privapp-permissions-twrpapp.xml", permission_path, 0644)) {
+ LOGERR("Error copying permission file\n");
+ goto exit;
+ }
+ if (chown(permission_path.c_str(), 1000, 1000)) {
+ LOGERR("chown %s error: %s\n", permission_path.c_str(), strerror(errno));
+ goto exit;
+ }
+ if (setfilecon(permission_path.c_str(), (security_context_t)context.c_str()) < 0) {
+ LOGERR("setfilecon %s error: %s\n", permission_path.c_str(), strerror(errno));
+ goto exit;
+ }
+
sync();
sync();
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true);