WifiConfigStore初始化读取-Android13

WifiConfigStore初始化读取

  • 1、StoreData创建并注册
  • 2、WifiConfigStore读取
    • 2.1 文件读取流程
    • 2.2 时序图
    • 2.3 日志


1、StoreData创建并注册

packages/modules/Wifi/service/java/com/android/server/wifi/WifiConfigManager.java

mWifiConfigStore.registerStoreData(mNetworkListSharedStoreData)
mWifiConfigStore.registerStoreData(mNetworkListUserStoreData)
mWifiConfigStore.registerStoreData(mRandomizedMacStoreData)
mWifiConfigStore.registerStoreData(mConnectedFreqStoreData)

packages/modules/Wifi/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java

wifiConfigStore.registerStoreData( wifiInjector.makeNetworkSuggestionStoreData(new NetworkSuggestionDataSource()))

2、WifiConfigStore读取

2.1 文件读取流程

1》当 SystemService.PHASE_SYSTEM_SERVICES_READY 系统服务准备,mImpl.checkAndStartWifi()通过WifiConfigManager.java#loadFromStore读取mWifiConfigStore.read()

/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
/data/misc/apexdata/com.android.wifi/WifiConfigStoreSoftAp.xml

2》当onUserUnlocking用户锁定,mImpl.handleUserUnlock通过WifiConfigManager.java#handleUserUnlockOrSwitch读取mWifiConfigStore.switchUserStoresAndRead(userStoreFiles)

/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStore.xml
/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStoreNetworkSuggestions.xml

packages/modules/Wifi/service/java/com/android/server/wifi/WifiService.java
packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java

   @Override
   public void onBootPhase(int phase) {
       if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
           mImpl.checkAndStartWifi();
       } else if (phase == SystemService.PHASE_BOOT_COMPLETED) {
           mImpl.handleBootCompleted();
       }
   }
 
   @Override
   public void onUserSwitching(TargetUser from, TargetUser to) {
       mImpl.handleUserSwitch(to.getUserHandle().getIdentifier());
   }
 
   @Override
   public void onUserUnlocking(TargetUser user) {
       mImpl.handleUserUnlock(user.getUserHandle().getIdentifier());
   }

packages/modules/Wifi/service/java/com/android/server/wifi/WifiConfigManager.java

    public boolean loadFromStore() {
        // If the user unlock comes in before we load from store, which means the user store have
        // not been setup yet for the current user. Setup the user store before the read so that
        // configurations for the current user will also being loaded.
        if (mDeferredUserUnlockRead) {
            Log.i(TAG, "Handling user unlock before loading from store.");
            List<WifiConfigStore.StoreFile> userStoreFiles =
                    WifiConfigStore.createUserFiles(
                            mCurrentUserId, mFrameworkFacade.isNiapModeOn(mContext));
            if (userStoreFiles == null) {
                Log.wtf(TAG, "Failed to create user store files");
                return false;
            }
            mWifiConfigStore.setUserStores(userStoreFiles);
            mDeferredUserUnlockRead = false;
        }

        try {
            mWifiConfigStore.read();
        } catch (IOException | IllegalStateException e) {
            Log.wtf(TAG, "Reading from new store failed. All saved networks are lost!", e);
            return handleConfigStoreFailure(false);
        } catch (XmlPullParserException e) {
            Log.wtf(TAG, "XML deserialization of store failed. All saved networks are lost!", e);
            return handleConfigStoreFailure(false);
        }

        loadInternalData(mNetworkListSharedStoreData.getConfigurations(),
                mNetworkListUserStoreData.getConfigurations(),
                mRandomizedMacStoreData.getMacMapping(),
                mConnectedFreqStoreData.getFreqList());
        return true;
    }

    private void handleUserUnlockOrSwitch(int userId) {
        if (mVerboseLoggingEnabled) {
            Log.v(TAG, "Loading from store after user switch/unlock for " + userId);
        }
        // Switch out the user store file.
        if (loadFromUserStoreAfterUnlockOrSwitch(userId)) {
            saveToStore(true);
            mPendingUnlockStoreRead = false;
        }
    }

    private boolean loadFromUserStoreAfterUnlockOrSwitch(int userId) {
        try {
            List<WifiConfigStore.StoreFile> userStoreFiles =
                    WifiConfigStore.createUserFiles(
                            userId, mFrameworkFacade.isNiapModeOn(mContext));
            if (userStoreFiles == null) {
                Log.e(TAG, "Failed to create user store files");
                return false;
            }
            mWifiConfigStore.switchUserStoresAndRead(userStoreFiles);
        } catch (IOException | IllegalStateException e) {
            Log.wtf(TAG, "Reading from new store failed. All saved private networks are lost!", e);
            return handleConfigStoreFailure(true);
        } catch (XmlPullParserException e) {
            Log.wtf(TAG, "XML deserialization of store failed. All saved private networks are "
                    + "lost!", e);
            return handleConfigStoreFailure(true);
        }
        loadInternalDataFromUserStore(mNetworkListUserStoreData.getConfigurations());
        return true;
    }

2.2 时序图

WifiConfigStore初始化读取-Android13_第1张图片

2.3 日志

02-06 17:21:42.574  7067  7238 E WifiConfigManager: xhbruce loadFromStore
02-06 17:21:42.581  7067  7238 E WifiConfigStore: xhbruce readFromSharedStoreFiles : sharedStoreFile=/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:42.593  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.WifiCarrierInfoStoreManagerData@3b32c54:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@7c3a7fd
02-06 17:21:42.613  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.NetworkListSharedStoreData@28b6069:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@7c3a7fd
02-06 17:21:42.615  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.RandomizedMacStoreData@6ee3aee:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@7c3a7fd
02-06 17:21:42.615  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.ConnectedFreqManager$ConnectedFreqStoreData@b77cb8f:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@7c3a7fd
02-06 17:21:42.616  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.WifiSettingsConfigStore$StoreData@4655008:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@7c3a7fd
02-06 17:21:42.616  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.hotspot2.PasspointConfigSharedStoreData@89eb9c6:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@7c3a7fd
02-06 17:21:42.616  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeDatasInvoked=[com.android.server.wifi.RandomizedMacStoreData@6ee3aee, com.android.server.wifi.NetworkListSharedStoreData@28b6069, com.android.server.wifi.WifiCarrierInfoStoreManagerData@3b32c54, com.android.server.wifi.ConnectedFreqManager$ConnectedFreqStoreData@b77cb8f, com.android.server.wifi.hotspot2.PasspointConfigSharedStoreData@89eb9c6, com.android.server.wifi.WifiSettingsConfigStore$StoreData@4655008]
02-06 17:21:42.617  7067  7238 E WifiConfigStore: xhbruce readFromSharedStoreFiles : sharedStoreFile=/data/misc/apexdata/com.android.wifi/WifiConfigStoreSoftAp.xml
02-06 17:21:42.626  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.SoftApStoreData@91a0f05:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@38a1b5a
02-06 17:21:42.626  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeDatasInvoked=[com.android.server.wifi.SoftApStoreData@91a0f05]
02-06 17:21:42.627  7067  7238 D WifiConfigStore: Reading from all stores completed in 50 ms.
02-06 17:21:42.627  7067  7238 E WifiConfigManager: xhbruce loadFromStore : mNetworkListSharedStoreData=[- DSBLE ID: -1 SSID: "guest_5G" PROVIDER-NAME: null BSSID: null FQDN: null HOME-PROVIDER-NETWORK: false PRIO: 0 HIDDEN: false PMF: false CarrierId: -1 SubscriptionId: -1 SubscriptionGroup: null
02-06 17:21:42.635  7067  7238 E WifiConfigStore: xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:45.963  7067  7238 E WifiConfigStore:  xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:45.986  7067  7238 D WifiConfigStore: Writing to stores completed in 18 ms.
02-06 17:21:48.971  7067  7238 E WifiConfigStore:  xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:48.989  7067  7238 D WifiConfigStore: Writing to stores completed in 17 ms.
02-06 17:21:48.996  7067  7238 E WifiConfigStore:  xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:49.000  7067  7238 D WifiConfigStore: Writing to stores completed in 4 ms.
02-06 17:21:51.863  7067  7238 V WifiConfigManager: Handling user unlock for 0
02-06 17:21:51.868  7067  7238 V WifiConfigManager: Loading from store after user switch/unlock for 0
02-06 17:21:51.905  7067  7238 E WifiConfigStore: xhbruce readFromUserStoreFiles : userStoreFile=/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:51.915  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.ImsiPrivacyProtectionExemptionStoreData@eeb7cd8:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@15e2831
02-06 17:21:51.936  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.NetworkListUserStoreData@2bc166d:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@15e2831
02-06 17:21:51.959  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.hotspot2.PasspointConfigUserStoreData@378db33:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@15e2831
02-06 17:21:51.970  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.SsidSetStoreData@b302a1c:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@15e2831
02-06 17:21:51.970  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.NetworkRequestStoreData@dfea625:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@15e2831
02-06 17:21:51.971  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.WakeupConfigStoreData@1aa33fa:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@15e2831
02-06 17:21:51.971  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeDatasInvoked=[com.android.server.wifi.WakeupConfigStoreData@1aa33fa, com.android.server.wifi.NetworkListUserStoreData@2bc166d, com.android.server.wifi.ImsiPrivacyProtectionExemptionStoreData@eeb7cd8, com.android.server.wifi.hotspot2.PasspointConfigUserStoreData@378db33, com.android.server.wifi.NetworkRequestStoreData@dfea625, com.android.server.wifi.SsidSetStoreData@b302a1c]
02-06 17:21:51.971  7067  7238 E WifiConfigStore: xhbruce readFromUserStoreFiles : userStoreFile=/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStoreNetworkSuggestions.xml
02-06 17:21:51.976  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeData=com.android.server.wifi.NetworkSuggestionStoreData@69c74dd:storeFile:com.android.server.wifi.WifiConfigStore$StoreFile@c274852
02-06 17:21:51.982  7067  7238 E WifiConfigStore: xhbruce deserializeData : storeDatasInvoked=[com.android.server.wifi.NetworkSuggestionStoreData@69c74dd]
02-06 17:21:51.982  7067  7238 D WifiConfigStore: Reading from user stores completed in 98 ms.
02-06 17:21:51.999  7067  7238 E WifiConfigStore:  xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:52.020  7067  7238 E WifiConfigStore:  xhbruce write :userStoreFile:/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:52.084  7067  7238 E WifiConfigStore:  xhbruce write :userStoreFile:/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStoreNetworkSuggestions.xml
02-06 17:21:52.178  7067  7238 D WifiConfigStore: Writing to stores completed in 21 ms.
02-06 17:21:52.332  7067  7238 E WifiConfigStore:  xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:52.357  7067  7238 E WifiConfigStore:  xhbruce write :userStoreFile:/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:52.362  7067  7238 E WifiConfigStore:  xhbruce write :userStoreFile:/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStoreNetworkSuggestions.xml
02-06 17:21:52.379  7067  7238 D WifiConfigStore: Writing to stores completed in 17 ms.
02-06 17:21:52.386  7067  7238 E WifiConfigStore:  xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:52.401  7067  7238 E WifiConfigStore:  xhbruce write :userStoreFile:/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:52.419  7067  7238 D WifiConfigStore: Writing to stores completed in 18 ms.
02-06 17:21:54.247  7067  7238 E WifiConfigStore:  xhbruce write :sharedStoreFile:/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
02-06 17:21:54.247  7067  7238 E WifiConfigStore:  xhbruce write :userStoreFile:/data/misc_ce/0/apexdata/com.android.wifi/WifiConfigStore.xml

你可能感兴趣的:(Android,#,WiFI,Android,WiFi)