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

Commit 489e391d authored by Meng Wang's avatar Meng Wang
Browse files

TelephonyManager: do not acceess hidden API

... PhoneStateListener.mSubId; move the logic to
TelephonyRegistryManager.

Bug: 140908357
Test: make
Change-Id: I2594cdfe178b02aeab9f88dc16586418eca985ff
parent f8355978
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -20,8 +20,12 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.content.Context;
import android.os.Binder;
import android.os.Build;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.Annotation.ApnType;
@@ -198,6 +202,13 @@ public class TelephonyRegistryManager {
        }
    }

    /**
     * To check the SDK version for {@link #listenForSubscriber}.
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.P)
    private static final long LISTEN_CODE_CHANGE = 147600208L;

    /**
     * Listen for incoming subscriptions
     * @param subId Subscription ID
@@ -210,6 +221,16 @@ public class TelephonyRegistryManager {
    public void listenForSubscriber(int subId, @NonNull String pkg, @NonNull String featureId,
            @NonNull PhoneStateListener listener, int events, boolean notifyNow) {
        try {
            // subId from PhoneStateListener is deprecated Q on forward, use the subId from
            // TelephonyManager instance. Keep using subId from PhoneStateListener for pre-Q.
            if (Compatibility.isChangeEnabled(LISTEN_CODE_CHANGE)) {
                // Since mSubId in PhoneStateListener is deprecated from Q on forward, this is
                // the only place to set mSubId and its for "informational" only.
                listener.mSubId = (events == PhoneStateListener.LISTEN_NONE)
                        ? SubscriptionManager.INVALID_SUBSCRIPTION_ID : subId;
            } else if (listener.mSubId != null) {
                subId = listener.mSubId;
            }
            sRegistry.listenForSubscriber(
                    subId, pkg, featureId, listener.callback, events, notifyNow);
        } catch (RemoteException e) {
+1 −20
Original line number Diff line number Diff line
@@ -5639,13 +5639,6 @@ public class TelephonyManager {
    //
    //

    /**
     * To check the SDK version for {@link TelephonyManager#listen}.
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.P)
    private static final long LISTEN_CODE_CHANGE = 147600208L;

    /**
     * Registers a listener object to receive notification of changes
     * in specified telephony states.
@@ -5683,19 +5676,7 @@ public class TelephonyManager {
                (TelephonyRegistryManager)
                        mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
        if (telephonyRegistry != null) {
            // subId from PhoneStateListener is deprecated Q on forward, use the subId from
            // TelephonyManager instance. keep using subId from PhoneStateListener for pre-Q.
            int subId = mSubId;
            if (Compatibility.isChangeEnabled(LISTEN_CODE_CHANGE)) {
                // since mSubId in PhoneStateListener is deprecated from Q on forward, this is
                // the only place to set mSubId and its for "informational" only.
                //  TODO: remove this once we completely get rid of mSubId in PhoneStateListener
                listener.mSubId = (events == PhoneStateListener.LISTEN_NONE)
                        ? SubscriptionManager.INVALID_SUBSCRIPTION_ID : subId;
            } else if (listener.mSubId != null) {
                subId = listener.mSubId;
            }
            telephonyRegistry.listenForSubscriber(subId, getOpPackageName(), getFeatureId(),
            telephonyRegistry.listenForSubscriber(mSubId, getOpPackageName(), getFeatureId(),
                    listener, events, notifyNow);
        } else {
            Rlog.w(TAG, "telephony registry not ready.");