Refactor WifiStateTracker
Implement WifiStateTracker as a HSM. Change-Id: Ic12fd78f1f183b5c4dea8ad2301002267ceff0cb
This commit is contained in:
@@ -97,7 +97,7 @@ public class NetworkInfo implements Parcelable {
|
|||||||
stateMap.put(DetailedState.DISCONNECTED, State.DISCONNECTED);
|
stateMap.put(DetailedState.DISCONNECTED, State.DISCONNECTED);
|
||||||
stateMap.put(DetailedState.FAILED, State.DISCONNECTED);
|
stateMap.put(DetailedState.FAILED, State.DISCONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int mNetworkType;
|
private int mNetworkType;
|
||||||
private int mSubtype;
|
private int mSubtype;
|
||||||
private String mTypeName;
|
private String mTypeName;
|
||||||
@@ -144,7 +144,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the network type
|
* @return the network type
|
||||||
*/
|
*/
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return mNetworkType;
|
synchronized (this) {
|
||||||
|
return mNetworkType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,12 +155,16 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the network subtype
|
* @return the network subtype
|
||||||
*/
|
*/
|
||||||
public int getSubtype() {
|
public int getSubtype() {
|
||||||
return mSubtype;
|
synchronized (this) {
|
||||||
|
return mSubtype;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSubtype(int subtype, String subtypeName) {
|
void setSubtype(int subtype, String subtypeName) {
|
||||||
mSubtype = subtype;
|
synchronized (this) {
|
||||||
mSubtypeName = subtypeName;
|
mSubtype = subtype;
|
||||||
|
mSubtypeName = subtypeName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +173,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the name of the network type
|
* @return the name of the network type
|
||||||
*/
|
*/
|
||||||
public String getTypeName() {
|
public String getTypeName() {
|
||||||
return mTypeName;
|
synchronized (this) {
|
||||||
|
return mTypeName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,7 +183,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the name of the network subtype
|
* @return the name of the network subtype
|
||||||
*/
|
*/
|
||||||
public String getSubtypeName() {
|
public String getSubtypeName() {
|
||||||
return mSubtypeName;
|
synchronized (this) {
|
||||||
|
return mSubtypeName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,7 +198,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* of being established, {@code false} otherwise.
|
* of being established, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isConnectedOrConnecting() {
|
public boolean isConnectedOrConnecting() {
|
||||||
return mState == State.CONNECTED || mState == State.CONNECTING;
|
synchronized (this) {
|
||||||
|
return mState == State.CONNECTED || mState == State.CONNECTING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,7 +209,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return {@code true} if network connectivity exists, {@code false} otherwise.
|
* @return {@code true} if network connectivity exists, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return mState == State.CONNECTED;
|
synchronized (this) {
|
||||||
|
return mState == State.CONNECTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,7 +227,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return {@code true} if the network is available, {@code false} otherwise
|
* @return {@code true} if the network is available, {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return mIsAvailable;
|
synchronized (this) {
|
||||||
|
return mIsAvailable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,7 +239,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void setIsAvailable(boolean isAvailable) {
|
public void setIsAvailable(boolean isAvailable) {
|
||||||
mIsAvailable = isAvailable;
|
synchronized (this) {
|
||||||
|
mIsAvailable = isAvailable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,7 +252,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isFailover() {
|
public boolean isFailover() {
|
||||||
return mIsFailover;
|
synchronized (this) {
|
||||||
|
return mIsFailover;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,7 +264,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void setFailover(boolean isFailover) {
|
public void setFailover(boolean isFailover) {
|
||||||
mIsFailover = isFailover;
|
synchronized (this) {
|
||||||
|
mIsFailover = isFailover;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,11 +276,15 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return {@code true} if roaming is in effect, {@code false} otherwise.
|
* @return {@code true} if roaming is in effect, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isRoaming() {
|
public boolean isRoaming() {
|
||||||
return mIsRoaming;
|
synchronized (this) {
|
||||||
|
return mIsRoaming;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRoaming(boolean isRoaming) {
|
void setRoaming(boolean isRoaming) {
|
||||||
mIsRoaming = isRoaming;
|
synchronized (this) {
|
||||||
|
mIsRoaming = isRoaming;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -266,7 +292,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the coarse-grained state
|
* @return the coarse-grained state
|
||||||
*/
|
*/
|
||||||
public State getState() {
|
public State getState() {
|
||||||
return mState;
|
synchronized (this) {
|
||||||
|
return mState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,7 +302,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the fine-grained state
|
* @return the fine-grained state
|
||||||
*/
|
*/
|
||||||
public DetailedState getDetailedState() {
|
public DetailedState getDetailedState() {
|
||||||
return mDetailedState;
|
synchronized (this) {
|
||||||
|
return mDetailedState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -287,10 +317,12 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void setDetailedState(DetailedState detailedState, String reason, String extraInfo) {
|
public void setDetailedState(DetailedState detailedState, String reason, String extraInfo) {
|
||||||
this.mDetailedState = detailedState;
|
synchronized (this) {
|
||||||
this.mState = stateMap.get(detailedState);
|
this.mDetailedState = detailedState;
|
||||||
this.mReason = reason;
|
this.mState = stateMap.get(detailedState);
|
||||||
this.mExtraInfo = extraInfo;
|
this.mReason = reason;
|
||||||
|
this.mExtraInfo = extraInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -299,7 +331,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the reason for failure, or null if not available
|
* @return the reason for failure, or null if not available
|
||||||
*/
|
*/
|
||||||
public String getReason() {
|
public String getReason() {
|
||||||
return mReason;
|
synchronized (this) {
|
||||||
|
return mReason;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -309,20 +343,24 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @return the extra information, or null if not available
|
* @return the extra information, or null if not available
|
||||||
*/
|
*/
|
||||||
public String getExtraInfo() {
|
public String getExtraInfo() {
|
||||||
return mExtraInfo;
|
synchronized (this) {
|
||||||
|
return mExtraInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder("NetworkInfo: ");
|
synchronized (this) {
|
||||||
builder.append("type: ").append(getTypeName()).append("[").append(getSubtypeName()).
|
StringBuilder builder = new StringBuilder("NetworkInfo: ");
|
||||||
append("], state: ").append(mState).append("/").append(mDetailedState).
|
builder.append("type: ").append(getTypeName()).append("[").append(getSubtypeName()).
|
||||||
append(", reason: ").append(mReason == null ? "(unspecified)" : mReason).
|
append("], state: ").append(mState).append("/").append(mDetailedState).
|
||||||
append(", extra: ").append(mExtraInfo == null ? "(none)" : mExtraInfo).
|
append(", reason: ").append(mReason == null ? "(unspecified)" : mReason).
|
||||||
append(", roaming: ").append(mIsRoaming).
|
append(", extra: ").append(mExtraInfo == null ? "(none)" : mExtraInfo).
|
||||||
append(", failover: ").append(mIsFailover).
|
append(", roaming: ").append(mIsRoaming).
|
||||||
append(", isAvailable: ").append(mIsAvailable);
|
append(", failover: ").append(mIsFailover).
|
||||||
return builder.toString();
|
append(", isAvailable: ").append(mIsAvailable);
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -338,17 +376,19 @@ public class NetworkInfo implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeInt(mNetworkType);
|
synchronized (this) {
|
||||||
dest.writeInt(mSubtype);
|
dest.writeInt(mNetworkType);
|
||||||
dest.writeString(mTypeName);
|
dest.writeInt(mSubtype);
|
||||||
dest.writeString(mSubtypeName);
|
dest.writeString(mTypeName);
|
||||||
dest.writeString(mState.name());
|
dest.writeString(mSubtypeName);
|
||||||
dest.writeString(mDetailedState.name());
|
dest.writeString(mState.name());
|
||||||
dest.writeInt(mIsFailover ? 1 : 0);
|
dest.writeString(mDetailedState.name());
|
||||||
dest.writeInt(mIsAvailable ? 1 : 0);
|
dest.writeInt(mIsFailover ? 1 : 0);
|
||||||
dest.writeInt(mIsRoaming ? 1 : 0);
|
dest.writeInt(mIsAvailable ? 1 : 0);
|
||||||
dest.writeString(mReason);
|
dest.writeInt(mIsRoaming ? 1 : 0);
|
||||||
dest.writeString(mExtraInfo);
|
dest.writeString(mReason);
|
||||||
|
dest.writeString(mExtraInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
*/
|
*/
|
||||||
private List mNetRequestersPids[];
|
private List mNetRequestersPids[];
|
||||||
|
|
||||||
|
private WifiWatchdogService mWifiWatchdogService;
|
||||||
|
|
||||||
// priority order of the nettrackers
|
// priority order of the nettrackers
|
||||||
// (excluding dynamically set mNetworkPreference)
|
// (excluding dynamically set mNetworkPreference)
|
||||||
// TODO - move mNetworkTypePreference into this
|
// TODO - move mNetworkTypePreference into this
|
||||||
@@ -318,6 +320,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
|
mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
|
||||||
wst.startMonitoring();
|
wst.startMonitoring();
|
||||||
|
|
||||||
|
//TODO: as part of WWS refactor, create only when needed
|
||||||
|
mWifiWatchdogService = new WifiWatchdogService(context, wst);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TYPE_MOBILE:
|
case ConnectivityManager.TYPE_MOBILE:
|
||||||
mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
|
mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
|
||||||
|
|||||||
Reference in New Issue
Block a user