summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNingyuan Wang <nywang@google.com>2016-06-03 14:21:27 -0700
committerNingyuan Wang <nywang@google.com>2016-06-06 13:07:18 -0700
commit0091305175e8c6fe7fc6d01efb9d405961db4ac7 (patch)
treeb30d35ba8001455ba1b1946824be8989d0ea72f3
parentd722d068b68772e52dd7621cfb915fce5ac08482 (diff)
downloadandroid_frameworks_opt_net_wifi-0091305175e8c6fe7fc6d01efb9d405961db4ac7.tar.gz
android_frameworks_opt_net_wifi-0091305175e8c6fe7fc6d01efb9d405961db4ac7.tar.bz2
android_frameworks_opt_net_wifi-0091305175e8c6fe7fc6d01efb9d405961db4ac7.zip
Continue supporting persisting country code
Some devices rely on Setup Wizard to set a persistent country code. This CL honors the persistent option, fixing corresponding 5GHz AP problem. This also includes addtional unit tests for this change. BUG=28127280 TEST=compile TEST=runtest frameworks-wifi Change-Id: I2f36216e143d0ac4959f26a9965def061a06aabf
-rw-r--r--service/java/com/android/server/wifi/FrameworkFacade.java4
-rw-r--r--service/java/com/android/server/wifi/WifiCountryCode.java27
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java20
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java37
4 files changed, 67 insertions, 21 deletions
diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java
index dd5c1e9f2..c2579e089 100644
--- a/service/java/com/android/server/wifi/FrameworkFacade.java
+++ b/service/java/com/android/server/wifi/FrameworkFacade.java
@@ -65,6 +65,10 @@ public class FrameworkFacade {
return Settings.Global.getLong(context.getContentResolver(), name, def);
}
+ public boolean setStringSetting(Context context, String name, String def) {
+ return Settings.Global.putString(context.getContentResolver(), name, def);
+ }
+
public String getStringSetting(Context context, String name) {
return Settings.Global.getString(context.getContentResolver(), name);
}
diff --git a/service/java/com/android/server/wifi/WifiCountryCode.java b/service/java/com/android/server/wifi/WifiCountryCode.java
index b603d904a..bd9b14b4b 100644
--- a/service/java/com/android/server/wifi/WifiCountryCode.java
+++ b/service/java/com/android/server/wifi/WifiCountryCode.java
@@ -36,14 +36,19 @@ public class WifiCountryCode {
private String mTelephonyCountryCode = null;
private String mCurrentCountryCode = null;
- public WifiCountryCode(WifiNative wifiNative, String defaultCountryCode,
+ public WifiCountryCode(
+ WifiNative wifiNative,
+ String oemDefaultCountryCode,
+ String persistentCountryCode,
boolean revertCountryCodeOnCellularLoss) {
+
mWifiNative = wifiNative;
mRevertCountryCodeOnCellularLoss = revertCountryCodeOnCellularLoss;
- if (!TextUtils.isEmpty(defaultCountryCode)) {
- mDefaultCountryCode = defaultCountryCode;
- mDefaultCountryCode = mDefaultCountryCode.toUpperCase();
+ if (!TextUtils.isEmpty(persistentCountryCode)) {
+ mDefaultCountryCode = persistentCountryCode.toUpperCase();
+ } else if (!TextUtils.isEmpty(oemDefaultCountryCode)) {
+ mDefaultCountryCode = oemDefaultCountryCode.toUpperCase();
} else {
if (mRevertCountryCodeOnCellularLoss) {
Log.w(TAG, "config_wifi_revert_country_code_on_cellular_loss is set, "
@@ -122,21 +127,25 @@ public class WifiCountryCode {
* @param countryCode The country code intended to set.
* This is supposed to be from Telephony service.
* otherwise we think it is from other applications.
+ * @return Returns true if the country code passed in is acceptable.
*/
- public synchronized void setCountryCode(String countryCode) {
+ public synchronized boolean setCountryCode(String countryCode, boolean persist) {
if (DBG) Log.d(TAG, "Receive set country code request: " + countryCode);
// Ignore empty country code.
- if (countryCode.length() == 0) {
+ if (TextUtils.isEmpty(countryCode)) {
if (DBG) Log.d(TAG, "Ignore empty country code");
- return;
+ return false;
+ }
+ if (persist) {
+ mDefaultCountryCode = countryCode;
}
- mTelephonyCountryCode = countryCode;
- mTelephonyCountryCode = mTelephonyCountryCode.toUpperCase();
+ mTelephonyCountryCode = countryCode.toUpperCase();
// If wpa_supplicant is ready we set the country code now, otherwise it will be
// set once wpa_supplicant is ready.
if (mReady) {
updateCountryCode();
}
+ return true;
}
/**
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index ab4f234fc..7193580de 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -128,6 +128,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
final WifiStateMachine mWifiStateMachine;
private final Context mContext;
+ private final FrameworkFacade mFacade;
final LockList mLocks = new LockList();
// some wifi lock statistics
@@ -320,7 +321,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
public WifiServiceImpl(Context context) {
mContext = context;
mWifiInjector = WifiInjector.getInstance();
- FrameworkFacade facade = new FrameworkFacade();
+ mFacade = new FrameworkFacade();
HandlerThread wifiThread = new HandlerThread("WifiService");
wifiThread.start();
mWifiMetrics = mWifiInjector.getWifiMetrics();
@@ -329,11 +330,13 @@ public class WifiServiceImpl extends IWifiManager.Stub {
mUserManager = UserManager.get(mContext);
HandlerThread wifiStateMachineThread = new HandlerThread("WifiStateMachine");
wifiStateMachineThread.start();
- mCountryCode = new WifiCountryCode(WifiNative.getWlanNativeInterface(),
+ mCountryCode = new WifiCountryCode(
+ WifiNative.getWlanNativeInterface(),
SystemProperties.get(BOOT_DEFAULT_WIFI_COUNTRY_CODE),
+ mFacade.getStringSetting(mContext, Settings.Global.WIFI_COUNTRY_CODE),
mContext.getResources().getBoolean(
R.bool.config_wifi_revert_country_code_on_cellular_loss));
- mWifiStateMachine = new WifiStateMachine(mContext, facade,
+ mWifiStateMachine = new WifiStateMachine(mContext, mFacade,
wifiStateMachineThread.getLooper(), mUserManager, mWifiInjector,
new BackupManagerProxy(), mCountryCode);
mSettingsStore = new WifiSettingsStore(mContext);
@@ -344,12 +347,12 @@ public class WifiServiceImpl extends IWifiManager.Stub {
mCertManager = new WifiCertManager(mContext);
mNotificationController = new WifiNotificationController(mContext,
- wifiThread.getLooper(), mWifiStateMachine, facade, null);
+ wifiThread.getLooper(), mWifiStateMachine, mFacade, null);
mClientHandler = new ClientHandler(wifiThread.getLooper());
mWifiStateMachineHandler = new WifiStateMachineHandler(wifiThread.getLooper());
mWifiController = new WifiController(mContext, mWifiStateMachine,
- mSettingsStore, mLocks, wifiThread.getLooper(), facade);
+ mSettingsStore, mLocks, wifiThread.getLooper(), mFacade);
}
@@ -1113,7 +1116,12 @@ public class WifiServiceImpl extends IWifiManager.Stub {
enforceConnectivityInternalPermission();
final long token = Binder.clearCallingIdentity();
try {
- mCountryCode.setCountryCode(countryCode);
+ if (mCountryCode.setCountryCode(countryCode, persist) && persist) {
+ // Save this country code to persistent storage
+ mFacade.setStringSetting(mContext,
+ Settings.Global.WIFI_COUNTRY_CODE,
+ countryCode);
+ }
} finally {
Binder.restoreCallingIdentity(token);
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
index 33cf2170b..2e62a309b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
@@ -18,6 +18,7 @@ package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -38,6 +39,7 @@ public class WifiCountryCodeTest {
private static final String TAG = "WifiCountryCodeTest";
private String mDefaultCountryCode = "US";
private String mTelephonyCountryCode = "JP";
+ private String mPersistCountryCode = "";
private boolean mRevertCountryCodeOnCellularLoss = true;
@Mock WifiNative mWifiNative;
private WifiCountryCode mWifiCountryCode;
@@ -51,7 +53,10 @@ public class WifiCountryCodeTest {
when(mWifiNative.setCountryCode(anyString())).thenReturn(true);
- mWifiCountryCode = new WifiCountryCode(mWifiNative, mDefaultCountryCode,
+ mWifiCountryCode = new WifiCountryCode(
+ mWifiNative,
+ mDefaultCountryCode,
+ mPersistCountryCode,
mRevertCountryCodeOnCellularLoss);
}
@@ -75,7 +80,7 @@ public class WifiCountryCodeTest {
*/
@Test
public void useTelephonyCountryCode() throws Exception {
- mWifiCountryCode.setCountryCode(mTelephonyCountryCode);
+ mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false);
assertEquals(null, mWifiCountryCode.getCurrentCountryCode());
// Supplicant started.
mWifiCountryCode.setReadyForChange(true);
@@ -95,7 +100,7 @@ public class WifiCountryCodeTest {
mWifiCountryCode.setReadyForChange(true);
assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode());
// Telephony country code arrives.
- mWifiCountryCode.setCountryCode(mTelephonyCountryCode);
+ mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false);
// Wifi get L2 connected.
mWifiCountryCode.setReadyForChange(false);
verify(mWifiNative, times(2)).setCountryCode(anyString());
@@ -113,7 +118,7 @@ public class WifiCountryCodeTest {
// Wifi get L2 connected.
mWifiCountryCode.setReadyForChange(false);
// Telephony country code arrives.
- mWifiCountryCode.setCountryCode(mTelephonyCountryCode);
+ mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false);
// Telephony coutry code won't be applied at this time.
assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode());
mWifiCountryCode.setReadyForChange(true);
@@ -128,7 +133,7 @@ public class WifiCountryCodeTest {
*/
@Test
public void resetCountryCodeWhenSIMCardRemoved() throws Exception {
- mWifiCountryCode.setCountryCode(mTelephonyCountryCode);
+ mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false);
// Supplicant started.
mWifiCountryCode.setReadyForChange(true);
// Wifi get L2 connected.
@@ -150,7 +155,7 @@ public class WifiCountryCodeTest {
*/
@Test
public void resetCountryCodeWhenAirplaneModeEnabled() throws Exception {
- mWifiCountryCode.setCountryCode(mTelephonyCountryCode);
+ mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false);
// Supplicant started.
mWifiCountryCode.setReadyForChange(true);
// Wifi get L2 connected.
@@ -165,4 +170,24 @@ public class WifiCountryCodeTest {
verify(mWifiNative, times(2)).setCountryCode(anyString());
assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode());
}
+
+ /**
+ * Test if we will set the persistent country code if it is not empty.
+ * @throws Exception
+ */
+ @Test
+ public void usePersistentCountryCode() throws Exception {
+ String persistentCountryCode = "CH";
+ mWifiCountryCode = new WifiCountryCode(
+ mWifiNative,
+ mDefaultCountryCode,
+ persistentCountryCode,
+ mRevertCountryCodeOnCellularLoss);
+ // Supplicant started.
+ mWifiCountryCode.setReadyForChange(true);
+ // Wifi get L2 connected.
+ mWifiCountryCode.setReadyForChange(false);
+ verify(mWifiNative).setCountryCode(anyString());
+ assertEquals(persistentCountryCode, mWifiCountryCode.getCurrentCountryCode());
+ }
}