summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2019-11-21 23:32:49 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-11-21 23:32:49 +0000
commit2d574117086afb9dbf2303c99f15f7e4b92f5068 (patch)
tree74f7044a48a59b9c5fd34cd92f5a0a83f4206d39
parentd868dc640012bcc174fd075b59f5584519193af4 (diff)
parentf11468f2884b7c3b809654126c84a0360e93ca54 (diff)
Merge "Remove WifiManager.notifyUserOfApBandConversion()"
-rw-r--r--service/java/com/android/server/wifi/WifiApConfigStore.java123
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java2
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java16
-rw-r--r--service/res/values/strings.xml15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java63
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java27
6 files changed, 15 insertions, 231 deletions
diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java
index 48ad9b1c0..80421e78c 100644
--- a/service/java/com/android/server/wifi/WifiApConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiApConfigStore.java
@@ -17,12 +17,7 @@
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.MacAddress;
import android.net.wifi.SoftApConfiguration;
@@ -35,7 +30,6 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.wifi.R;
import java.io.BufferedInputStream;
@@ -91,13 +85,10 @@ public class WifiApConfigStore {
private ArrayList<Integer> mAllowed2GChannel = null;
private final Context mContext;
- private final WifiInjector mWifiInjector;
private final Handler mHandler;
private final BackupManagerProxy mBackupManagerProxy;
- private final FrameworkFacade mFrameworkFacade;
private final MacAddressUtil mMacAddressUtil;
private final Mac mMac;
- private final WifiConfigStore mWifiConfigStore;
private final WifiConfigManager mWifiConfigManager;
private boolean mRequiresApBandConversion = false;
private boolean mHasNewDataToSerialize = false;
@@ -133,26 +124,22 @@ public class WifiApConfigStore {
}
WifiApConfigStore(Context context, WifiInjector wifiInjector, Handler handler,
- BackupManagerProxy backupManagerProxy, FrameworkFacade frameworkFacade,
- WifiConfigStore wifiConfigStore, WifiConfigManager wifiConfigManager) {
- this(context, wifiInjector, handler, backupManagerProxy, frameworkFacade, wifiConfigStore,
+ BackupManagerProxy backupManagerProxy, WifiConfigStore wifiConfigStore,
+ WifiConfigManager wifiConfigManager) {
+ this(context, wifiInjector, handler, backupManagerProxy, wifiConfigStore,
wifiConfigManager, LEGACY_AP_CONFIG_FILE);
}
WifiApConfigStore(Context context,
- WifiInjector wifiInjector,
- Handler handler,
- BackupManagerProxy backupManagerProxy,
- FrameworkFacade frameworkFacade,
- WifiConfigStore wifiConfigStore,
- WifiConfigManager wifiConfigManager,
- String apConfigFile) {
+ WifiInjector wifiInjector,
+ Handler handler,
+ BackupManagerProxy backupManagerProxy,
+ WifiConfigStore wifiConfigStore,
+ WifiConfigManager wifiConfigManager,
+ String apConfigFile) {
mContext = context;
- mWifiInjector = wifiInjector;
mHandler = handler;
mBackupManagerProxy = backupManagerProxy;
- mFrameworkFacade = frameworkFacade;
- mWifiConfigStore = wifiConfigStore;
mWifiConfigManager = wifiConfigManager;
String ap2GChannelListStr = mContext.getResources().getString(
@@ -188,14 +175,12 @@ public class WifiApConfigStore {
}
// Register store data listener
- mWifiConfigStore.registerStoreData(
- mWifiInjector.makeSoftApStoreData(new SoftApStoreDataSource()));
+ wifiConfigStore.registerStoreData(
+ wifiInjector.makeSoftApStoreData(new SoftApStoreDataSource()));
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_HOTSPOT_CONFIG_USER_TAPPED_CONTENT);
- mContext.registerReceiver(
- mBroadcastReceiver, filter, null /* broadcastPermission */, mHandler);
- mMacAddressUtil = mWifiInjector.getMacAddressUtil();
+ mMacAddressUtil = wifiInjector.getMacAddressUtil();
mMac = mMacAddressUtil.obtainMacRandHashFunctionForSap(Process.WIFI_UID);
if (mMac == null) {
Log.wtf(TAG, "Failed to obtain secret for SAP MAC randomization."
@@ -203,23 +188,6 @@ public class WifiApConfigStore {
}
}
- 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.
*/
@@ -257,47 +225,6 @@ 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.getResources().getText(R.string.wifi_softap_config_change);
- CharSequence contentSummary =
- mContext.getResources().getText(R.string.wifi_softap_config_change_summary);
- CharSequence content =
- mContext.getResources().getText(R.string.wifi_softap_config_change_detailed);
- int color =
- mContext.getResources().getColor(
- android.R.color.system_notification_accent_color, mContext.getTheme());
-
- return new Notification.Builder(mContext, WifiStackService.NOTIFICATION_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 sanitizePersistentApConfig(WifiConfiguration config) {
WifiConfiguration convertedConfig = null;
@@ -572,32 +499,6 @@ 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(mWifiInjector.getWifiStackPackageName());
- return mFrameworkFacade.getBroadcast(
- mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- }
-
private static String generatePassword() {
// Characters that will be used for password generation. Some characters commonly known to
// be confusing like 0 and O excluded from this list.
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 3c77c09f7..3ccd640d9 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -266,7 +266,7 @@ public class WifiInjector {
mWifiMetrics.setWifiConfigManager(mWifiConfigManager);
mWifiApConfigStore = new WifiApConfigStore(
- mContext, this, wifiHandler, mBackupManagerProxy, mFrameworkFacade,
+ mContext, this, wifiHandler, mBackupManagerProxy,
mWifiConfigStore, mWifiConfigManager);
mWifiConnectivityHelper = new WifiConnectivityHelper(mWifiNative);
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index b4e749ca7..83fb40338 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -81,7 +81,6 @@ import android.os.BatteryStats;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
-import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
@@ -1564,21 +1563,6 @@ public class WifiServiceImpl extends BaseWifiService {
}
/**
- * 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
diff --git a/service/res/values/strings.xml b/service/res/values/strings.xml
index 69d210670..4a39e9875 100644
--- a/service/res/values/strings.xml
+++ b/service/res/values/strings.xml
@@ -63,21 +63,6 @@
<!--Notification content for when Wi-Fi Wake enables Wi-Fi. %1$s is the SSID of the nearby saved network that triggered the wakeup. -->
<string name="wifi_wakeup_enabled_content">You\u0027re near a saved network: <xliff:g id="network_ssid">%1$s</xliff:g></string>
- <!-- A notification is shown when the user's softap config has been changed due to underlying
- hardware restrictions. This is the notifications's title.
- [CHAR_LIMIT=NONE] -->
- <string name="wifi_softap_config_change">Changes to your hotspot settings</string>
-
- <!-- A notification is shown when the user's softap config has been changed due to underlying
- hardware restrictions. This is the notification's summary message.
- [CHAR_LIMIT=NONE] -->
- <string name="wifi_softap_config_change_summary">Your hotspot band has changed.</string>
-
- <!-- A notification is shown when the user's softap config has been changed due to underlying
- hardware restrictions. This is the notification's full message.
- [CHAR_LIMIT=NONE] -->
- <string name="wifi_softap_config_change_detailed">This device doesn\u2019t support your preference for 5GHz only. Instead, this device will use the 5GHz band when available.</string>
-
<!-- A notification is shown when a user's selected SSID is later disabled due to connectivity problems. This is the notification's title / ticker. -->
<string name="wifi_watchdog_network_disabled">Couldn\'t connect to Wi-Fi</string>
<!-- A notification is shown when a user's selected SSID is later disabled due to connectivity problems. The complete alert msg is: <hotspot name> + this string, i.e. "Linksys has a poor internet connection" -->
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
index 71b034a2e..851289c0d 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
@@ -23,17 +23,12 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.net.MacAddress;
import android.net.wifi.SoftApConfiguration;
@@ -45,7 +40,6 @@ import android.os.test.TestLooper;
import androidx.test.filters.SmallTest;
-import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.wifi.R;
import org.junit.Before;
@@ -74,13 +68,8 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
private static final String TEST_AP_CONFIG_FILE_PREFIX = "APConfig_";
private static final String TEST_DEFAULT_2G_CHANNEL_LIST = "1,2,3,4,5,6";
private static final String TEST_DEFAULT_AP_SSID = "TestAP";
- private static final String TEST_CONFIGURED_AP_SSID = "ConfiguredAP";
private static final String TEST_DEFAULT_HOTSPOT_SSID = "TestShare";
private static final String TEST_DEFAULT_HOTSPOT_PSK = "TestPassword";
- private static final String TEST_APCONFIG_CHANGE_NOTIFICATION_TITLE = "Notification title";
- private static final String TEST_APCONFIG_CHANGE_NOTIFICATION_SUMMARY = "Notification summary";
- private static final String TEST_APCONFIG_CHANGE_NOTIFICATION_DETAILED =
- "Notification detailed";
private static final int RAND_SSID_INT_MIN = 1000;
private static final int RAND_SSID_INT_MAX = 9999;
private static final String TEST_CHAR_SET_AS_STRING = "abcdefghijklmnopqrstuvwxyz0123456789";
@@ -96,15 +85,12 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
private TestLooper mLooper;
private Handler mHandler;
@Mock private BackupManagerProxy mBackupManagerProxy;
- @Mock private FrameworkFacade mFrameworkFacade;
@Mock private WifiConfigStore mWifiConfigStore;
@Mock private WifiConfigManager mWifiConfigManager;
private File mLegacyApConfigFile;
private Random mRandom;
private MockResources mResources;
@Mock private ApplicationInfo mMockApplInfo;
- private BroadcastReceiver mBroadcastReceiver;
- @Mock private NotificationManager mNotificationManager;
@Mock private MacAddressUtil mMacAddressUtil;
private SoftApStoreData.DataSource mDataStoreSource;
private ArrayList<Integer> mKnownGood2GChannelList;
@@ -114,8 +100,6 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
mLooper = new TestLooper();
mHandler = new Handler(mLooper.getLooper());
MockitoAnnotations.initMocks(this);
- when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
- .thenReturn(mNotificationManager);
mMockApplInfo.targetSdkVersion = Build.VERSION_CODES.P;
when(mContext.getApplicationInfo()).thenReturn(mMockApplInfo);
@@ -129,12 +113,6 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
TEST_DEFAULT_HOTSPOT_SSID);
/* Default to device that does not require ap band conversion */
mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, false);
- mResources.setText(R.string.wifi_softap_config_change,
- TEST_APCONFIG_CHANGE_NOTIFICATION_TITLE);
- mResources.setText(R.string.wifi_softap_config_change_summary,
- TEST_APCONFIG_CHANGE_NOTIFICATION_SUMMARY);
- mResources.setText(R.string.wifi_softap_config_change_detailed,
- TEST_APCONFIG_CHANGE_NOTIFICATION_DETAILED);
when(mContext.getResources()).thenReturn(mResources);
// build the known good 2G channel list: TEST_DEFAULT_2G_CHANNEL_LIST
@@ -152,19 +130,14 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
WifiApConfigStore store;
if (legacyFilePath == null) {
store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
+ mContext, mWifiInjector, mHandler, mBackupManagerProxy,
mWifiConfigStore, mWifiConfigManager);
} else {
store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
+ mContext, mWifiInjector, mHandler, mBackupManagerProxy,
mWifiConfigStore, mWifiConfigManager, legacyFilePath);
}
- ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor =
- ArgumentCaptor.forClass(BroadcastReceiver.class);
- verify(mContext).registerReceiver(broadcastReceiverCaptor.capture(), any(), any(), any());
- mBroadcastReceiver = broadcastReceiverCaptor.getValue();
-
verify(mWifiConfigStore).registerStoreData(any());
ArgumentCaptor<SoftApStoreData.DataSource> dataStoreSourceArgumentCaptor =
ArgumentCaptor.forClass(SoftApStoreData.DataSource.class);
@@ -840,36 +813,4 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
assertTrue(mKnownGood2GChannelList.contains(channel));
}
}
-
- /**
- * Verify a notification is posted when triggered when the ap config was converted.
- */
- @Test
- public void testNotifyUserOfApBandConversion() throws Exception {
- WifiApConfigStore store = createWifiApConfigStore();
- store.notifyUserOfApBandConversion(TAG);
- // verify the notification is posted
- ArgumentCaptor<Notification> notificationCaptor =
- ArgumentCaptor.forClass(Notification.class);
- verify(mNotificationManager).notify(eq(SystemMessage.NOTE_SOFTAP_CONFIG_CHANGED),
- notificationCaptor.capture());
- Notification notification = notificationCaptor.getValue();
- assertEquals(TEST_APCONFIG_CHANGE_NOTIFICATION_TITLE,
- notification.extras.getCharSequence(Notification.EXTRA_TITLE));
- assertEquals(TEST_APCONFIG_CHANGE_NOTIFICATION_DETAILED,
- notification.extras.getCharSequence(Notification.EXTRA_BIG_TEXT));
- assertEquals(TEST_APCONFIG_CHANGE_NOTIFICATION_SUMMARY,
- notification.extras.getCharSequence(Notification.EXTRA_SUMMARY_TEXT));
- }
-
- /**
- * Verify the posted notification is cleared when the user interacts with it.
- */
- @Test
- public void testNotificationClearedWhenContentIsTapped() throws Exception {
- WifiApConfigStore store = createWifiApConfigStore();
- Intent intent = new Intent(WifiApConfigStore.ACTION_HOTSPOT_CONFIG_USER_TAPPED_CONTENT);
- mBroadcastReceiver.onReceive(mContext, intent);
- verify(mNotificationManager).cancel(eq(SystemMessage.NOTE_SOFTAP_CONFIG_CHANGED));
- }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 9224d69b5..ddb49f0b1 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -3335,33 +3335,6 @@ public class WifiServiceImplTest extends WifiBaseTest {
}
/**
- * Verify calls to notify users of a softap config change check the NETWORK_SETTINGS permission.
- */
- @Test
- public void testNotifyUserOfApBandConversionChecksNetworkSettingsPermission() {
- mWifiServiceImpl.notifyUserOfApBandConversion(TEST_PACKAGE_NAME);
- verify(mContext).enforceCallingOrSelfPermission(
- eq(android.Manifest.permission.NETWORK_SETTINGS),
- eq("WifiService"));
- verify(mWifiApConfigStore).notifyUserOfApBandConversion(eq(TEST_PACKAGE_NAME));
- }
-
- /**
- * Verify calls to notify users do not trigger a notification when NETWORK_SETTINGS is not held
- * by the caller.
- */
- @Test
- public void testNotifyUserOfApBandConversionThrowsExceptionWithoutNetworkSettingsPermission() {
- doThrow(new SecurityException()).when(mContext)
- .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
- eq("WifiService"));
- try {
- mWifiServiceImpl.notifyUserOfApBandConversion(TEST_PACKAGE_NAME);
- fail("Expected Security exception");
- } catch (SecurityException e) { }
- }
-
- /**
* Verify that a call to registerTrafficStateCallback throws a SecurityException if the caller
* does not have NETWORK_SETTINGS permission.
*/