91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android  Wifi的forget()操作實例詳解

發布時間:2020-08-27 13:44:26 來源:腳本之家 閱讀:271 作者:極限人格 欄目:移動開發

Android  Wifi的forget()操作實例詳解

我們在處理某個Wifi連接時,有時會需要忘掉當前連接的密碼信息。執行這項操作,我們需要調用WifiManager::forget()函數:

/** 
 * Delete the network in the supplicant config. 
 * 
 * This function is used instead of a sequence of removeNetwork() 
 * and saveConfiguration(). 
 * 
 * @param config the set of variables that describe the configuration, 
 *      contained in a {@link WifiConfiguration} object. 
 * @param listener for callbacks on success or failure. Can be null. 
 * @throws IllegalStateException if the WifiManager instance needs to be 
 * initialized again 
 * @hide 
 */ 
public void forget(int netId, ActionListener listener) { 
  if (netId < 0) throw new IllegalArgumentException("Network id cannot be negative"); 
  validateChannel(); 
  sAsyncChannel.sendMessage(FORGET_NETWORK, netId, putListener(listener)); 
} 

從函數介紹可知,調用forget()函數,當前網絡連接的配置信息就會從wpa_supplicant.conf中刪掉;之后這個網絡就不會有自動重連的動作,因為conf文件中已經沒有該網絡的配置信息。

跟蹤FORGET_NETWORK消息,WifiServiceImpl::ClientHandler處理:

case WifiManager.FORGET_NETWORK: 
  if (isOwner(msg.sendingUid)) { 
    mWifiStateMachine.sendMessage(Message.obtain(msg)); 
  } else { 
    Slog.e(TAG, "Forget is not authorized for user"); 
    replyFailed(msg, WifiManager.FORGET_NETWORK_FAILED, 
        WifiManager.NOT_AUTHORIZED); 
  } 
  break; 

簡單地將該消息轉發給WifiStateMachine。此時Wifi是連接狀態,WifiStateMachine中當前狀態是ConnectedState,它的父狀態ConnectModeState處理:

case WifiManager.FORGET_NETWORK: 
  // Debug only, remember last configuration that was forgotten 
  WifiConfiguration toRemove 
      = mWifiConfigStore.getWifiConfiguration(message.arg1); 
  if (toRemove == null) { 
    lastForgetConfigurationAttempt = null; 
  } else { 
    lastForgetConfigurationAttempt = new WifiConfiguration(toRemove); 
  } 
  // check that the caller owns this network 
  netId = message.arg1; 
 
  if (!mWifiConfigStore.canModifyNetwork(message.sendingUid, netId, 
      /* onlyAnnotate */ false)) { 
    logw("Not authorized to forget network " 
       + " cnid=" + netId 
       + " uid=" + message.sendingUid); 
    replyToMessage(message, WifiManager.FORGET_NETWORK_FAILED, 
        WifiManager.NOT_AUTHORIZED); 
    break; 
  } 
 
  if (mWifiConfigStore.forgetNetwork(message.arg1)) { 
    replyToMessage(message, WifiManager.FORGET_NETWORK_SUCCEEDED); 
    broadcastWifiCredentialChanged(WifiManager.WIFI_CREDENTIAL_FORGOT, 
        (WifiConfiguration) message.obj); 
  } else { 
    loge("Failed to forget network"); 
    replyToMessage(message, WifiManager.FORGET_NETWORK_FAILED, 
        WifiManager.ERROR); 
  } 
  break; 

mWifiConfigStore.forgetNetwork():

/** 
 * Forget the specified network and save config 
 * 
 * @param netId network to forget 
 * @return {@code true} if it succeeds, {@code false} otherwise 
 */ 
boolean forgetNetwork(int netId) { 
  if (showNetworks) localLog("forgetNetwork", netId); 
 
  WifiConfiguration config = mConfiguredNetworks.get(netId); 
  boolean remove = removeConfigAndSendBroadcastIfNeeded(netId); 
  if (!remove) { 
    //success but we dont want to remove the network from supplicant conf file 
    return true; 
  } 
  if (mWifiNative.removeNetwork(netId)) { 
    if (config != null && config.isPasspoint()) { 
      writePasspointConfigs(config.FQDN, null); 
    } 
    mWifiNative.saveConfig(); 
    writeKnownNetworkHistory(true); 
    return true; 
  } else { 
    loge("Failed to remove network " + netId); 
    return false; 
  } 
} 

根據傳入的當前網絡的netId,分別調用WifiNative的removeNetwork()、saveConfig()方法刪除conf文件的配置信息并進行保存;執行完成后,forget()函數結束了。通過代碼我們發現,執行forget()函數并不會引起WifiStateMachine中狀態的切換。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

舟曲县| 东台市| 溆浦县| 社会| 酉阳| 巩义市| 九龙城区| 武夷山市| 苏尼特右旗| 西宁市| 宁晋县| 白朗县| 清水河县| 江达县| 明星| 姜堰市| 宁都县| 南宁市| 新密市| 淮北市| 威海市| 高邑县| 岚皋县| 兴宁市| 宿州市| 巴林左旗| 和政县| 封丘县| 木兰县| 临汾市| 淳化县| 四川省| 杭州市| 彭山县| 梁平县| 英超| 无棣县| 南召县| 衢州市| 海宁市| 吐鲁番市|