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

Commit 85ddb705 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Cache ITelephony service.

Building on top of ag/10255108 that did the same for some other services
in telephony.

Test: basic telephony validity
Bug: 166314475
Merged-in: Icc3e9db5901655eb1102d5b7be81c26a685aa20d
Change-Id: Icc3e9db5901655eb1102d5b7be81c26a685aa20d
(cherry picked from commit 78f5a82f)
parent ab6c9f32
Loading
Loading
Loading
Loading
+41 −9
Original line number Diff line number Diff line
@@ -304,6 +304,8 @@ public class TelephonyManager {
    /** @hide */
    private static boolean sServiceHandleCacheEnabled = true;
    @GuardedBy("sCacheLock")
    private static ITelephony sITelephony;
    @GuardedBy("sCacheLock")
    private static IPhoneSubInfo sIPhoneSubInfo;
    @GuardedBy("sCacheLock")
@@ -5509,8 +5511,34 @@ public class TelephonyManager {
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
    private ITelephony getITelephony() {
        return ITelephony.Stub.asInterface(TelephonyFrameworkInitializer
                .getTelephonyServiceManager().getTelephonyServiceRegisterer().get());
        // Keeps cache disabled until test fixes are checked into AOSP.
        if (!sServiceHandleCacheEnabled) {
            return ITelephony.Stub.asInterface(
                    TelephonyFrameworkInitializer
                            .getTelephonyServiceManager()
                            .getTelephonyServiceRegisterer()
                            .get());
        }
        if (sITelephony == null) {
            ITelephony temp = ITelephony.Stub.asInterface(
                    TelephonyFrameworkInitializer
                            .getTelephonyServiceManager()
                            .getTelephonyServiceRegisterer()
                            .get());
            synchronized (sCacheLock) {
                if (sITelephony == null && temp != null) {
                    try {
                        sITelephony = temp;
                        sITelephony.asBinder().linkToDeath(sServiceDeath, 0);
                    } catch (Exception e) {
                        // something has gone horribly wrong
                        sITelephony = null;
                    }
                }
            }
        }
        return sITelephony;
    }
    private IOns getIOns() {
@@ -13444,6 +13472,10 @@ public class TelephonyManager {
    */
    private static void resetServiceCache() {
        synchronized (sCacheLock) {
            if (sITelephony != null) {
                sITelephony.asBinder().unlinkToDeath(sServiceDeath, 0);
                sITelephony = null;
            }
            if (sISub != null) {
                sISub.asBinder().unlinkToDeath(sServiceDeath, 0);
                sISub = null;