diff options
-rw-r--r-- | res/values/unrestricted_packages.xml | 27 | ||||
-rw-r--r-- | src/com/android/providers/contacts/ContactsDatabaseHelper.java | 44 | ||||
-rw-r--r-- | src/com/android/providers/contacts/ContactsProvider2.java | 10 |
3 files changed, 56 insertions, 25 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright (C) 2009 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <!-- The list of packages that have access to data that is marked as being restricted --> + <string-array name="unrestricted_packages"> + + <item>com.android.contacts</item> + + </string-array> + +</resources> 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 |