diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-17 19:38:51 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-17 19:38:51 +0000 |
commit | ba25b199d6ebd5f598093eabf6e621048c541f6e (patch) | |
tree | 27f43257350c42b9c73737e7fb8e64e4c1e4179b | |
parent | 9db28054d285ef26aa3b42b8d32d87d7ad410e5d (diff) | |
parent | 89dd37151bb7c198d1f9278206c5e72dda6a1765 (diff) | |
download | Telephony-android11-platform-release.tar.gz |
Merge cherrypicks of ['googleplex-android-review.googlesource.com/20316772', 'googleplex-android-review.googlesource.com/23515301'] into rvc-platform-release.android-platform-11.0.0_r40android-platform-11.0.0_r39android-platform-11.0.0_r38android-platform-11.0.0_r37android-platform-11.0.0_r36android-platform-11.0.0_r35android-platform-11.0.0_r34android11-platform-release
Change-Id: Ice0a948e87c452638f3dbf46d37e8649a1b4e9e2
4 files changed, 87 insertions, 8 deletions
diff --git a/src/com/android/phone/GsmUmtsCallForwardOptions.java b/src/com/android/phone/GsmUmtsCallForwardOptions.java index fda0ea526..db830deb6 100644 --- a/src/com/android/phone/GsmUmtsCallForwardOptions.java +++ b/src/com/android/phone/GsmUmtsCallForwardOptions.java @@ -1,10 +1,13 @@ package com.android.phone; import android.app.ActionBar; +import android.content.ContentProvider; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.os.PersistableBundle; +import android.os.Process; +import android.os.UserHandle; import android.preference.Preference; import android.preference.PreferenceScreen; import android.telephony.CarrierConfigManager; @@ -203,6 +206,15 @@ public class GsmUmtsCallForwardOptions extends TimeConsumingPreferenceActivity { } 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)) { + + Log.w(LOG_TAG, "onActivityResult: Contact data of different user, " + + "cannot access"); + return; + } cursor = getContentResolver().query(data.getData(), NUM_PROJECTION, null, null, null); if ((cursor == null) || (!cursor.moveToFirst())) { diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java index d740c8f6a..244d2143a 100755 --- a/src/com/android/phone/PhoneInterfaceManager.java +++ b/src/com/android/phone/PhoneInterfaceManager.java @@ -94,6 +94,7 @@ import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyHistogram; import android.telephony.TelephonyManager; import android.telephony.TelephonyScanManager; +import android.telephony.UiccAccessRule; import android.telephony.UiccCardInfo; import android.telephony.UiccSlotInfo; import android.telephony.UssdResponse; @@ -5836,14 +5837,18 @@ public class PhoneInterfaceManager extends ITelephony.Stub { PackageManager pkgMgr = phone.getContext().getPackageManager(); String[] packages = pkgMgr.getPackagesForUid(uid); + if (packages == null) { + return privilegeFromSim; + } final long identity = Binder.clearCallingIdentity(); try { - SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); - SubscriptionManager subManager = (SubscriptionManager) - phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); + int subId = phone.getSubId(); + SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); + List<UiccAccessRule> 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 @@ public class PhoneInterfaceManager extends ITelephony.Stub { 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<UiccAccessRule> 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<UiccAccessRule> 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/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java index a930dba62..886ce3c69 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.Bundle; 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; @@ -522,6 +525,17 @@ public class VoicemailSettingsActivity extends PreferenceActivity 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 140cc74c6..edb9f8eff 100644 --- a/src/com/android/phone/settings/fdn/EditFdnContactScreen.java +++ b/src/com/android/phone/settings/fdn/EditFdnContactScreen.java @@ -18,9 +18,12 @@ package com.android.phone.settings.fdn; 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.net.Uri; 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 @@ public class EditFdnContactScreen extends Activity { } 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())) { |