Refactor getPersistedNetworkPreference am: a8aa160836

Original change: undetermined

Change-Id: Ifc544d6b8f094995520b4693fded8a96cde1b1c3
This commit is contained in:
Jianzheng Zhou
2021-05-31 05:50:54 +00:00
committed by Automerger Merge Worker
2 changed files with 28 additions and 6 deletions

View File

@@ -328,6 +328,18 @@ public class ConnectivityManager {
/** {@hide} */
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;
/**

View File

@@ -412,8 +412,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
ConnectivityManager.MAX_NETWORK_TYPE+1];
mCurrentLinkProperties = new LinkProperties[ConnectivityManager.MAX_NETWORK_TYPE+1];
mNetworkPreference = getPersistedNetworkPreference();
mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_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];
for (int i : mPriorityList) {
mNetRequestersPids[i] = new ArrayList();
@@ -726,11 +739,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
final int networkPrefSetting = Settings.Global
.getInt(cr, Settings.Global.NETWORK_PREFERENCE, -1);
if (networkPrefSetting != -1) {
return networkPrefSetting;
}
return ConnectivityManager.DEFAULT_NETWORK_PREFERENCE;
return networkPrefSetting;
}
/**