Solve the problem that BUG of can not automatically reconnect WIFI after android equipment is powered off and restarted

  • 2021-11-13 18:08:25
  • OfStack

Description:

For example, there is a high probability that WIFI cannot be reconnected for online devices, but this will not happen when restarting in non-power-off mode (reboot).

Analysis:

After analysis, this is related to the file system storage mechanism of Linux. When the user layer writes files, the system stores the files in memory first, and then writes the data to flash after CPU is idle. This is a cache mechanism, which aims to improve the efficiency of reading and writing files. But it brings the risk of losing data when the machine suddenly loses power.

Solution:

In the Linux system, there is a command sync, the purpose of which is to force the data to be written in memory to be forced into flash. Back to our question, we can call the sync command after saving the WIFI password.

Add fileSync () to document frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative. java as follows; You can


private void fileSync(){
     Runtime runtime = Runtime.getRuntime();
         try {
           runtime.exec("sync");
         } catch (IOException e) {
           e.printStackTrace();
             Log.e(TAG, "fileSync"); 
        }
  }
 public boolean saveConfig() {
   boolean ret;
   ret = doBooleanCommand("SAVE_CONFIG");
    fileSync();// New additions 
   return ret;
 }

Summarize


Related articles: