diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 0a26c78c3e..6930d75eb5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -228,6 +228,9 @@ + + + carrierConfigAccessRules = subInfo.getCarrierConfigAccessRules(); + for (String pkg : packages) { - if (subManager.canManageSubscription(subInfo, pkg)) { + if (hasCarrierConfigAccess(pkg, pkgMgr, carrierConfigAccessRules)) { return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; } } @@ -5862,16 +5867,51 @@ private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim final long identity = Binder.clearCallingIdentity(); try { - SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); - SubscriptionManager subManager = (SubscriptionManager) - phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); - return subManager.canManageSubscription(subInfo, pkgName) + int subId = phone.getSubId(); + SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); + List carrierConfigAccessRules = subInfo.getCarrierConfigAccessRules(); + + return hasCarrierConfigAccess(pkgName, phone.getContext().getPackageManager(), + carrierConfigAccessRules) ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; } finally { Binder.restoreCallingIdentity(identity); } } + /** + * Check whether carrier privilege status can be granted to the provided app for this + * subscription based on the carrier config access rules of the subscription. + * + * @param packageName package name of the app to check + * @param packageManager package manager + * @param carrierConfigAccessRules carrier config access rules of the subscription + * @return true if the app is included in the mCarrierConfigAccessRules of this subscription. + */ + private boolean hasCarrierConfigAccess(String packageName, PackageManager packageManager, + @NonNull List carrierConfigAccessRules) { + if ((packageName == null) || (carrierConfigAccessRules.isEmpty())) { + return false; + } + + PackageInfo packageInfo; + try { + packageInfo = packageManager.getPackageInfo(packageName, + PackageManager.GET_SIGNING_CERTIFICATES); + } catch (PackageManager.NameNotFoundException e) { + logv("Unknown package: " + packageName); + return false; + } + + for (UiccAccessRule rule : carrierConfigAccessRules) { + if (rule.getCarrierPrivilegeStatus(packageInfo) + == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { + return true; + } + } + return false; + } + @Override public int getCarrierPrivilegeStatus(int subId) { final Phone phone = getPhone(subId); diff --git a/src/com/android/phone/settings/AccessibilitySettingsActivity.java b/src/com/android/phone/settings/AccessibilitySettingsActivity.java index 99b14780db..7cc18f6be6 100644 --- a/src/com/android/phone/settings/AccessibilitySettingsActivity.java +++ b/src/com/android/phone/settings/AccessibilitySettingsActivity.java @@ -20,17 +20,21 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.view.MenuItem; +import android.view.WindowManager; import com.android.phone.R; public class AccessibilitySettingsActivity extends PreferenceActivity { - @Override + @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); + getWindow().addSystemFlags( + android.view.WindowManager.LayoutParams + .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); final ActionBar actionBar = getActionBar(); if (actionBar != null) { - actionBar.setTitle(R.string.accessibility_settings_activity_title); + actionBar.setTitle(R.string.accessibility_settings_activity_title); } getFragmentManager().beginTransaction().replace( android.R.id.content, new AccessibilitySettingsFragment()).commit(); diff --git a/src/com/android/phone/settings/PhoneAccountSettingsActivity.java b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java index 56f5594660..e15be39a2b 100644 --- a/src/com/android/phone/settings/PhoneAccountSettingsActivity.java +++ b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java @@ -20,6 +20,7 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.view.MenuItem; +import android.view.WindowManager; import com.android.phone.R; @@ -28,6 +29,9 @@ public class PhoneAccountSettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); + getWindow().addSystemFlags( + android.view.WindowManager.LayoutParams + .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); final ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setTitle(R.string.phone_accounts); diff --git a/src/com/android/phone/settings/PickSmsSubscriptionActivity.java b/src/com/android/phone/settings/PickSmsSubscriptionActivity.java index cfbce28a31..97dada00c8 100644 --- a/src/com/android/phone/settings/PickSmsSubscriptionActivity.java +++ b/src/com/android/phone/settings/PickSmsSubscriptionActivity.java @@ -22,6 +22,7 @@ import android.os.Bundle; import android.os.RemoteException; import android.telephony.SubscriptionManager; +import android.view.WindowManager; import android.util.Log; import com.android.internal.telephony.IIntegerConsumer; @@ -91,6 +92,9 @@ private static void sendResultAndClear(int resultId) { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getWindow().addSystemFlags( + android.view.WindowManager.LayoutParams + .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); mPreviouslyStopped = false; } diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java index 66b1af96f1..886ce3c69f 100644 --- a/src/com/android/phone/settings/VoicemailSettingsActivity.java +++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java @@ -17,6 +17,7 @@ package com.android.phone.settings; import android.app.Dialog; +import android.content.ContentProvider; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; @@ -25,6 +26,8 @@ import android.os.Handler; import android.os.Message; import android.os.PersistableBundle; +import android.os.Process; +import android.os.UserHandle; import android.os.UserManager; import android.preference.Preference; import android.preference.PreferenceActivity; @@ -39,6 +42,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.MenuItem; +import android.view.WindowManager; import android.widget.ListAdapter; import android.widget.Toast; @@ -211,6 +215,9 @@ public class VoicemailSettingsActivity extends PreferenceActivity @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); + getWindow().addSystemFlags( + android.view.WindowManager.LayoutParams + .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); // Make sure we are running as the primary user only UserManager userManager = getApplicationContext().getSystemService(UserManager.class); if (!userManager.isPrimaryUser()) { @@ -518,6 +525,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { Cursor cursor = null; try { + // check if the URI returned by the user belongs to the user + final int currentUser = UserHandle.getUserId(Process.myUid()); + if (currentUser + != ContentProvider.getUserIdFromUri(data.getData(), currentUser)) { + + if (DBG) { + log("onActivityResult: Contact data of different user, " + + "cannot access"); + } + return; + } cursor = getContentResolver().query(data.getData(), new String[] { CommonDataKinds.Phone.NUMBER }, null, null, null); if ((cursor == null) || (!cursor.moveToFirst())) { diff --git a/src/com/android/phone/settings/fdn/EditFdnContactScreen.java b/src/com/android/phone/settings/fdn/EditFdnContactScreen.java index 140cc74c65..edb9f8eff6 100644 --- a/src/com/android/phone/settings/fdn/EditFdnContactScreen.java +++ b/src/com/android/phone/settings/fdn/EditFdnContactScreen.java @@ -18,9 +18,12 @@ import static android.view.Window.PROGRESS_VISIBILITY_OFF; import static android.view.Window.PROGRESS_VISIBILITY_ON; +import static android.app.Activity.RESULT_OK; + import android.app.Activity; import android.content.AsyncQueryHandler; +import android.content.ContentProvider; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Intent; @@ -30,6 +33,8 @@ import android.os.Bundle; import android.os.Handler; import android.os.PersistableBundle; +import android.os.Process; +import android.os.UserHandle; import android.provider.ContactsContract.CommonDataKinds; import android.telephony.PhoneNumberUtils; import android.text.Editable; @@ -166,6 +171,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent) } Cursor cursor = null; try { + // check if the URI returned by the user belongs to the user + final int currentUser = UserHandle.getUserId(Process.myUid()); + if (currentUser + != ContentProvider.getUserIdFromUri(intent.getData(), currentUser)) { + Log.w(LOG_TAG, "onActivityResult: Contact data of different user, " + + "cannot access"); + return; + } cursor = getContentResolver().query(intent.getData(), NUM_PROJECTION, null, null, null); if ((cursor == null) || (!cursor.moveToFirst())) {