From 1bbcd4ef884e14007de07df558425196e1abd9a7 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Wed, 9 Dec 2020 22:43:33 -0800 Subject: [Suggestion] Add listener for user approval status change Bug: 160648511 Test: atest android.net.wifi Change-Id: I2a1959a2504e274de83f9cd0e44300222bbe8aac --- .../ISuggestionUserApprovalStatusListener.aidl | 27 +++++++ wifi/java/android/net/wifi/IWifiManager.aidl | 5 ++ wifi/java/android/net/wifi/WifiManager.java | 91 ++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 wifi/java/android/net/wifi/ISuggestionUserApprovalStatusListener.aidl (limited to 'wifi/java') diff --git a/wifi/java/android/net/wifi/ISuggestionUserApprovalStatusListener.aidl b/wifi/java/android/net/wifi/ISuggestionUserApprovalStatusListener.aidl new file mode 100644 index 000000000000..5aa3a90ee2bb --- /dev/null +++ b/wifi/java/android/net/wifi/ISuggestionUserApprovalStatusListener.aidl @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 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 android.net.wifi; + +/** + * Interface for suggestion user approval status listener. + * + * @hide + */ +oneway interface ISuggestionUserApprovalStatusListener +{ + void onUserApprovalStatusChange(); +} diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index e7b8475405ad..8fa35c38f30f 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -35,6 +35,7 @@ import android.net.wifi.IOnWifiUsabilityStatsListener; import android.net.wifi.IScanResultsCallback; import android.net.wifi.ISoftApCallback; import android.net.wifi.ISuggestionConnectionStatusListener; +import android.net.wifi.ISuggestionUserApprovalStatusListener; import android.net.wifi.ITrafficStateCallback; import android.net.wifi.IWifiConnectedNetworkScorer; import android.net.wifi.ScanResult; @@ -302,4 +303,8 @@ interface IWifiManager boolean isCarrierNetworkOffloadEnabled(int subscriptionId, boolean merged); void restartWifiSubsystem(String reason); + + boolean addSuggestionUserApprovalStatusListener(in IBinder binder, in ISuggestionUserApprovalStatusListener listener, int listenerIdentifier, String packageName, String featureId); + + void removeSuggestionUserApprovalStatusListener(int listenerIdentifier, String packageName); } diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 9fd70cbf6bc0..7e76a200492d 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -6852,4 +6852,95 @@ public class WifiManager { } } + /** + * Interface for network suggestion user approval status change listener. + * Should be implemented by applications and registered using + * {@link #addSuggestionUserApprovalStatusListener(Executor, + * SuggestionUserApprovalStatusListener)} ( + */ + public interface SuggestionUserApprovalStatusListener { + + /** + * Called when the user approval status of the App has changed. The current status can be + * queried by {@link #getNetworkSuggestionUserApprovalStatus()} + */ + void onUserApprovalStatusChange(); + } + + private class SuggestionUserApprovalStatusListenerProxy extends + ISuggestionUserApprovalStatusListener.Stub { + private final Executor mExecutor; + private final SuggestionUserApprovalStatusListener mListener; + + SuggestionUserApprovalStatusListenerProxy(@NonNull Executor executor, + @NonNull SuggestionUserApprovalStatusListener listener) { + mExecutor = executor; + mListener = listener; + } + + @Override + public void onUserApprovalStatusChange() { + mExecutor.execute(() -> mListener.onUserApprovalStatusChange()); + } + + } + + /** + * Add a listener for Wi-Fi network suggestion user approval status. + * See {@link SuggestionUserApprovalStatusListener}. + * Caller will receive a callback when the user approval status of the caller has changed. + * Caller can remove a previously registered listener using + * {@link WifiManager#removeSuggestionUserApprovalStatusListener( + * SuggestionUserApprovalStatusListener)} + * A caller can add multiple listeners to monitor the event. + * @param executor The executor to execute the listener of the {@code listener} object. + * @param listener listener for suggestion user approval status changes. + * @return true if succeed otherwise false. + */ + @RequiresPermission(ACCESS_WIFI_STATE) + public boolean addSuggestionUserApprovalStatusListener( + @NonNull @CallbackExecutor Executor executor, + @NonNull SuggestionUserApprovalStatusListener listener) { + if (!SdkLevel.isAtLeastS()) { + throw new UnsupportedOperationException(); + } + if (listener == null) throw new IllegalArgumentException("Listener cannot be null"); + if (executor == null) throw new IllegalArgumentException("Executor cannot be null"); + Log.v(TAG, "addSuggestionUserApprovalStatusListener listener=" + listener + + ", executor=" + executor); + try { + return mService.addSuggestionUserApprovalStatusListener(new Binder(), + new SuggestionUserApprovalStatusListenerProxy(executor, listener), + listener.hashCode(), mContext.getOpPackageName(), mContext.getAttributionTag()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + + } + + /** + * Allow callers to remove a previously registered listener using + * {@link #addSuggestionUserApprovalStatusListener(Executor, + * SuggestionUserApprovalStatusListener)}. After calling this method, + * applications will no longer receive network suggestion user approval status change through + * that listener. + * + * @param listener listener to remove. + */ + @RequiresPermission(ACCESS_WIFI_STATE) + public void removeSuggestionUserApprovalStatusListener( + @NonNull SuggestionUserApprovalStatusListener listener) { + if (!SdkLevel.isAtLeastS()) { + throw new UnsupportedOperationException(); + } + if (listener == null) throw new IllegalArgumentException("Listener cannot be null"); + Log.v(TAG, "removeSuggestionUserApprovalStatusListener: listener=" + listener); + try { + mService.removeSuggestionUserApprovalStatusListener(listener.hashCode(), + mContext.getOpPackageName()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + } -- cgit v1.2.3-59-g8ed1b