1 /* 2 * Copyright (C) 2017 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 com.android.settings; 18 19 import static android.support.test.espresso.Espresso.onView; 20 import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist; 21 import static android.support.test.espresso.assertion.ViewAssertions.matches; 22 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 23 import static android.support.test.espresso.matcher.ViewMatchers.withText; 24 25 import android.app.ActivityManager; 26 import android.app.Instrumentation; 27 import android.content.Context; 28 import android.content.Intent; 29 import android.provider.Settings; 30 import android.support.test.InstrumentationRegistry; 31 import android.support.test.filters.SmallTest; 32 import android.support.test.runner.AndroidJUnit4; 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 37 @RunWith(AndroidJUnit4.class) 38 @SmallTest 39 public class ManagedAccessSettingsLowRamTest { 40 41 private Instrumentation mInstrumentation; 42 private Context mTargetContext; 43 44 @Before setUp()45 public void setUp() { 46 mInstrumentation = InstrumentationRegistry.getInstrumentation(); 47 mTargetContext = mInstrumentation.getTargetContext(); 48 } 49 50 @Test testManagedAccessOptionsVisibility()51 public void testManagedAccessOptionsVisibility() throws Exception { 52 mInstrumentation.startActivitySync(new Intent(mTargetContext, 53 com.android.settings.Settings.SpecialAccessSettingsActivity.class)); 54 55 String[] managedServiceLabels = new String[] {"Do Not Disturb access", 56 "VR helper services", "Notification access", "Picture-in-picture"}; 57 for (String label : managedServiceLabels) { 58 if (ActivityManager.isLowRamDeviceStatic()) { 59 onView(withText(label)).check(doesNotExist()); 60 } else { 61 onView(withText(label)).check(matches(isDisplayed())); 62 } 63 } 64 } 65 66 @Test launchNotificationSetting_onlyWorksIfNotLowRam()67 public void launchNotificationSetting_onlyWorksIfNotLowRam() { 68 final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); 69 70 mInstrumentation.startActivitySync(intent); 71 72 final String label = "This feature is not available on this device"; 73 if (ActivityManager.isLowRamDeviceStatic()) { 74 onView(withText(label)).check(matches(isDisplayed())); 75 } else { 76 onView(withText(label)).check(doesNotExist()); 77 } 78 } 79 80 @Test launchDndSetting_onlyWorksIfNotLowRam()81 public void launchDndSetting_onlyWorksIfNotLowRam() { 82 final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); 83 84 mInstrumentation.startActivitySync(intent); 85 86 final String label = "This feature is not available on this device"; 87 if (ActivityManager.isLowRamDeviceStatic()) { 88 onView(withText(label)).check(matches(isDisplayed())); 89 } else { 90 onView(withText(label)).check(doesNotExist()); 91 } 92 } 93 94 @Test launchVrSetting_onlyWorksIfNotLowRam()95 public void launchVrSetting_onlyWorksIfNotLowRam() { 96 final Intent intent = new Intent(Settings.ACTION_VR_LISTENER_SETTINGS); 97 98 mInstrumentation.startActivitySync(intent); 99 100 final String label = "This feature is not available on this device"; 101 if (ActivityManager.isLowRamDeviceStatic()) { 102 onView(withText(label)).check(matches(isDisplayed())); 103 } else { 104 onView(withText(label)).check(doesNotExist()); 105 } 106 } 107 108 @Test launchPictureInPictureSetting_onlyWorksIfNotLowRam()109 public void launchPictureInPictureSetting_onlyWorksIfNotLowRam() { 110 final Intent intent = new Intent(Settings.ACTION_PICTURE_IN_PICTURE_SETTINGS); 111 112 mInstrumentation.startActivitySync(intent); 113 114 final String label = "This feature is not available on this device"; 115 if (ActivityManager.isLowRamDeviceStatic()) { 116 onView(withText(label)).check(matches(isDisplayed())); 117 } else { 118 onView(withText(label)).check(doesNotExist()); 119 } 120 } 121 } 122