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

Commit 31c7d616 authored by Nathan Harold's avatar Nathan Harold
Browse files

Add a Compat Flag for Throwing For Null Telephony

In order to prevent a sea of random crashes as part
of migrating to throwing behavior for callback APIs that
hit null ITelephony and null IOns objects, this change
re-introduces backwards-compatible behavior for APIs that
are being "upgraded" to throwing behavior.

Bug: 182185642
Test: atest CtsTelephonyTestCases
Change-Id: I492ba6a79e74350986afbd6ab5cc5e7b05b8cd35
parent 8c23380d
Loading
Loading
Loading
Loading
+56 −6
Original line number Diff line number Diff line
@@ -5898,7 +5898,7 @@ public class TelephonyManager {
        /**
         * Error response to
         * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}.
         * {@link TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}.
         *
         * Invoked when an error condition prevents updated {@link CellInfo} from being fetched
         * and returned from the modem. Callers of requestCellInfoUpdate() should override this
@@ -5915,6 +5915,20 @@ public class TelephonyManager {
        }
    };
    /**
     * Used for checking if the target SDK version for the current process is S or above.
     *
     * <p> Applies to the following methods:
     * {@link #requestCellInfoUpdate},
     * {@link #setPreferredOpportunisticDataSubscription},
     * {@link #updateAvailableNetworks},
     * requestNumberVerification(),
     * setSimPowerStateForSlot(),
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
    private static final long NULL_TELEPHONY_THROW_NO_CB = 182185642L;
    /**
     * Requests all available cell information from the current subscription for observed
     * camped/registered, serving, and neighboring cells.
@@ -5935,7 +5949,13 @@ public class TelephonyManager {
            @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) {
        try {
            ITelephony telephony = getITelephony();
            if (telephony == null) throw new IllegalStateException("Telephony is null");
            if (telephony == null) {
                if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) {
                    throw new IllegalStateException("Telephony is null");
                } else {
                    return;
                }
            }
            telephony.requestCellInfoUpdate(
                    getSubId(),
@@ -5992,7 +6012,14 @@ public class TelephonyManager {
            @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) {
        try {
            ITelephony telephony = getITelephony();
            if (telephony == null) throw new IllegalStateException("Telephony is null");
            if (telephony == null) {
                if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) {
                    throw new IllegalStateException("Telephony is null");
                } else {
                    return;
                }
            }
            telephony.requestCellInfoUpdateWithWorkSource(
                    getSubId(),
                    new ICellInfoCallback.Stub() {
@@ -6988,7 +7015,13 @@ public class TelephonyManager {
        try {
            ITelephony telephony = getITelephony();
            if (telephony == null) throw new IllegalStateException("Telephony is null");
            if (telephony == null) {
                if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) {
                    throw new IllegalStateException("Telephony is null");
                } else {
                    return;
                }
            }
            telephony.requestNumberVerification(range, timeoutMillis, internalCallback,
                    getOpPackageName());
@@ -10371,6 +10404,13 @@ public class TelephonyManager {
                            Binder.withCleanCallingIdentity(() -> callback.accept(result)));
                }
            };
            if (telephony == null) {
                if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) {
                    throw new IllegalStateException("Telephony is null");
                } else {
                    return;
                }
            }
            telephony.setSimPowerStateForSlotWithCallback(slotIndex, state, internalCallback);
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e);
@@ -12805,7 +12845,12 @@ public class TelephonyManager {
        try {
            IOns iOpportunisticNetworkService = getIOns();
            if (iOpportunisticNetworkService == null) {
                if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) {
                    throw new IllegalStateException("Opportunistic Network Service is null");
                } else {
                    // Let the general remote exception handling catch this.
                    throw new RemoteException("Null Opportunistic Network Service!");
                }
            }
            ISetOpportunisticDataCallback callbackStub = new ISetOpportunisticDataCallback.Stub() {
                @Override
@@ -12900,7 +12945,12 @@ public class TelephonyManager {
        try {
            IOns iOpportunisticNetworkService = getIOns();
            if (iOpportunisticNetworkService == null) {
                if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) {
                    throw new IllegalStateException("Opportunistic Network Service is null");
                } else {
                    // Let the general remote exception handling catch this.
                    throw new RemoteException("Null Opportunistic Network Service!");
                }
            }
            IUpdateAvailableNetworksCallback callbackStub =