mardi 24 février 2015

Accessing Resources of Content Providers in Android System


I am currently trying to understand the framework for accessing resources of content providers in the android system. I am familiar with the different layers and as far as I understand, this happens in the Android Application Framework Layer. I believe I have understood the overall structure and general steps of the process so far, but I am struggling to find out where things are happening in the source code. What I think happens:



  1. Application requests some resource

  2. ContentResolver to queries that resource from appropriate ContentReceiver

  3. ContentReceiver might take some actions and returns the results.


Now, what I can find in the source code is the following:



  • ContentProviders in /framework/base/core/java/android/provider

  • General ContentResolver abstract class in /framework/base/core/java/android/content/ContentResolver.java (probably for Applications to use and define their own ContentResolver)


Somewhere it also has to be checked, if the application is allowed to access the resource (that is, has the permission to do so) and I know that the PackageManager and PackageManagerService play a role in this. I just cannot seem to find out where this is happening; neither in code nor in theory. I know that several classes are involved in this, inlcuding the ActivityManager, ActivityManagerNative Binder, ActivityManagerServe and PackageManagerService and PackageManager. There are several different checkPermission()-methods, and right now I feel like the PackageManagerServie-method checkPermission() is the one it all comes down to, but I am not sure of it.



@Override
public int checkPermission(String permName, String pkgName) {
synchronized (mPackages) {
PackageParser.Package p = mPackages.get(pkgName);
if (p != null && p.mExtras != null) {
PackageSetting ps = (PackageSetting)p.mExtras;
if (ps.sharedUser != null) {
if (ps.sharedUser.grantedPermissions.contains(permName)) {
return PackageManager.PERMISSION_GRANTED;
}
} else if (ps.grantedPermissions.contains(permName)) {
return PackageManager.PERMISSION_GRANTED;
}
}
}
return PackageManager.PERMISSION_DENIED;
}

@Override
public int checkUidPermission(String permName, int uid) {
synchronized (mPackages) {
Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
if (obj != null) {
GrantedPermissions gp = (GrantedPermissions)obj;
if (gp.grantedPermissions.contains(permName)) {
return PackageManager.PERMISSION_GRANTED;
}
} else {
HashSet<String> perms = mSystemPermissions.get(uid);
if (perms != null && perms.contains(permName)) {
return PackageManager.PERMISSION_GRANTED;
}
}
}
return PackageManager.PERMISSION_DENIED;
}


I am not really sure what is happening here. I know that there is data about which user (that is, application with uid) has which permission (with permission id, pid), but that't not enough to understand the code here.


I am not looking for an one-sentence answer, as I know that this is not possible. I've read lots and lots of pages on the internet and several chapters in books as well, but no one seems to really explain how this works. It would be great if someone could explain or give some source for me to read! I've figured out some of the things myself, but I cannot seem get any further! Any kind of help is very appreciated!





Aucun commentaire:

Enregistrer un commentaire