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.provider.DeviceConfig 21 import android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY 22 import com.android.net.module.util.NetworkStackConstants 23 import com.android.testutils.DeviceConfigRule 24 import com.android.testutils.runAsShell 25 26 /** 27 * Collection of utility methods for configuring network validation. 28 */ 29 internal object NetworkValidationTestUtil { 30 val TAG = NetworkValidationTestUtil::class.simpleName 31 32 /** 33 * Clear the test network validation URLs. 34 */ clearValidationTestUrlsDeviceConfignull35 @JvmStatic fun clearValidationTestUrlsDeviceConfig() { 36 runAsShell(WRITE_DEVICE_CONFIG) { 37 DeviceConfig.setProperty(NAMESPACE_CONNECTIVITY, 38 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTPS_URL, null, false) 39 DeviceConfig.setProperty(NAMESPACE_CONNECTIVITY, 40 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTP_URL, null, false) 41 DeviceConfig.setProperty(NAMESPACE_CONNECTIVITY, 42 NetworkStackConstants.TEST_URL_EXPIRATION_TIME, null, false) 43 } 44 } 45 46 /** 47 * Set the test validation HTTPS URL. 48 * 49 * @see NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTPS_URL 50 */ 51 @JvmStatic setHttpsUrlDeviceConfignull52 fun setHttpsUrlDeviceConfig(rule: DeviceConfigRule, url: String?) = 53 rule.setConfig(NAMESPACE_CONNECTIVITY, 54 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTPS_URL, url) 55 56 /** 57 * Set the test validation HTTP URL. 58 * 59 * @see NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTP_URL 60 */ 61 @JvmStatic 62 fun setHttpUrlDeviceConfig(rule: DeviceConfigRule, url: String?) = 63 rule.setConfig(NAMESPACE_CONNECTIVITY, 64 NetworkStackConstants.TEST_CAPTIVE_PORTAL_HTTP_URL, url) 65 66 /** 67 * Set the test validation URL expiration. 68 * 69 * @see NetworkStackConstants.TEST_URL_EXPIRATION_TIME 70 */ 71 @JvmStatic 72 fun setUrlExpirationDeviceConfig(rule: DeviceConfigRule, timestamp: Long?) = 73 rule.setConfig(NAMESPACE_CONNECTIVITY, 74 NetworkStackConstants.TEST_URL_EXPIRATION_TIME, timestamp?.toString()) 75 } 76