diff options
author | Rebecca Silberstein <silberst@google.com> | 2018-06-01 17:30:13 -0700 |
---|---|---|
committer | Rebecca Silberstein <silberst@google.com> | 2018-06-19 15:07:03 -0700 |
commit | 9903d87381aa374571b933ff5a5e376dfa9850b2 (patch) | |
tree | 256b56e2874d5e7106ed325ce39bdafd363c2df4 /service | |
parent | a5f380856579e7c125b48d2feaff7fb7fa7ac07f (diff) |
WifiServiceImpl: notify user of apBand conversion
Notify users of softap config changes. Some hardware is incompatible
with available options for softap configs. When the user's stored data
is restored and a config change is detected, put up a Notification to
the user. Tapping the notification opens the wifi tethering config
page.
Bug: 80251951
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manually confirmed configs are converted for different device
Test: manually confirmed notification is displayed
Test: manually confirmed tapping notification opens tether settings
Test: manually confirmed notification is not displayed when conversion
is not done
Change-Id: Ib1f45128d51fb9a6e634c838d722c111934d29ae
Diffstat (limited to 'service')
4 files changed, 124 insertions, 14 deletions
diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java index 15b9cc738..26cb4ff7b 100644 --- a/service/java/com/android/server/wifi/FrameworkFacade.java +++ b/service/java/com/android/server/wifi/FrameworkFacade.java @@ -136,17 +136,6 @@ public class FrameworkFacade { return true; } - /** - * Create a new instance of WifiApConfigStore. - * @param context reference to a Context - * @param backupManagerProxy reference to a BackupManagerProxy - * @return an instance of WifiApConfigStore - */ - public WifiApConfigStore makeApConfigStore(Context context, - BackupManagerProxy backupManagerProxy) { - return new WifiApConfigStore(context, backupManagerProxy); - } - public long getTxPackets(String iface) { return TrafficStats.getTxPackets(iface); } diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java index 109c0a7af..d21452c8c 100644 --- a/service/java/com/android/server/wifi/WifiApConfigStore.java +++ b/service/java/com/android/server/wifi/WifiApConfigStore.java @@ -17,15 +17,25 @@ package com.android.server.wifi; import android.annotation.NonNull; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.KeyMgmt; import android.os.Environment; +import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import android.util.Log; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; +import com.android.internal.notification.SystemNotificationChannels; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -44,6 +54,10 @@ import java.util.UUID; */ public class WifiApConfigStore { + // Intent when user has interacted with the softap settings change notification + public static final String ACTION_HOTSPOT_CONFIG_USER_TAPPED_CONTENT = + "com.android.server.wifi.WifiApConfigStoreUtil.HOTSPOT_CONFIG_USER_TAPPED_CONTENT"; + private static final String TAG = "WifiApConfigStore"; private static final String DEFAULT_AP_CONFIG_FILE = @@ -71,19 +85,26 @@ public class WifiApConfigStore { private ArrayList<Integer> mAllowed2GChannel = null; private final Context mContext; + private final Handler mHandler; private final String mApConfigFile; private final BackupManagerProxy mBackupManagerProxy; + private final FrameworkFacade mFrameworkFacade; private boolean mRequiresApBandConversion = false; - WifiApConfigStore(Context context, BackupManagerProxy backupManagerProxy) { - this(context, backupManagerProxy, DEFAULT_AP_CONFIG_FILE); + WifiApConfigStore(Context context, Looper looper, + BackupManagerProxy backupManagerProxy, FrameworkFacade frameworkFacade) { + this(context, looper, backupManagerProxy, frameworkFacade, DEFAULT_AP_CONFIG_FILE); } WifiApConfigStore(Context context, + Looper looper, BackupManagerProxy backupManagerProxy, + FrameworkFacade frameworkFacade, String apConfigFile) { mContext = context; + mHandler = new Handler(looper); mBackupManagerProxy = backupManagerProxy; + mFrameworkFacade = frameworkFacade; mApConfigFile = apConfigFile; String ap2GChannelListStr = mContext.getResources().getString( @@ -111,8 +132,30 @@ public class WifiApConfigStore { /* Save the default configuration to persistent storage. */ writeApConfiguration(mApConfigFile, mWifiApConfig); } + + IntentFilter filter = new IntentFilter(); + filter.addAction(ACTION_HOTSPOT_CONFIG_USER_TAPPED_CONTENT); + mContext.registerReceiver( + mBroadcastReceiver, filter, null /* broadcastPermission */, mHandler); } + private final BroadcastReceiver mBroadcastReceiver = + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + // For now we only have one registered listener, but we easily could expand this + // to support multiple signals. Starting off with a switch to support trivial + // expansion. + switch(intent.getAction()) { + case ACTION_HOTSPOT_CONFIG_USER_TAPPED_CONTENT: + handleUserHotspotConfigTappedContent(); + break; + default: + Log.e(TAG, "Unknown action " + intent.getAction()); + } + } + }; + /** * Return the current soft access point configuration. */ @@ -145,6 +188,43 @@ public class WifiApConfigStore { return mAllowed2GChannel; } + /** + * Helper method to create and send notification to user of apBand conversion. + * + * @param packageName name of the calling app + */ + public void notifyUserOfApBandConversion(String packageName) { + Log.w(TAG, "ready to post notification - triggered by " + packageName); + Notification notification = createConversionNotification(); + NotificationManager notificationManager = (NotificationManager) + mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(SystemMessage.NOTE_SOFTAP_CONFIG_CHANGED, notification); + } + + private Notification createConversionNotification() { + CharSequence title = mContext.getText(R.string.wifi_softap_config_change); + CharSequence contentSummary = mContext.getText(R.string.wifi_softap_config_change_summary); + CharSequence content = mContext.getText(R.string.wifi_softap_config_change_detailed); + int color = mContext.getResources() + .getColor(R.color.system_notification_accent_color, mContext.getTheme()); + + return new Notification.Builder(mContext, SystemNotificationChannels.NETWORK_STATUS) + .setSmallIcon(R.drawable.ic_wifi_settings) + .setPriority(Notification.PRIORITY_HIGH) + .setCategory(Notification.CATEGORY_SYSTEM) + .setContentTitle(title) + .setContentText(contentSummary) + .setContentIntent(getPrivateBroadcast(ACTION_HOTSPOT_CONFIG_USER_TAPPED_CONTENT)) + .setTicker(title) + .setShowWhen(false) + .setLocalOnly(true) + .setColor(color) + .setStyle(new Notification.BigTextStyle().bigText(content) + .setBigContentTitle(title) + .setSummaryText(contentSummary)) + .build(); + } + private WifiConfiguration apBandCheckConvert(WifiConfiguration config) { if (mRequiresApBandConversion) { // some devices are unable to support 5GHz only operation, check for 5GHz and @@ -386,4 +466,29 @@ public class WifiApConfigStore { return true; } + + /** + * Helper method to start up settings on the softap config page. + */ + private void startSoftApSettings() { + mContext.startActivity( + new Intent("com.android.settings.WIFI_TETHER_SETTINGS") + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + } + + /** + * Helper method to trigger settings to open the softap config page + */ + private void handleUserHotspotConfigTappedContent() { + startSoftApSettings(); + NotificationManager notificationManager = (NotificationManager) + mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(SystemMessage.NOTE_SOFTAP_CONFIG_CHANGED); + } + + private PendingIntent getPrivateBroadcast(String action) { + Intent intent = new Intent(action).setPackage("android"); + return mFrameworkFacade.getBroadcast( + mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 199548090..dbf730a73 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -205,7 +205,8 @@ public class WifiInjector { SystemProperties.get(BOOT_DEFAULT_WIFI_COUNTRY_CODE), mContext.getResources() .getBoolean(R.bool.config_wifi_revert_country_code_on_cellular_loss)); - mWifiApConfigStore = new WifiApConfigStore(mContext, mBackupManagerProxy); + mWifiApConfigStore = new WifiApConfigStore( + mContext, wifiStateMachineLooper, mBackupManagerProxy, mFrameworkFacade); // WifiConfigManager/Store objects and their dependencies. // New config store diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index a0bbded9d..cb16efd99 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -1583,6 +1583,21 @@ public class WifiServiceImpl extends IWifiManager.Stub { } /** + * Method used to inform user of Ap Configuration conversion due to hardware. + */ + @Override + public void notifyUserOfApBandConversion(String packageName) { + enforceNetworkSettingsPermission(); + + if (mVerboseLoggingEnabled) { + mLog.info("notifyUserOfApBandConversion uid=% packageName=%") + .c(Binder.getCallingUid()).c(packageName).flush(); + } + + mWifiApConfigStore.notifyUserOfApBandConversion(packageName); + } + + /** * see {@link android.net.wifi.WifiManager#isScanAlwaysAvailable()} */ @Override |