1 /** 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 * express or implied. See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 package android.accessibilityservice.cts; 15 16 import static android.app.AppOpsManager.OPSTR_BIND_ACCESSIBILITY_SERVICE; 17 18 import static junit.framework.Assert.assertTrue; 19 20 import android.accessibility.cts.common.AccessibilityDumpOnFailureRule; 21 import android.content.Context; 22 import android.platform.test.annotations.Presubmit; 23 24 import androidx.test.InstrumentationRegistry; 25 import androidx.test.runner.AndroidJUnit4; 26 27 import com.android.compatibility.common.util.AppOpsUtils; 28 29 import org.junit.Rule; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 @RunWith(AndroidJUnit4.class) 34 @Presubmit 35 public class AccessibilityLoggingTest { 36 37 @Rule 38 public final AccessibilityDumpOnFailureRule mDumpOnFailureRule = 39 new AccessibilityDumpOnFailureRule(); 40 41 /** 42 * Tests that new accessibility services are logged by the system. 43 */ 44 @Test testServiceLogged()45 public void testServiceLogged() throws Exception { 46 Context context = InstrumentationRegistry.getInstrumentation().getContext(); 47 String packageName = context.getPackageName(); 48 49 // There are accessibility services defined in this test package, and this fact must be 50 // logged. 51 assertTrue("Accessibility service was bound, but this wasn't logged by app ops", 52 AppOpsUtils.allowedOperationLogged(packageName, OPSTR_BIND_ACCESSIBILITY_SERVICE)); 53 } 54 } 55