有时候我们内置了第三方应用,在DefaultPermissionGrantPolicy.Java赋给应用默认权限,但是会影响GTS测试,下面的方法可以规避此问题
@Override
public int checkPermission(String permName, String pkgName) {
try {
String taker = mContext.getPackageName();
if ("com.google.android.permission.gts".equals(taker)) {
String[] whiteLists = new String[] { "包名"};
for (String pkg : whiteLists) {
if (pkg.equals(pkgName)) {
return PERMISSION_DENIED;
}
}
}
return mPM.checkPermission(permName, pkgName, mContext.getUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public int checkPermission(String permName, String pkgName) {
try {
String taker = mContext.getPackageName();
if ("com.google.android.permission.gts".equals(taker)) {
String[] whiteLists = new String[] { "包名"};
for (String pkg : whiteLists) {
if (pkg.equals(pkgName)) {
return PERMISSION_DENIED;
}
}
}
return mPM.checkPermission(permName, pkgName, mContext.getUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}