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

Commit d19da863 authored by Collin Fijalkovich's avatar Collin Fijalkovich Committed by Automerger Merge Worker
Browse files

Merge "Cache getDefaultSubscriptionId Binder calls" into rvc-dev am: cffe9470

Change-Id: I179ec77f5277ec872006c07d471df77c5f7589a6
parents 9b1b1e7b cffe9470
Loading
Loading
Loading
Loading
+43 −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
@@ -1840,19 +1868,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);
    }

    /**
@@ -3274,4 +3290,18 @@ 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);
    }

    /**
     * Clears all process-local binder caches.
     *
     * @hide
     */
    public static void clearCaches() {
        sDefaultSubIdCache.clear();
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -13119,6 +13119,7 @@ public class TelephonyManager {
            if (sISub != null) {
                sISub.asBinder().unlinkToDeath(sServiceDeath, 0);
                sISub = null;
                SubscriptionManager.clearCaches();
            }
            if (sISms != null) {
                sISms.asBinder().unlinkToDeath(sServiceDeath, 0);