From d91272b48f97243533c6580981e12a4847b5783f Mon Sep 17 00:00:00 2001 From: Jeff Hamilton Date: Tue, 29 Sep 2009 17:39:00 -0700 Subject: Read the unrestricted pacakages list from XML. Change-Id: I9af814b8bb1b95051a0371d1e3d3769c052ffd95 --- res/values/unrestricted_packages.xml | 27 +++++++++++++ .../providers/contacts/ContactsDatabaseHelper.java | 44 ++++++++++++---------- .../providers/contacts/ContactsProvider2.java | 10 ++--- 3 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 res/values/unrestricted_packages.xml diff --git a/res/values/unrestricted_packages.xml b/res/values/unrestricted_packages.xml new file mode 100644 index 0000000..090c72a --- /dev/null +++ b/res/values/unrestricted_packages.xml @@ -0,0 +1,27 @@ + + + + + + + + + com.android.contacts + + + + diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index 0ade2f5..4439fbb 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Resources; import android.database.DatabaseUtils; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; @@ -474,6 +475,11 @@ import java.util.HashMap; private boolean mUseStrictPhoneNumberComparation; + /** + * List of package names with access to {@link RawContacts#IS_RESTRICTED} data. + */ + private String[] mUnrestrictedPackages; + public static synchronized ContactsDatabaseHelper getInstance(Context context) { if (sSingleton == null) { sSingleton = new ContactsDatabaseHelper(context); @@ -488,12 +494,16 @@ import java.util.HashMap; ContactsDatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); Log.i(TAG, "Creating OpenHelper"); + Resources resources = context.getResources(); mContext = context; mSyncState = new SyncStateContentProviderHelper(); mUseStrictPhoneNumberComparation = - context.getResources().getBoolean( - com.android.internal.R.bool.config_use_strict_phone_number_comparation); + resources.getBoolean( + com.android.internal.R.bool.config_use_strict_phone_number_comparation); + mUnrestrictedPackages = resources.getStringArray( + resources.getIdentifier("unrestricted_packages", "array", + context.getPackageName())); } @Override @@ -1622,24 +1632,16 @@ import java.util.HashMap; } /** - * List of package names with access to {@link RawContacts#IS_RESTRICTED} data. - */ - static final String[] sAllowedPackages = new String[] { - "com.android.contacts", - "com.facebook.katana", - }; - - /** * Check if {@link Binder#getCallingUid()} should be allowed access to * {@link RawContacts#IS_RESTRICTED} data. */ - boolean hasRestrictedAccess() { + boolean hasAccessToRestrictedData() { final PackageManager pm = mContext.getPackageManager(); final String[] callerPackages = pm.getPackagesForUid(Binder.getCallingUid()); // Has restricted access if caller matches any packages for (String callerPackage : callerPackages) { - if (hasRestrictedAccess(callerPackage)) { + if (hasAccessToRestrictedData(callerPackage)) { return true; } } @@ -1650,10 +1652,12 @@ import java.util.HashMap; * Check if requestingPackage should be allowed access to * {@link RawContacts#IS_RESTRICTED} data. */ - static boolean hasRestrictedAccess(String requestingPackage) { - for (String allowedPackage : sAllowedPackages) { - if (allowedPackage.equals(requestingPackage)) { - return true; + boolean hasAccessToRestrictedData(String requestingPackage) { + if (mUnrestrictedPackages != null) { + for (String allowedPackage : mUnrestrictedPackages) { + if (allowedPackage.equals(requestingPackage)) { + return true; + } } } return false; @@ -1664,7 +1668,7 @@ import java.util.HashMap; } public String getDataView(boolean requireRestrictedView) { - return (hasRestrictedAccess() && !requireRestrictedView) ? + return (hasAccessToRestrictedData() && !requireRestrictedView) ? Views.DATA_ALL : Views.DATA_RESTRICTED; } @@ -1673,7 +1677,7 @@ import java.util.HashMap; } public String getRawContactView(boolean requireRestrictedView) { - return (hasRestrictedAccess() && !requireRestrictedView) ? + return (hasAccessToRestrictedData() && !requireRestrictedView) ? Views.RAW_CONTACTS_ALL : Views.RAW_CONTACTS_RESTRICTED; } @@ -1682,7 +1686,7 @@ import java.util.HashMap; } public String getContactView(boolean requireRestrictedView) { - return (hasRestrictedAccess() && !requireRestrictedView) ? + return (hasAccessToRestrictedData() && !requireRestrictedView) ? Views.CONTACTS_ALL : Views.CONTACTS_RESTRICTED; } @@ -1695,7 +1699,7 @@ import java.util.HashMap; } public String getContactEntitiesView(boolean requireRestrictedView) { - return (hasRestrictedAccess() && !requireRestrictedView) ? + return (hasAccessToRestrictedData() && !requireRestrictedView) ? Tables.CONTACT_ENTITIES : Tables.CONTACT_ENTITIES_RESTRICTED; } diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 32cefdc..ef5fb66 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -3760,7 +3760,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun String requestingPackage = uri.getQueryParameter( ContactsContract.REQUESTING_PACKAGE_PARAM_KEY); if (requestingPackage != null) { - excludeRestrictedData = !ContactsDatabaseHelper.hasRestrictedAccess(requestingPackage); + excludeRestrictedData = !mDbHelper.hasAccessToRestrictedData(requestingPackage); } sb.append(mDbHelper.getContactView(excludeRestrictedData)); if (mDbHelper.isInProjection(projection, @@ -3788,7 +3788,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun String requestingPackage = uri.getQueryParameter( ContactsContract.REQUESTING_PACKAGE_PARAM_KEY); if (requestingPackage != null) { - excludeRestrictedData = !ContactsDatabaseHelper.hasRestrictedAccess(requestingPackage); + excludeRestrictedData = !mDbHelper.hasAccessToRestrictedData(requestingPackage); } sb.append(mDbHelper.getRawContactView(excludeRestrictedData)); qb.setTables(sb.toString()); @@ -3807,7 +3807,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun ContactsContract.REQUESTING_PACKAGE_PARAM_KEY); if (requestingPackage != null) { excludeRestrictedData = excludeRestrictedData - || !ContactsDatabaseHelper.hasRestrictedAccess(requestingPackage); + || !mDbHelper.hasAccessToRestrictedData(requestingPackage); } sb.append(mDbHelper.getDataView(excludeRestrictedData)); @@ -3948,7 +3948,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun } String getContactsRestrictions() { - if (mDbHelper.hasRestrictedAccess()) { + if (mDbHelper.hasAccessToRestrictedData()) { return "1"; } else { return RawContacts.IS_RESTRICTED + "=0"; @@ -3956,7 +3956,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun } public String getContactsRestrictionExceptionAsNestedQuery(String contactIdColumn) { - if (mDbHelper.hasRestrictedAccess()) { + if (mDbHelper.hasAccessToRestrictedData()) { return "1"; } else { return "(SELECT " + RawContacts.IS_RESTRICTED + " FROM " + Tables.RAW_CONTACTS -- cgit v1.1