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

Commit 47262c05 authored by Jack Yu's avatar Jack Yu
Browse files

Added builder for PreciseDataConnectionState

Added builder for PreciseDataConnectionState. No functionality
changed.

Bug: 161572838
Test: FrameworksTelephonyTests
Merged-In: I9d2d4cc3d717878d9246989f7a88bedc0805d86e
Change-Id: I9d2d4cc3d717878d9246989f7a88bedc0805d86e
(cherry picked from commit 9919a292)
parent bf5158f9
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ import android.telephony.CellSignalStrengthLte;
import android.telephony.CellSignalStrengthNr;
import android.telephony.CellSignalStrengthTdscdma;
import android.telephony.CellSignalStrengthWcdma;
import android.telephony.DataFailCause;
import android.telephony.DisconnectCause;
import android.telephony.LocationAccessPolicy;
import android.telephony.PhoneCapability;
@@ -1801,11 +1800,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            if (validatePhoneId(phoneId)) {
                mPreciseDataConnectionStates.get(phoneId).put(
                        apnType,
                        new PreciseDataConnectionState(
                                TelephonyManager.DATA_UNKNOWN,
                                TelephonyManager.NETWORK_TYPE_UNKNOWN,
                                apnType, null, null,
                                DataFailCause.NONE, null));
                        new PreciseDataConnectionState.Builder()
                                .setApnTypes(apnType)
                                .build());
                for (Record r : mRecords) {
                    if (r.matchPhoneStateListenerEvent(
                            PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
@@ -1983,11 +1980,10 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            if (validatePhoneId(phoneId)) {
                mPreciseDataConnectionStates.get(phoneId).put(
                        apnType,
                        new PreciseDataConnectionState(
                                TelephonyManager.DATA_UNKNOWN,
                                TelephonyManager.NETWORK_TYPE_UNKNOWN,
                                apnType, null, null,
                                failCause, null));
                        new PreciseDataConnectionState.Builder()
                                .setApnTypes(apnType)
                                .setFailCause(failCause)
                                .build());
                for (Record r : mRecords) {
                    if (r.matchPhoneStateListenerEvent(
                            PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
+152 −42
Original line number Diff line number Diff line
@@ -53,14 +53,13 @@ import java.util.Objects;
 *
 */
public final class PreciseDataConnectionState implements Parcelable {

    private @DataState int mState = TelephonyManager.DATA_UNKNOWN;
    private @NetworkType int mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
    private @DataFailureCause int mFailCause = DataFailCause.NONE;
    private @ApnType int mApnTypes = ApnSetting.TYPE_NONE;
    private String mApn = "";
    private LinkProperties mLinkProperties = null;
    private ApnSetting mApnSetting = null;
    private final @DataState int mState;
    private final @NetworkType int mNetworkType;
    private final @DataFailureCause int mFailCause;
    private final @ApnType int mApnTypes;
    private final String mApn;
    private final LinkProperties mLinkProperties;
    private final ApnSetting mApnSetting;

    /**
     * Constructor
@@ -84,20 +83,21 @@ public final class PreciseDataConnectionState implements Parcelable {
    /**
     * Constructor of PreciseDataConnectionState
     *
     * @param state the state of the 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 apn the APN of this data 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 state The state of the 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 apn The APN of this data 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
     *        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
     * @hide
     */
    public PreciseDataConnectionState(@DataState int state,
    private PreciseDataConnectionState(@DataState int state,
                                      @NetworkType int networkType,
                                      @ApnType int apnTypes, @NonNull String apn,
                                      @ApnType int apnTypes,
                                      @NonNull String apn,
                                      @Nullable LinkProperties linkProperties,
                                      @DataFailureCause int failCause,
                                      @Nullable ApnSetting apnSetting) {
@@ -110,14 +110,6 @@ public final class PreciseDataConnectionState implements Parcelable {
        mApnSetting = apnSetting;
    }

    /**
     * Empty Constructor
     *
     * @hide
     */
    public PreciseDataConnectionState() {
    }

    /**
     * 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
     * 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
@@ -274,24 +266,23 @@ public final class PreciseDataConnectionState implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(mState, mNetworkType, mApnTypes, mApn, mLinkProperties,
                mFailCause, mApnSetting);
        return Objects.hash(mState, mNetworkType, mFailCause, mApnTypes, mApn, mLinkProperties,
                mApnSetting);
    }

    @Override
    public boolean equals(@Nullable Object obj) {

        if (!(obj instanceof PreciseDataConnectionState)) {
            return false;
        }

        PreciseDataConnectionState other = (PreciseDataConnectionState) obj;
        return Objects.equals(mApn, other.mApn) && mApnTypes == other.mApnTypes
                && mFailCause == other.mFailCause
                && Objects.equals(mLinkProperties, other.mLinkProperties)
                && mNetworkType == other.mNetworkType
                && mState == other.mState
                && Objects.equals(mApnSetting, other.mApnSetting);
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PreciseDataConnectionState that = (PreciseDataConnectionState) o;
        return mState == that.mState
                && mNetworkType == that.mNetworkType
                && mFailCause == that.mFailCause
                && mApnTypes == that.mApnTypes
                && Objects.equals(mApn, that.mApn)
                && Objects.equals(mLinkProperties, that.mLinkProperties)
                && Objects.equals(mApnSetting, that.mApnSetting);
    }

    @NonNull
@@ -309,4 +300,123 @@ public final class PreciseDataConnectionState implements Parcelable {

        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);
        }
    }
}