Set country code in the driver and remove channel set

With dual band support, using country code
settings is the way to go

Bug: 2936741
Change-Id: I760dce4c43b1af19ee205c28f0d287420c8d9e85
This commit is contained in:
Irfan Sheriff
2010-10-29 15:32:10 -07:00
parent 98444a944c
commit ed4f28b492
11 changed files with 112 additions and 294 deletions

View File

@@ -1199,12 +1199,6 @@ public final class Settings {
*/
public static final String WIFI_STATIC_DNS2 = "wifi_static_dns2";
/**
* The number of radio channels that are allowed in the local
* 802.11 regulatory domain.
* @hide
*/
public static final String WIFI_NUM_ALLOWED_CHANNELS = "wifi_num_allowed_channels";
/**
* Determines whether remote devices may discover and/or connect to
@@ -2701,11 +2695,11 @@ public final class Settings {
"wifi_networks_available_repeat_delay";
/**
* The number of radio channels that are allowed in the local
* 802.11 regulatory domain.
* 802.11 country code in ISO 3166 format
* @hide
*/
public static final String WIFI_NUM_ALLOWED_CHANNELS = "wifi_num_allowed_channels";
public static final String WIFI_COUNTRY_CODE = "wifi_country_code";
/**
* When the number of open networks exceeds this number, the
@@ -3638,7 +3632,7 @@ public final class Settings {
TTS_ENABLED_PLUGINS,
WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
WIFI_NUM_ALLOWED_CHANNELS,
WIFI_COUNTRY_CODE,
WIFI_NUM_OPEN_NETWORKS_KEPT,
MOUNT_PLAY_NOTIFICATION_SND,
MOUNT_UMS_AUTOSTART,

View File

@@ -198,11 +198,25 @@ static jint android_net_wifi_wpsPinFromDeviceCommand(JNIEnv* env, jobject clazz,
env->ReleaseStringUTFChars(bssid, bssidStr);
if ((numWritten == -1) || (numWritten >= (int)sizeof(cmdstr))) {
return false;
return -1;
}
return doIntCommand(cmdstr);
}
static jboolean android_net_wifi_setCountryCodeCommand(JNIEnv* env, jobject clazz, jstring country)
{
char cmdstr[BUF_SIZE];
jboolean isCopy;
const char *countryStr = env->GetStringUTFChars(country, &isCopy);
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER COUNTRY %s", countryStr);
env->ReleaseStringUTFChars(country, countryStr);
if ((numWritten == -1) || (numWritten >= (int)sizeof(cmdstr))) {
return false;
}
return doBooleanCommand(cmdstr, "OK");
}
static jboolean android_net_wifi_setNetworkVariableCommand(JNIEnv* env,
jobject clazz,
@@ -484,32 +498,6 @@ static jint android_net_wifi_getBandCommand(JNIEnv* env, jobject clazz)
return (jint)band;
}
static jboolean android_net_wifi_setNumAllowedChannelsCommand(JNIEnv* env, jobject clazz, jint numChannels)
{
char cmdstr[BUF_SIZE];
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER SCAN-CHANNELS %u", numChannels);
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
return (jboolean)!cmdTooLong && doBooleanCommand(cmdstr, "OK");
}
static jint android_net_wifi_getNumAllowedChannelsCommand(JNIEnv* env, jobject clazz)
{
char reply[BUF_SIZE];
int numChannels;
if (doCommand("DRIVER SCAN-CHANNELS", reply, sizeof(reply)) != 0) {
return -1;
}
// reply comes back in the form "Scan-Channels = X" where X is the
// number of channels
if (sscanf(reply, "%*s = %u", &numChannels) == 1)
return numChannels;
else
return -1;
}
static jboolean android_net_wifi_setBluetoothCoexistenceModeCommand(JNIEnv* env, jobject clazz, jint mode)
{
char cmdstr[BUF_SIZE];
@@ -645,8 +633,6 @@ static JNINativeMethod gWifiMethods[] = {
{ "getPowerModeCommand", "()I", (void*) android_net_wifi_getPowerModeCommand },
{ "setBandCommand", "(I)Z", (void*) android_net_wifi_setBandCommand},
{ "getBandCommand", "()I", (void*) android_net_wifi_getBandCommand},
{ "setNumAllowedChannelsCommand", "(I)Z", (void*) android_net_wifi_setNumAllowedChannelsCommand },
{ "getNumAllowedChannelsCommand", "()I", (void*) android_net_wifi_getNumAllowedChannelsCommand },
{ "setBluetoothCoexistenceModeCommand", "(I)Z",
(void*) android_net_wifi_setBluetoothCoexistenceModeCommand },
{ "setBluetoothCoexistenceScanModeCommand", "(Z)Z",
@@ -668,6 +654,8 @@ static JNINativeMethod gWifiMethods[] = {
(void*) android_net_wifi_wpsPinFromDeviceCommand },
{ "setSuspendOptimizationsCommand", "(Z)Z",
(void*) android_net_wifi_setSuspendOptimizationsCommand},
{ "setCountryCodeCommand", "(Ljava/lang/String;)Z",
(void*) android_net_wifi_setCountryCodeCommand},
{ "doDhcpRequest", "(Landroid/net/DhcpInfo;)Z", (void*) android_net_wifi_doDhcpRequest },
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_wifi_getDhcpError },
};

View File

@@ -2345,10 +2345,9 @@
<!-- This string appears (on two lines) when you type a number into contacts search, to let you create a contact whose phone number is the number you typed. The first line will be in bigger type than the second. -->
<string name="create_contact_using">Create contact\nusing <xliff:g id="number" example="555">%s</xliff:g></string>
<!-- This string array should be overridden by the manufacture to present a list of carrier-id,locale,wifi-channel sets. This is used at startup to set system defaults by checking the system property ro.carrier for the carrier-id and searching through this array -->
<!-- This string array should be overridden by the manufacture to present a list of carrier-id,locale. The wifi regulatory domain is extracted from the locale information. This is used at startup to set system defaults by checking the system property ro.carrier for the carrier-id and searching through this array -->
<!-- An Array of [[Carrier-ID] -->
<!-- [default-locale] -->
<!-- [default-wifi-allowed-channels]] -->
<!-- [default-locale]] -->
<string-array translatable="false" name="carrier_properties">
</string-array>

View File

@@ -134,12 +134,6 @@ public class WifiService extends IWifiManager.Stub {
*/
private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */
/**
* Number of allowed radio frequency channels in various regulatory domains.
* This list is sufficient for 802.11b/g networks (2.4GHz range).
*/
private static int[] sValidRegulatoryChannelCounts = new int[] {11, 13, 14};
private static final String ACTION_DEVICE_IDLE =
"com.android.server.WifiManager.action.DEVICE_IDLE";
@@ -737,82 +731,19 @@ public class WifiService extends IWifiManager.Stub {
}
/**
* Set the number of radio frequency channels that are allowed to be used
* in the current regulatory domain. This method should be used only
* if the correct number of channels cannot be determined automatically
* for some reason. If the operation is successful, the new value may be
* persisted as a Secure setting.
* @param numChannels the number of allowed channels. Must be greater than 0
* and less than or equal to 16.
* Set the country code
* @param countryCode ISO 3166 country code.
* @param persist {@code true} if the setting should be remembered.
* @return {@code true} if the operation succeeds, {@code false} otherwise, e.g.,
* {@code numChannels} is outside the valid range.
*
* The persist behavior exists so that wifi can fall back to the last
* persisted country code on a restart, when the locale information is
* not available from telephony.
*/
public synchronized boolean setNumAllowedChannels(int numChannels, boolean persist) {
Slog.i(TAG, "WifiService trying to setNumAllowed to "+numChannels+
" with persist set to "+persist);
public void setCountryCode(String countryCode, boolean persist) {
Slog.i(TAG, "WifiService trying to set country code to " + countryCode +
" with persist set to " + persist);
enforceChangePermission();
/*
* Validate the argument. We'd like to let the Wi-Fi driver do this,
* but if Wi-Fi isn't currently enabled, that's not possible, and
* we want to persist the setting anyway,so that it will take
* effect when Wi-Fi does become enabled.
*/
boolean found = false;
for (int validChan : sValidRegulatoryChannelCounts) {
if (validChan == numChannels) {
found = true;
break;
}
}
if (!found) {
return false;
}
if (persist) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS,
numChannels);
}
mWifiStateMachine.setNumAllowedChannels(numChannels);
return true;
}
/**
* Return the number of frequency channels that are allowed
* to be used in the current regulatory domain.
* @return the number of allowed channels, or {@code -1} if an error occurs
*/
public int getNumAllowedChannels() {
int numChannels;
enforceAccessPermission();
/*
* If we can't get the value from the driver (e.g., because
* Wi-Fi is not currently enabled), get the value from
* Settings.
*/
numChannels = mWifiStateMachine.getNumAllowedChannels();
if (numChannels < 0) {
numChannels = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS,
-1);
}
return numChannels;
}
/**
* Return the list of valid values for the number of allowed radio channels
* for various regulatory domains.
* @return the list of channel counts
*/
public int[] getValidChannelCounts() {
enforceAccessPermission();
return sValidRegulatoryChannelCounts;
mWifiStateMachine.setCountryCode(countryCode, persist);
}
/**

View File

@@ -48,22 +48,16 @@ public final class MccTable
String iso;
int smallestDigitsMnc;
String language;
int wifiChannels;
MccEntry(int mnc, String iso, int smallestDigitsMCC) {
this(mnc, iso, smallestDigitsMCC, null);
}
MccEntry(int mnc, String iso, int smallestDigitsMCC, String language) {
this(mnc, iso, smallestDigitsMCC, language, 0);
}
MccEntry(int mnc, String iso, int smallestDigitsMCC, String language, int wifiChannels) {
this.mcc = mnc;
this.iso = iso;
this.smallestDigitsMnc = smallestDigitsMCC;
this.language = language;
this.wifiChannels = wifiChannels;
}
@@ -170,23 +164,6 @@ public final class MccTable
}
}
/**
* Given a GSM Mobile Country Code, returns the number of wifi
* channels allowed in that country. Returns 0 if unavailable.
*/
public static int
wifiChannelsForMcc(int mcc) {
MccEntry entry;
entry = entryForMcc(mcc);
if (entry == null) {
return 0;
} else {
return entry.wifiChannels;
}
}
/**
* Updates MCC and MNC device configuration information for application retrieving
* correct version of resources. If either MCC or MNC is 0, they will be ignored (not set).
@@ -210,7 +187,7 @@ public final class MccTable
if (mcc != 0) {
setTimezoneFromMccIfNeeded(phone, mcc);
setLocaleFromMccIfNeeded(phone, mcc);
setWifiChannelsFromMcc(phone, mcc);
setWifiCountryCodeFromMcc(phone, mcc);
}
try {
Configuration config = ActivityManagerNative.getDefault().getConfiguration();
@@ -266,14 +243,14 @@ public final class MccTable
* @param phone PhoneBase to act on (get context from).
* @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
*/
private static void setWifiChannelsFromMcc(PhoneBase phone, int mcc) {
int wifiChannels = MccTable.wifiChannelsForMcc(mcc);
if (wifiChannels != 0) {
private static void setWifiCountryCodeFromMcc(PhoneBase phone, int mcc) {
String country = MccTable.countryCodeForMcc(mcc);
if (!country.isEmpty()) {
Context context = phone.getContext();
Log.d(LOG_TAG, "WIFI_NUM_ALLOWED_CHANNELS set to " + wifiChannels);
Log.d(LOG_TAG, "WIFI_COUNTRY_CODE set to " + country);
WifiManager wM = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
//persist
wM.setNumAllowedChannels(wifiChannels, true);
wM.setCountryCode(country, true);
}
}
@@ -297,7 +274,7 @@ public final class MccTable
*/
table.add(new MccEntry(202,"gr",2)); //Greece
table.add(new MccEntry(204,"nl",2,"nl",13)); //Netherlands (Kingdom of the)
table.add(new MccEntry(204,"nl",2,"nl")); //Netherlands (Kingdom of the)
table.add(new MccEntry(206,"be",2)); //Belgium
table.add(new MccEntry(208,"fr",2,"fr")); //France
table.add(new MccEntry(212,"mc",2)); //Monaco (Principality of)
@@ -311,11 +288,11 @@ public final class MccTable
table.add(new MccEntry(225,"va",2,"it")); //Vatican City State
table.add(new MccEntry(226,"ro",2)); //Romania
table.add(new MccEntry(228,"ch",2,"de")); //Switzerland (Confederation of)
table.add(new MccEntry(230,"cz",2,"cs",13)); //Czech Republic
table.add(new MccEntry(230,"cz",2,"cs")); //Czech Republic
table.add(new MccEntry(231,"sk",2)); //Slovak Republic
table.add(new MccEntry(232,"at",2,"de",13)); //Austria
table.add(new MccEntry(234,"gb",2,"en",13)); //United Kingdom of Great Britain and Northern Ireland
table.add(new MccEntry(235,"gb",2,"en",13)); //United Kingdom of Great Britain and Northern Ireland
table.add(new MccEntry(232,"at",2,"de")); //Austria
table.add(new MccEntry(234,"gb",2,"en")); //United Kingdom of Great Britain and Northern Ireland
table.add(new MccEntry(235,"gb",2,"en")); //United Kingdom of Great Britain and Northern Ireland
table.add(new MccEntry(238,"dk",2)); //Denmark
table.add(new MccEntry(240,"se",2)); //Sweden
table.add(new MccEntry(242,"no",2)); //Norway
@@ -328,7 +305,7 @@ public final class MccTable
table.add(new MccEntry(257,"by",2)); //Belarus (Republic of)
table.add(new MccEntry(259,"md",2)); //Moldova (Republic of)
table.add(new MccEntry(260,"pl",2)); //Poland (Republic of)
table.add(new MccEntry(262,"de",2,"de",13)); //Germany (Federal Republic of)
table.add(new MccEntry(262,"de",2,"de")); //Germany (Federal Republic of)
table.add(new MccEntry(266,"gi",2)); //Gibraltar
table.add(new MccEntry(268,"pt",2)); //Portugal
table.add(new MccEntry(270,"lu",2)); //Luxembourg
@@ -349,15 +326,15 @@ public final class MccTable
table.add(new MccEntry(294,"mk",2)); //The Former Yugoslav Republic of Macedonia
table.add(new MccEntry(295,"li",2)); //Liechtenstein (Principality of)
table.add(new MccEntry(297,"me",2)); //Montenegro (Republic of)
table.add(new MccEntry(302,"ca",3,"",11)); //Canada
table.add(new MccEntry(302,"ca",3,"")); //Canada
table.add(new MccEntry(308,"pm",2)); //Saint Pierre and Miquelon (Collectivit territoriale de la Rpublique franaise)
table.add(new MccEntry(310,"us",3,"en",11)); //United States of America
table.add(new MccEntry(311,"us",3,"en",11)); //United States of America
table.add(new MccEntry(312,"us",3,"en",11)); //United States of America
table.add(new MccEntry(313,"us",3,"en",11)); //United States of America
table.add(new MccEntry(314,"us",3,"en",11)); //United States of America
table.add(new MccEntry(315,"us",3,"en",11)); //United States of America
table.add(new MccEntry(316,"us",3,"en",11)); //United States of America
table.add(new MccEntry(310,"us",3,"en")); //United States of America
table.add(new MccEntry(311,"us",3,"en")); //United States of America
table.add(new MccEntry(312,"us",3,"en")); //United States of America
table.add(new MccEntry(313,"us",3,"en")); //United States of America
table.add(new MccEntry(314,"us",3,"en")); //United States of America
table.add(new MccEntry(315,"us",3,"en")); //United States of America
table.add(new MccEntry(316,"us",3,"en")); //United States of America
table.add(new MccEntry(330,"pr",2)); //Puerto Rico
table.add(new MccEntry(332,"vi",2)); //United States Virgin Islands
table.add(new MccEntry(334,"mx",3)); //Mexico
@@ -414,27 +391,27 @@ public final class MccTable
table.add(new MccEntry(436,"tj",2)); //Tajikistan (Republic of)
table.add(new MccEntry(437,"kg",2)); //Kyrgyz Republic
table.add(new MccEntry(438,"tm",2)); //Turkmenistan
table.add(new MccEntry(440,"jp",2,"ja",14)); //Japan
table.add(new MccEntry(441,"jp",2,"ja",14)); //Japan
table.add(new MccEntry(450,"kr",2,"ko",13)); //Korea (Republic of)
table.add(new MccEntry(440,"jp",2,"ja")); //Japan
table.add(new MccEntry(441,"jp",2,"ja")); //Japan
table.add(new MccEntry(450,"kr",2,"ko")); //Korea (Republic of)
table.add(new MccEntry(452,"vn",2)); //Viet Nam (Socialist Republic of)
table.add(new MccEntry(454,"hk",2)); //"Hong Kong, China"
table.add(new MccEntry(455,"mo",2)); //"Macao, China"
table.add(new MccEntry(456,"kh",2)); //Cambodia (Kingdom of)
table.add(new MccEntry(457,"la",2)); //Lao People's Democratic Republic
table.add(new MccEntry(460,"cn",2,"zh",13)); //China (People's Republic of)
table.add(new MccEntry(461,"cn",2,"zh",13)); //China (People's Republic of)
table.add(new MccEntry(460,"cn",2,"zh")); //China (People's Republic of)
table.add(new MccEntry(461,"cn",2,"zh")); //China (People's Republic of)
table.add(new MccEntry(466,"tw",2)); //"Taiwan, China"
table.add(new MccEntry(467,"kp",2)); //Democratic People's Republic of Korea
table.add(new MccEntry(470,"bd",2)); //Bangladesh (People's Republic of)
table.add(new MccEntry(472,"mv",2)); //Maldives (Republic of)
table.add(new MccEntry(502,"my",2)); //Malaysia
table.add(new MccEntry(505,"au",2,"en",11)); //Australia
table.add(new MccEntry(505,"au",2,"en")); //Australia
table.add(new MccEntry(510,"id",2)); //Indonesia (Republic of)
table.add(new MccEntry(514,"tl",2)); //Democratic Republic of Timor-Leste
table.add(new MccEntry(515,"ph",2)); //Philippines (Republic of the)
table.add(new MccEntry(520,"th",2)); //Thailand
table.add(new MccEntry(525,"sg",2,"en",11)); //Singapore (Republic of)
table.add(new MccEntry(525,"sg",2,"en")); //Singapore (Republic of)
table.add(new MccEntry(528,"bn",2)); //Brunei Darussalam
table.add(new MccEntry(530,"nz",2, "en")); //New Zealand
table.add(new MccEntry(534,"mp",2)); //Northern Mariana Islands (Commonwealth of the)

View File

@@ -558,11 +558,6 @@ public abstract class PhoneBase extends Handler implements Phone {
String c = carrierLocales[i].toString();
if (carrier.equals(c)) {
String l = carrierLocales[i+1].toString();
int wifiChannels = 0;
try {
wifiChannels = Integer.parseInt(
carrierLocales[i+2].toString());
} catch (NumberFormatException e) { }
String language = l.substring(0, 2);
String country = "";
@@ -571,15 +566,15 @@ public abstract class PhoneBase extends Handler implements Phone {
}
setSystemLocale(language, country);
if (wifiChannels != 0) {
if (!country.isEmpty()) {
try {
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS);
Settings.Secure.WIFI_COUNTRY_CODE);
} catch (Settings.SettingNotFoundException e) {
// note this is not persisting
WifiManager wM = (WifiManager)
mContext.getSystemService(Context.WIFI_SERVICE);
wM.setNumAllowedChannels(wifiChannels, false);
wM.setCountryCode(country, false);
}
}
return;

View File

@@ -72,16 +72,4 @@ public class MccTableTest extends AndroidTestCase {
assertEquals(MccTable.smallestDigitsMccForMnc(0), 2); // mcc not defined, hence default
assertEquals(MccTable.smallestDigitsMccForMnc(2000), 2); // mcc not defined, hence default
}
@SmallTest
public void testWifi() throws Exception {
assertEquals(MccTable.wifiChannelsForMcc(262), 13);
assertEquals(MccTable.wifiChannelsForMcc(234), 13);
assertEquals(MccTable.wifiChannelsForMcc(505), 11);
assertEquals(MccTable.wifiChannelsForMcc(313), 11);
assertEquals(MccTable.wifiChannelsForMcc(330), 0); // wifi not defined, hence default
assertEquals(MccTable.wifiChannelsForMcc(0), 0); // mcc not defined, hence default
assertEquals(MccTable.wifiChannelsForMcc(2000), 0); // mcc not defined, hence default
}
}

View File

@@ -58,11 +58,7 @@ interface IWifiManager
int getWifiEnabledState();
int getNumAllowedChannels();
boolean setNumAllowedChannels(int numChannels, boolean persist);
int[] getValidChannelCounts();
void setCountryCode(String country, boolean persist);
boolean saveConfiguration();

View File

@@ -672,56 +672,18 @@ public class WifiManager {
}
/**
* Return the number of frequency channels that are allowed
* to be used in the current regulatory domain.
* @return the number of allowed channels, or {@code -1} if an error occurs
* Set the country code.
* @param countryCode country code in ISO 3166 format.
* @param persist {@code true} if this needs to be remembered
*
* @hide pending API council
* @hide
*/
public int getNumAllowedChannels() {
public void setCountryCode(String country, boolean persist) {
try {
return mService.getNumAllowedChannels();
} catch (RemoteException e) {
return -1;
}
mService.setCountryCode(country, persist);
} catch (RemoteException e) { }
}
/**
* Set the number of frequency channels that are allowed to be used
* in the current regulatory domain. This method should be used only
* if the correct number of channels cannot be determined automatically
* for some reason.
* @param numChannels the number of allowed channels. Must be greater than 0
* and less than or equal to 16.
* @param persist {@code true} if you want this remembered
* @return {@code true} if the operation succeeds, {@code false} otherwise, e.g.,
* {@code numChannels} is out of range.
*
* @hide pending API council
*/
public boolean setNumAllowedChannels(int numChannels, boolean persist) {
try {
return mService.setNumAllowedChannels(numChannels, persist);
} catch (RemoteException e) {
return false;
}
}
/**
* Return the list of valid values for the number of allowed radio channels
* for various regulatory domains.
* @return the list of channel counts, or {@code null} if the operation fails
*
* @hide pending API council review
*/
public int[] getValidChannelCounts() {
try {
return mService.getValidChannelCounts();
} catch (RemoteException e) {
return null;
}
}
/**
* Return the DHCP-assigned addresses from the last successful DHCP request,
* if any.

View File

@@ -117,10 +117,6 @@ public class WifiNative {
public native static int getPowerModeCommand();
public native static boolean setNumAllowedChannelsCommand(int numChannels);
public native static int getNumAllowedChannelsCommand();
/**
* Sets the bluetooth coexistence mode.
*
@@ -163,6 +159,8 @@ public class WifiNative {
public native static boolean setSuspendOptimizationsCommand(boolean enabled);
public native static boolean setCountryCodeCommand(String countryCode);
/**
* Wait for the supplicant to send an event, returning the event string.
* @return the event string sent by the supplicant.

View File

@@ -111,7 +111,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private String mInterfaceName;
private int mNumAllowedChannels = 0;
private int mLastSignalLevel = -1;
private String mLastBssid;
private int mLastNetworkId;
@@ -271,8 +270,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* false(0)
*/
private static final int CMD_SET_BLUETOOTH_SCAN_MODE = 79;
/* Set number of allowed channels */
private static final int CMD_SET_NUM_ALLOWED_CHANNELS = 80;
/* Set the country code */
private static final int CMD_SET_COUNTRY_CODE = 80;
/* Request connectivity manager wake lock before driver stop */
private static final int CMD_REQUEST_CM_WAKELOCK = 81;
/* Enables RSSI poll */
@@ -308,6 +307,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private static final int CMD_START_WPS_PIN_FROM_AP = 90;
/* Start Wi-Fi protected setup pin method configuration with pin obtained from device */
private static final int CMD_START_WPS_PIN_FROM_DEVICE = 91;
/**
* Interval in milliseconds between polling for connection
* status items that are not sent via asynchronous events.
@@ -831,42 +831,17 @@ public class WifiStateMachine extends HierarchicalStateMachine {
}
/**
* Set the number of allowed radio frequency channels from the system
* setting value, if any.
* Set the country code
* @param countryCode following ISO 3166 format
* @param persist {@code true} if the setting should be remembered.
*/
public void setNumAllowedChannels() {
try {
setNumAllowedChannels(
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS));
} catch (Settings.SettingNotFoundException e) {
if (mNumAllowedChannels != 0) {
setNumAllowedChannels(mNumAllowedChannels);
}
// otherwise, use the driver default
public void setCountryCode(String countryCode, boolean persist) {
if (persist) {
Settings.Secure.putString(mContext.getContentResolver(),
Settings.Secure.WIFI_COUNTRY_CODE,
countryCode);
}
}
/**
* Set the number of radio frequency channels that are allowed to be used
* in the current regulatory domain.
* @param numChannels the number of allowed channels. Must be greater than 0
* and less than or equal to 16.
*/
public void setNumAllowedChannels(int numChannels) {
sendMessage(obtainMessage(CMD_SET_NUM_ALLOWED_CHANNELS, numChannels, 0));
}
/**
* Get number of allowed channels
*
* @return channel count, -1 on failure
*
* TODO: this is not a public API and needs to be removed in favor
* of asynchronous reporting. unused for now.
*/
public int getNumAllowedChannels() {
return -1;
sendMessage(obtainMessage(CMD_SET_COUNTRY_CODE, countryCode));
}
/**
@@ -957,7 +932,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sb.append("mWifiInfo ").append(mWifiInfo).append(LS);
sb.append("mDhcpInfo ").append(mDhcpInfo).append(LS);
sb.append("mNetworkInfo ").append(mNetworkInfo).append(LS);
sb.append("mNumAllowedChannels ").append(mNumAllowedChannels).append(LS);
sb.append("mLastSignalLevel ").append(mLastSignalLevel).append(LS);
sb.append("mLastBssid ").append(mLastBssid).append(LS);
sb.append("mLastNetworkId ").append(mLastNetworkId).append(LS);
@@ -977,6 +951,19 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* Internal private functions
********************************************************/
/**
* Set the country code from the system setting value, if any.
*/
private void setCountryCode() {
String countryCode = Settings.Secure.getString(mContext.getContentResolver(),
Settings.Secure.WIFI_COUNTRY_CODE);
if (countryCode != null && !countryCode.isEmpty()) {
setCountryCode(countryCode, false);
} else {
//use driver default
}
}
private void setWifiState(int wifiState) {
final int previousWifiState = mWifiState.get();
@@ -1563,7 +1550,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_HIGH_PERF_MODE:
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_NUM_ALLOWED_CHANNELS:
case CMD_SET_COUNTRY_CODE:
case CMD_REQUEST_CM_WAKELOCK:
case CMD_CONNECT_NETWORK:
case CMD_SAVE_NETWORK:
@@ -1665,7 +1652,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_HIGH_PERF_MODE:
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_NUM_ALLOWED_CHANNELS:
case CMD_SET_COUNTRY_CODE:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
deferMessage(message);
@@ -1793,7 +1780,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_HIGH_PERF_MODE:
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_NUM_ALLOWED_CHANNELS:
case CMD_SET_COUNTRY_CODE:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
deferMessage(message);
@@ -1890,7 +1877,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_HIGH_PERF_MODE:
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_NUM_ALLOWED_CHANNELS:
case CMD_SET_COUNTRY_CODE:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
deferMessage(message);
@@ -2034,7 +2021,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_HIGH_PERF_MODE:
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_NUM_ALLOWED_CHANNELS:
case CMD_SET_COUNTRY_CODE:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
case CMD_START_SCAN:
@@ -2060,8 +2047,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
mIsRunning = true;
updateBatteryWorkSource(null);
/* Initialize channel count */
setNumAllowedChannels();
/* set country code */
setCountryCode();
if (mIsScanMode) {
WifiNative.setScanResultHandlingCommand(SCAN_ONLY_MODE);
@@ -2093,9 +2080,12 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_BLUETOOTH_SCAN_MODE:
WifiNative.setBluetoothCoexistenceScanModeCommand(message.arg1 == 1);
break;
case CMD_SET_NUM_ALLOWED_CHANNELS:
mNumAllowedChannels = message.arg1;
WifiNative.setNumAllowedChannelsCommand(message.arg1);
case CMD_SET_COUNTRY_CODE:
String country = (String) message.obj;
Log.d(TAG, "set country code " + country);
if (!WifiNative.setCountryCodeCommand(country.toUpperCase())) {
Log.e(TAG, "Failed to set country code " + country);
}
break;
case CMD_STOP_DRIVER:
mWakeLock.acquire();
@@ -2151,7 +2141,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_HIGH_PERF_MODE:
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_NUM_ALLOWED_CHANNELS:
case CMD_SET_COUNTRY_CODE:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
case CMD_START_SCAN: