diff options
| author | Meng Wang <mewan@google.com> | 2020-01-27 17:17:34 -0800 |
|---|---|---|
| committer | Meng Wang <mewan@google.com> | 2020-01-27 18:10:24 -0800 |
| commit | 489e391d8f97359a20c42fe276dfb076c67775c9 (patch) | |
| tree | 7c34101a7e9f8426a1a9eb90747a31cffe33d664 /core/java/android/telephony/TelephonyRegistryManager.java | |
| parent | f83559781f8f793694b5895b86e809e1837ae472 (diff) | |
TelephonyManager: do not acceess hidden API
... PhoneStateListener.mSubId; move the logic to
TelephonyRegistryManager.
Bug: 140908357
Test: make
Change-Id: I2594cdfe178b02aeab9f88dc16586418eca985ff
Diffstat (limited to 'core/java/android/telephony/TelephonyRegistryManager.java')
| -rw-r--r-- | core/java/android/telephony/TelephonyRegistryManager.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/java/android/telephony/TelephonyRegistryManager.java b/core/java/android/telephony/TelephonyRegistryManager.java index 6787c46c046e..4024db1e16c4 100644 --- a/core/java/android/telephony/TelephonyRegistryManager.java +++ b/core/java/android/telephony/TelephonyRegistryManager.java @@ -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; @@ -199,6 +203,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 * @param pkg Package name @@ -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) { |
