summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-01-20 08:05:27 -0800
committerRoshan Pius <rpius@google.com>2019-01-23 11:44:24 -0800
commitf5d58eb73fe91a5543fd737e2aa6a8840f9bda9b (patch)
tree155f8994651d5410b852ec08741755687374a500 /service/java/com/android/server
parentf68d19cdb8895d586417e6d67c3f37c2acef03f3 (diff)
downloadandroid_frameworks_opt_net_wifi-f5d58eb73fe91a5543fd737e2aa6a8840f9bda9b.tar.gz
android_frameworks_opt_net_wifi-f5d58eb73fe91a5543fd737e2aa6a8840f9bda9b.tar.bz2
android_frameworks_opt_net_wifi-f5d58eb73fe91a5543fd737e2aa6a8840f9bda9b.zip
WifiConfigManager: App attribution for suggestion/request
Add new field to mark a WifiConfiguration as created from a network specifier or suggestion. WifiConfiguration.creatorName for such networks will contain the package name of the app that added the corresponding specifier/suggestion. This can be used by the settings app to display the app's name in the wifi picker summary. Bug: 115504887 Bug: 113878056 Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I673a9e309a3faeb01723211d8f80f75d9477994a
Diffstat (limited to 'service/java/com/android/server')
-rw-r--r--service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java11
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java46
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkFactory.java6
3 files changed, 47 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java b/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java
index f248e08be..2c231a0c4 100644
--- a/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java
+++ b/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiNetworkSuggestion;
-import android.os.Process;
import android.util.LocalLog;
import java.util.Comparator;
@@ -124,18 +123,22 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv
existingSavedNetwork.networkId));
return existingSavedNetwork;
}
- return addCandidateToWifiConfigManager(candidateNetworkSuggestion.wifiConfiguration);
+ return addCandidateToWifiConfigManager(
+ candidateNetworkSuggestion.wifiConfiguration,
+ candidateNetworkSuggestion.suggestorUid,
+ candidateNetworkSuggestion.suggestorPackageName);
}
// Add and enable this network to the central database (i.e WifiConfigManager).
// Returns the copy of WifiConfiguration with the allocated network ID filled in.
private WifiConfiguration addCandidateToWifiConfigManager(
- @NonNull WifiConfiguration wifiConfiguration) {
+ @NonNull WifiConfiguration wifiConfiguration, int uid, @NonNull String packageName) {
// Mark the network ephemeral because we don't want these persisted by WifiConfigManager.
wifiConfiguration.ephemeral = true;
+ wifiConfiguration.fromWifiNetworkSuggestion = true;
NetworkUpdateResult result =
- mWifiConfigManager.addOrUpdateNetwork(wifiConfiguration, Process.WIFI_UID);
+ mWifiConfigManager.addOrUpdateNetwork(wifiConfiguration, uid, packageName);
if (!result.isSuccess()) {
mLocalLog.log("Failed to add network suggestion");
return null;
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index bd5ffe905..9ad1f44e4 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -16,6 +16,7 @@
package com.android.server.wifi;
+import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.admin.DeviceAdminInfo;
import android.app.admin.DevicePolicyManagerInternal;
@@ -1008,7 +1009,7 @@ public class WifiConfigManager {
* configuration.
*/
private WifiConfiguration createNewInternalWifiConfigurationFromExternal(
- WifiConfiguration externalConfig, int uid) {
+ WifiConfiguration externalConfig, int uid, @Nullable String packageName) {
WifiConfiguration newInternalConfig = new WifiConfiguration();
// First allocate a new network ID for the configuration.
@@ -1028,6 +1029,8 @@ public class WifiConfigManager {
newInternalConfig.ephemeral = externalConfig.ephemeral;
newInternalConfig.osu = externalConfig.osu;
newInternalConfig.trusted = externalConfig.trusted;
+ newInternalConfig.fromWifiNetworkSuggestion = externalConfig.fromWifiNetworkSuggestion;
+ newInternalConfig.fromWifiNetworkSpecifier = externalConfig.fromWifiNetworkSpecifier;
newInternalConfig.useExternalScores = externalConfig.useExternalScores;
newInternalConfig.shared = externalConfig.shared;
newInternalConfig.updateIdentifier = externalConfig.updateIdentifier;
@@ -1035,7 +1038,7 @@ public class WifiConfigManager {
// Add debug information for network addition.
newInternalConfig.creatorUid = newInternalConfig.lastUpdateUid = uid;
newInternalConfig.creatorName = newInternalConfig.lastUpdateName =
- mContext.getPackageManager().getNameForUid(uid);
+ packageName != null ? packageName : mContext.getPackageManager().getNameForUid(uid);
newInternalConfig.creationTime = newInternalConfig.updateTime =
createDebugTimeStampString(mClock.getWallClockMillis());
updateRandomizedMacAddress(newInternalConfig);
@@ -1078,7 +1081,8 @@ public class WifiConfigManager {
* configuration.
*/
private WifiConfiguration updateExistingInternalWifiConfigurationFromExternal(
- WifiConfiguration internalConfig, WifiConfiguration externalConfig, int uid) {
+ WifiConfiguration internalConfig, WifiConfiguration externalConfig, int uid,
+ @Nullable String packageName) {
WifiConfiguration newInternalConfig = new WifiConfiguration(internalConfig);
// Copy over all the public elements from the provided configuration.
@@ -1086,7 +1090,8 @@ public class WifiConfigManager {
// Add debug information for network update.
newInternalConfig.lastUpdateUid = uid;
- newInternalConfig.lastUpdateName = mContext.getPackageManager().getNameForUid(uid);
+ newInternalConfig.lastUpdateName =
+ packageName != null ? packageName : mContext.getPackageManager().getNameForUid(uid);
newInternalConfig.updateTime = createDebugTimeStampString(mClock.getWallClockMillis());
return newInternalConfig;
@@ -1098,10 +1103,12 @@ public class WifiConfigManager {
* network configuration. Otherwise, the networkId should refer to an existing configuration.
*
* @param config provided WifiConfiguration object.
- * @param uid UID of the app requesting the network addition/deletion.
+ * @param uid UID of the app requesting the network addition/modification.
+ * @param packageName Package name of the app requesting the network addition/modification.
* @return NetworkUpdateResult object representing status of the update.
*/
- private NetworkUpdateResult addOrUpdateNetworkInternal(WifiConfiguration config, int uid) {
+ private NetworkUpdateResult addOrUpdateNetworkInternal(WifiConfiguration config, int uid,
+ @Nullable String packageName) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Adding/Updating network " + config.getPrintableSsid());
}
@@ -1115,7 +1122,8 @@ public class WifiConfigManager {
Log.e(TAG, "Cannot add network with invalid config");
return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
}
- newInternalConfig = createNewInternalWifiConfigurationFromExternal(config, uid);
+ newInternalConfig =
+ createNewInternalWifiConfigurationFromExternal(config, uid, packageName);
// Since the original config provided may have had an empty
// {@link WifiConfiguration#allowedKeyMgmt} field, check again if we already have a
// network with the the same configkey.
@@ -1136,7 +1144,7 @@ public class WifiConfigManager {
}
newInternalConfig =
updateExistingInternalWifiConfigurationFromExternal(
- existingInternalConfig, config, uid);
+ existingInternalConfig, config, uid, packageName);
}
// Only add networks with proxy settings if the user has permission to
@@ -1220,10 +1228,12 @@ public class WifiConfigManager {
* network configuration. Otherwise, the networkId should refer to an existing configuration.
*
* @param config provided WifiConfiguration object.
- * @param uid UID of the app requesting the network addition/modification.
+ * @param uid UID of the app requesting the network addition/modification.
+ * @param packageName Package name of the app requesting the network addition/modification.
* @return NetworkUpdateResult object representing status of the update.
*/
- public NetworkUpdateResult addOrUpdateNetwork(WifiConfiguration config, int uid) {
+ public NetworkUpdateResult addOrUpdateNetwork(WifiConfiguration config, int uid,
+ @Nullable String packageName) {
if (!doesUidBelongToCurrentUser(uid)) {
Log.e(TAG, "UID " + uid + " not visible to the current user");
return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
@@ -1236,7 +1246,7 @@ public class WifiConfigManager {
Log.e(TAG, "Cannot add/update network before store is read!");
return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
}
- NetworkUpdateResult result = addOrUpdateNetworkInternal(config, uid);
+ NetworkUpdateResult result = addOrUpdateNetworkInternal(config, uid, packageName);
if (!result.isSuccess()) {
Log.e(TAG, "Failed to add/update network " + config.getPrintableSsid());
return result;
@@ -1259,6 +1269,20 @@ public class WifiConfigManager {
}
}
return result;
+
+ }
+
+ /**
+ * Add a network or update a network configuration to our database.
+ * If the supplied networkId is INVALID_NETWORK_ID, we create a new empty
+ * network configuration. Otherwise, the networkId should refer to an existing configuration.
+ *
+ * @param config provided WifiConfiguration object.
+ * @param uid UID of the app requesting the network addition/modification.
+ * @return NetworkUpdateResult object representing status of the update.
+ */
+ public NetworkUpdateResult addOrUpdateNetwork(WifiConfiguration config, int uid) {
+ return addOrUpdateNetwork(config, uid, null);
}
/**
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java
index 42e7aa98f..1bd93c635 100644
--- a/service/java/com/android/server/wifi/WifiNetworkFactory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java
@@ -662,7 +662,9 @@ public class WifiNetworkFactory extends NetworkFactory {
return existingSavedNetwork.networkId;
}
NetworkUpdateResult networkUpdateResult =
- mWifiConfigManager.addOrUpdateNetwork(network, Process.WIFI_UID);
+ mWifiConfigManager.addOrUpdateNetwork(
+ network, mActiveSpecificNetworkRequestSpecifier.requestorUid,
+ mActiveSpecificNetworkRequestSpecifier.requestorPackageName);
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Added network to config manager " + networkUpdateResult.netId);
}
@@ -706,6 +708,8 @@ public class WifiNetworkFactory extends NetworkFactory {
// Mark the network ephemeral so that it's automatically removed at the end of connection.
network.ephemeral = true;
+ network.fromWifiNetworkSpecifier = true;
+
// Store the user selected network.
mUserSelectedNetwork = network;