Merge "Refactor getPersistedNetworkPreference"

This commit is contained in:
Robert Greenwalt
2012-12-07 09:09:05 -08:00
committed by Android (Google) Code Review
5 changed files with 29 additions and 12 deletions

View File

@ -12554,7 +12554,7 @@ package android.net {
method public int stopUsingNetworkFeature(int, java.lang.String);
field public static final deprecated java.lang.String ACTION_BACKGROUND_DATA_SETTING_CHANGED = "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
field public static final java.lang.String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
field public static final int DEFAULT_NETWORK_PREFERENCE = 1; // 0x1
field public static final deprecated int DEFAULT_NETWORK_PREFERENCE = 1; // 0x1
field public static final java.lang.String EXTRA_EXTRA_INFO = "extraInfo";
field public static final java.lang.String EXTRA_IS_FAILOVER = "isFailover";
field public static final deprecated java.lang.String EXTRA_NETWORK_INFO = "networkInfo";

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

@ -43,8 +43,6 @@
-->
<string name="def_location_providers_allowed" translatable="false">gps</string>
<bool name="assisted_gps_enabled">true</bool>
<!-- 0 == mobile, 1 == wifi. -->
<integer name="def_network_preference">1</integer>
<bool name="def_netstats_enabled">true</bool>
<bool name="def_usb_mass_storage_enabled">true</bool>
<bool name="def_wifi_on">false</bool>

View File

@ -2161,9 +2161,6 @@ public class DatabaseHelper extends SQLiteOpenHelper {
loadBooleanSetting(stmt, Settings.Global.INSTALL_NON_MARKET_APPS,
R.bool.def_install_non_market_apps);
loadIntegerSetting(stmt, Settings.Global.NETWORK_PREFERENCE,
R.integer.def_network_preference);
loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED,
R.bool.def_usb_mass_storage_enabled);

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;
}
/**