Refactor WifiStateTracker

Implement WifiStateTracker as a HSM.

Change-Id: Ic12fd78f1f183b5c4dea8ad2301002267ceff0cb
This commit is contained in:
Irfan Sheriff
2010-06-07 09:03:04 -07:00
parent a7dfbd3a1d
commit 653e2a2f64
2 changed files with 88 additions and 43 deletions

View File

@@ -144,8 +144,10 @@ public class NetworkInfo implements Parcelable {
* @return the network type
*/
public int getType() {
synchronized (this) {
return mNetworkType;
}
}
/**
* Return a network-type-specific integer describing the subtype
@@ -153,13 +155,17 @@ public class NetworkInfo implements Parcelable {
* @return the network subtype
*/
public int getSubtype() {
synchronized (this) {
return mSubtype;
}
}
void setSubtype(int subtype, String subtypeName) {
synchronized (this) {
mSubtype = subtype;
mSubtypeName = subtypeName;
}
}
/**
* Return a human-readable name describe the type of the network,
@@ -167,16 +173,20 @@ public class NetworkInfo implements Parcelable {
* @return the name of the network type
*/
public String getTypeName() {
synchronized (this) {
return mTypeName;
}
}
/**
* Return a human-readable name describing the subtype of the network.
* @return the name of the network subtype
*/
public String getSubtypeName() {
synchronized (this) {
return mSubtypeName;
}
}
/**
* Indicates whether network connectivity exists or is in the process
@@ -188,8 +198,10 @@ public class NetworkInfo implements Parcelable {
* of being established, {@code false} otherwise.
*/
public boolean isConnectedOrConnecting() {
synchronized (this) {
return mState == State.CONNECTED || mState == State.CONNECTING;
}
}
/**
* Indicates whether network connectivity exists and it is possible to establish
@@ -197,8 +209,10 @@ public class NetworkInfo implements Parcelable {
* @return {@code true} if network connectivity exists, {@code false} otherwise.
*/
public boolean isConnected() {
synchronized (this) {
return mState == State.CONNECTED;
}
}
/**
* Indicates whether network connectivity is possible. A network is unavailable
@@ -213,8 +227,10 @@ public class NetworkInfo implements Parcelable {
* @return {@code true} if the network is available, {@code false} otherwise
*/
public boolean isAvailable() {
synchronized (this) {
return mIsAvailable;
}
}
/**
* Sets if the network is available, ie, if the connectivity is possible.
@@ -223,8 +239,10 @@ public class NetworkInfo implements Parcelable {
* @hide
*/
public void setIsAvailable(boolean isAvailable) {
synchronized (this) {
mIsAvailable = isAvailable;
}
}
/**
* Indicates whether the current attempt to connect to the network
@@ -234,8 +252,10 @@ public class NetworkInfo implements Parcelable {
* otherwise.
*/
public boolean isFailover() {
synchronized (this) {
return mIsFailover;
}
}
/**
* Set the failover boolean.
@@ -244,8 +264,10 @@ public class NetworkInfo implements Parcelable {
* @hide
*/
public void setFailover(boolean isFailover) {
synchronized (this) {
mIsFailover = isFailover;
}
}
/**
* Indicates whether the device is currently roaming on this network.
@@ -254,28 +276,36 @@ public class NetworkInfo implements Parcelable {
* @return {@code true} if roaming is in effect, {@code false} otherwise.
*/
public boolean isRoaming() {
synchronized (this) {
return mIsRoaming;
}
}
void setRoaming(boolean isRoaming) {
synchronized (this) {
mIsRoaming = isRoaming;
}
}
/**
* Reports the current coarse-grained state of the network.
* @return the coarse-grained state
*/
public State getState() {
synchronized (this) {
return mState;
}
}
/**
* Reports the current fine-grained state of the network.
* @return the fine-grained state
*/
public DetailedState getDetailedState() {
synchronized (this) {
return mDetailedState;
}
}
/**
* Sets the fine-grained state of the network.
@@ -287,11 +317,13 @@ public class NetworkInfo implements Parcelable {
* @hide
*/
public void setDetailedState(DetailedState detailedState, String reason, String extraInfo) {
synchronized (this) {
this.mDetailedState = detailedState;
this.mState = stateMap.get(detailedState);
this.mReason = reason;
this.mExtraInfo = extraInfo;
}
}
/**
* Report the reason an attempt to establish connectivity failed,
@@ -299,8 +331,10 @@ public class NetworkInfo implements Parcelable {
* @return the reason for failure, or null if not available
*/
public String getReason() {
synchronized (this) {
return mReason;
}
}
/**
* Report the extra information about the network state, if any was
@@ -309,11 +343,14 @@ public class NetworkInfo implements Parcelable {
* @return the extra information, or null if not available
*/
public String getExtraInfo() {
synchronized (this) {
return mExtraInfo;
}
}
@Override
public String toString() {
synchronized (this) {
StringBuilder builder = new StringBuilder("NetworkInfo: ");
builder.append("type: ").append(getTypeName()).append("[").append(getSubtypeName()).
append("], state: ").append(mState).append("/").append(mDetailedState).
@@ -324,6 +361,7 @@ public class NetworkInfo implements Parcelable {
append(", isAvailable: ").append(mIsAvailable);
return builder.toString();
}
}
/**
* Implement the Parcelable interface
@@ -338,6 +376,7 @@ public class NetworkInfo implements Parcelable {
* @hide
*/
public void writeToParcel(Parcel dest, int flags) {
synchronized (this) {
dest.writeInt(mNetworkType);
dest.writeInt(mSubtype);
dest.writeString(mTypeName);
@@ -350,6 +389,7 @@ public class NetworkInfo implements Parcelable {
dest.writeString(mReason);
dest.writeString(mExtraInfo);
}
}
/**
* Implement the Parcelable interface.

View File

@@ -88,6 +88,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
*/
private List mNetRequestersPids[];
private WifiWatchdogService mWifiWatchdogService;
// priority order of the nettrackers
// (excluding dynamically set mNetworkPreference)
// TODO - move mNetworkTypePreference into this
@@ -318,6 +320,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
wst.startMonitoring();
//TODO: as part of WWS refactor, create only when needed
mWifiWatchdogService = new WifiWatchdogService(context, wst);
break;
case ConnectivityManager.TYPE_MOBILE:
mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,