Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android 10 how to disable Randomized Mac Address in source code

Currently, I am working on connecting specific WiFi in the source code.

But the problem is, since Android 10, the default setting is to set a random macArress. Yeah i forcibly set the mac adrress to wifi info or I want to turn off random mac adrress option

this is my code

if(BasicInfo.wifiEncryption == BasicInfo.WPA_PSK){
            BasicInfo.debug(TAG,"setWiFiConfigForJellyBean :BasicInfo.WPA_PSK");


            config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
            config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); 
            config.allowedProtocols.set(WifiConfiguration.Protocol.RSN); 
            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
            config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
            config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);

            config.preSharedKey = "\"".concat(BasicInfo.WIFI_PASSWORD).concat("\"");


            BasicInfo.debug(TAG,"BasicInfo.WPA_PSK Password :" + BasicInfo.WIFI_PASSWORD);

        }
like image 436
sangHoon Avatar asked Jun 01 '26 07:06

sangHoon


1 Answers

It's only possible on non Play Store applications.

There is global settings called wifi_connected_mac_randomization_enabled, but

  1. You need to have android.permission.WRITE_SETTINGS granted to modify it.
  2. It may not work on some devices.
  3. Sometimes you will need to reconnect network to apply setting change.

Here is an example how you can use it:

public static void setMacRandomization(Context context, boolean enabled){
    ContentResolver cr = Objects.requireNonNull(context).getContentResolver();
    try {
        Settings.Global.putString(cr, "wifi_connected_mac_randomization_enabled", enabled ? "1" : "0");
    } catch (Exception e) {
        //Missing permission or setting not found on this device or something else
    }
}
like image 168
Jan Rozenbajgier Avatar answered Jun 04 '26 12:06

Jan Rozenbajgier