The current Android Permission System causes the following issue:
App A defines the custom permission of:
com.package.permission.READ_APP_DATA
When app B is installed declaring the custom permission, it is granted.
However, if app A is installed after app B, then the permission is not granted to app B.
Whilst this may not be a common occurrence, due to app B often being a plugin of app A, it of course can occur and does for my application.
With SuperUser applications agreeing to introduce the global custom permission of android.permission.ACCESS_SUPERUSER
this may well be a big problem should a user decide to switch SuperUser app.
In order to handle the issue, I intend to use the following code in my application for the custom permission I am about to start declaring:
checkPermissions(this, getCallingActivity().getPackageName()); // get the package name from the sender first
private boolean checkPermissions(Context context, String callingPackage) {
final List<PackageInfo> apps = context.getPackageManager().getInstalledPackages(PackageManager.GET_PERMISSIONS);
for (PackageInfo pi : apps) {
if (pi.packageName.equals(callingPackage)) {
String[] permissions = pi.requestedPermissions;
if (permissions != null) {
for (String permission : permissions) {
if (permission.equals("com.package.permission.READ_APP_DATA")) {
return true;
}
}
}
}
}
return false;
As per the title of this question: Is this method 'safe'? Or is there a way/root-hack that an application's manifest could be altered after it is installed and the permission programmatically 'added' to app B?