1 /* 2 * Copyright (C) 2016 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.tests; 18 19 import android.app.Instrumentation; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.pm.PackageManager; 23 import android.support.test.InstrumentationRegistry; 24 import android.support.test.uiautomator.UiDevice; 25 26 import org.junit.runner.RunWith; 27 import android.support.test.filters.SmallTest; 28 import android.support.test.runner.AndroidJUnit4; 29 import android.support.test.uiautomator.UiScrollable; 30 import android.support.test.uiautomator.UiSelector; 31 import org.junit.Test; 32 import com.android.settings.R; 33 34 import static android.support.test.espresso.Espresso.onView; 35 import static android.support.test.espresso.action.ViewActions.click; 36 import static android.support.test.espresso.assertion.ViewAssertions.matches; 37 import static android.support.test.espresso.matcher.ViewMatchers.isEnabled; 38 import static android.support.test.espresso.matcher.ViewMatchers.withText; 39 import static org.hamcrest.core.IsNot.not; 40 import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu; 41 42 @RunWith(AndroidJUnit4.class) 43 @SmallTest 44 public class DrawOverlayDetailsTest { 45 private final static String PACKAGE_SYSTEM_UI = "com.android.systemui"; 46 47 @Test 48 public void testSystemUiDrawOverlayDetails_Disabled() throws Exception{ 49 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 50 instrumentation.startActivitySync(new Intent(android.provider.Settings 51 .ACTION_MANAGE_OVERLAY_PERMISSION)); 52 53 final Context targetContext = instrumentation.getTargetContext(); 54 55 final PackageManager packageManager = targetContext.getPackageManager(); 56 final String appName = (String) packageManager.getApplicationLabel(packageManager 57 .getApplicationInfo(PACKAGE_SYSTEM_UI, PackageManager.GET_META_DATA)); 58 59 final UiDevice device = UiDevice.getInstance(instrumentation); 60 device.waitForIdle(); 61 62 openActionBarOverflowOrOptionsMenu(targetContext); 63 onView(withText(targetContext.getString(R.string.menu_show_system))).perform(click()); 64 device.waitForIdle(); 65 66 final UiScrollable settings = new UiScrollable( 67 new UiSelector().packageName(targetContext.getPackageName()).scrollable(true)); 68 settings.scrollTextIntoView(appName); 69 onView(withText(appName)).perform(click()); 70 onView(withText(targetContext.getString(R.string.permit_draw_overlay))).check(matches 71 (not(isEnabled()))); 72 } 73 74 } 75