From b73e0a91dcf3fa04cf07c2d096fb20c229d6cd28 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 15 Sep 2017 14:45:40 -0700 Subject: NetworkListStoreData: Set creatorUid for all networks on load Some network configurations saved during N have the creatorUid set to -1. (Not sure what was the root cause in N which introduced this issue in saved networks) Ensure that we set |creatorUid| for such networks with invalid uid to SYSTEM_UID on loading. The networks with invalid creatorUid can anyway only be modified only by settings/sysui (because they possess NETWORK_SETTINGS permission). Bug: 65623732 Test: Unit tests Change-Id: Ib6f61b81e19877cdf0c42d29c9f5ae3869725517 --- .../android/server/wifi/NetworkListStoreData.java | 21 ++++++++++++++++++++- .../java/com/android/server/wifi/WifiInjector.java | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'service') 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 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 fc3af83e5..923983958 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); -- cgit v1.2.3 From 7cede48303b0faabb3b6861a1ac7229f76fca006 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Mon, 25 Sep 2017 14:51:37 -0700 Subject: WifiStateMachine: Handle WifiManager.save() when wifi is off Bug: 66909738 Test: Verified that you can save networks even when wifi is off using ag/2930541. Test: Unit tests Change-Id: I38c316456e74ce5ad1ec43750b075f0999c28327 --- .../com/android/server/wifi/WifiStateMachine.java | 75 ++++++++++++---------- 1 file changed, 42 insertions(+), 33 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index faad0e2d1..ca9cdfdfd 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)) { @@ -7210,6 +7182,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 attributes = new ArrayList<>(6); if (lp.hasIPv4Address()) { -- cgit v1.2.3