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

Commit 19bc3e13 authored by Collin Fijalkovich's avatar Collin Fijalkovich Committed by Android (Google) Code Review
Browse files

Merge "Cache getDefaultSubscriptionId Binder calls"

parents 67b06153 839258cc
Loading
Loading
Loading
Loading
+34 −13
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.PendingIntent;
import android.app.PropertyInvalidatedCache;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Intent;
@@ -130,6 +131,33 @@ public class SubscriptionManager {
    @UnsupportedAppUsage
    public static final Uri CONTENT_URI = SimInfo.CONTENT_URI;

    /** @hide */
    public static final String CACHE_KEY_DEFAULT_SUB_ID_PROPERTY =
            "cache_key.telephony.get_default_sub_id";

    private static final int DEFAULT_SUB_ID_CACHE_SIZE = 1;

    private static PropertyInvalidatedCache<Void, Integer> sDefaultSubIdCache =
            new PropertyInvalidatedCache<Void, Integer>(
                    DEFAULT_SUB_ID_CACHE_SIZE,
                    CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) {
                @Override
                protected Integer recompute(Void query) {
                    int subId = INVALID_SUBSCRIPTION_ID;

                    try {
                        ISub iSub = TelephonyManager.getSubscriptionService();
                        if (iSub != null) {
                            subId = iSub.getDefaultSubId();
                        }
                    } catch (RemoteException ex) {
                        // ignore it
                    }

                    if (VDBG) logd("getDefaultSubId=" + subId);
                    return subId;
                }
            };
    /**
     * Generates a content {@link Uri} used to receive updates on simInfo change
     * on the given subscriptionId
@@ -1826,19 +1854,7 @@ public class SubscriptionManager {
     * @return the "system" default subscription id.
     */
    public static int getDefaultSubscriptionId() {
        int subId = INVALID_SUBSCRIPTION_ID;

        try {
            ISub iSub = TelephonyManager.getSubscriptionService();
            if (iSub != null) {
                subId = iSub.getDefaultSubId();
            }
        } catch (RemoteException ex) {
            // ignore it
        }

        if (VDBG) logd("getDefaultSubId=" + subId);
        return subId;
        return sDefaultSubIdCache.query(null);
    }

    /**
@@ -3260,4 +3276,9 @@ public class SubscriptionManager {
        intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
    }

    /** @hide */
    public static void invalidateDefaultSubIdCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SUB_ID_PROPERTY);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -13079,6 +13079,7 @@ public class TelephonyManager {
            if (sISub != null) {
                sISub.asBinder().unlinkToDeath(sServiceDeath, 0);
                sISub = null;
                SubscriptionManager.invalidateDefaultSubIdCaches();
            }
            if (sISms != null) {
                sISms.asBinder().unlinkToDeath(sServiceDeath, 0);