From a335880efee8fcb7c1d03fcb17553c78a9997ffa Mon Sep 17 00:00:00 2001 From: danielwbhuang Date: Mon, 11 Mar 2019 11:52:10 +0800 Subject: [PATCH] Modify API return type and add callback. 1. Modify the type from boolean to void for updateAvailableNetworks(). 2. Adding callback for updateAvailableNetworks(). 3. Define error codes for update available networks results. Test: build pass Bug: 124616182 Merged-In: I32fe1407deabe36485227ec75931bec334d85abe Change-Id: I32fe1407deabe36485227ec75931bec334d85abe --- Android.bp | 1 + api/current.txt | 7 +- .../telephony/SubscriptionManager.java | 3 +- .../android/telephony/TelephonyManager.java | 77 ++++++++++++++++--- .../com/android/internal/telephony/IOns.aidl | 7 +- .../IUpdateAvailableNetworksCallback.aidl | 25 ++++++ 6 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 telephony/java/com/android/internal/telephony/IUpdateAvailableNetworksCallback.aidl diff --git a/Android.bp b/Android.bp index b099babcf4fcd..aff62eb925f20 100644 --- a/Android.bp +++ b/Android.bp @@ -558,6 +558,7 @@ java_defaults { "telephony/java/com/android/internal/telephony/IOns.aidl", "telephony/java/com/android/internal/telephony/ITelephony.aidl", "telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl", + "telephony/java/com/android/internal/telephony/IUpdateAvailableNetworksCallback.aidl", "telephony/java/com/android/internal/telephony/IWapPushManager.aidl", "telephony/java/com/android/internal/telephony/euicc/IAuthenticateServerCallback.aidl", "telephony/java/com/android/internal/telephony/euicc/ICancelSessionCallback.aidl", diff --git a/api/current.txt b/api/current.txt index 55f885cdf7af6..e6687e8bf89f1 100755 --- a/api/current.txt +++ b/api/current.txt @@ -43123,7 +43123,7 @@ package android.telephony { method @Deprecated public void setVoicemailRingtoneUri(android.telecom.PhoneAccountHandle, android.net.Uri); method @Deprecated public void setVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void switchMultiSimConfig(int); - method public boolean updateAvailableNetworks(java.util.List); + method public void updateAvailableNetworks(@NonNull java.util.List, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.Consumer); field public static final String ACTION_CONFIGURE_VOICEMAIL = "android.telephony.action.CONFIGURE_VOICEMAIL"; field public static final String ACTION_NETWORK_COUNTRY_CHANGED = "android.telephony.action.NETWORK_COUNTRY_CHANGED"; field @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final String ACTION_PHONE_STATE_CHANGED = "android.intent.action.PHONE_STATE"; @@ -43215,6 +43215,11 @@ package android.telephony { field public static final int UNINITIALIZED_CARD_ID = -2; // 0xfffffffe field public static final int UNKNOWN_CARRIER_ID = -1; // 0xffffffff field public static final int UNSUPPORTED_CARD_ID = -1; // 0xffffffff + field public static final int UPDATE_AVAILABLE_NETWORKS_ABORTED = 2; // 0x2 + field public static final int UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS = 3; // 0x3 + field public static final int UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE = 4; // 0x4 + field public static final int UPDATE_AVAILABLE_NETWORKS_SUCCESS = 0; // 0x0 + field public static final int UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE = 1; // 0x1 field public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; // 0xfffffffe field public static final int USSD_RETURN_FAILURE = -1; // 0xffffffff field public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 17a4fd8867d97..e6bf5a30c5c8f 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -2701,7 +2701,8 @@ public class SubscriptionManager { * 1) Even if it's active, it will be dormant most of the time. The modem will not try * to scan or camp until it knows an available network is nearby to save power. * 2) Telephony relies on system app or carrier input to notify nearby available networks. - * See {@link TelephonyManager#updateAvailableNetworks(List)} for more information. + * See {@link TelephonyManager#updateAvailableNetworks(List, Executor, Consumer)} + * for more information. * 3) In multi-SIM devices, when the network is nearby and camped, system may automatically * switch internet data between it and default data subscription, based on carrier * recommendation and its signal strength and metered-ness, etc. diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 6e762b3a91cde..1922c2c70a538 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -83,6 +83,7 @@ import com.android.internal.telephony.IOns; import com.android.internal.telephony.IPhoneSubInfo; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.ITelephonyRegistry; +import com.android.internal.telephony.IUpdateAvailableNetworksCallback; import com.android.internal.telephony.OperatorInfo; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.RILConstants; @@ -98,6 +99,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.Executor; +import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -10132,6 +10134,41 @@ public class TelephonyManager { */ public static final int SET_OPPORTUNISTIC_SUB_INVALID_PARAMETER = 2; + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = {"UPDATE_AVAILABLE_NETWORKS"}, value = { + UPDATE_AVAILABLE_NETWORKS_SUCCESS, + UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE, + UPDATE_AVAILABLE_NETWORKS_ABORTED, + UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS, + UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE}) + public @interface UpdateAvailableNetworksResult {} + + /** + * No error. Operation succeeded. + */ + public static final int UPDATE_AVAILABLE_NETWORKS_SUCCESS = 0; + + /** + * There is a unknown failure happened. + */ + public static final int UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE = 1; + + /** + * The request is aborted. + */ + public static final int UPDATE_AVAILABLE_NETWORKS_ABORTED = 2; + + /** + * The parameter passed in is invalid. + */ + public static final int UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS = 3; + + /** + * No carrier privilege. + */ + public static final int UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE = 4; + /** * Set preferred opportunistic data subscription id. * @@ -10192,31 +10229,49 @@ public class TelephonyManager { /** * Update availability of a list of networks in the current location. * - * This api should be called to inform OpportunisticNetwork Service about the availability - * of a network at the current location. This information will be used by OpportunisticNetwork - * service to decide to attach to the network opportunistically. If an empty list is passed, - * it is assumed that no network is available. + * This api should be called by opportunistic network selection app to inform + * OpportunisticNetwork Service about the availability of a network at the current location. + * This information will be used by OpportunisticNetwork service to decide to attach to the + * network opportunistically. + * If an empty list is passed, it is assumed that no network is available. * Requires that the calling app has carrier privileges on both primary and * secondary subscriptions (see {@link #hasCarrierPrivileges}), or has permission * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. * @param availableNetworks is a list of available network information. - * @return true if request is accepted + * @param executor The executor of where the callback will execute. + * @param callback Callback will be triggered once it succeeds or failed. * */ @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges - public boolean updateAvailableNetworks(List availableNetworks) { + public void updateAvailableNetworks(@NonNull List availableNetworks, + @Nullable @CallbackExecutor Executor executor, + @UpdateAvailableNetworksResult @Nullable Consumer callback) { String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; - boolean ret = false; try { IOns iOpportunisticNetworkService = getIOns(); - if (iOpportunisticNetworkService != null && availableNetworks != null) { - ret = iOpportunisticNetworkService.updateAvailableNetworks(availableNetworks, - pkgForDebug); + if (iOpportunisticNetworkService == null || availableNetworks == null) { + Binder.withCleanCallingIdentity(() -> executor.execute(() -> { + callback.accept(UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); + })); + return; } + IUpdateAvailableNetworksCallback callbackStub = + new IUpdateAvailableNetworksCallback.Stub() { + @Override + public void onComplete(int result) { + if (executor == null || callback == null) { + return; + } + Binder.withCleanCallingIdentity(() -> executor.execute(() -> { + callback.accept(result); + })); + } + }; + iOpportunisticNetworkService.updateAvailableNetworks(availableNetworks, callbackStub, + pkgForDebug); } catch (RemoteException ex) { Rlog.e(TAG, "updateAvailableNetworks RemoteException", ex); } - return ret; } /** diff --git a/telephony/java/com/android/internal/telephony/IOns.aidl b/telephony/java/com/android/internal/telephony/IOns.aidl index 0e3d12b7f8382..4672e2d443012 100755 --- a/telephony/java/com/android/internal/telephony/IOns.aidl +++ b/telephony/java/com/android/internal/telephony/IOns.aidl @@ -17,6 +17,7 @@ package com.android.internal.telephony; import android.telephony.AvailableNetworkInfo; +import com.android.internal.telephony.IUpdateAvailableNetworksCallback; interface IOns { @@ -93,9 +94,9 @@ interface IOns { * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. * @param availableNetworks is a list of available network information. * @param callingPackage caller's package name - * @return true if request is accepted + * @param callback callback upon request completion. * */ - boolean updateAvailableNetworks(in List availableNetworks, - String callingPackage); + void updateAvailableNetworks(in List availableNetworks, + IUpdateAvailableNetworksCallback callbackStub, String callingPackage); } diff --git a/telephony/java/com/android/internal/telephony/IUpdateAvailableNetworksCallback.aidl b/telephony/java/com/android/internal/telephony/IUpdateAvailableNetworksCallback.aidl new file mode 100644 index 0000000000000..ed77ff310e8a1 --- /dev/null +++ b/telephony/java/com/android/internal/telephony/IUpdateAvailableNetworksCallback.aidl @@ -0,0 +1,25 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.telephony; + +/** + * Callback to provide asynchronous result of updateAvailableNetworks. + * @hide + */ +oneway interface IUpdateAvailableNetworksCallback { + void onComplete(int result); +} \ No newline at end of file