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