summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNingyuan Wang <nywang@google.com>2016-06-07 16:10:28 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-06-07 16:10:28 +0000
commitff6f1149718d709ce4799883af4d77251c2652dc (patch)
tree0d5951a5cbc3e30fd0a1a5b46424381cfa5f5d94 /service
parent2d7797eae8364c2c42d7368090b25adc74de3ff1 (diff)
parent0091305175e8c6fe7fc6d01efb9d405961db4ac7 (diff)
Merge "Continue supporting persisting country code" into nyc-dev
Diffstat (limited to 'service')
-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
3 files changed, 36 insertions, 15 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);
}