summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Liu <steveliu@google.com>2019-08-19 14:32:09 -0700
committerSteven Liu <steveliu@google.com>2019-10-29 14:42:50 -0700
commite4cb48546eff7305a98b11646fd991d213345630 (patch)
tree702b4abc03500c618838a3cbb3dc0a4b3c7de69d
parent2bf5f0154051d5e31f8e553803dae38bc6fad421 (diff)
Add carrier ID field for WifiConfiguration and PasspointConfiguration.
This is only for the load and save carrier ID field. Bug: 130875004 Test: build, boot up, unit test. Change-Id: Ie190fc331862a61df29a7ad4a01b818a016122bf
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java21
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointXmlUtils.java5
-rw-r--r--service/java/com/android/server/wifi/util/XmlUtil.java5
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java59
6 files changed, 90 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index d530cdbfc..a16d9684d 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -40,6 +40,7 @@ import android.net.wifi.WifiNetworkSuggestion;
import android.net.wifi.WifiScanner;
import android.os.Handler;
import android.os.UserHandle;
+import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -599,6 +600,9 @@ public class WifiNetworkSuggestionsManager {
Log.w(TAG, "Empty list of network suggestions for " + packageName + ". Ignoring");
return WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS;
}
+ if (!validateNetworkSuggestions(networkSuggestions, uid, packageName)) {
+ return WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED;
+ }
PerAppInfo perAppInfo = mActiveNetworkSuggestionsPerApp.get(packageName);
if (perAppInfo == null) {
perAppInfo = new PerAppInfo(packageName);
@@ -654,6 +658,23 @@ public class WifiNetworkSuggestionsManager {
return WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS;
}
+ private boolean validateNetworkSuggestions(
+ List<WifiNetworkSuggestion> networkSuggestions, int uid, String packageName) {
+ if (mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) {
+ return true;
+ }
+ for (WifiNetworkSuggestion suggestion : networkSuggestions) {
+ WifiConfiguration config = suggestion.wifiConfiguration;
+ if (config != null
+ && config.carrierId != TelephonyManager.UNKNOWN_CARRIER_ID) {
+ Log.e(TAG, "bad wifi suggestion from app: " + packageName);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
private void stopTrackingAppOpsChange(@NonNull String packageName) {
AppOpsChangedListener appOpsChangedListener =
mAppOpsChangedListenerPerApp.remove(packageName);
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointXmlUtils.java b/service/java/com/android/server/wifi/hotspot2/PasspointXmlUtils.java
index 683728dc5..71eba0908 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointXmlUtils.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointXmlUtils.java
@@ -110,6 +110,7 @@ public class PasspointXmlUtils {
private static final String XML_TAG_USAGE_LIMIT_START_TIME = "UsageLimitStartTime";
private static final String XML_TAG_USAGE_LIMIT_DATA_LIMIT = "UsageLimitDataLimit";
private static final String XML_TAG_USAGE_LIMIT_TIME_LIMIT = "UsageLimitTimeLimit";
+ private static final String XML_TAG_CARRIER_ID = "CarrierId";
/**
* Serialize a {@link PasspointConfiguration} to the output stream as a XML block.
@@ -146,6 +147,7 @@ public class PasspointXmlUtils {
XmlUtil.writeNextValue(out, XML_TAG_FRIENDLY_NAME_LIST,
config.getServiceFriendlyNames());
}
+ XmlUtil.writeNextValue(out, XML_TAG_CARRIER_ID, config.getCarrierId());
}
/**
@@ -199,6 +201,9 @@ public class PasspointXmlUtils {
case XML_TAG_FRIENDLY_NAME_LIST:
config.setServiceFriendlyNames((Map<String, String>) value);
break;
+ case XML_TAG_CARRIER_ID:
+ config.setCarrierId((int) value);
+ break;
default:
throw new XmlPullParserException("Unknown value under "
+ "PasspointConfiguration: " + in.getName());
diff --git a/service/java/com/android/server/wifi/util/XmlUtil.java b/service/java/com/android/server/wifi/util/XmlUtil.java
index e1c48785a..f73b9974d 100644
--- a/service/java/com/android/server/wifi/util/XmlUtil.java
+++ b/service/java/com/android/server/wifi/util/XmlUtil.java
@@ -349,6 +349,7 @@ public class XmlUtil {
public static final String XML_TAG_RANDOMIZED_MAC_ADDRESS = "RandomizedMacAddress";
public static final String XML_TAG_MAC_RANDOMIZATION_SETTING = "MacRandomizationSetting";
public static final String XML_TAG_SAE_PASSWORD_ID_KEY = "SaePasswordId";
+ public static final String XML_TAG_CARRIER_ID = "CarrierId";
/**
* Write WepKeys to the XML stream.
@@ -479,6 +480,7 @@ public class XmlUtil {
configuration.getRandomizedMacAddress().toString());
XmlUtil.writeNextValue(out, XML_TAG_MAC_RANDOMIZATION_SETTING,
configuration.macRandomizationSetting);
+ XmlUtil.writeNextValue(out, XML_TAG_CARRIER_ID, configuration.carrierId);
}
/**
@@ -666,6 +668,9 @@ public class XmlUtil {
configuration.macRandomizationSetting = (int) value;
macRandomizationSettingExists = true;
break;
+ case XML_TAG_CARRIER_ID:
+ configuration.carrierId = (int) value;
+ break;
default:
throw new XmlPullParserException(
"Unknown value name found: " + valueName[0]);
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java
index 6032680b6..d9b565494 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java
@@ -103,6 +103,7 @@ public class NetworkListStoreDataTest extends WifiBaseTest {
+ "<long-array name=\"RoamingConsortiumOIs\" num=\"0\" />\n"
+ "<string name=\"RandomizedMacAddress\">%s</string>\n"
+ "<int name=\"MacRandomizationSetting\" value=\"1\" />\n"
+ + "<int name=\"CarrierId\" value=\"-1\" />\n"
+ "</WifiConfiguration>\n"
+ "<NetworkStatus>\n"
+ "<string name=\"SelectionStatus\">NETWORK_SELECTION_ENABLED</string>\n"
@@ -159,6 +160,7 @@ public class NetworkListStoreDataTest extends WifiBaseTest {
+ "<long-array name=\"RoamingConsortiumOIs\" num=\"0\" />\n"
+ "<string name=\"RandomizedMacAddress\">%s</string>\n"
+ "<int name=\"MacRandomizationSetting\" value=\"1\" />\n"
+ + "<int name=\"CarrierId\" value=\"-1\" />\n"
+ "</WifiConfiguration>\n"
+ "<NetworkStatus>\n"
+ "<string name=\"SelectionStatus\">NETWORK_SELECTION_ENABLED</string>\n"
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
index 799ad70f0..5eba36461 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
@@ -123,6 +123,7 @@ public class WifiConfigStoreTest extends WifiBaseTest {
+ "<long-array name=\"RoamingConsortiumOIs\" num=\"0\" />\n"
+ "<string name=\"RandomizedMacAddress\">%s</string>\n"
+ "<int name=\"MacRandomizationSetting\" value=\"1\" />\n"
+ + "<int name=\"CarrierId\" value=\"-1\" />\n"
+ "</WifiConfiguration>\n"
+ "<NetworkStatus>\n"
+ "<string name=\"SelectionStatus\">NETWORK_SELECTION_ENABLED</string>\n"
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 0726514bb..5755c5858 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -91,6 +91,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
private static final String TEST_FQDN = "FQDN";
private static final int TEST_UID_1 = 5667;
private static final int TEST_UID_2 = 4537;
+ private static final int VALID_CARRIER_ID = 1;
private @Mock Context mContext;
private @Mock Resources mResources;
@@ -1137,7 +1138,6 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
TEST_PACKAGE_1));
- verify(mWifiPermissionsUtil).checkNetworkCarrierProvisioningPermission(TEST_UID_1);
assertFalse(mWifiNetworkSuggestionsManager.hasUserApprovedForApp(TEST_PACKAGE_1));
WifiConfiguration connectNetwork =
@@ -1176,7 +1176,6 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
TEST_PACKAGE_1));
- verify(mWifiPermissionsUtil).checkNetworkCarrierProvisioningPermission(TEST_UID_1);
mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1);
WifiConfiguration connectNetwork =
@@ -1215,7 +1214,6 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
TEST_PACKAGE_1));
- verify(mWifiPermissionsUtil).checkNetworkCarrierProvisioningPermission(TEST_UID_1);
mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1);
doThrow(new SecurityException())
@@ -2400,4 +2398,59 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertNotNull(mBroadcastReceiverCaptor.getValue());
mBroadcastReceiverCaptor.getValue().onReceive(mContext, intent);
}
+
+ @Test
+ public void testAddSuggestionWithValidCarrierIdWithCarrierProvisionPermission() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ config.carrierId = VALID_CARRIER_ID;
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ config, null, true, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>();
+ networkSuggestionList.add(networkSuggestion);
+ when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1))
+ .thenReturn(true);
+
+ int status = mWifiNetworkSuggestionsManager
+ .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1);
+
+ assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
+
+ }
+
+ @Test
+ public void testAddSuggestionWithValidCarrierIdWithoutCarrierProvisionPermission() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ config.carrierId = VALID_CARRIER_ID;
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ config, null, true, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>();
+ networkSuggestionList.add(networkSuggestion);
+ when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1))
+ .thenReturn(false);
+
+ int status = mWifiNetworkSuggestionsManager
+ .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1);
+
+ assertEquals(status,
+ WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED);
+ }
+
+ @Test
+ public void testAddSuggestionWithDefaultCarrierIdWithoutCarrierProvisionPermission() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ config, null, true, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>();
+ networkSuggestionList.add(networkSuggestion);
+ when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1))
+ .thenReturn(false);
+
+ int status = mWifiNetworkSuggestionsManager
+ .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1);
+
+ assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
+ }
}