1

我正在开发与安全相关的应用程序。即使用户将设备重置为出厂设置,也无法删除应用程序。要做到这一点,设备必须植根。但是,当我尝试以用户身份获取位置时,出现root此错误Android Jellybean (4.1.1)

uncaughtException # Exception found!!
java.lang.SecurityException: invalid UID 0
at android.os.Parcel.readException(Parcel.java:1379)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:659)
at android.location.LocationManager._requestLocationUpdates(LocationManager.java:664)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:486)

当我查看 Android 源代码时,我看到 Google 在这里增加了额外的安全性LocationManagerService.java

requestLocationUpdates函数中它调用

 checkPackageName(Binder.getCallingUid(), packageName); 

这是checkPackageName功能

 private void checkPackageName(int uid, String packageName) {
    if (packageName == null) {
        throw new SecurityException("packageName cannot be null");
    }
    String[] packages = mPackageManager.getPackagesForUid(uid);
    if (packages == null) {
        throw new SecurityException("invalid UID " + uid);
    }
    for (String pkg : packages) {
        if (packageName.equals(pkg)) return;
    }
    throw new SecurityException("invalid package name");

}

任何想法如何解决这个问题?如果您有类似的问题,请建议如何解决。谢谢!

4

1 回答 1

0

在调用定位服务之前:

final long ident = Binder.clearCallingIdentity();

调用后:

Binder.restoreCallingIdentity(ident);
于 2013-08-11T20:58:09.687 回答