From 32d484c8e0745e3f5141410d67d68270dc76355d Mon Sep 17 00:00:00 2001 From: Alireza Forouzan Date: Tue, 16 Mar 2021 22:10:55 -0700 Subject: Add an API to getPhoneAccountHandle for a TelephonyManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change allows the carrier privilege app to get the PhoneAccountHandle associated with its TelephonyManager without requiring the READ_PRIVILEGED_PHONE_STATE permission. Bug: 182966851 Test: manual,CTS Change-Id: I83392c58d241ff02d099170294278b1273f11571 --- core/api/current.txt | 1 + .../java/android/telephony/TelephonyManager.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index 7acad18752ed..aac98980694c 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -42283,6 +42283,7 @@ package android.telephony { method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public void getNetworkSlicingConfiguration(@NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver); method public String getNetworkSpecifier(); method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int getNetworkType(); + method @Nullable @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public android.telecom.PhoneAccountHandle getPhoneAccountHandle(); method @Deprecated public int getPhoneCount(); method public int getPhoneType(); method @RequiresPermission(anyOf={"android.permission.READ_PRIVILEGED_PHONE_STATE", android.Manifest.permission.READ_PHONE_STATE}) public int getPreferredOpportunisticDataSubscription(); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index f06b538bf3b1..02d04eaa62d3 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -11036,6 +11036,25 @@ public class TelephonyManager { return retval; } + /** + * Determines the {@link PhoneAccountHandle} associated with this TelephonyManager. + * + *

If this object has been created with {@link #createForSubscriptionId}, applies to the + * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} + * + *

Requires Permission android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE or that the + * calling app has carrier privileges (see {@link #hasCarrierPrivileges}) + * + * @return The {@link PhoneAccountHandle} associated with the TelphonyManager, or {@code null} + * if there is no associated {@link PhoneAccountHandle}; this can happen if the subscription is + * data-only or an opportunistic subscription. + */ + @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + public @Nullable PhoneAccountHandle getPhoneAccountHandle() { + return getPhoneAccountHandleForSubscriptionId(getSubId()); + } + /** * Determines the {@link PhoneAccountHandle} associated with a subscription Id. * -- cgit v1.2.3-59-g8ed1b