Merge changes I94a881df,I59fd7765
* changes: VpnPreferenceControllerTest converted to JUnit Warning / Info icon added for the VPN Preference
This commit is contained in:
committed by
Android (Google) Code Review
commit
18b91319bd
26
res/drawable/ic_warning_circle_24dp.xml
Normal file
26
res/drawable/ic_warning_circle_24dp.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 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.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorError"
|
||||
android:pathData="M11,15h2v2h-2v-2zM11,7h2v6h-2L11,7zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
|
||||
</vector>
|
29
res/layout/preference_widget_warning.xml
Normal file
29
res/layout/preference_widget_warning.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 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.
|
||||
-->
|
||||
|
||||
<!-- Warning button -->
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/warning_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_warning_circle_24dp"
|
||||
android:contentDescription="@string/warning_button_text" />
|
@@ -7480,6 +7480,8 @@
|
||||
<string name="help_uri_nfc_and_payment_settings" translatable="false"></string>
|
||||
<!-- url for battery page if battery is not present -->
|
||||
<string name="help_url_battery_missing" translatable="false"></string>
|
||||
<!-- url for vpn page if connected vpn is not a secure type -->
|
||||
<string name="help_url_insecure_vpn" translatable="false"></string>
|
||||
|
||||
<!-- User account title [CHAR LIMIT=30] -->
|
||||
<string name="user_account_title">Account for content</string>
|
||||
@@ -9549,6 +9551,9 @@
|
||||
settings button -->
|
||||
<string name="notification_app_settings_button">Notification settings</string>
|
||||
|
||||
<!-- Content description for help icon button [CHAR LIMIT=20] -->
|
||||
<string name="warning_button_text">Warning</string>
|
||||
|
||||
<!-- Generic label for suggestion card's ok button [CHAR LIMIT=20] -->
|
||||
<string name="suggestion_button_text">Ok</string>
|
||||
|
||||
|
@@ -22,7 +22,6 @@ import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -32,34 +31,38 @@ import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.VpnManager;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.net.VpnConfig;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class VpnPreferenceControllerTest {
|
||||
private static final String VPN_PREFERENCE_KEY = "vpn_settings";
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
private VpnManager mVpnManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
@@ -68,12 +71,21 @@ public class VpnPreferenceControllerTest {
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
|
||||
@Before
|
||||
@UiThreadTest
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mContext.getSystemService(VpnManager.class)).thenReturn(mVpnManager);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||
mScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||
when(mPreference.getKey()).thenReturn(VPN_PREFERENCE_KEY);
|
||||
mScreen.addPreference(mPreference);
|
||||
|
||||
mController = spy(new VpnPreferenceController(mContext));
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
@@ -83,13 +95,20 @@ public class VpnPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void displayPreference_available_shouldSetDependency() {
|
||||
doReturn(true).when(mController).isAvailable();
|
||||
mController.displayPreference(mScreen);
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS, "");
|
||||
VpnPreferenceController controller = spy(new VpnPreferenceController(mContext));
|
||||
doReturn(true).when(controller).isAvailable();
|
||||
|
||||
controller.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setDependency(SettingsSlicesContract.KEY_AIRPLANE_MODE);
|
||||
}
|
||||
|
||||
@Test
|
||||
// TODO(b/176821216) re-enable this test once VpnPreferenceController is edited to notify
|
||||
// the preference of legacy VPNs
|
||||
@Ignore
|
||||
public void goThroughLifecycle_shouldRegisterUnregisterListener() {
|
||||
doReturn(true).when(mController).isAvailable();
|
||||
|
||||
@@ -107,7 +126,7 @@ public class VpnPreferenceControllerTest {
|
||||
final VpnConfig config = new VpnConfig();
|
||||
config.legacy = true;
|
||||
final VpnPreferenceController controller =
|
||||
new VpnPreferenceController(RuntimeEnvironment.application);
|
||||
new VpnPreferenceController(ApplicationProvider.getApplicationContext());
|
||||
|
||||
final String summary = controller.getNameForVpnConfig(config, UserHandle.CURRENT);
|
||||
|
Reference in New Issue
Block a user