Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed4f28b4 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

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
parent 98444a94
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -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,
+17 −29
Original line number Diff line number Diff line
@@ -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 },
};
+2 −3
Original line number Diff line number Diff line
@@ -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>

+10 −79
Original line number Diff line number Diff line
@@ -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+
    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);
    }

    /**
+27 −50
Original line number Diff line number Diff line
@@ -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)
Loading