From 1f2850c472a9ce95635f879bd44a70b440d05f90 Mon Sep 17 00:00:00 2001 From: danielwbhuang Date: Wed, 6 Mar 2019 22:00:29 +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 Change-Id: I32fe1407deabe36485227ec75931bec334d85abe --- Android.bp | 1 + api/current.txt | 7 +- .../telephony/SubscriptionManager.java | 3 +- .../android/telephony/TelephonyManager.java | 76 ++++++++++++++++--- .../com/android/internal/telephony/IOns.aidl | 7 +- .../IUpdateAvailableNetworksCallback.aidl | 25 ++++++ 6 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 telephony/java/com/android/internal/telephony/IUpdateAvailableNetworksCallback.aidl diff --git a/Android.bp b/Android.bp index 9077344adf211..5145ca52905d2 100644 --- a/Android.bp +++ b/Android.bp @@ -604,6 +604,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 efd2170a8314a..2856ce454e5cb 100644 --- a/api/current.txt +++ b/api/current.txt @@ -45225,7 +45225,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_CARRIER_MESSAGING_CLIENT_SERVICE = "android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE"; 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"; @@ -45318,6 +45318,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 8edc5b4f404a6..c2cdb976940aa 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -2706,7 +2706,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 04f3c6b395b20..9a0a54bb7e9fd 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -84,6 +84,7 @@ import com.android.internal.telephony.IPhoneSubInfo; import com.android.internal.telephony.ISetOpportunisticDataCallback; 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; @@ -10176,6 +10177,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. * @@ -10255,31 +10291,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 0364477ead8cd..2c48b6512421c 100755 --- a/telephony/java/com/android/internal/telephony/IOns.aidl +++ b/telephony/java/com/android/internal/telephony/IOns.aidl @@ -19,6 +19,7 @@ package com.android.internal.telephony; import android.telephony.AvailableNetworkInfo; import com.android.internal.telephony.ISetOpportunisticDataCallback; +import com.android.internal.telephony.IUpdateAvailableNetworksCallback; interface IOns { @@ -97,9 +98,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..8fe086cea1f93 --- /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); +}