Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6429d03 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add property invalidated cache for getSubscriptionId." into tm-dev am: 0536e035

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17243456

Change-Id: I0ade052d3e57c1f23103d987be4a4893ef468ef1
parents 20cbe80b 0536e035
Loading
Loading
Loading
Loading
+38 −13
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.WorkerThread;
import android.app.PendingIntent;
import android.app.PropertyInvalidatedCache;
import android.app.role.RoleManager;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
@@ -361,6 +362,42 @@ public class TelephonyManager {
    @GuardedBy("sCacheLock")
    private static final DeathRecipient sServiceDeath = new DeathRecipient();
    /**
     * Cache key for a {@link PropertyInvalidatedCache} which maps from {@link PhoneAccountHandle}
     * to subscription Id.  The cache is initialized in {@code PhoneInterfaceManager}'s constructor
     * when {@link PropertyInvalidatedCache#invalidateCache(String)} is called.
     * The cache is cleared from {@code TelecomAccountRegistry#tearDown} when all phone accounts are
     * removed from Telecom.
     * @hide
     */
    public static final String CACHE_KEY_PHONE_ACCOUNT_TO_SUBID =
            "cache_key.telephony.phone_account_to_subid";
    private static final int CACHE_MAX_SIZE = 4;
    /**
     * A {@link PropertyInvalidatedCache} which lives in an app's {@link TelephonyManager} instance.
     * Caches any queries for a mapping between {@link PhoneAccountHandle} and {@code subscription
     * id}.  The cache may be invalidated from Telephony when phone account re-registration takes
     * place.
     */
    private PropertyInvalidatedCache<PhoneAccountHandle, Integer> mPhoneAccountHandleToSubIdCache =
            new PropertyInvalidatedCache<PhoneAccountHandle, Integer>(CACHE_MAX_SIZE,
                    CACHE_KEY_PHONE_ACCOUNT_TO_SUBID) {
                @Override
                public Integer recompute(PhoneAccountHandle phoneAccountHandle) {
                    try {
                        ITelephony telephony = getITelephony();
                        if (telephony != null) {
                            return telephony.getSubIdForPhoneAccountHandle(phoneAccountHandle,
                                    mContext.getOpPackageName(), mContext.getAttributionTag());
                        }
                    } catch (RemoteException e) {
                        throw e.rethrowAsRuntimeException();
                    }
                    return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
                }
            };
    /** Enum indicating multisim variants
     *  DSDS - Dual SIM Dual Standby
     *  DSDA - Dual SIM Dual Active
@@ -11881,19 +11918,7 @@ public class TelephonyManager {
    @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)
    public int getSubscriptionId(@NonNull PhoneAccountHandle phoneAccountHandle) {
        int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        try {
            ITelephony service = getITelephony();
            if (service != null) {
                retval = service.getSubIdForPhoneAccountHandle(
                        phoneAccountHandle, mContext.getOpPackageName(),
                        mContext.getAttributionTag());
            }
        } catch (RemoteException ex) {
            Log.e(TAG, "getSubscriptionId RemoteException", ex);
            ex.rethrowAsRuntimeException();
        }
        return retval;
        return mPhoneAccountHandleToSubIdCache.query(phoneAccountHandle);
    }
    /**