【问题标题】:Load service from APK with android:exported=false使用 android:exported=false 从 APK 加载服务
【发布时间】:2013-06-13 19:15:22
【问题描述】:

我想从位于 /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导出 p>

[]的

【问题讨论】:

    标签: android security reflection apk


    【解决方案1】:

    有没有办法加载它?

    不,对不起。如果服务不导出,则只能在自己的应用内部使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-10
      • 2016-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多