From 22241e178887f1288758fc8c1515e654be6ba587 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Tue, 5 Mar 2019 14:31:01 -0800 Subject: [PATCH 1/3] Added annotations to the API Added @NonNull and @Nullable to APIs. Test: Build Bug: 126702898 Merged-In: I697298837858829bb0851aba389159701fa0fc5e Change-Id: I697298837858829bb0851aba389159701fa0fc5e (cherry picked from commit 1eb3f0cdaed5a7156e9dcb11223f7f4ac82f1360) --- api/system-current.txt | 6 +++--- telephony/java/android/telephony/data/DataProfile.java | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 97b210fb04fbf..4ca9e8d2230a7 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6535,19 +6535,19 @@ package android.telephony.data { } public final class DataProfile implements android.os.Parcelable { - method public String getApn(); + method @NonNull public String getApn(); method public int getAuthType(); method public int getBearerBitmap(); method public int getMaxConns(); method public int getMaxConnsTime(); method public int getMtu(); - method public String getPassword(); + method @Nullable public String getPassword(); method public int getProfileId(); method public int getProtocol(); method public int getRoamingProtocol(); method public int getSupportedApnTypesBitmap(); method public int getType(); - method public String getUserName(); + method @Nullable public String getUserName(); method public int getWaitTime(); method public boolean isEnabled(); method public boolean isPersistent(); diff --git a/telephony/java/android/telephony/data/DataProfile.java b/telephony/java/android/telephony/data/DataProfile.java index 1d196f9b2885b..d49ef3a493c4d 100644 --- a/telephony/java/android/telephony/data/DataProfile.java +++ b/telephony/java/android/telephony/data/DataProfile.java @@ -19,6 +19,8 @@ package android.telephony.data; import static android.telephony.data.ApnSetting.ProtocolType; import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.SystemApi; import android.os.Build; import android.os.Parcel; @@ -158,6 +160,7 @@ public final class DataProfile implements Parcelable { /** * @return The APN to establish data connection. */ + @NonNull public String getApn() { return mApn; } /** @@ -173,11 +176,13 @@ public final class DataProfile implements Parcelable { /** * @return The username for APN. Can be null. */ + @Nullable public String getUserName() { return mUserName; } /** * @return The password for APN. Can be null. */ + @Nullable public String getPassword() { return mPassword; } /** From aff62b8a329984f49e6b8771dd0e882ef2e735c2 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Sun, 10 Mar 2019 12:45:52 -0700 Subject: [PATCH 2/3] Unhide methods required for Parcelable class Those methods were already public in the base class. Test: Build FIXES: 126702898 Merged-In: Ibce8f9bf5d1a3ebf9225fa46422dc3c78e29b1f6 Change-Id: Ibce8f9bf5d1a3ebf9225fa46422dc3c78e29b1f6 (cherry picked from commit 654bb21f703f943d24586323c9eb822fc06a0857) --- api/system-current.txt | 3 +++ telephony/java/android/telephony/data/DataProfile.java | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 4ca9e8d2230a7..54930a66322ea 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6535,6 +6535,7 @@ package android.telephony.data { } public final class DataProfile implements android.os.Parcelable { + method public int describeContents(); method @NonNull public String getApn(); method public int getAuthType(); method public int getBearerBitmap(); @@ -6552,6 +6553,8 @@ package android.telephony.data { method public boolean isEnabled(); method public boolean isPersistent(); method public boolean isPreferred(); + method public void writeToParcel(android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; field public static final int TYPE_3GPP = 1; // 0x1 field public static final int TYPE_3GPP2 = 2; // 0x2 field public static final int TYPE_COMMON = 0; // 0x0 diff --git a/telephony/java/android/telephony/data/DataProfile.java b/telephony/java/android/telephony/data/DataProfile.java index d49ef3a493c4d..bcb47f73cb4d6 100644 --- a/telephony/java/android/telephony/data/DataProfile.java +++ b/telephony/java/android/telephony/data/DataProfile.java @@ -243,7 +243,6 @@ public final class DataProfile implements Parcelable { */ public boolean isPreferred() { return mPreferred; } - /** @hide */ @Override public int describeContents() { return 0; @@ -266,7 +265,6 @@ public final class DataProfile implements Parcelable { return (o == this || toString().equals(o.toString())); } - /** @hide */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mProfileId); @@ -288,8 +286,7 @@ public final class DataProfile implements Parcelable { dest.writeBoolean(mPreferred); } - /** @hide */ - public static final Parcelable.Creator CREATOR = + public static final @android.annotation.NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public DataProfile createFromParcel(Parcel source) { From c876b65663fab631dbd8c57aacd5d10d10251b99 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Mon, 18 Mar 2019 00:12:03 -0700 Subject: [PATCH 3/3] IWLAN API review changes Made several API changes per API council suggestions. Test: Manual + unit tests Bug: 127812471 Bug: 128607082 Merged-In: I0f93c07207b10b566e9f858361e55b18dc0881a0 Change-Id: I0f93c07207b10b566e9f858361e55b18dc0881a0 (cherry picked from commit 806b64228db64e25bd04ab5da607094932561b36) --- api/system-current.txt | 94 ++-- api/system-removed.txt | 8 + .../android/telephony/INetworkService.aidl | 2 +- .../telephony/INetworkServiceCallback.aidl | 2 +- .../android/telephony/NetworkService.java | 24 +- .../telephony/NetworkServiceCallback.java | 18 +- .../java/android/telephony/ServiceState.java | 2 +- .../telephony/data/DataCallResponse.java | 398 +++++++++++++---- .../android/telephony/data/DataProfile.java | 403 ++++++++++++++++-- .../android/telephony/data/DataService.java | 44 +- .../telephony/data/DataServiceCallback.java | 10 +- .../android/telephony/data/IDataService.aidl | 2 +- .../telephony/data/IDataServiceCallback.aidl | 2 +- .../data/IQualifiedNetworksService.aidl | 4 +- .../data/QualifiedNetworksService.java | 114 ++--- 15 files changed, 857 insertions(+), 270 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 54930a66322ea..e31884b01fffe 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6072,19 +6072,19 @@ package android.telephony { ctor public NetworkService(); method public android.os.IBinder onBind(android.content.Intent); method @Nullable public abstract android.telephony.NetworkService.NetworkServiceProvider onCreateNetworkServiceProvider(int); - field public static final String NETWORK_SERVICE_INTERFACE = "android.telephony.NetworkService"; + field public static final String SERVICE_INTERFACE = "android.telephony.NetworkService"; } public abstract class NetworkService.NetworkServiceProvider implements java.lang.AutoCloseable { ctor public NetworkService.NetworkServiceProvider(int); method public abstract void close(); - method public void getNetworkRegistrationInfo(int, @NonNull android.telephony.NetworkServiceCallback); method public final int getSlotIndex(); method public final void notifyNetworkRegistrationInfoChanged(); + method public void requestNetworkRegistrationInfo(int, @NonNull android.telephony.NetworkServiceCallback); } public class NetworkServiceCallback { - method public void onGetNetworkRegistrationInfoComplete(int, @Nullable android.telephony.NetworkRegistrationInfo); + method public void onRequestNetworkRegistrationInfoComplete(int, @Nullable android.telephony.NetworkRegistrationInfo); field public static final int RESULT_ERROR_BUSY = 3; // 0x3 field public static final int RESULT_ERROR_FAILED = 5; // 0x5 field public static final int RESULT_ERROR_ILLEGAL_STATE = 4; // 0x4 @@ -6517,39 +6517,55 @@ package android.telephony { package android.telephony.data { public final class DataCallResponse implements android.os.Parcelable { - ctor public DataCallResponse(int, int, int, int, int, @Nullable String, @Nullable java.util.List, @Nullable java.util.List, @Nullable java.util.List, @Nullable java.util.List, int); method public int describeContents(); - method public int getActive(); method @NonNull public java.util.List getAddresses(); - method public int getCallId(); - method @NonNull public java.util.List getDnses(); - method @NonNull public java.util.List getGateways(); - method @NonNull public String getIfname(); + method public int getCause(); + method @NonNull public java.util.List getDnsAddresses(); + method @NonNull public java.util.List getGatewayAddresses(); + method public int getId(); + method @NonNull public String getInterfaceName(); + method public int getLinkStatus(); method public int getMtu(); - method @NonNull public java.util.List getPcscfs(); + method @NonNull public java.util.List getPcscfAddresses(); method public int getProtocolType(); - method public int getStatus(); method public int getSuggestedRetryTime(); method public void writeToParcel(android.os.Parcel, int); - field public static final android.os.Parcelable.Creator CREATOR; + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + field public static final int LINK_STATUS_ACTIVE = 2; // 0x2 + field public static final int LINK_STATUS_DORMANT = 1; // 0x1 + field public static final int LINK_STATUS_INACTIVE = 0; // 0x0 + field public static final int LINK_STATUS_UNKNOWN = -1; // 0xffffffff + } + + public static final class DataCallResponse.Builder { + ctor public DataCallResponse.Builder(); + method @NonNull public android.telephony.data.DataCallResponse build(); + method @NonNull public android.telephony.data.DataCallResponse.Builder setAddresses(@NonNull java.util.List); + method @NonNull public android.telephony.data.DataCallResponse.Builder setCause(int); + method @NonNull public android.telephony.data.DataCallResponse.Builder setDnsAddresses(@NonNull java.util.List); + method @NonNull public android.telephony.data.DataCallResponse.Builder setGatewayAddresses(@NonNull java.util.List); + method @NonNull public android.telephony.data.DataCallResponse.Builder setId(int); + method @NonNull public android.telephony.data.DataCallResponse.Builder setInterfaceName(@NonNull String); + method @NonNull public android.telephony.data.DataCallResponse.Builder setLinkStatus(int); + method @NonNull public android.telephony.data.DataCallResponse.Builder setMtu(int); + method @NonNull public android.telephony.data.DataCallResponse.Builder setPcscfAddresses(@NonNull java.util.List); + method @NonNull public android.telephony.data.DataCallResponse.Builder setProtocolType(int); + method @NonNull public android.telephony.data.DataCallResponse.Builder setSuggestedRetryTime(int); } public final class DataProfile implements android.os.Parcelable { method public int describeContents(); method @NonNull public String getApn(); method public int getAuthType(); - method public int getBearerBitmap(); - method public int getMaxConns(); - method public int getMaxConnsTime(); + method public int getBearerBitmask(); method public int getMtu(); method @Nullable public String getPassword(); method public int getProfileId(); - method public int getProtocol(); - method public int getRoamingProtocol(); - method public int getSupportedApnTypesBitmap(); + method public int getProtocolType(); + method public int getRoamingProtocolType(); + method public int getSupportedApnTypesBitmask(); method public int getType(); method @Nullable public String getUserName(); - method public int getWaitTime(); method public boolean isEnabled(); method public boolean isPersistent(); method public boolean isPreferred(); @@ -6560,32 +6576,52 @@ package android.telephony.data { field public static final int TYPE_COMMON = 0; // 0x0 } + public static final class DataProfile.Builder { + ctor public DataProfile.Builder(); + method @NonNull public android.telephony.data.DataProfile build(); + method @NonNull public android.telephony.data.DataProfile.Builder enable(boolean); + method @NonNull public android.telephony.data.DataProfile.Builder setApn(@NonNull String); + method @NonNull public android.telephony.data.DataProfile.Builder setAuthType(int); + method @NonNull public android.telephony.data.DataProfile.Builder setBearerBitmask(int); + method @NonNull public android.telephony.data.DataProfile.Builder setMtu(int); + method @NonNull public android.telephony.data.DataProfile.Builder setPassword(@NonNull String); + method @NonNull public android.telephony.data.DataProfile.Builder setPersistent(boolean); + method @NonNull public android.telephony.data.DataProfile.Builder setPreferred(boolean); + method @NonNull public android.telephony.data.DataProfile.Builder setProfileId(int); + method @NonNull public android.telephony.data.DataProfile.Builder setProtocolType(int); + method @NonNull public android.telephony.data.DataProfile.Builder setRoamingProtocolType(int); + method @NonNull public android.telephony.data.DataProfile.Builder setSupportedApnTypesBitmask(int); + method @NonNull public android.telephony.data.DataProfile.Builder setType(int); + method @NonNull public android.telephony.data.DataProfile.Builder setUserName(@NonNull String); + } + public abstract class DataService extends android.app.Service { ctor public DataService(); method public android.os.IBinder onBind(android.content.Intent); method @Nullable public abstract android.telephony.data.DataService.DataServiceProvider onCreateDataServiceProvider(int); - field public static final String DATA_SERVICE_INTERFACE = "android.telephony.data.DataService"; field public static final int REQUEST_REASON_HANDOVER = 3; // 0x3 field public static final int REQUEST_REASON_NORMAL = 1; // 0x1 field public static final int REQUEST_REASON_SHUTDOWN = 2; // 0x2 + field public static final int REQUEST_REASON_UNKNOWN = 0; // 0x0 + field public static final String SERVICE_INTERFACE = "android.telephony.data.DataService"; } public abstract class DataService.DataServiceProvider implements java.lang.AutoCloseable { ctor public DataService.DataServiceProvider(int); method public abstract void close(); method public void deactivateDataCall(int, int, @Nullable android.telephony.data.DataServiceCallback); - method public void getDataCallList(@NonNull android.telephony.data.DataServiceCallback); method public final int getSlotIndex(); method public final void notifyDataCallListChanged(java.util.List); - method public void setDataProfile(@NonNull java.util.List, boolean, @Nullable android.telephony.data.DataServiceCallback); - method public void setInitialAttachApn(@NonNull android.telephony.data.DataProfile, boolean, @Nullable android.telephony.data.DataServiceCallback); - method public void setupDataCall(int, @NonNull android.telephony.data.DataProfile, boolean, boolean, int, @Nullable android.net.LinkProperties, @Nullable android.telephony.data.DataServiceCallback); + method public void requestDataCallList(@NonNull android.telephony.data.DataServiceCallback); + method public void setDataProfile(@NonNull java.util.List, boolean, @NonNull android.telephony.data.DataServiceCallback); + method public void setInitialAttachApn(@NonNull android.telephony.data.DataProfile, boolean, @NonNull android.telephony.data.DataServiceCallback); + method public void setupDataCall(int, @NonNull android.telephony.data.DataProfile, boolean, boolean, int, @Nullable android.net.LinkProperties, @NonNull android.telephony.data.DataServiceCallback); } public class DataServiceCallback { method public void onDataCallListChanged(@NonNull java.util.List); method public void onDeactivateDataCallComplete(int); - method public void onGetDataCallListComplete(int, @NonNull java.util.List); + method public void onRequestDataCallListComplete(int, @NonNull java.util.List); method public void onSetDataProfileComplete(int); method public void onSetInitialAttachApnComplete(int); method public void onSetupDataCallComplete(int, @Nullable android.telephony.data.DataCallResponse); @@ -6598,15 +6634,15 @@ package android.telephony.data { public abstract class QualifiedNetworksService extends android.app.Service { ctor public QualifiedNetworksService(); - method @NonNull public abstract android.telephony.data.QualifiedNetworksService.NetworkAvailabilityUpdater createNetworkAvailabilityUpdater(int); + method @NonNull public abstract android.telephony.data.QualifiedNetworksService.NetworkAvailabilityProvider onCreateNetworkAvailabilityProvider(int); field public static final String QUALIFIED_NETWORKS_SERVICE_INTERFACE = "android.telephony.data.QualifiedNetworksService"; } - public abstract class QualifiedNetworksService.NetworkAvailabilityUpdater implements java.lang.AutoCloseable { - ctor public QualifiedNetworksService.NetworkAvailabilityUpdater(int); + public abstract class QualifiedNetworksService.NetworkAvailabilityProvider implements java.lang.AutoCloseable { + ctor public QualifiedNetworksService.NetworkAvailabilityProvider(int); method public abstract void close(); method public final int getSlotIndex(); - method public final void updateQualifiedNetworkTypes(int, @Nullable int[]); + method public final void updateQualifiedNetworkTypes(int, @NonNull java.util.List); } } diff --git a/api/system-removed.txt b/api/system-removed.txt index 478ec2873efc2..2ac7fb992e7ea 100644 --- a/api/system-removed.txt +++ b/api/system-removed.txt @@ -154,3 +154,11 @@ package android.telephony { } +package android.telephony.data { + + public final class DataCallResponse implements android.os.Parcelable { + ctor public DataCallResponse(int, int, int, int, int, @Nullable String, @Nullable java.util.List, @Nullable java.util.List, @Nullable java.util.List, @Nullable java.util.List, int); + } + +} + diff --git a/telephony/java/android/telephony/INetworkService.aidl b/telephony/java/android/telephony/INetworkService.aidl index 67e5650ab359a..3a9c3a5bd45db 100644 --- a/telephony/java/android/telephony/INetworkService.aidl +++ b/telephony/java/android/telephony/INetworkService.aidl @@ -25,7 +25,7 @@ oneway interface INetworkService { void createNetworkServiceProvider(int slotId); void removeNetworkServiceProvider(int slotId); - void getNetworkRegistrationInfo(int slotId, int domain, INetworkServiceCallback callback); + void requestNetworkRegistrationInfo(int slotId, int domain, INetworkServiceCallback callback); void registerForNetworkRegistrationInfoChanged(int slotId, INetworkServiceCallback callback); void unregisterForNetworkRegistrationInfoChanged(int slotId, INetworkServiceCallback callback); } diff --git a/telephony/java/android/telephony/INetworkServiceCallback.aidl b/telephony/java/android/telephony/INetworkServiceCallback.aidl index 33b3ac0940b5a..c35986c65f374 100644 --- a/telephony/java/android/telephony/INetworkServiceCallback.aidl +++ b/telephony/java/android/telephony/INetworkServiceCallback.aidl @@ -24,6 +24,6 @@ import android.telephony.NetworkRegistrationInfo; */ oneway interface INetworkServiceCallback { - void onGetNetworkRegistrationInfoComplete(int result, in NetworkRegistrationInfo state); + void onRequestNetworkRegistrationInfoComplete(int result, in NetworkRegistrationInfo state); void onNetworkStateChanged(); } diff --git a/telephony/java/android/telephony/NetworkService.java b/telephony/java/android/telephony/NetworkService.java index bc989dd8c5adf..8c5e10788b895 100644 --- a/telephony/java/android/telephony/NetworkService.java +++ b/telephony/java/android/telephony/NetworkService.java @@ -18,6 +18,7 @@ package android.telephony; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SdkConstant; import android.annotation.SystemApi; import android.app.Service; import android.content.Intent; @@ -54,7 +55,8 @@ public abstract class NetworkService extends Service { private final String TAG = NetworkService.class.getSimpleName(); - public static final String NETWORK_SERVICE_INTERFACE = "android.telephony.NetworkService"; + @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) + public static final String SERVICE_INTERFACE = "android.telephony.NetworkService"; private static final int NETWORK_SERVICE_CREATE_NETWORK_SERVICE_PROVIDER = 1; private static final int NETWORK_SERVICE_REMOVE_NETWORK_SERVICE_PROVIDER = 2; @@ -104,13 +106,14 @@ public abstract class NetworkService extends Service { } /** - * API to get network registration info. The result will be passed to the callback. + * Request network registration info. The result will be passed to the callback. + * * @param domain Network domain * @param callback The callback for reporting network registration info */ - public void getNetworkRegistrationInfo(@Domain int domain, - @NonNull NetworkServiceCallback callback) { - callback.onGetNetworkRegistrationInfoComplete( + public void requestNetworkRegistrationInfo(@Domain int domain, + @NonNull NetworkServiceCallback callback) { + callback.onRequestNetworkRegistrationInfoComplete( NetworkServiceCallback.RESULT_ERROR_UNSUPPORTED, null); } @@ -192,7 +195,7 @@ public abstract class NetworkService extends Service { case NETWORK_SERVICE_GET_REGISTRATION_INFO: if (serviceProvider == null) break; int domainId = message.arg2; - serviceProvider.getNetworkRegistrationInfo(domainId, + serviceProvider.requestNetworkRegistrationInfo(domainId, new NetworkServiceCallback(callback)); break; @@ -231,14 +234,15 @@ public abstract class NetworkService extends Service { * will call this method after binding the network service for each active SIM slot id. * * @param slotIndex SIM slot id the network service associated with. - * @return Network service object + * @return Network service object. Null if failed to create the provider (e.g. invalid slot + * index) */ @Nullable public abstract NetworkServiceProvider onCreateNetworkServiceProvider(int slotIndex); @Override public IBinder onBind(Intent intent) { - if (intent == null || !NETWORK_SERVICE_INTERFACE.equals(intent.getAction())) { + if (intent == null || !SERVICE_INTERFACE.equals(intent.getAction())) { loge("Unexpected intent " + intent); return null; } @@ -280,8 +284,8 @@ public abstract class NetworkService extends Service { } @Override - public void getNetworkRegistrationInfo( - int slotIndex, int domain, INetworkServiceCallback callback) { + public void requestNetworkRegistrationInfo(int slotIndex, int domain, + INetworkServiceCallback callback) { mHandler.obtainMessage(NETWORK_SERVICE_GET_REGISTRATION_INFO, slotIndex, domain, callback).sendToTarget(); } diff --git a/telephony/java/android/telephony/NetworkServiceCallback.java b/telephony/java/android/telephony/NetworkServiceCallback.java index cc2524000091a..1c64bcd289661 100644 --- a/telephony/java/android/telephony/NetworkServiceCallback.java +++ b/telephony/java/android/telephony/NetworkServiceCallback.java @@ -28,9 +28,9 @@ import java.lang.ref.WeakReference; /** * Network service callback. Object of this class is passed to NetworkServiceProvider upon - * calling getNetworkRegistrationInfo, to receive asynchronous feedback from NetworkServiceProvider - * upon onGetNetworkRegistrationInfoComplete. It's like a wrapper of INetworkServiceCallback - * because INetworkServiceCallback can't be a parameter type in public APIs. + * calling requestNetworkRegistrationInfo, to receive asynchronous feedback from + * NetworkServiceProvider upon onRequestNetworkRegistrationInfoComplete. It's like a wrapper of + * INetworkServiceCallback because INetworkServiceCallback can't be a parameter type in public APIs. * * @hide */ @@ -70,20 +70,20 @@ public class NetworkServiceCallback { /** * Called to indicate result of - * {@link NetworkServiceProvider#getNetworkRegistrationInfo(int, NetworkServiceCallback)} + * {@link NetworkServiceProvider#requestNetworkRegistrationInfo(int, NetworkServiceCallback)} * * @param result Result status like {@link NetworkServiceCallback#RESULT_SUCCESS} or - * {@link NetworkServiceCallback#RESULT_ERROR_UNSUPPORTED} + * {@link NetworkServiceCallback#RESULT_ERROR_UNSUPPORTED} * @param state The state information to be returned to callback. */ - public void onGetNetworkRegistrationInfoComplete(int result, - @Nullable NetworkRegistrationInfo state) { + public void onRequestNetworkRegistrationInfoComplete(int result, + @Nullable NetworkRegistrationInfo state) { INetworkServiceCallback callback = mCallback.get(); if (callback != null) { try { - callback.onGetNetworkRegistrationInfoComplete(result, state); + callback.onRequestNetworkRegistrationInfoComplete(result, state); } catch (RemoteException e) { - Rlog.e(mTag, "Failed to onGetNetworkRegistrationInfoComplete on the remote"); + Rlog.e(mTag, "Failed to onRequestNetworkRegistrationInfoComplete on the remote"); } } else { Rlog.e(mTag, "Weak reference of callback is null."); diff --git a/telephony/java/android/telephony/ServiceState.java b/telephony/java/android/telephony/ServiceState.java index 589a4deaadd1e..a500eba9fa2b0 100644 --- a/telephony/java/android/telephony/ServiceState.java +++ b/telephony/java/android/telephony/ServiceState.java @@ -1586,7 +1586,7 @@ public class ServiceState implements Parcelable { == NetworkRegistrationInfo.REGISTRATION_STATE_HOME) { // If the device is on IWLAN, return IWLAN as the network type. This is to simulate the // behavior of legacy mode device. In the future caller should use - // getNetworkRegistrationInfo() to retrieve the actual data network type on cellular + // requestNetworkRegistrationInfo() to retrieve the actual data network type on cellular // or on IWLAN. return iwlanRegState.getAccessNetworkTechnology(); } diff --git a/telephony/java/android/telephony/data/DataCallResponse.java b/telephony/java/android/telephony/data/DataCallResponse.java index 6d74deda1ac49..3806a7e2cbe01 100644 --- a/telephony/java/android/telephony/data/DataCallResponse.java +++ b/telephony/java/android/telephony/data/DataCallResponse.java @@ -17,16 +17,21 @@ package android.telephony.data; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.net.LinkAddress; import android.os.Parcel; import android.os.Parcelable; +import android.telephony.DataFailCause; +import android.telephony.DataFailCause.FailCause; import android.telephony.data.ApnSetting.ProtocolType; import com.android.internal.annotations.VisibleForTesting; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.net.InetAddress; import java.util.ArrayList; import java.util.List; @@ -39,83 +44,114 @@ import java.util.Objects; */ @SystemApi public final class DataCallResponse implements Parcelable { - private final int mStatus; + + /** {@hide} */ + @IntDef(prefix = "LINK_STATUS_", value = { + LINK_STATUS_UNKNOWN, + LINK_STATUS_INACTIVE, + LINK_STATUS_DORMANT, + LINK_STATUS_ACTIVE + }) + @Retention(RetentionPolicy.SOURCE) + public @interface LinkStatus {} + + /** Unknown status */ + public static final int LINK_STATUS_UNKNOWN = -1; + + /** Indicates the data connection is inactive. */ + public static final int LINK_STATUS_INACTIVE = 0; + + /** Indicates the data connection is active with physical link dormant. */ + public static final int LINK_STATUS_DORMANT = 1; + + /** Indicates the data connection is active with physical link up. */ + public static final int LINK_STATUS_ACTIVE = 2; + + private final @FailCause int mCause; private final int mSuggestedRetryTime; - private final int mCid; - private final int mActive; - private final int mProtocolType; - private final String mIfname; + private final int mId; + private final @LinkStatus int mLinkStatus; + private final @ProtocolType int mProtocolType; + private final String mInterfaceName; private final List mAddresses; - private final List mDnses; - private final List mGateways; - private final List mPcscfs; + private final List mDnsAddresses; + private final List mGatewayAddresses; + private final List mPcscfAddresses; private final int mMtu; /** - * @param status Data call fail cause. 0 indicates no error. + * @param cause Data call fail cause. {@link DataFailCause#NONE} indicates no error. * @param suggestedRetryTime The suggested data retry time in milliseconds. - * @param cid The unique id of the data connection. - * @param active Data connection active status. 0 = inactive, 1 = dormant, 2 = active. + * @param id The unique id of the data connection. + * @param linkStatus Data connection link status. * @param protocolType The connection protocol, should be one of the PDP_type values in 3GPP - * TS 27.007 section 10.1.1. For example, "IP", "IPV6", "IPV4V6", or "PPP". - * @param ifname The network interface name. + * TS 27.007 section 10.1.1. For example, "IP", "IPV6", "IPV4V6", or "PPP". + * @param interfaceName The network interface name. * @param addresses A list of addresses with optional "/" prefix length, e.g., - * "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". Typically 1 IPv4 or 1 IPv6 or - * one of each. If the prefix length is absent the addresses are assumed to be - * point to point with IPv4 having a prefix length of 32 and IPv6 128. - * @param dnses A list of DNS server addresses, e.g., "192.0.1.3" or - * "192.0.1.11 2001:db8::1". Null if no dns server addresses returned. - * @param gateways A list of default gateway addresses, e.g., "192.0.1.3" or - * "192.0.1.11 2001:db8::1". When null, the addresses represent point to point - * connections. - * @param pcscfs A list of Proxy Call State Control Function address via PCO(Protocol - * Configuration Option) for IMS client. - * @param mtu MTU (Maximum transmission unit) received from network Value <= 0 means network has - * either not sent a value or sent an invalid value. + * "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". Typically 1 IPv4 or 1 IPv6 or + * one of each. If the prefix length is absent the addresses are assumed to be + * point to point with IPv4 having a prefix length of 32 and IPv6 128. + * @param dnsAddresses A list of DNS server addresses, e.g., "192.0.1.3" or + * "192.0.1.11 2001:db8::1". Null if no dns server addresses returned. + * @param gatewayAddresses A list of default gateway addresses, e.g., "192.0.1.3" or + * "192.0.1.11 2001:db8::1". When null, the addresses represent point to point connections. + * @param pcscfAddresses A list of Proxy Call State Control Function address via PCO (Protocol + * Configuration Option) for IMS client. + * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or negative + * values means network has either not sent a value or sent an invalid value. + * either not sent a value or sent an invalid value. + * + * @removed Use the {@link Builder()} instead. */ - public DataCallResponse(int status, int suggestedRetryTime, int cid, int active, - @ProtocolType int protocolType, @Nullable String ifname, + public DataCallResponse(@FailCause int cause, int suggestedRetryTime, int id, + @LinkStatus int linkStatus, + @ProtocolType int protocolType, @Nullable String interfaceName, @Nullable List addresses, - @Nullable List dnses, - @Nullable List gateways, - @Nullable List pcscfs, int mtu) { - mStatus = status; + @Nullable List dnsAddresses, + @Nullable List gatewayAddresses, + @Nullable List pcscfAddresses, int mtu) { + mCause = cause; mSuggestedRetryTime = suggestedRetryTime; - mCid = cid; - mActive = active; + mId = id; + mLinkStatus = linkStatus; mProtocolType = protocolType; - mIfname = (ifname == null) ? "" : ifname; - mAddresses = (addresses == null) ? new ArrayList<>() : addresses; - mDnses = (dnses == null) ? new ArrayList<>() : dnses; - mGateways = (gateways == null) ? new ArrayList<>() : gateways; - mPcscfs = (pcscfs == null) ? new ArrayList<>() : pcscfs; + mInterfaceName = (interfaceName == null) ? "" : interfaceName; + mAddresses = (addresses == null) + ? new ArrayList<>() : new ArrayList<>(addresses); + mDnsAddresses = (dnsAddresses == null) + ? new ArrayList<>() : new ArrayList<>(dnsAddresses); + mGatewayAddresses = (gatewayAddresses == null) + ? new ArrayList<>() : new ArrayList<>(gatewayAddresses); + mPcscfAddresses = (pcscfAddresses == null) + ? new ArrayList<>() : new ArrayList<>(pcscfAddresses); mMtu = mtu; } /** @hide */ @VisibleForTesting public DataCallResponse(Parcel source) { - mStatus = source.readInt(); + mCause = source.readInt(); mSuggestedRetryTime = source.readInt(); - mCid = source.readInt(); - mActive = source.readInt(); + mId = source.readInt(); + mLinkStatus = source.readInt(); mProtocolType = source.readInt(); - mIfname = source.readString(); + mInterfaceName = source.readString(); mAddresses = new ArrayList<>(); source.readList(mAddresses, LinkAddress.class.getClassLoader()); - mDnses = new ArrayList<>(); - source.readList(mDnses, InetAddress.class.getClassLoader()); - mGateways = new ArrayList<>(); - source.readList(mGateways, InetAddress.class.getClassLoader()); - mPcscfs = new ArrayList<>(); - source.readList(mPcscfs, InetAddress.class.getClassLoader()); + mDnsAddresses = new ArrayList<>(); + source.readList(mDnsAddresses, InetAddress.class.getClassLoader()); + mGatewayAddresses = new ArrayList<>(); + source.readList(mGatewayAddresses, InetAddress.class.getClassLoader()); + mPcscfAddresses = new ArrayList<>(); + source.readList(mPcscfAddresses, InetAddress.class.getClassLoader()); mMtu = source.readInt(); } /** - * @return Data call fail cause. 0 indicates no error. + * @return Data call fail cause. {@link DataFailCause#NONE} indicates no error. */ - public int getStatus() { return mStatus; } + @FailCause + public int getCause() { return mCause; } /** * @return The suggested data retry time in milliseconds. @@ -125,12 +161,12 @@ public final class DataCallResponse implements Parcelable { /** * @return The unique id of the data connection. */ - public int getCallId() { return mCid; } + public int getId() { return mId; } /** - * @return 0 = inactive, 1 = dormant, 2 = active. + * @return The link status */ - public int getActive() { return mActive; } + @LinkStatus public int getLinkStatus() { return mLinkStatus; } /** * @return The connection protocol type. @@ -139,13 +175,13 @@ public final class DataCallResponse implements Parcelable { public int getProtocolType() { return mProtocolType; } /** - * @return The network interface name. + * @return The network interface name (e.g. "rmnet_data1"). */ @NonNull - public String getIfname() { return mIfname; } + public String getInterfaceName() { return mInterfaceName; } /** - * @return A list of {@link LinkAddress} + * @return A list of addresses of this data connection. */ @NonNull public List getAddresses() { return mAddresses; } @@ -155,25 +191,25 @@ public final class DataCallResponse implements Parcelable { * "192.0.1.11 2001:db8::1". Empty list if no dns server addresses returned. */ @NonNull - public List getDnses() { return mDnses; } + public List getDnsAddresses() { return mDnsAddresses; } /** * @return A list of default gateway addresses, e.g., "192.0.1.3" or * "192.0.1.11 2001:db8::1". Empty list if the addresses represent point to point connections. */ @NonNull - public List getGateways() { return mGateways; } + public List getGatewayAddresses() { return mGatewayAddresses; } /** - * @return A list of Proxy Call State Control Function address via PCO(Protocol Configuration + * @return A list of Proxy Call State Control Function address via PCO (Protocol Configuration * Option) for IMS client. */ @NonNull - public List getPcscfs() { return mPcscfs; } + public List getPcscfAddresses() { return mPcscfAddresses; } /** - * @return MTU received from network Value <= 0 means network has either not sent a value or - * sent an invalid value + * @return MTU (maximum transmission unit) in bytes received from network. Zero or negative + * values means network has either not sent a value or sent an invalid value. */ public int getMtu() { return mMtu; } @@ -181,16 +217,16 @@ public final class DataCallResponse implements Parcelable { public String toString() { StringBuffer sb = new StringBuffer(); sb.append("DataCallResponse: {") - .append(" status=").append(mStatus) + .append(" cause=").append(mCause) .append(" retry=").append(mSuggestedRetryTime) - .append(" cid=").append(mCid) - .append(" active=").append(mActive) + .append(" cid=").append(mId) + .append(" linkStatus=").append(mLinkStatus) .append(" protocolType=").append(mProtocolType) - .append(" ifname=").append(mIfname) + .append(" ifname=").append(mInterfaceName) .append(" addresses=").append(mAddresses) - .append(" dnses=").append(mDnses) - .append(" gateways=").append(mGateways) - .append(" pcscf=").append(mPcscfs) + .append(" dnses=").append(mDnsAddresses) + .append(" gateways=").append(mGatewayAddresses) + .append(" pcscf=").append(mPcscfAddresses) .append(" mtu=").append(mMtu) .append("}"); return sb.toString(); @@ -200,32 +236,33 @@ public final class DataCallResponse implements Parcelable { public boolean equals (Object o) { if (this == o) return true; - if (o == null || !(o instanceof DataCallResponse)) { + if (!(o instanceof DataCallResponse)) { return false; } DataCallResponse other = (DataCallResponse) o; - return this.mStatus == other.mStatus + return this.mCause == other.mCause && this.mSuggestedRetryTime == other.mSuggestedRetryTime - && this.mCid == other.mCid - && this.mActive == other.mActive + && this.mId == other.mId + && this.mLinkStatus == other.mLinkStatus && this.mProtocolType == other.mProtocolType - && this.mIfname.equals(other.mIfname) + && this.mInterfaceName.equals(other.mInterfaceName) && mAddresses.size() == other.mAddresses.size() && mAddresses.containsAll(other.mAddresses) - && mDnses.size() == other.mDnses.size() - && mDnses.containsAll(other.mDnses) - && mGateways.size() == other.mGateways.size() - && mGateways.containsAll(other.mGateways) - && mPcscfs.size() == other.mPcscfs.size() - && mPcscfs.containsAll(other.mPcscfs) + && mDnsAddresses.size() == other.mDnsAddresses.size() + && mDnsAddresses.containsAll(other.mDnsAddresses) + && mGatewayAddresses.size() == other.mGatewayAddresses.size() + && mGatewayAddresses.containsAll(other.mGatewayAddresses) + && mPcscfAddresses.size() == other.mPcscfAddresses.size() + && mPcscfAddresses.containsAll(other.mPcscfAddresses) && mMtu == other.mMtu; } @Override public int hashCode() { - return Objects.hash(mStatus, mSuggestedRetryTime, mCid, mActive, mProtocolType, mIfname, - mAddresses, mDnses, mGateways, mPcscfs, mMtu); + return Objects.hash(mCause, mSuggestedRetryTime, mId, mLinkStatus, mProtocolType, + mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses, mPcscfAddresses, + mMtu); } @Override @@ -235,20 +272,20 @@ public final class DataCallResponse implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mStatus); + dest.writeInt(mCause); dest.writeInt(mSuggestedRetryTime); - dest.writeInt(mCid); - dest.writeInt(mActive); + dest.writeInt(mId); + dest.writeInt(mLinkStatus); dest.writeInt(mProtocolType); - dest.writeString(mIfname); + dest.writeString(mInterfaceName); dest.writeList(mAddresses); - dest.writeList(mDnses); - dest.writeList(mGateways); - dest.writeList(mPcscfs); + dest.writeList(mDnsAddresses); + dest.writeList(mGatewayAddresses); + dest.writeList(mPcscfAddresses); dest.writeInt(mMtu); } - public static final Parcelable.Creator CREATOR = + public static final @NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public DataCallResponse createFromParcel(Parcel source) { @@ -260,4 +297,183 @@ public final class DataCallResponse implements Parcelable { return new DataCallResponse[size]; } }; -} \ No newline at end of file + + /** + * Provides a convenient way to set the fields of a {@link DataCallResponse} when creating a new + * instance. + * + *

The example below shows how you might create a new {@code DataCallResponse}: + * + *


+     *
+     * DataCallResponse response = new DataCallResponse.Builder()
+     *     .setAddresses(Arrays.asList("192.168.1.2"))
+     *     .setProtocolType(ApnSetting.PROTOCOL_IPV4V6)
+     *     .build();
+     * 
+ */ + public static final class Builder { + private @FailCause int mCause; + + private int mSuggestedRetryTime; + + private int mId; + + private @LinkStatus int mLinkStatus; + + private @ProtocolType int mProtocolType; + + private String mInterfaceName; + + private List mAddresses; + + private List mDnsAddresses; + + private List mGatewayAddresses; + + private List mPcscfAddresses; + + private int mMtu; + + /** + * Default constructor for Builder. + */ + public Builder() { + } + + /** + * Set data call fail cause. + * + * @param cause Data call fail cause. {@link DataFailCause#NONE} indicates no error. + * @return The same instance of the builder. + */ + public @NonNull Builder setCause(@FailCause int cause) { + mCause = cause; + return this; + } + + /** + * Set the suggested data retry time. + * + * @param suggestedRetryTime The suggested data retry time in milliseconds. + * @return The same instance of the builder. + */ + public @NonNull Builder setSuggestedRetryTime(int suggestedRetryTime) { + mSuggestedRetryTime = suggestedRetryTime; + return this; + } + + /** + * Set the unique id of the data connection. + * + * @param id The unique id of the data connection. + * @return The same instance of the builder. + */ + public @NonNull Builder setId(int id) { + mId = id; + return this; + } + + /** + * Set the link status + * + * @param linkStatus The link status + * @return The same instance of the builder. + */ + public @NonNull Builder setLinkStatus(@LinkStatus int linkStatus) { + mLinkStatus = linkStatus; + return this; + } + + /** + * Set the connection protocol type. + * + * @param protocolType The connection protocol type. + * @return The same instance of the builder. + */ + public @NonNull Builder setProtocolType(@ProtocolType int protocolType) { + mProtocolType = protocolType; + return this; + } + + /** + * Set the network interface name. + * + * @param interfaceName The network interface name (e.g. "rmnet_data1"). + * @return The same instance of the builder. + */ + public @NonNull Builder setInterfaceName(@NonNull String interfaceName) { + mInterfaceName = interfaceName; + return this; + } + + /** + * Set the addresses of this data connection. + * + * @param addresses The list of address of the data connection. + * @return The same instance of the builder. + */ + public @NonNull Builder setAddresses(@NonNull List addresses) { + mAddresses = addresses; + return this; + } + + /** + * Set the DNS addresses of this data connection + * + * @param dnsAddresses The list of DNS address of the data connection. + * @return The same instance of the builder. + */ + public @NonNull Builder setDnsAddresses(@NonNull List dnsAddresses) { + mDnsAddresses = dnsAddresses; + return this; + } + + /** + * Set the gateway addresses of this data connection + * + * @param gatewayAddresses The list of gateway address of the data connection. + * @return The same instance of the builder. + */ + public @NonNull Builder setGatewayAddresses(@NonNull List gatewayAddresses) { + mGatewayAddresses = gatewayAddresses; + return this; + } + + /** + * Set the Proxy Call State Control Function address via PCO(Protocol Configuration + * Option) for IMS client. + * + * @param pcscfAddresses The list of pcscf address of the data connection. + * @return The same instance of the builder. + */ + public @NonNull Builder setPcscfAddresses(@NonNull List pcscfAddresses) { + mPcscfAddresses = pcscfAddresses; + return this; + } + + /** + * Set maximum transmission unit of the data connection. + * + * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or + * negative values means network has either not sent a value or sent an invalid value. + * + * @return The same instance of the builder. + */ + public @NonNull Builder setMtu(int mtu) { + mMtu = mtu; + return this; + } + + /** + * Build the DataCallResponse. + * + * @return the DataCallResponse object. + */ + public @NonNull DataCallResponse build() { + return new DataCallResponse(mCause, mSuggestedRetryTime, mId, mLinkStatus, + mProtocolType, mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses, + mPcscfAddresses, mMtu); + } + } +} diff --git a/telephony/java/android/telephony/data/DataProfile.java b/telephony/java/android/telephony/data/DataProfile.java index bcb47f73cb4d6..c53ade16cae42 100644 --- a/telephony/java/android/telephony/data/DataProfile.java +++ b/telephony/java/android/telephony/data/DataProfile.java @@ -34,6 +34,7 @@ import com.android.internal.telephony.RILConstants; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Objects; /** * Description of a mobile data profile used for establishing @@ -50,7 +51,7 @@ public final class DataProfile implements Parcelable { TYPE_COMMON, TYPE_3GPP, TYPE_3GPP2}) - public @interface DataProfileType {} + public @interface Type {} /** Common data profile */ public static final int TYPE_COMMON = 0; @@ -75,25 +76,25 @@ public final class DataProfile implements Parcelable { private final String mPassword; - @DataProfileType + @Type private final int mType; - private final int mMaxConnsTime; + private final int mMaxConnectionsTime; - private final int mMaxConns; + private final int mMaxConnections; private final int mWaitTime; private final boolean mEnabled; @ApnType - private final int mSupportedApnTypesBitmap; + private final int mSupportedApnTypesBitmask; @ProtocolType private final int mRoamingProtocolType; @NetworkTypeBitMask - private final int mBearerBitmap; + private final int mBearerBitmask; private final int mMtu; @@ -102,11 +103,13 @@ public final class DataProfile implements Parcelable { private final boolean mPreferred; /** @hide */ - public DataProfile(int profileId, String apn, @ProtocolType int protocolType, int authType, - String userName, String password, int type, int maxConnsTime, int maxConns, - int waitTime, boolean enabled, @ApnType int supportedApnTypesBitmap, - @ProtocolType int roamingProtocolType, @NetworkTypeBitMask int bearerBitmap, - int mtu, boolean persistent, boolean preferred) { + private DataProfile(int profileId, String apn, @ProtocolType int protocolType, int authType, + String userName, String password, int type, int maxConnectionsTime, + int maxConnections, int waitTime, boolean enabled, + @ApnType int supportedApnTypesBitmask, + @ProtocolType int roamingProtocolType, + @NetworkTypeBitMask int bearerBitmask, int mtu, boolean persistent, + boolean preferred) { this.mProfileId = profileId; this.mApn = apn; this.mProtocolType = protocolType; @@ -118,21 +121,19 @@ public final class DataProfile implements Parcelable { this.mUserName = userName; this.mPassword = password; this.mType = type; - this.mMaxConnsTime = maxConnsTime; - this.mMaxConns = maxConns; + this.mMaxConnectionsTime = maxConnectionsTime; + this.mMaxConnections = maxConnections; this.mWaitTime = waitTime; this.mEnabled = enabled; - - this.mSupportedApnTypesBitmap = supportedApnTypesBitmap; + this.mSupportedApnTypesBitmask = supportedApnTypesBitmask; this.mRoamingProtocolType = roamingProtocolType; - this.mBearerBitmap = bearerBitmap; + this.mBearerBitmask = bearerBitmask; this.mMtu = mtu; this.mPersistent = persistent; this.mPreferred = preferred; } - /** @hide */ - public DataProfile(Parcel source) { + private DataProfile(Parcel source) { mProfileId = source.readInt(); mApn = source.readString(); mProtocolType = source.readInt(); @@ -140,13 +141,13 @@ public final class DataProfile implements Parcelable { mUserName = source.readString(); mPassword = source.readString(); mType = source.readInt(); - mMaxConnsTime = source.readInt(); - mMaxConns = source.readInt(); + mMaxConnectionsTime = source.readInt(); + mMaxConnections = source.readInt(); mWaitTime = source.readInt(); mEnabled = source.readBoolean(); - mSupportedApnTypesBitmap = source.readInt(); + mSupportedApnTypesBitmask = source.readInt(); mRoamingProtocolType = source.readInt(); - mBearerBitmap = source.readInt(); + mBearerBitmask = source.readInt(); mMtu = source.readInt(); mPersistent = source.readBoolean(); mPreferred = source.readBoolean(); @@ -158,7 +159,8 @@ public final class DataProfile implements Parcelable { public int getProfileId() { return mProfileId; } /** - * @return The APN to establish data connection. + * @return The APN (Access Point Name) to establish data connection. This is a string + * specifically defined by the carrier. */ @NonNull public String getApn() { return mApn; } @@ -166,7 +168,7 @@ public final class DataProfile implements Parcelable { /** * @return The connection protocol defined in 3GPP TS 27.007 section 10.1.1. */ - public @ProtocolType int getProtocol() { return mProtocolType; } + public @ProtocolType int getProtocolType() { return mProtocolType; } /** * @return The authentication protocol used for this PDP context. @@ -188,22 +190,28 @@ public final class DataProfile implements Parcelable { /** * @return The profile type. */ - public @DataProfileType int getType() { return mType; } + public @Type int getType() { return mType; } /** * @return The period in seconds to limit the maximum connections. + * + * @hide */ - public int getMaxConnsTime() { return mMaxConnsTime; } + public int getMaxConnectionsTime() { return mMaxConnectionsTime; } /** * @return The maximum connections allowed. + * + * @hide */ - public int getMaxConns() { return mMaxConns; } + public int getMaxConnections() { return mMaxConnections; } /** * @return The required wait time in seconds after a successful UE initiated disconnect of a * given PDN connection before the device can send a new PDN connection request for that given * PDN. + * + * @hide */ public int getWaitTime() { return mWaitTime; } @@ -213,19 +221,19 @@ public final class DataProfile implements Parcelable { public boolean isEnabled() { return mEnabled; } /** - * @return The supported APN types bitmap. + * @return The supported APN types bitmask. */ - public @ApnType int getSupportedApnTypesBitmap() { return mSupportedApnTypesBitmap; } + public @ApnType int getSupportedApnTypesBitmask() { return mSupportedApnTypesBitmask; } /** * @return The connection protocol on roaming network defined in 3GPP TS 27.007 section 10.1.1. */ - public @ProtocolType int getRoamingProtocol() { return mRoamingProtocolType; } + public @ProtocolType int getRoamingProtocolType() { return mRoamingProtocolType; } /** - * @return The bearer bitmap indicating the applicable networks for this data profile. + * @return The bearer bitmask indicating the applicable networks for this data profile. */ - public @NetworkTypeBitMask int getBearerBitmap() { return mBearerBitmap; } + public @NetworkTypeBitMask int getBearerBitmask() { return mBearerBitmask; } /** * @return The maximum transmission unit (MTU) size in bytes. @@ -239,7 +247,8 @@ public final class DataProfile implements Parcelable { /** * @return {@code true} if this data profile was used to bring up the last default - * (i.e internet) data connection successfully. + * (i.e internet) data connection successfully, or the one chosen by the user in Settings' + * APN editor. For one carrier there can be only one profiled preferred. */ public boolean isPreferred() { return mPreferred; } @@ -253,18 +262,12 @@ public final class DataProfile implements Parcelable { return "DataProfile=" + mProfileId + "/" + mProtocolType + "/" + mAuthType + "/" + (Build.IS_USER ? "***/***/***" : (mApn + "/" + mUserName + "/" + mPassword)) + "/" + mType + "/" - + mMaxConnsTime + "/" + mMaxConns + "/" - + mWaitTime + "/" + mEnabled + "/" + mSupportedApnTypesBitmap + "/" - + mRoamingProtocolType + "/" + mBearerBitmap + "/" + mMtu + "/" + mPersistent + "/" + + mMaxConnectionsTime + "/" + mMaxConnections + "/" + + mWaitTime + "/" + mEnabled + "/" + mSupportedApnTypesBitmask + "/" + + mRoamingProtocolType + "/" + mBearerBitmask + "/" + mMtu + "/" + mPersistent + "/" + mPreferred; } - @Override - public boolean equals(Object o) { - if (o instanceof DataProfile == false) return false; - return (o == this || toString().equals(o.toString())); - } - @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mProfileId); @@ -274,13 +277,13 @@ public final class DataProfile implements Parcelable { dest.writeString(mUserName); dest.writeString(mPassword); dest.writeInt(mType); - dest.writeInt(mMaxConnsTime); - dest.writeInt(mMaxConns); + dest.writeInt(mMaxConnectionsTime); + dest.writeInt(mMaxConnections); dest.writeInt(mWaitTime); dest.writeBoolean(mEnabled); - dest.writeInt(mSupportedApnTypesBitmap); + dest.writeInt(mSupportedApnTypesBitmask); dest.writeInt(mRoamingProtocolType); - dest.writeInt(mBearerBitmap); + dest.writeInt(mBearerBitmask); dest.writeInt(mMtu); dest.writeBoolean(mPersistent); dest.writeBoolean(mPreferred); @@ -298,4 +301,312 @@ public final class DataProfile implements Parcelable { return new DataProfile[size]; } }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DataProfile that = (DataProfile) o; + return mProfileId == that.mProfileId + && mProtocolType == that.mProtocolType + && mAuthType == that.mAuthType + && mType == that.mType + && mMaxConnectionsTime == that.mMaxConnectionsTime + && mMaxConnections == that.mMaxConnections + && mWaitTime == that.mWaitTime + && mEnabled == that.mEnabled + && mSupportedApnTypesBitmask == that.mSupportedApnTypesBitmask + && mRoamingProtocolType == that.mRoamingProtocolType + && mBearerBitmask == that.mBearerBitmask + && mMtu == that.mMtu + && mPersistent == that.mPersistent + && mPreferred == that.mPreferred + && Objects.equals(mApn, that.mApn) + && Objects.equals(mUserName, that.mUserName) + && Objects.equals(mPassword, that.mPassword); + } + + @Override + public int hashCode() { + return Objects.hash(mProfileId, mApn, mProtocolType, mAuthType, mUserName, mPassword, mType, + mMaxConnectionsTime, mMaxConnections, mWaitTime, mEnabled, + mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtu, mPersistent, + mPreferred); + } + + /** + * Provides a convenient way to set the fields of a {@link DataProfile} when creating a new + * instance. + * + *

The example below shows how you might create a new {@code DataProfile}: + * + *


+     *
+     * DataProfile dp = new DataProfile.Builder()
+     *     .setApn("apn.xyz.com")
+     *     .setProtocol(ApnSetting.PROTOCOL_IPV4V6)
+     *     .build();
+     * 
+ */ + public static final class Builder { + private int mProfileId; + + private String mApn; + + @ProtocolType + private int mProtocolType; + + @AuthType + private int mAuthType; + + private String mUserName; + + private String mPassword; + + @Type + private int mType; + + private int mMaxConnectionsTime; + + private int mMaxConnections; + + private int mWaitTime; + + private boolean mEnabled; + + @ApnType + private int mSupportedApnTypesBitmask; + + @ProtocolType + private int mRoamingProtocolType; + + @NetworkTypeBitMask + private int mBearerBitmask; + + private int mMtu; + + private boolean mPersistent; + + private boolean mPreferred; + + /** + * Default constructor for Builder. + */ + public Builder() { + } + + /** + * Set profile id. Note that this is not a global unique id of the data profile. This id + * is only used by certain CDMA carriers to identify the type of data profile. + * + * @param profileId Network domain. + * @return The same instance of the builder. + */ + public @NonNull Builder setProfileId(int profileId) { + mProfileId = profileId; + return this; + } + + /** + * Set the APN (Access Point Name) to establish data connection. This is a string + * specifically defined by the carrier. + * + * @param apn Access point name + * @return The same instance of the builder. + */ + public @NonNull Builder setApn(@NonNull String apn) { + mApn = apn; + return this; + } + + /** + * Set the connection protocol type. + * + * @param protocolType The connection protocol defined in 3GPP TS 27.007 section 10.1.1. + * @return The same instance of the builder. + */ + public @NonNull Builder setProtocolType(@ProtocolType int protocolType) { + mProtocolType = protocolType; + return this; + } + + /** + * Set the authentication type. + * + * @param authType The authentication type + * @return The same instance of the builder. + */ + public @NonNull Builder setAuthType(@AuthType int authType) { + mAuthType = authType; + return this; + } + + /** + * Set the user name + * + * @param userName The user name + * @return The same instance of the builder. + */ + public @NonNull Builder setUserName(@NonNull String userName) { + mUserName = userName; + return this; + } + + /** + * Set the password + * + * @param password The password + * @return The same instance of the builder. + */ + public @NonNull Builder setPassword(@NonNull String password) { + mPassword = password; + return this; + } + + /** + * Set the type + * + * @param type The profile type + * @return The same instance of the builder. + */ + public @NonNull Builder setType(@Type int type) { + mType = type; + return this; + } + + /** + * Set the period in seconds to limit the maximum connections. + * + * @param maxConnectionsTime The profile type + * @return The same instance of the builder. + * + * @hide + */ + public @NonNull Builder setMaxConnectionsTime(int maxConnectionsTime) { + mMaxConnectionsTime = maxConnectionsTime; + return this; + } + + /** + * Set the maximum connections allowed. + * + * @param maxConnections The maximum connections allowed. + * @return The same instance of the builder. + * + * @hide + */ + public @NonNull Builder setMaxConnections(int maxConnections) { + mMaxConnections = maxConnections; + return this; + } + + /** + * Set the period in seconds to limit the maximum connections. + * + * @param waitTime The required wait time in seconds after a successful UE initiated + * disconnect of a given PDN connection before the device can send a new PDN connection + * request for that given PDN. + * + * @return The same instance of the builder. + * + * @hide + */ + public @NonNull Builder setWaitTime(int waitTime) { + mWaitTime = waitTime; + return this; + } + + /** + * Enable the data profile + * + * @param isEnabled {@code true} to enable the data profile, otherwise disable. + * @return The same instance of the builder. + */ + public @NonNull Builder enable(boolean isEnabled) { + mEnabled = isEnabled; + return this; + } + + /** + * Set the supported APN types bitmask. + * + * @param supportedApnTypesBitmask The supported APN types bitmask. + * @return The same instance of the builder. + */ + public @NonNull Builder setSupportedApnTypesBitmask(@ApnType int supportedApnTypesBitmask) { + mSupportedApnTypesBitmask = supportedApnTypesBitmask; + return this; + } + + /** + * Set the connection protocol type for roaming. + * + * @param protocolType The connection protocol defined in 3GPP TS 27.007 section 10.1.1. + * @return The same instance of the builder. + */ + public @NonNull Builder setRoamingProtocolType(@ProtocolType int protocolType) { + mRoamingProtocolType = protocolType; + return this; + } + + /** + * Set the bearer bitmask indicating the applicable networks for this data profile. + * + * @param bearerBitmask The bearer bitmask indicating the applicable networks for this data + * profile. + * @return The same instance of the builder. + */ + public @NonNull Builder setBearerBitmask(@NetworkTypeBitMask int bearerBitmask) { + mBearerBitmask = bearerBitmask; + return this; + } + + /** + * Set the maximum transmission unit (MTU) size in bytes. + * + * @param mtu The maximum transmission unit (MTU) size in bytes. + * @return The same instance of the builder. + */ + public @NonNull Builder setMtu(int mtu) { + mMtu = mtu; + return this; + } + + /** + * Set data profile as preferred/non-preferred. + * + * @param isPreferred {@code true} if this data profile was used to bring up the last + * default (i.e internet) data connection successfully, or the one chosen by the user in + * Settings' APN editor. For one carrier there can be only one profiled preferred. + * @return The same instance of the builder. + */ + public @NonNull Builder setPreferred(boolean isPreferred) { + mPreferred = isPreferred; + return this; + } + + /** + * Set data profile as persistent/non-persistent + * + * @param isPersistent {@code true} if this data profile was used to bring up the last + * default (i.e internet) data connection successfully. + * @return The same instance of the builder. + */ + public @NonNull Builder setPersistent(boolean isPersistent) { + mPersistent = isPersistent; + return this; + } + + /** + * Build the DataProfile object + * + * @return The data profile object + */ + public @NonNull DataProfile build() { + return new DataProfile(mProfileId, mApn, mProtocolType, mAuthType, mUserName, mPassword, + mType, mMaxConnectionsTime, mMaxConnections, mWaitTime, mEnabled, + mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtu, + mPersistent, mPreferred); + } + } } diff --git a/telephony/java/android/telephony/data/DataService.java b/telephony/java/android/telephony/data/DataService.java index 59d1e1e7115af..372bdf1c0f812 100644 --- a/telephony/java/android/telephony/data/DataService.java +++ b/telephony/java/android/telephony/data/DataService.java @@ -19,6 +19,7 @@ package android.telephony.data; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SdkConstant; import android.annotation.SystemApi; import android.app.Service; import android.content.Intent; @@ -58,10 +59,12 @@ import java.util.List; public abstract class DataService extends Service { private static final String TAG = DataService.class.getSimpleName(); - public static final String DATA_SERVICE_INTERFACE = "android.telephony.data.DataService"; + @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) + public static final String SERVICE_INTERFACE = "android.telephony.data.DataService"; /** {@hide} */ @IntDef(prefix = "REQUEST_REASON_", value = { + REQUEST_REASON_UNKNOWN, REQUEST_REASON_NORMAL, REQUEST_REASON_HANDOVER, }) @@ -70,6 +73,7 @@ public abstract class DataService extends Service { /** {@hide} */ @IntDef(prefix = "REQUEST_REASON_", value = { + REQUEST_REASON_UNKNOWN, REQUEST_REASON_NORMAL, REQUEST_REASON_SHUTDOWN, REQUEST_REASON_HANDOVER, @@ -77,6 +81,8 @@ public abstract class DataService extends Service { @Retention(RetentionPolicy.SOURCE) public @interface DeactivateDataReason {} + /** The reason of the data request is unknown */ + public static final int REQUEST_REASON_UNKNOWN = 0; /** The reason of the data request is normal */ public static final int REQUEST_REASON_NORMAL = 1; @@ -94,7 +100,7 @@ public abstract class DataService extends Service { private static final int DATA_SERVICE_REQUEST_DEACTIVATE_DATA_CALL = 5; private static final int DATA_SERVICE_REQUEST_SET_INITIAL_ATTACH_APN = 6; private static final int DATA_SERVICE_REQUEST_SET_DATA_PROFILE = 7; - private static final int DATA_SERVICE_REQUEST_GET_DATA_CALL_LIST = 8; + private static final int DATA_SERVICE_REQUEST_REQUEST_DATA_CALL_LIST = 8; private static final int DATA_SERVICE_REQUEST_REGISTER_DATA_CALL_LIST_CHANGED = 9; private static final int DATA_SERVICE_REQUEST_UNREGISTER_DATA_CALL_LIST_CHANGED = 10; private static final int DATA_SERVICE_INDICATION_DATA_CALL_LIST_CHANGED = 11; @@ -149,14 +155,13 @@ public abstract class DataService extends Service { * {@link #REQUEST_REASON_HANDOVER}. * @param linkProperties If {@code reason} is {@link #REQUEST_REASON_HANDOVER}, this is the * link properties of the existing data connection, otherwise null. - * @param callback The result callback for this request. Null if the client does not care - * about the result. + * @param callback The result callback for this request. */ public void setupDataCall(int accessNetworkType, @NonNull DataProfile dataProfile, boolean isRoaming, boolean allowRoaming, @SetupDataReason int reason, @Nullable LinkProperties linkProperties, - @Nullable DataServiceCallback callback) { + @NonNull DataServiceCallback callback) { // The default implementation is to return unsupported. if (callback != null) { callback.onSetupDataCallComplete(DataServiceCallback.RESULT_ERROR_UNSUPPORTED, @@ -190,11 +195,10 @@ public abstract class DataService extends Service { * * @param dataProfile Data profile used for data call setup. See {@link DataProfile}. * @param isRoaming True if the device is data roaming. - * @param callback The result callback for this request. Null if the client does not care - * about the result. + * @param callback The result callback for this request. */ public void setInitialAttachApn(@NonNull DataProfile dataProfile, boolean isRoaming, - @Nullable DataServiceCallback callback) { + @NonNull DataServiceCallback callback) { // The default implementation is to return unsupported. if (callback != null) { callback.onSetInitialAttachApnComplete( @@ -209,11 +213,10 @@ public abstract class DataService extends Service { * * @param dps A list of data profiles. * @param isRoaming True if the device is data roaming. - * @param callback The result callback for this request. Null if the client does not care - * about the result. + * @param callback The result callback for this request. */ public void setDataProfile(@NonNull List dps, boolean isRoaming, - @Nullable DataServiceCallback callback) { + @NonNull DataServiceCallback callback) { // The default implementation is to return unsupported. if (callback != null) { callback.onSetDataProfileComplete(DataServiceCallback.RESULT_ERROR_UNSUPPORTED); @@ -225,9 +228,10 @@ public abstract class DataService extends Service { * * @param callback The result callback for this request. */ - public void getDataCallList(@NonNull DataServiceCallback callback) { + public void requestDataCallList(@NonNull DataServiceCallback callback) { // The default implementation is to return unsupported. - callback.onGetDataCallListComplete(DataServiceCallback.RESULT_ERROR_UNSUPPORTED, null); + callback.onRequestDataCallListComplete(DataServiceCallback.RESULT_ERROR_UNSUPPORTED, + null); } private void registerForDataCallListChanged(IDataServiceCallback callback) { @@ -409,10 +413,10 @@ public abstract class DataService extends Service { ? new DataServiceCallback(setDataProfileRequest.callback) : null); break; - case DATA_SERVICE_REQUEST_GET_DATA_CALL_LIST: + case DATA_SERVICE_REQUEST_REQUEST_DATA_CALL_LIST: if (serviceProvider == null) break; - serviceProvider.getDataCallList(new DataServiceCallback( + serviceProvider.requestDataCallList(new DataServiceCallback( (IDataServiceCallback) message.obj)); break; case DATA_SERVICE_REQUEST_REGISTER_DATA_CALL_LIST_CHANGED: @@ -455,14 +459,14 @@ public abstract class DataService extends Service { * will call this method after binding the data service for each active SIM slot id. * * @param slotIndex SIM slot id the data service associated with. - * @return Data service object + * @return Data service object. Null if failed to create the provider (e.g. invalid slot index) */ @Nullable public abstract DataServiceProvider onCreateDataServiceProvider(int slotIndex); @Override public IBinder onBind(Intent intent) { - if (intent == null || !DATA_SERVICE_INTERFACE.equals(intent.getAction())) { + if (intent == null || !SERVICE_INTERFACE.equals(intent.getAction())) { loge("Unexpected intent " + intent); return null; } @@ -531,12 +535,12 @@ public abstract class DataService extends Service { } @Override - public void getDataCallList(int slotIndex, IDataServiceCallback callback) { + public void requestDataCallList(int slotIndex, IDataServiceCallback callback) { if (callback == null) { - loge("getDataCallList: callback is null"); + loge("requestDataCallList: callback is null"); return; } - mHandler.obtainMessage(DATA_SERVICE_REQUEST_GET_DATA_CALL_LIST, slotIndex, 0, + mHandler.obtainMessage(DATA_SERVICE_REQUEST_REQUEST_DATA_CALL_LIST, slotIndex, 0, callback).sendToTarget(); } diff --git a/telephony/java/android/telephony/data/DataServiceCallback.java b/telephony/java/android/telephony/data/DataServiceCallback.java index 2d0cfe80366c8..5d8d79367ba4f 100644 --- a/telephony/java/android/telephony/data/DataServiceCallback.java +++ b/telephony/java/android/telephony/data/DataServiceCallback.java @@ -140,21 +140,21 @@ public class DataServiceCallback { } /** - * Called to indicate result for the request {@link DataServiceProvider#getDataCallList( + * Called to indicate result for the request {@link DataServiceProvider#requestDataCallList( * DataServiceCallback)}. * * @param result The result code. Must be one of the {@link ResultCode}. * @param dataCallList List of the current active data connection. If no data call is presented, * set it to an empty list. */ - public void onGetDataCallListComplete(@ResultCode int result, - @NonNull List dataCallList) { + public void onRequestDataCallListComplete(@ResultCode int result, + @NonNull List dataCallList) { IDataServiceCallback callback = mCallback.get(); if (callback != null) { try { - callback.onGetDataCallListComplete(result, dataCallList); + callback.onRequestDataCallListComplete(result, dataCallList); } catch (RemoteException e) { - Rlog.e(TAG, "Failed to onGetDataCallListComplete on the remote"); + Rlog.e(TAG, "Failed to onRequestDataCallListComplete on the remote"); } } } diff --git a/telephony/java/android/telephony/data/IDataService.aidl b/telephony/java/android/telephony/data/IDataService.aidl index d4d9be85ffa88..9c74dcccec54f 100644 --- a/telephony/java/android/telephony/data/IDataService.aidl +++ b/telephony/java/android/telephony/data/IDataService.aidl @@ -35,7 +35,7 @@ oneway interface IDataService IDataServiceCallback callback); void setDataProfile(int slotId, in List dps, boolean isRoaming, IDataServiceCallback callback); - void getDataCallList(int slotId, IDataServiceCallback callback); + void requestDataCallList(int slotId, IDataServiceCallback callback); void registerForDataCallListChanged(int slotId, IDataServiceCallback callback); void unregisterForDataCallListChanged(int slotId, IDataServiceCallback callback); } diff --git a/telephony/java/android/telephony/data/IDataServiceCallback.aidl b/telephony/java/android/telephony/data/IDataServiceCallback.aidl index 856185b2974fb..cec757d239882 100644 --- a/telephony/java/android/telephony/data/IDataServiceCallback.aidl +++ b/telephony/java/android/telephony/data/IDataServiceCallback.aidl @@ -28,6 +28,6 @@ oneway interface IDataServiceCallback void onDeactivateDataCallComplete(int result); void onSetInitialAttachApnComplete(int result); void onSetDataProfileComplete(int result); - void onGetDataCallListComplete(int result, in List dataCallList); + void onRequestDataCallListComplete(int result, in List dataCallList); void onDataCallListChanged(in List dataCallList); } diff --git a/telephony/java/android/telephony/data/IQualifiedNetworksService.aidl b/telephony/java/android/telephony/data/IQualifiedNetworksService.aidl index 9c80cb77e4351..3bf09bc197888 100644 --- a/telephony/java/android/telephony/data/IQualifiedNetworksService.aidl +++ b/telephony/java/android/telephony/data/IQualifiedNetworksService.aidl @@ -23,6 +23,6 @@ import android.telephony.data.IQualifiedNetworksServiceCallback; */ interface IQualifiedNetworksService { - oneway void createNetworkAvailabilityUpdater(int slotId, IQualifiedNetworksServiceCallback callback); - oneway void removeNetworkAvailabilityUpdater(int slotId); + oneway void createNetworkAvailabilityProvider(int slotId, IQualifiedNetworksServiceCallback callback); + oneway void removeNetworkAvailabilityProvider(int slotId); } diff --git a/telephony/java/android/telephony/data/QualifiedNetworksService.java b/telephony/java/android/telephony/data/QualifiedNetworksService.java index c38f2788ca929..0e1751d509494 100644 --- a/telephony/java/android/telephony/data/QualifiedNetworksService.java +++ b/telephony/java/android/telephony/data/QualifiedNetworksService.java @@ -17,7 +17,6 @@ package android.telephony.data; import android.annotation.NonNull; -import android.annotation.Nullable; import android.annotation.SystemApi; import android.app.Service; import android.content.Intent; @@ -34,14 +33,21 @@ import android.util.SparseArray; import com.android.internal.annotations.VisibleForTesting; +import java.util.List; + /** - * Base class of the qualified networks service. Services that extend QualifiedNetworksService must - * register the service in their AndroidManifest to be detected by the framework. They must be - * protected by the permission "android.permission.BIND_TELEPHONY_QUALIFIED_NETWORKS_SERVICE". - * The qualified networks service definition in the manifest must follow the following format: + * Base class of the qualified networks service, which is a vendor service providing up-to-date + * qualified network information to the frameworks for data handover control. A qualified network + * is defined as an access network that is ready for bringing up data connection for given APN + * types. + * + * Services that extend QualifiedNetworksService must register the service in their AndroidManifest + * to be detected by the framework. They must be protected by the permission + * "android.permission.BIND_TELEPHONY_DATA_SERVICE". The qualified networks service definition in + * the manifest must follow the following format: * ... * + * android:permission="android.permission.BIND_TELEPHONY_DATA_SERVICE" > * * * @@ -55,28 +61,28 @@ public abstract class QualifiedNetworksService extends Service { public static final String QUALIFIED_NETWORKS_SERVICE_INTERFACE = "android.telephony.data.QualifiedNetworksService"; - private static final int QNS_CREATE_NETWORK_AVAILABILITY_UPDATER = 1; - private static final int QNS_REMOVE_NETWORK_AVAILABILITY_UPDATER = 2; - private static final int QNS_REMOVE_ALL_NETWORK_AVAILABILITY_UPDATERS = 3; + private static final int QNS_CREATE_NETWORK_AVAILABILITY_PROVIDER = 1; + private static final int QNS_REMOVE_NETWORK_AVAILABILITY_PROVIDER = 2; + private static final int QNS_REMOVE_ALL_NETWORK_AVAILABILITY_PROVIDERS = 3; private static final int QNS_UPDATE_QUALIFIED_NETWORKS = 4; private final HandlerThread mHandlerThread; private final QualifiedNetworksServiceHandler mHandler; - private final SparseArray mUpdaters = new SparseArray<>(); + private final SparseArray mProviders = new SparseArray<>(); /** @hide */ @VisibleForTesting public final IQualifiedNetworksServiceWrapper mBinder = new IQualifiedNetworksServiceWrapper(); /** - * The abstract class of the network availability updater implementation. The vendor qualified + * The abstract class of the network availability provider implementation. The vendor qualified * network service must extend this class to report the available networks for data - * connection setup. Note that each instance of network availability updater is associated with + * connection setup. Note that each instance of network availability provider is associated with * one physical SIM slot. */ - public abstract class NetworkAvailabilityUpdater implements AutoCloseable { + public abstract class NetworkAvailabilityProvider implements AutoCloseable { private final int mSlotIndex; private IQualifiedNetworksServiceCallback mCallback; @@ -89,14 +95,14 @@ public abstract class QualifiedNetworksService extends Service { /** * Constructor - * @param slotIndex SIM slot index the network availability updater associated with. + * @param slotIndex SIM slot index the network availability provider associated with. */ - public NetworkAvailabilityUpdater(int slotIndex) { + public NetworkAvailabilityProvider(int slotIndex) { mSlotIndex = slotIndex; } /** - * @return SIM slot index the network availability updater associated with. + * @return SIM slot index the network availability provider associated with. */ public final int getSlotIndex() { return mSlotIndex; @@ -121,7 +127,7 @@ public abstract class QualifiedNetworksService extends Service { } /** - * Update the qualified networks list. Network availability updater must invoke this method + * Update the qualified networks list. Network availability provider must invoke this method * whenever the qualified networks changes. If this method is never invoked for certain * APN types, then frameworks will always use the default (i.e. cellular) data and network * service. @@ -129,14 +135,16 @@ public abstract class QualifiedNetworksService extends Service { * @param apnTypes APN types of the qualified networks. This must be a bitmask combination * of {@link ApnSetting.ApnType}. * @param qualifiedNetworkTypes List of network types which are qualified for data - * connection setup for {@link @apnType} in the preferred order. Each element in the array - * is a {@link AccessNetworkType}. An empty list or null indicates no networks are qualified + * connection setup for {@link @apnType} in the preferred order. Each element in the list + * is a {@link AccessNetworkType}. An empty list indicates no networks are qualified * for data setup. */ - public final void updateQualifiedNetworkTypes(@ApnType int apnTypes, - @Nullable int[] qualifiedNetworkTypes) { + public final void updateQualifiedNetworkTypes( + @ApnType int apnTypes, @NonNull List qualifiedNetworkTypes) { + int[] qualifiedNetworkTypesArray = + qualifiedNetworkTypes.stream().mapToInt(i->i).toArray(); mHandler.obtainMessage(QNS_UPDATE_QUALIFIED_NETWORKS, mSlotIndex, apnTypes, - qualifiedNetworkTypes).sendToTarget(); + qualifiedNetworkTypesArray).sendToTarget(); } private void onUpdateQualifiedNetworkTypes(@ApnType int apnTypes, @@ -152,7 +160,7 @@ public abstract class QualifiedNetworksService extends Service { } /** - * Called when the qualified networks updater is removed. The extended class should + * Called when the qualified networks provider is removed. The extended class should * implement this method to perform cleanup works. */ @Override @@ -168,48 +176,48 @@ public abstract class QualifiedNetworksService extends Service { public void handleMessage(Message message) { IQualifiedNetworksServiceCallback callback; final int slotIndex = message.arg1; - NetworkAvailabilityUpdater updater = mUpdaters.get(slotIndex); + NetworkAvailabilityProvider provider = mProviders.get(slotIndex); switch (message.what) { - case QNS_CREATE_NETWORK_AVAILABILITY_UPDATER: - if (mUpdaters.get(slotIndex) != null) { - loge("Network availability updater for slot " + slotIndex + case QNS_CREATE_NETWORK_AVAILABILITY_PROVIDER: + if (mProviders.get(slotIndex) != null) { + loge("Network availability provider for slot " + slotIndex + " already existed."); return; } - updater = createNetworkAvailabilityUpdater(slotIndex); - if (updater != null) { - mUpdaters.put(slotIndex, updater); + provider = onCreateNetworkAvailabilityProvider(slotIndex); + if (provider != null) { + mProviders.put(slotIndex, provider); callback = (IQualifiedNetworksServiceCallback) message.obj; - updater.registerForQualifiedNetworkTypesChanged(callback); + provider.registerForQualifiedNetworkTypesChanged(callback); } else { - loge("Failed to create network availability updater. slot index = " + loge("Failed to create network availability provider. slot index = " + slotIndex); } break; - case QNS_REMOVE_NETWORK_AVAILABILITY_UPDATER: - if (updater != null) { - updater.close(); - mUpdaters.remove(slotIndex); + case QNS_REMOVE_NETWORK_AVAILABILITY_PROVIDER: + if (provider != null) { + provider.close(); + mProviders.remove(slotIndex); } break; - case QNS_REMOVE_ALL_NETWORK_AVAILABILITY_UPDATERS: - for (int i = 0; i < mUpdaters.size(); i++) { - updater = mUpdaters.get(i); - if (updater != null) { - updater.close(); + case QNS_REMOVE_ALL_NETWORK_AVAILABILITY_PROVIDERS: + for (int i = 0; i < mProviders.size(); i++) { + provider = mProviders.get(i); + if (provider != null) { + provider.close(); } } - mUpdaters.clear(); + mProviders.clear(); break; case QNS_UPDATE_QUALIFIED_NETWORKS: - if (updater == null) break; - updater.onUpdateQualifiedNetworkTypes(message.arg2, (int[]) message.obj); + if (provider == null) break; + provider.onUpdateQualifiedNetworkTypes(message.arg2, (int[]) message.obj); break; } } @@ -227,8 +235,8 @@ public abstract class QualifiedNetworksService extends Service { } /** - * Create the instance of {@link NetworkAvailabilityUpdater}. Vendor qualified network service - * must override this method to facilitate the creation of {@link NetworkAvailabilityUpdater} + * Create the instance of {@link NetworkAvailabilityProvider}. Vendor qualified network service + * must override this method to facilitate the creation of {@link NetworkAvailabilityProvider} * instances. The system will call this method after binding the qualified networks service for * each active SIM slot index. * @@ -236,7 +244,7 @@ public abstract class QualifiedNetworksService extends Service { * @return Qualified networks service instance */ @NonNull - public abstract NetworkAvailabilityUpdater createNetworkAvailabilityUpdater(int slotIndex); + public abstract NetworkAvailabilityProvider onCreateNetworkAvailabilityProvider(int slotIndex); /** @hide */ @Override @@ -251,7 +259,7 @@ public abstract class QualifiedNetworksService extends Service { /** @hide */ @Override public boolean onUnbind(Intent intent) { - mHandler.obtainMessage(QNS_REMOVE_ALL_NETWORK_AVAILABILITY_UPDATERS).sendToTarget(); + mHandler.obtainMessage(QNS_REMOVE_ALL_NETWORK_AVAILABILITY_PROVIDERS).sendToTarget(); return false; } @@ -267,15 +275,15 @@ public abstract class QualifiedNetworksService extends Service { */ private class IQualifiedNetworksServiceWrapper extends IQualifiedNetworksService.Stub { @Override - public void createNetworkAvailabilityUpdater(int slotIndex, - IQualifiedNetworksServiceCallback callback) { - mHandler.obtainMessage(QNS_CREATE_NETWORK_AVAILABILITY_UPDATER, slotIndex, 0, + public void createNetworkAvailabilityProvider(int slotIndex, + IQualifiedNetworksServiceCallback callback) { + mHandler.obtainMessage(QNS_CREATE_NETWORK_AVAILABILITY_PROVIDER, slotIndex, 0, callback).sendToTarget(); } @Override - public void removeNetworkAvailabilityUpdater(int slotIndex) { - mHandler.obtainMessage(QNS_REMOVE_NETWORK_AVAILABILITY_UPDATER, slotIndex, 0) + public void removeNetworkAvailabilityProvider(int slotIndex) { + mHandler.obtainMessage(QNS_REMOVE_NETWORK_AVAILABILITY_PROVIDER, slotIndex, 0) .sendToTarget(); } }