Andrid WiFi響應多用戶切換

由於管理wifi的service(WifiService)是屬於java framework的systemserver中的服務,繼承於 SystemService。因此,WIfiService也可以在用戶切換的過程中,由AMS回調onStartUser和onSwitchUser。
可以看到WifiService實現了onSwitchUser函數

@Override
public void onSwitchUser(int userId) {
    mImpl.handleUserSwitch(userId);
}

mImpl是WifiServiceImpl類的實例

public void handleUserSwitch(int userId) {
    mWifiStateMachine.handleUserSwitch(userId);
}

mWifiStateMachine是WifiStateMachine類的實例

public void handleUserSwitch(int userId) {
    sendMessage(CMD_USER_SWITCH, userId);
}
//下面是DefauleState中處理message的函數
case CMD_USER_SWITCH:
    Set<Integer> removedNetworkIds =
        mWifiConfigManager.handleUserSwitch(message.arg1);
    if (removedNetworkIds.contains(mTargetNetworkId) ||
        removedNetworkIds.contains(mLastNetworkId)) {
        // Disconnect and let autojoin reselect a new network
        sendMessage(CMD_DISCONNECT);
    }
    break;

mWifiConfigManager是WifiConfigManager類的實例

public Set<Integer> handleUserSwitch(int userId) {
    ......
    Set<Integer> removedNetworkIds = clearInternalUserData(mCurrentUserId);
    mConfiguredNetworks.setNewUser(userId);
    mCurrentUserId = userId;

    if (mUserManager.isUserUnlockingOrUnlocked(mCurrentUserId)) {
        handleUserUnlockOrSwitch(mCurrentUserId);
    } else {
        // Cannot read data from new user's CE store file before they log-in.
        mPendingUnlockStoreRead = true;
        Log.i(TAG, "Waiting for user unlock to load from store");
    }
    return removedNetworkIds;
}

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.  下面是加載新用戶wifi配置的重點
    if (loadFromUserStoreAfterUnlockOrSwitch(userId)) {
        saveToStore(true);
        mPendingUnlockStoreRead = false;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章