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