くらげになりたい。

くらげのようにふわふわ生きたい日曜プログラマなブログ。趣味の備忘録です。

【Android】NetworkInfo.StateとNetworkInfo.DetailedStateとSupplicantStateの関係

AndroidWifiの状態を知りたいなーと思ったら、いろいろなStateがあるらしい。。
対応関係がわからないな...と思ったので調べてみたときの備忘録。

対応関係はこんな感じ。SupplicantStateだと、
NetworkInfo.StateのCONNECTEDSUSPENDEDに当たるものがないので注意。

NetworkInfo.State NetworkInfo.DetailedState SupplicantState
DISCONNECTED IDLE INACTIVE
UNINITIALIZED
SCANNING SCANNING
CONNECTING CONNECTING AUTHENTICATING
ASSOCIATING
ASSOCIATED
AUTHENTICATING FOUR_WAY_HANDSHAKE
GROUP_HANDSHAKE
OBTAINING_IPADDR COMPLETED
CONNECTED CONNECTED -
SUSPENDED SUSPENDED -
DISCONNECTING DISCONNECTING -
DISCONNECTED DISCONNECTED DISCONNECTED
INTERFACE_DISABLED
DORMANT
FAILED INVALID

NetworkInfo.DetailedStateとNetworkInfo.Stateの対応

core/java/android/net/NetworkInfo.java - platform/frameworks/base - Git at Googleより

stateMap.put(DetailedState.IDLE, State.DISCONNECTED);
stateMap.put(DetailedState.SCANNING, State.DISCONNECTED);
stateMap.put(DetailedState.CONNECTING, State.CONNECTING);
stateMap.put(DetailedState.AUTHENTICATING, State.CONNECTING);
stateMap.put(DetailedState.OBTAINING_IPADDR, State.CONNECTING);
stateMap.put(DetailedState.CONNECTED, State.CONNECTED);
stateMap.put(DetailedState.SUSPENDED, State.SUSPENDED);
stateMap.put(DetailedState.DISCONNECTING, State.DISCONNECTING);
stateMap.put(DetailedState.DISCONNECTED, State.DISCONNECTED);
stateMap.put(DetailedState.FAILED, State.DISCONNECTED);

SupplicantStateとNetworkInfo.DetailedStateの対応

wifi/java/android/net/wifi/WifiInfo.java - platform/frameworks/base - Git at Googleより

stateMap.put(SupplicantState.DISCONNECTED, DetailedState.DISCONNECTED);
stateMap.put(SupplicantState.INTERFACE_DISABLED, DetailedState.DISCONNECTED);
stateMap.put(SupplicantState.INACTIVE, DetailedState.IDLE);
stateMap.put(SupplicantState.SCANNING, DetailedState.SCANNING);
stateMap.put(SupplicantState.AUTHENTICATING, DetailedState.CONNECTING);
stateMap.put(SupplicantState.ASSOCIATING, DetailedState.CONNECTING);
stateMap.put(SupplicantState.ASSOCIATED, DetailedState.CONNECTING);
stateMap.put(SupplicantState.FOUR_WAY_HANDSHAKE, DetailedState.AUTHENTICATING);
stateMap.put(SupplicantState.GROUP_HANDSHAKE, DetailedState.AUTHENTICATING);
stateMap.put(SupplicantState.COMPLETED, DetailedState.OBTAINING_IPADDR);
stateMap.put(SupplicantState.DORMANT, DetailedState.DISCONNECTED);
stateMap.put(SupplicantState.UNINITIALIZED, DetailedState.IDLE);
stateMap.put(SupplicantState.INVALID, DetailedState.FAILED);

参考にしたサイト様

以上!!