diff options
author | Roshan Pius <rpius@google.com> | 2017-09-29 22:13:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-09-29 22:13:42 +0000 |
commit | 9d7cf1434fc63dec2d63d5a9c7330c2fa37aefc5 (patch) | |
tree | 235d8a92ee4185576a2d4d46eeb4e5e76dc19d1b /service | |
parent | dbaf29e09adbf2e44a598438fa8ad38f70c47b5b (diff) | |
parent | 7cede48303b0faabb3b6861a1ac7229f76fca006 (diff) |
Merge changes I38c31645,Ib6f61b81 into oc-mr1-dev
* changes:
WifiStateMachine: Handle WifiManager.save() when wifi is off
NetworkListStoreData: Set creatorUid for all networks on load
Diffstat (limited to 'service')
3 files changed, 63 insertions, 35 deletions
diff --git a/service/java/com/android/server/wifi/NetworkListStoreData.java b/service/java/com/android/server/wifi/NetworkListStoreData.java index 5ddfd4dfb..f287d4b98 100644 --- a/service/java/com/android/server/wifi/NetworkListStoreData.java +++ b/service/java/com/android/server/wifi/NetworkListStoreData.java @@ -16,10 +16,12 @@ package com.android.server.wifi; +import android.content.Context; import android.net.IpConfiguration; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiEnterpriseConfig; +import android.os.Process; import android.util.Log; import android.util.Pair; @@ -52,6 +54,8 @@ public class NetworkListStoreData implements WifiConfigStore.StoreData { private static final String XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION = "WifiEnterpriseConfiguration"; + private final Context mContext; + /** * List of saved shared networks visible to all the users to be stored in the shared store file. */ @@ -62,7 +66,9 @@ public class NetworkListStoreData implements WifiConfigStore.StoreData { */ private List<WifiConfiguration> mUserConfigurations; - NetworkListStoreData() {} + NetworkListStoreData(Context context) { + mContext = context; + } @Override public void serializeData(XmlSerializer out, boolean shared) @@ -282,6 +288,19 @@ public class NetworkListStoreData implements WifiConfigStore.StoreData { "Configuration key does not match. Retrieved: " + configKeyParsed + ", Calculated: " + configKeyCalculated); } + // Set creatorUid/creatorName for networks which don't have it set to valid value. + String creatorName = mContext.getPackageManager().getNameForUid(configuration.creatorUid); + if (creatorName == null) { + Log.e(TAG, "Invalid creatorUid for saved network " + configuration.configKey() + + ", creatorUid=" + configuration.creatorUid); + configuration.creatorUid = Process.SYSTEM_UID; + configuration.creatorName = creatorName; + } else if (!creatorName.equals(configuration.creatorName)) { + Log.w(TAG, "Invalid creatorName for saved network " + configuration.configKey() + + ", creatorUid=" + configuration.creatorUid + + ", creatorName=" + configuration.creatorName); + configuration.creatorName = creatorName; + } configuration.setNetworkSelectionStatus(status); configuration.setIpConfiguration(ipConfiguration); diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 4a42c339d..4b8e6829e 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -197,7 +197,7 @@ public class WifiInjector { mWifiConfigManager = new WifiConfigManager(mContext, mClock, UserManager.get(mContext), TelephonyManager.from(mContext), mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil, - mWifiPermissionsWrapper, new NetworkListStoreData(), + mWifiPermissionsWrapper, new NetworkListStoreData(mContext), new DeletedEphemeralSsidsStoreData()); mWifiMetrics.setWifiConfigManager(mWifiConfigManager); mWifiConnectivityHelper = new WifiConnectivityHelper(mWifiNative); diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index e96c15dad..a3054c92b 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -3980,9 +3980,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss deleteNetworkConfigAndSendReply(message, true); break; case WifiManager.SAVE_NETWORK: - messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL; - replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED, - WifiManager.BUSY); + saveNetworkConfigAndSendReply(message); break; case WifiManager.START_WPS: replyToMessage(message, WifiManager.WPS_FAILED, @@ -5270,36 +5268,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss replyToMessage(message, WifiManager.CONNECT_NETWORK_SUCCEEDED); break; case WifiManager.SAVE_NETWORK: - config = (WifiConfiguration) message.obj; - mWifiConnectionStatistics.numWifiManagerJoinAttempt++; - if (config == null) { - loge("SAVE_NETWORK with null configuration" - + mSupplicantStateTracker.getSupplicantStateName() - + " my state " + getCurrentState().getName()); - messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL; - replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED, - WifiManager.ERROR); - break; - } - result = mWifiConfigManager.addOrUpdateNetwork(config, message.sendingUid); - if (!result.isSuccess()) { - loge("SAVE_NETWORK adding/updating config=" + config + " failed"); - messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL; - replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED, - WifiManager.ERROR); - break; - } - if (!mWifiConfigManager.enableNetwork( - result.getNetworkId(), false, message.sendingUid)) { - loge("SAVE_NETWORK enabling config=" + config + " failed"); - messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL; - replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED, - WifiManager.ERROR); - break; - } + result = saveNetworkConfigAndSendReply(message); netId = result.getNetworkId(); - if (mWifiInfo.getNetworkId() == netId) { + if (result.isSuccess() && mWifiInfo.getNetworkId() == netId) { + mWifiConnectionStatistics.numWifiManagerJoinAttempt++; if (result.hasCredentialChanged()) { + config = (WifiConfiguration) message.obj; // The network credentials changed and we're connected to this network, // start a new connection with the updated credentials. logi("SAVE_NETWORK credential changed for config=" + config.configKey() @@ -5322,8 +5296,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } } } - broadcastWifiCredentialChanged(WifiManager.WIFI_CREDENTIAL_SAVED, config); - replyToMessage(message, WifiManager.SAVE_NETWORK_SUCCEEDED); break; case WifiManager.FORGET_NETWORK: if (!deleteNetworkConfigAndSendReply(message, true)) { @@ -7217,6 +7189,43 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } } + /** + * Private method to handle calling WifiConfigManager to add & enable network configs and reply + * to the message from the sender of the outcome. + * + * @return NetworkUpdateResult with networkId of the added/updated configuration. Will return + * {@link WifiConfiguration#INVALID_NETWORK_ID} in case of error. + */ + private NetworkUpdateResult saveNetworkConfigAndSendReply(Message message) { + WifiConfiguration config = (WifiConfiguration) message.obj; + if (config == null) { + loge("SAVE_NETWORK with null configuration " + + mSupplicantStateTracker.getSupplicantStateName() + + " my state " + getCurrentState().getName()); + messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL; + replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED, WifiManager.ERROR); + return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID); + } + NetworkUpdateResult result = + mWifiConfigManager.addOrUpdateNetwork(config, message.sendingUid); + if (!result.isSuccess()) { + loge("SAVE_NETWORK adding/updating config=" + config + " failed"); + messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL; + replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED, WifiManager.ERROR); + return result; + } + if (!mWifiConfigManager.enableNetwork( + result.getNetworkId(), false, message.sendingUid)) { + loge("SAVE_NETWORK enabling config=" + config + " failed"); + messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL; + replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED, WifiManager.ERROR); + return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID); + } + broadcastWifiCredentialChanged(WifiManager.WIFI_CREDENTIAL_SAVED, config); + replyToMessage(message, WifiManager.SAVE_NETWORK_SUCCEEDED); + return result; + } + private static String getLinkPropertiesSummary(LinkProperties lp) { List<String> attributes = new ArrayList<>(6); if (lp.hasIPv4Address()) { |