Refactor getPersistedNetworkPreference
Optimize for updating mNetworkPreference according to device's networkAttributes setting from overlay config.xml when connectivityservice start. Change-Id: I90286332d4f453038f1ddac7dd9d1265d96b4859 Signed-off-by: Jianzheng Zhou <jianzheng.zhou@freescale.com>
This commit is contained in:
committed by
Robert Greenwalt
parent
402d9c853f
commit
028d203d0f
@@ -328,6 +328,18 @@ public class ConnectivityManager {
|
|||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P;
|
public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you want to set the default network preference,you can directly
|
||||||
|
* change the networkAttributes array in framework's config.xml.
|
||||||
|
*
|
||||||
|
* @deprecated Since we support so many more networks now, the single
|
||||||
|
* network default network preference can't really express
|
||||||
|
* the heirarchy. Instead, the default is defined by the
|
||||||
|
* networkAttributes in config.xml. You can determine
|
||||||
|
* the current value by calling {@link getNetworkPreference()}
|
||||||
|
* from an App.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
|
public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -412,8 +412,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
ConnectivityManager.MAX_NETWORK_TYPE+1];
|
ConnectivityManager.MAX_NETWORK_TYPE+1];
|
||||||
mCurrentLinkProperties = new LinkProperties[ConnectivityManager.MAX_NETWORK_TYPE+1];
|
mCurrentLinkProperties = new LinkProperties[ConnectivityManager.MAX_NETWORK_TYPE+1];
|
||||||
|
|
||||||
mNetworkPreference = getPersistedNetworkPreference();
|
|
||||||
|
|
||||||
mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
|
mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
|
||||||
mNetConfigs = new NetworkConfig[ConnectivityManager.MAX_NETWORK_TYPE+1];
|
mNetConfigs = new NetworkConfig[ConnectivityManager.MAX_NETWORK_TYPE+1];
|
||||||
|
|
||||||
@@ -495,6 +493,21 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update mNetworkPreference according to user mannually first then overlay config.xml
|
||||||
|
mNetworkPreference = getPersistedNetworkPreference();
|
||||||
|
if (mNetworkPreference == -1) {
|
||||||
|
for (int n : mPriorityList) {
|
||||||
|
if (mNetConfigs[n].isDefault() && ConnectivityManager.isNetworkTypeValid(n)) {
|
||||||
|
mNetworkPreference = n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mNetworkPreference == -1) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"You should set at least one default Network in config.xml!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mNetRequestersPids = new ArrayList[ConnectivityManager.MAX_NETWORK_TYPE+1];
|
mNetRequestersPids = new ArrayList[ConnectivityManager.MAX_NETWORK_TYPE+1];
|
||||||
for (int i : mPriorityList) {
|
for (int i : mPriorityList) {
|
||||||
mNetRequestersPids[i] = new ArrayList();
|
mNetRequestersPids[i] = new ArrayList();
|
||||||
@@ -726,11 +739,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
final int networkPrefSetting = Settings.Global
|
final int networkPrefSetting = Settings.Global
|
||||||
.getInt(cr, Settings.Global.NETWORK_PREFERENCE, -1);
|
.getInt(cr, Settings.Global.NETWORK_PREFERENCE, -1);
|
||||||
if (networkPrefSetting != -1) {
|
|
||||||
return networkPrefSetting;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConnectivityManager.DEFAULT_NETWORK_PREFERENCE;
|
return networkPrefSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user