1 /* 2 * Copyright (C) 2023 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 android.autofillservice.cts.commontests; 18 19 import android.autofillservice.cts.testcore.Helper; 20 import android.autofillservice.cts.testcore.InstrumentedFieldClassificationService; 21 22 import org.junit.After; 23 import org.junit.Before; 24 25 public abstract class FieldClassificationServiceManualActivityLaunchTestCase extends 26 AutoFillServiceTestCase.ManualActivityLaunch { 27 28 private static final String TAG = "FieldClassificationServiceManualActivityLaunchTestCase"; 29 30 protected static InstrumentedFieldClassificationService.Replier sClassificationReplier; 31 32 private static InstrumentedFieldClassificationService.ServiceWatcher sServiceWatcher; 33 34 @Before setFixtures()35 public void setFixtures() throws Exception { 36 sClassificationReplier = InstrumentedFieldClassificationService.getReplier(); 37 sClassificationReplier.reset(); 38 } 39 40 @After resetService()41 public void resetService() throws Exception { 42 // Wait on service disconnect 43 // if sServiceWatcher is null, it means connections hasn't been set up before 44 if (sServiceWatcher != null) { 45 // Rest service with adb command 46 Helper.resetAutofillDetectionService(); 47 sServiceWatcher.waitOnDisconnected(); 48 } 49 } 50 enablePccDetectionService()51 protected InstrumentedFieldClassificationService enablePccDetectionService() 52 throws InterruptedException { 53 sServiceWatcher = InstrumentedFieldClassificationService.setServiceWatcher(); 54 55 // Set service with adb command 56 Helper.setAutofillDetectionService(InstrumentedFieldClassificationService.SERVICE_NAME); 57 InstrumentedFieldClassificationService service = sServiceWatcher.waitOnConnected(); 58 service.waitUntilConnected(); 59 return service; 60 } 61 } 62