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

Commit 5e1e516b authored by Nathan Harold's avatar Nathan Harold Committed by Android (Google) Code Review
Browse files

Merge changes from topic "433336412" into main

* changes:
  Fix Range Checking on registerTelephonyCallback
  Clean up TelephonyRegistryManager Caching
parents 2b677b45 65d8e201
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ import java.time.Duration;
import java.util.Arrays;
import java.util.Arrays;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import java.util.stream.Collectors;
@@ -805,9 +806,7 @@ public class TelephonyCallback {
     * @hide
     * @hide
     */
     */
    public void init(@NonNull @CallbackExecutor Executor executor) {
    public void init(@NonNull @CallbackExecutor Executor executor) {
        if (executor == null) {
        Objects.requireNonNull(executor, "TelephonyCallback Executor must be non-null");
            throw new IllegalArgumentException("TelephonyCallback Executor must be non-null");
        }
        callback = new IPhoneStateListenerStub(this, executor);
        callback = new IPhoneStateListenerStub(this, executor);
    }
    }


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

        callback.init(executor);
        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,
        listenFromCallback(renounceFineLocationAccess, renounceCoarseLocationAccess, subId,
                pkgName, attributionTag, callback,
                pkgName, attributionTag, callback, events, notifyNow);
                getEventsFromCallback(callback).stream().mapToInt(i -> i).toArray(), notifyNow);
    }
    }


    /**
    /**
+30 −36
Original line number Original line Diff line number Diff line
@@ -193,7 +193,6 @@ import java.util.stream.IntStream;
public class TelephonyManager {
public class TelephonyManager {
    private static final String TAG = "TelephonyManager";
    private static final String TAG = "TelephonyManager";
    private TelephonyRegistryManager mTelephonyRegistryMgr;
    /**
    /**
     * To expand the error codes for {@link TelephonyManager#updateAvailableNetworks} and
     * To expand the error codes for {@link TelephonyManager#updateAvailableNetworks} and
     * {@link TelephonyManager#setPreferredOpportunisticDataSubscription}.
     * {@link TelephonyManager#setPreferredOpportunisticDataSubscription}.
@@ -17865,20 +17864,15 @@ public class TelephonyManager {
            throw new IllegalStateException("telephony service is null.");
            throw new IllegalStateException("telephony service is null.");
        }
        }
        if (executor == null || callback == null) {
        TelephonyRegistryManager mgr = mContext.getSystemService(TelephonyRegistryManager.class);
            throw new IllegalArgumentException("TelephonyCallback and executor must be non-null");
        }
        if (mgr == null) throw new IllegalStateException("telephony service is null.");
        mTelephonyRegistryMgr = (TelephonyRegistryManager)
                mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
        mgr.registerTelephonyCallback(
        if (mTelephonyRegistryMgr != null) {
            mTelephonyRegistryMgr.registerTelephonyCallback(
                includeLocationData != INCLUDE_LOCATION_DATA_FINE,
                includeLocationData != INCLUDE_LOCATION_DATA_FINE,
                includeLocationData == INCLUDE_LOCATION_DATA_NONE,
                includeLocationData == INCLUDE_LOCATION_DATA_NONE,
                executor, mSubId, getOpPackageName(),
                executor, mSubId, getOpPackageName(),
                getAttributionTag(), callback, getITelephony() != null);
                getAttributionTag(), callback, getITelephony() != null);
        } else {
            throw new IllegalStateException("telephony service is null.");
        }
    }
    }
    /**
    /**
@@ -17887,22 +17881,21 @@ public class TelephonyManager {
     * @param callback The {@link TelephonyCallback} object to unregister.
     * @param callback The {@link TelephonyCallback} object to unregister.
     */
     */
    public void unregisterTelephonyCallback(@NonNull TelephonyCallback callback) {
    public void unregisterTelephonyCallback(@NonNull TelephonyCallback callback) {
        if (mContext == null) {
        if (mContext == null) {
            throw new IllegalStateException("telephony service is null.");
            throw new IllegalStateException("telephony service is null.");
        }
        }
        if (callback.callback == null) {
        Objects.requireNonNull(callback,
            return;
                "unregisterTelephonyCallback: cannot unregister a null callback");
        }
        if (callback.callback == null) return; // Already unregistered
        mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class);
        TelephonyRegistryManager mgr = mContext.getSystemService(TelephonyRegistryManager.class);
        if (mTelephonyRegistryMgr != null) {
            mTelephonyRegistryMgr.unregisterTelephonyCallback(mSubId, getOpPackageName(),
        if (mgr == null) throw new IllegalStateException("telephony service is null.");
        mgr.unregisterTelephonyCallback(mSubId, getOpPackageName(),
                getAttributionTag(), callback, getITelephony() != null);
                getAttributionTag(), callback, getITelephony() != null);
        } else {
            throw new IllegalStateException("telephony service is null.");
        }
    }
    }
    /** @hide */
    /** @hide */
@@ -18867,11 +18860,12 @@ public class TelephonyManager {
            throw new IllegalArgumentException(
            throw new IllegalArgumentException(
                    "CarrierPrivilegesCallback and executor must be non-null");
                    "CarrierPrivilegesCallback and executor must be non-null");
        }
        }
        mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class);
        if (mTelephonyRegistryMgr == null) {
        TelephonyRegistryManager mgr = mContext.getSystemService(TelephonyRegistryManager.class);
            throw new IllegalStateException("Telephony registry service is null");
        }
        if (mgr == null) throw new IllegalStateException("telephony service is null.");
        mTelephonyRegistryMgr.addCarrierPrivilegesCallback(logicalSlotIndex, executor, callback);
        mgr.addCarrierPrivilegesCallback(logicalSlotIndex, executor, callback);
    }
    }
    /**
    /**
@@ -18887,11 +18881,11 @@ public class TelephonyManager {
        } else if (callback == null) {
        } else if (callback == null) {
            throw new IllegalArgumentException("CarrierPrivilegesCallback must be non-null");
            throw new IllegalArgumentException("CarrierPrivilegesCallback must be non-null");
        }
        }
        mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class);
        TelephonyRegistryManager mgr = mContext.getSystemService(TelephonyRegistryManager.class);
        if (mTelephonyRegistryMgr == null) {
            throw new IllegalStateException("Telephony registry service is null");
        if (mgr == null) throw new IllegalStateException("telephony service is null.");
        }
        mTelephonyRegistryMgr.removeCarrierPrivilegesCallback(callback);
        mgr.removeCarrierPrivilegesCallback(callback);
    }
    }
    /**
    /**