From 23d57e8c8af57fd8b3523bdb0d7293190cb0126d Mon Sep 17 00:00:00 2001 From: Fan Wu Date: Fri, 12 Jan 2024 15:49:42 +0800 Subject: [PATCH] Remove unnecessary custom shadow of android.system.Os Bug: 319052511 Test: atest SettingsRoboTests Change-Id: Ie551e6f3b3884a505f60acc5874b439010d43533 --- .../PrivateDnsModeDialogPreferenceTest.java | 2 +- .../settings/testutils/shadow/ShadowOs.java | 54 ------------------- 2 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 tests/robotests/src/com/android/settings/testutils/shadow/ShadowOs.java diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogPreferenceTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogPreferenceTest.java index 85a67f6d62f..458000292df 100644 --- a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogPreferenceTest.java @@ -38,7 +38,6 @@ import android.widget.LinearLayout; import androidx.appcompat.app.AlertDialog; import com.android.settings.R; -import com.android.settings.testutils.shadow.ShadowOs; import com.android.settingslib.CustomDialogPreferenceCompat.CustomPreferenceDialogFragment; import org.junit.Before; @@ -48,6 +47,7 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowOs; import org.robolectric.util.ReflectionHelpers; @RunWith(RobolectricTestRunner.class) diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowOs.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowOs.java deleted file mode 100644 index 72dfcb80de7..00000000000 --- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowOs.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.testutils.shadow; - -import static android.system.OsConstants.AF_INET; -import static android.system.OsConstants.AF_INET6; - -import android.system.Os; - -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.regex.Pattern; - -@Implements(Os.class) -public class ShadowOs { - // These are not actually correct, but good enough for the test - private static final Pattern IPV4_PATTERN = - Pattern.compile("^\\d{1,3}(\\.\\d{1,3}){3}$"); - private static final Pattern IPV6_PATTERN = - Pattern.compile("^[0-9a-f]{1,4}(:[0-9a-f]{0,4}){0,6}$"); - - private static final byte[] IPV4_BYTES = new byte[4]; - private static final byte[] IPV6_BYTES = new byte[16]; - - @Implementation - protected static InetAddress inet_pton(int family, String address) { - if ((AF_INET == family && IPV4_PATTERN.matcher(address).find()) || - (AF_INET6 == family && IPV6_PATTERN.matcher(address).find())) { - try { - return InetAddress.getByAddress((AF_INET == family) ? IPV4_BYTES : IPV6_BYTES); - } catch (UnknownHostException uhe) { - // Shouldn't be reached. - } - } - return null; - } -}