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

Commit 65d8e201 authored by Nathan Harold's avatar Nathan Harold
Browse files

Fix Range Checking on registerTelephonyCallback

-Require that callbacks be registered with at least
 on valid event.
-Update the null checking to throw consistent NPEs
 as per the Android API Guidelines

Bug: 431293947
Test: atest TelephonyCallbackTest#testRegisterTelephonyCallback
Flag: EXEMPT bugfix
Change-Id: Id2d57f2078946bd163a82e6e4e3665c791adb788
parent a9b9b71f
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
@@ -805,9 +806,7 @@ public class TelephonyCallback {
     * @hide
     */
    public void init(@NonNull @CallbackExecutor Executor executor) {
        if (executor == null) {
            throw new IllegalArgumentException("TelephonyCallback Executor must be non-null");
        }
        Objects.requireNonNull(executor, "TelephonyCallback Executor must be non-null");
        callback = new IPhoneStateListenerStub(this, executor);
    }

+10 −5
Original line number Diff line number Diff line
@@ -1554,13 +1554,18 @@ public class TelephonyRegistryManager {
            @NonNull @CallbackExecutor Executor executor,
            int subId, String pkgName, String attributionTag, @NonNull TelephonyCallback callback,
            boolean notifyNow) {
        if (callback == null) {
            throw new IllegalStateException("telephony service is null.");
        }
        Objects.requireNonNull(executor, "registerTelephonyCallback: executor cannot be null.");
        Objects.requireNonNull(callback, "registerTelephonyCallback: callback cannot be null.");

        callback.init(executor);
        final int[] events = getEventsFromCallback(callback).stream().mapToInt(i -> i).toArray();
        if (events.length == 0) {
            throw new IllegalArgumentException(
                    "registerTelephonyCallback(): callback must implement at least one listener.");
        }

        listenFromCallback(renounceFineLocationAccess, renounceCoarseLocationAccess, subId,
                pkgName, attributionTag, callback,
                getEventsFromCallback(callback).stream().mapToInt(i -> i).toArray(), notifyNow);
                pkgName, attributionTag, callback, events, notifyNow);
    }

    /**
+0 −4
Original line number Diff line number Diff line
@@ -18058,10 +18058,6 @@ public class TelephonyManager {
            throw new IllegalStateException("telephony service is null.");
        }
        if (executor == null || callback == null) {
            throw new IllegalArgumentException("TelephonyCallback and executor must be non-null");
        }
        TelephonyRegistryManager mgr = mContext.getSystemService(TelephonyRegistryManager.class);
        if (mgr == null) throw new IllegalStateException("telephony service is null.");