From 0091305175e8c6fe7fc6d01efb9d405961db4ac7 Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Fri, 3 Jun 2016 14:21:27 -0700 Subject: 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 --- .../com/android/server/wifi/FrameworkFacade.java | 4 ++++ .../com/android/server/wifi/WifiCountryCode.java | 27 ++++++++++++++-------- .../com/android/server/wifi/WifiServiceImpl.java | 20 +++++++++++----- 3 files changed, 36 insertions(+), 15 deletions(-) (limited to 'service') 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); } -- cgit v1.2.3