抽取方法:
boolean checkPlatformSignatureByUid(int uid){
if (mContext.getPackageManager().checkSignatures(Process.SYSTEM_UID, uid) == PackageManager.SIGNATURE_MATCH) {
return true;
}
return false;
}
使用时,通过 Binder.getCallingUid() 获取当前调用者的uid
checkPlatformSignatureByUid(Binder.getCallingUid()) == false
源码
有两个方法,packageName 或者 uid 比较
frameworks/base/core/java/android/content/pm/PackageManager.java
@CheckResult
@SignatureResult
public abstract int checkSignatures(@NonNull String packageName1,
@NonNull String packageName2);
@CheckResult
public abstract @SignatureResult int checkSignatures(int uid1, int uid2);