Use changeID and Compatibility.isChangeEnabled for Mainline

Test: Treehugger
Bug: 145147528
Bug: 147600208

Change-Id: I8092f4c7d3be046da337cdcbadeed89844b3aaab
This commit is contained in:
Shuo Qian
2020-01-13 16:01:46 -08:00
parent 10432c775d
commit d0c818129a
2 changed files with 27 additions and 7 deletions

View File

@@ -20,6 +20,9 @@ import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.os.Build; import android.os.Build;
@@ -31,8 +34,6 @@ import android.telephony.Annotation.DataState;
import android.telephony.Annotation.NetworkType; import android.telephony.Annotation.NetworkType;
import android.telephony.data.ApnSetting; import android.telephony.data.ApnSetting;
import dalvik.system.VMRuntime;
import java.util.Objects; import java.util.Objects;
@@ -133,6 +134,13 @@ public final class PreciseDataConnectionState implements Parcelable {
mApnSetting = (ApnSetting) in.readParcelable(null); mApnSetting = (ApnSetting) in.readParcelable(null);
} }
/**
* To check the SDK version for {@link PreciseDataConnectionState#getDataConnectionState}.
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
private static final long GET_DATA_CONNECTION_STATE_CODE_CHANGE = 147600208L;
/** /**
* Returns the state of data connection that supported the apn types returned by * Returns the state of data connection that supported the apn types returned by
* {@link #getDataConnectionApnTypeBitMask()} * {@link #getDataConnectionApnTypeBitMask()}
@@ -144,7 +152,7 @@ public final class PreciseDataConnectionState implements Parcelable {
@SystemApi @SystemApi
public @DataState int getDataConnectionState() { public @DataState int getDataConnectionState() {
if (mState == TelephonyManager.DATA_DISCONNECTING if (mState == TelephonyManager.DATA_DISCONNECTING
&& VMRuntime.getRuntime().getTargetSdkVersion() < Build.VERSION_CODES.R) { && !Compatibility.isChangeEnabled(GET_DATA_CONNECTION_STATE_CODE_CHANGE)) {
return TelephonyManager.DATA_CONNECTED; return TelephonyManager.DATA_CONNECTED;
} }

View File

@@ -109,8 +109,6 @@ import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.SmsApplication; import com.android.internal.telephony.SmsApplication;
import com.android.telephony.Rlog; import com.android.telephony.Rlog;
import dalvik.system.VMRuntime;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@@ -5410,6 +5408,13 @@ public class TelephonyManager {
*/ */
public static final int DATA_DISCONNECTING = 4; public static final int DATA_DISCONNECTING = 4;
/**
* To check the SDK version for {@link TelephonyManager#getDataState}.
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
private static final long GET_DATA_STATE_CODE_CHANGE = 147600208L;
/** /**
* Returns a constant indicating the current data connection state * Returns a constant indicating the current data connection state
* (cellular). * (cellular).
@@ -5428,7 +5433,7 @@ public class TelephonyManager {
int state = telephony.getDataStateForSubId( int state = telephony.getDataStateForSubId(
getSubId(SubscriptionManager.getActiveDataSubscriptionId())); getSubId(SubscriptionManager.getActiveDataSubscriptionId()));
if (state == TelephonyManager.DATA_DISCONNECTING if (state == TelephonyManager.DATA_DISCONNECTING
&& VMRuntime.getRuntime().getTargetSdkVersion() < Build.VERSION_CODES.R) { && !Compatibility.isChangeEnabled(GET_DATA_STATE_CODE_CHANGE)) {
return TelephonyManager.DATA_CONNECTED; return TelephonyManager.DATA_CONNECTED;
} }
@@ -5489,6 +5494,13 @@ public class TelephonyManager {
// //
// //
/**
* To check the SDK version for {@link TelephonyManager#listen}.
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
private static final long LISTEN_CODE_CHANGE = 147600208L;
/** /**
* Registers a listener object to receive notification of changes * Registers a listener object to receive notification of changes
* in specified telephony states. * in specified telephony states.
@@ -5528,7 +5540,7 @@ public class TelephonyManager {
// subId from PhoneStateListener is deprecated Q on forward, use the subId from // subId from PhoneStateListener is deprecated Q on forward, use the subId from
// TelephonyManager instance. keep using subId from PhoneStateListener for pre-Q. // TelephonyManager instance. keep using subId from PhoneStateListener for pre-Q.
int subId = mSubId; int subId = mSubId;
if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q) { if (Compatibility.isChangeEnabled(LISTEN_CODE_CHANGE)) {
// since mSubId in PhoneStateListener is deprecated from Q on forward, this is // since mSubId in PhoneStateListener is deprecated from Q on forward, this is
// the only place to set mSubId and its for "informational" only. // the only place to set mSubId and its for "informational" only.
// TODO: remove this once we completely get rid of mSubId in PhoneStateListener // TODO: remove this once we completely get rid of mSubId in PhoneStateListener