Added builder for PreciseDataConnectionState am: 47262c052b am: 8ada8a5ccf

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1436353

Change-Id: Ibea0f7223901aa7e37c8f44114d9fd72f8419495
This commit is contained in:
Jack Yu
2020-09-25 07:09:30 +00:00
committed by Automerger Merge Worker
2 changed files with 159 additions and 53 deletions

View File

@@ -63,7 +63,6 @@ import android.telephony.CellSignalStrengthLte;
import android.telephony.CellSignalStrengthNr; import android.telephony.CellSignalStrengthNr;
import android.telephony.CellSignalStrengthTdscdma; import android.telephony.CellSignalStrengthTdscdma;
import android.telephony.CellSignalStrengthWcdma; import android.telephony.CellSignalStrengthWcdma;
import android.telephony.DataFailCause;
import android.telephony.DisconnectCause; import android.telephony.DisconnectCause;
import android.telephony.LocationAccessPolicy; import android.telephony.LocationAccessPolicy;
import android.telephony.PhoneCapability; import android.telephony.PhoneCapability;
@@ -1801,11 +1800,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
if (validatePhoneId(phoneId)) { if (validatePhoneId(phoneId)) {
mPreciseDataConnectionStates.get(phoneId).put( mPreciseDataConnectionStates.get(phoneId).put(
apnType, apnType,
new PreciseDataConnectionState( new PreciseDataConnectionState.Builder()
TelephonyManager.DATA_UNKNOWN, .setApnTypes(apnType)
TelephonyManager.NETWORK_TYPE_UNKNOWN, .build());
apnType, null, null,
DataFailCause.NONE, null));
for (Record r : mRecords) { for (Record r : mRecords) {
if (r.matchPhoneStateListenerEvent( if (r.matchPhoneStateListenerEvent(
PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
@@ -1983,11 +1980,10 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
if (validatePhoneId(phoneId)) { if (validatePhoneId(phoneId)) {
mPreciseDataConnectionStates.get(phoneId).put( mPreciseDataConnectionStates.get(phoneId).put(
apnType, apnType,
new PreciseDataConnectionState( new PreciseDataConnectionState.Builder()
TelephonyManager.DATA_UNKNOWN, .setApnTypes(apnType)
TelephonyManager.NETWORK_TYPE_UNKNOWN, .setFailCause(failCause)
apnType, null, null, .build());
failCause, null));
for (Record r : mRecords) { for (Record r : mRecords) {
if (r.matchPhoneStateListenerEvent( if (r.matchPhoneStateListenerEvent(
PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)

View File

@@ -53,14 +53,13 @@ import java.util.Objects;
* *
*/ */
public final class PreciseDataConnectionState implements Parcelable { public final class PreciseDataConnectionState implements Parcelable {
private final @DataState int mState;
private @DataState int mState = TelephonyManager.DATA_UNKNOWN; private final @NetworkType int mNetworkType;
private @NetworkType int mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN; private final @DataFailureCause int mFailCause;
private @DataFailureCause int mFailCause = DataFailCause.NONE; private final @ApnType int mApnTypes;
private @ApnType int mApnTypes = ApnSetting.TYPE_NONE; private final String mApn;
private String mApn = ""; private final LinkProperties mLinkProperties;
private LinkProperties mLinkProperties = null; private final ApnSetting mApnSetting;
private ApnSetting mApnSetting = null;
/** /**
* Constructor * Constructor
@@ -84,20 +83,21 @@ public final class PreciseDataConnectionState implements Parcelable {
/** /**
* Constructor of PreciseDataConnectionState * Constructor of PreciseDataConnectionState
* *
* @param state the state of the data connection * @param state The state of the data connection
* @param networkType the access network that is/would carry this data connection * @param networkType The access network that is/would carry this data connection
* @param apnTypes the APN types that this data connection carries * @param apnTypes The APN types that this data connection carries
* @param apn the APN of this data connection * @param apn The APN of this data connection
* @param linkProperties if the data connection is connected, the properties of the connection * @param linkProperties If the data connection is connected, the properties of the connection
* @param failCause in case a procedure related to this data connection fails, a non-zero error * @param failCause In case a procedure related to this data connection fails, a non-zero error
* code indicating the cause of the failure. * code indicating the cause of the failure.
* @param apnSetting if there is a valid APN for this Data Connection, then the APN Settings; * @param apnSetting If there is a valid APN for this Data Connection, then the APN Settings;
* if there is no valid APN setting for the specific type, then this will be null * if there is no valid APN setting for the specific type, then this will be null
* @hide * @hide
*/ */
public PreciseDataConnectionState(@DataState int state, private PreciseDataConnectionState(@DataState int state,
@NetworkType int networkType, @NetworkType int networkType,
@ApnType int apnTypes, @NonNull String apn, @ApnType int apnTypes,
@NonNull String apn,
@Nullable LinkProperties linkProperties, @Nullable LinkProperties linkProperties,
@DataFailureCause int failCause, @DataFailureCause int failCause,
@Nullable ApnSetting apnSetting) { @Nullable ApnSetting apnSetting) {
@@ -110,14 +110,6 @@ public final class PreciseDataConnectionState implements Parcelable {
mApnSetting = apnSetting; mApnSetting = apnSetting;
} }
/**
* Empty Constructor
*
* @hide
*/
public PreciseDataConnectionState() {
}
/** /**
* Construct a PreciseDataConnectionState object from the given parcel. * Construct a PreciseDataConnectionState object from the given parcel.
* *
@@ -167,9 +159,9 @@ public final class PreciseDataConnectionState implements Parcelable {
} }
/** /**
* Returns the network type associated with this data connection. * Get the network type associated with this data connection.
* *
* Return the current/latest (radio) bearer technology that carries this data connection. * @return The current/latest (radio) bearer technology that carries this data connection.
* For a variety of reasons, the network type can change during the life of the data * For a variety of reasons, the network type can change during the life of the data
* connection, and this information is not reliable unless the physical link is currently * connection, and this information is not reliable unless the physical link is currently
* active; (there is currently no mechanism to know whether the physical link is active at * active; (there is currently no mechanism to know whether the physical link is active at
@@ -274,24 +266,23 @@ public final class PreciseDataConnectionState implements Parcelable {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mState, mNetworkType, mApnTypes, mApn, mLinkProperties, return Objects.hash(mState, mNetworkType, mFailCause, mApnTypes, mApn, mLinkProperties,
mFailCause, mApnSetting); mApnSetting);
} }
@Override @Override
public boolean equals(@Nullable Object obj) { public boolean equals(Object o) {
if (this == o) return true;
if (!(obj instanceof PreciseDataConnectionState)) { if (o == null || getClass() != o.getClass()) return false;
return false; PreciseDataConnectionState that = (PreciseDataConnectionState) o;
} return mState == that.mState
&& mNetworkType == that.mNetworkType
PreciseDataConnectionState other = (PreciseDataConnectionState) obj; && mFailCause == that.mFailCause
return Objects.equals(mApn, other.mApn) && mApnTypes == other.mApnTypes && mApnTypes == that.mApnTypes
&& mFailCause == other.mFailCause && Objects.equals(mApn, that.mApn)
&& Objects.equals(mLinkProperties, other.mLinkProperties) && Objects.equals(mLinkProperties, that.mLinkProperties)
&& mNetworkType == other.mNetworkType && Objects.equals(mApnSetting, that.mApnSetting);
&& mState == other.mState
&& Objects.equals(mApnSetting, other.mApnSetting);
} }
@NonNull @NonNull
@@ -309,4 +300,123 @@ public final class PreciseDataConnectionState implements Parcelable {
return sb.toString(); return sb.toString();
} }
/**
* {@link PreciseDataConnectionState} builder
*
* @hide
*/
public static final class Builder {
/** The state of the data connection */
private @DataState int mState = TelephonyManager.DATA_UNKNOWN;
/** The network type associated with this data connection */
private @NetworkType int mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
/** The APN types that this data connection carries */
private @ApnType int mApnTypes = ApnSetting.TYPE_NONE;
/** The APN of this data connection */
private @NonNull String mApn = "";
/** If the data connection is connected, the properties of the connection */
private @Nullable LinkProperties mLinkProperties = null;
/**
* In case a procedure related to this data connection fails, a non-zero error code
* indicating the cause of the failure.
*/
private @DataFailureCause int mFailCause = DataFailCause.NONE;
/** The APN Setting for this data connection */
private @Nullable ApnSetting mApnSetting = null;
/**
* Set the state of the data connection.
*
* @param state The state of the data connection
* @return The builder
*/
public Builder setState(@DataState int state) {
mState = state;
return this;
}
/**
* Set the network type associated with this data connection.
*
* @param networkType The network type
* @return The builder
*/
public Builder setNetworkType(@NetworkType int networkType) {
mNetworkType = networkType;
return this;
}
/**
* Set the APN types that this data connection carries
*
* @param apnTypes The APN types
* @return The builder
*/
public Builder setApnTypes(@ApnType int apnTypes) {
mApnTypes = apnTypes;
return this;
}
/**
* Set the APN of this data connection
*
* @param apn The APN of this data connection
* @return The builder
*/
public Builder setApn(@NonNull String apn) {
mApn = apn;
return this;
}
/**
* Set the link properties of the connection.
*
* @param linkProperties Link properties
* @return The builder
*/
public Builder setLinkProperties(@NonNull LinkProperties linkProperties) {
mLinkProperties = linkProperties;
return this;
}
/**
* Set the fail cause of the data connection.
*
* @param failCause In case a procedure related to this data connection fails, a non-zero
* error code indicating the cause of the failure.
* @return The builder
*/
public Builder setFailCause(@DataFailureCause int failCause) {
mFailCause = failCause;
return this;
}
/**
* Set the APN Setting for this data connection.
*
* @param apnSetting APN setting
* @return This builder
*/
public Builder setApnSetting(@NonNull ApnSetting apnSetting) {
mApnSetting = apnSetting;
return this;
}
/**
* Build the {@link PreciseDataConnectionState} instance.
*
* @return The {@link PreciseDataConnectionState} instance
*/
public PreciseDataConnectionState build() {
return new PreciseDataConnectionState(mState, mNetworkType, mApnTypes, mApn,
mLinkProperties, mFailCause, mApnSetting);
}
}
} }