我想从位于 /system/app/LALA 的 APK 加载服务。问题是,我收到以下错误,因为在 APP AndroidManifest 中,服务有android:exported = false
. 有什么办法可以加载吗?
代码
String packagePath = "other.app.package";
String apkName = null;
try {
apkName = getPackageManager().getApplicationInfo(packagePath, 0).sourceDir;
} catch (Exception e) {
e.printStackTrace();
}
PathClassLoader cLoader = new PathClassLoader(apkName, ClassLoader.getSystemClassLoader());
Context otherAppContext = createPackageContext(appPackage, CONTEXT_IGNORE_SECURITY | CONTEXT_INCLUDE_CODE);
String servicePath = packagePath + ".path.to.Service";
Class<?> Service = null;
try {
Service = Class.forName(servicePath, true, cLoader);
} catch (Exception e) {
e.printStackTrace();
}
otherAppContext.startService(new Intent(otherAppContext, Service));
错误
原因:java.lang.SecurityException: Not allowed to start service Intent { cmp=other.app.package/.path.to.Service } 未经许可未从 uid X 导出
[]的