1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net.cts 18 19 import android.Manifest.permission.WRITE_DEVICE_CONFIG 20 import android.Manifest.permission.WRITE_ALLOWLISTED_DEVICE_CONFIG 21 import android.provider.DeviceConfig 22 import android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY 23 import com.android.net.module.util.NetworkStackConstants 24 import com.android.testutils.DeviceConfigRule 25 import com.android.testutils.runAsShell 26 27 /** 28 * Collection of utility methods for configuring network validation. 29 */ 30 internal object NetworkValidationTestUtil { 31 val TAG = NetworkValidationTestUtil::class.simpleName 32 33 /** 34 * Clear the test network validation URLs. 35 */ clearValidationTestUrlsDeviceConfignull36 @JvmStatic fun clearValidationTestUrlsDeviceConfig() { 37 runAsShell(WRITE_DEVICE_CONFIG, WRITE_ALLOWLISTED_DEVICE_CONFIG) { 38 DeviceConfig.setProperty(NAMESPACE_CONNECTIVITY, 39 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTPS_URL, null, false) 40 DeviceConfig.setProperty(NAMESPACE_CONNECTIVITY, 41 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTP_URL, null, false) 42 DeviceConfig.setProperty(NAMESPACE_CONNECTIVITY, 43 NetworkStackConstants.TEST_URL_EXPIRATION_TIME, null, false) 44 } 45 } 46 47 /** 48 * Set the test validation HTTPS URL. 49 * 50 * @see NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTPS_URL 51 */ 52 @JvmStatic setHttpsUrlDeviceConfignull53 fun setHttpsUrlDeviceConfig(rule: DeviceConfigRule, url: String?) = 54 rule.setConfig(NAMESPACE_CONNECTIVITY, 55 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTPS_URL, url) 56 57 /** 58 * Set the test validation HTTP URL. 59 * 60 * @see NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTP_URL 61 */ 62 @JvmStatic 63 fun setHttpUrlDeviceConfig(rule: DeviceConfigRule, url: String?) = 64 rule.setConfig(NAMESPACE_CONNECTIVITY, 65 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTP_URL, url) 66 67 /** 68 * Set the test validation URL expiration. 69 * 70 * @see NetworkStackConstants.TEST_URL_EXPIRATION_TIME 71 */ 72 @JvmStatic 73 fun setUrlExpirationDeviceConfig(rule: DeviceConfigRule, timestamp: Long?) = 74 rule.setConfig(NAMESPACE_CONNECTIVITY, 75 NetworkStackConstants.TEST_URL_EXPIRATION_TIME, timestamp?.toString()) 76 } 77