我正在处理与安全相关的应用。即使用户将设备重置为出厂设置,也无法删除应用程序。要做到这一点,设备必须扎根。但是,当我尝试以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
here
在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");
}
任何想法如何解决这个问题?如果你有类似的问题如何解决这个问题请建议。谢谢!
答案 0 :(得分:0)
在致电位置服务之前:
final long ident = Binder.clearCallingIdentity();
致电:
Binder.restoreCallingIdentity(ident);