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 com.android.adservices.shared.testing; 18 19 import android.app.job.JobService; 20 21 import com.android.adservices.shared.testing.concurrency.DeviceSideSyncCallback; 22 import com.android.adservices.shared.testing.concurrency.SyncCallbackFactory; 23 import com.android.adservices.shared.testing.concurrency.SyncCallbackSettings; 24 25 // TODO(b/344610522): add unit test 26 /** 27 * A synchronized callback used for logging {@link JobService} on testing purpose. 28 * 29 * <p>The logging methods in {@link AdServicesJobServiceLogger} are offloaded to a separate thread. 30 * In order to make the test result deterministic, use this callback to help wait for the completion 31 * of such logging methods. 32 */ 33 public final class JobServiceLoggingCallback extends DeviceSideSyncCallback { 34 JobServiceLoggingCallback()35 public JobServiceLoggingCallback() { 36 this(SyncCallbackFactory.newDefaultSettings()); 37 } 38 JobServiceLoggingCallback(SyncCallbackSettings settings)39 public JobServiceLoggingCallback(SyncCallbackSettings settings) { 40 super(settings); 41 } 42 43 /** This is used for checking a stub method is called. */ onLoggingMethodCalled()44 public void onLoggingMethodCalled() { 45 internalSetCalled("onLoggingMethodCalled()"); 46 } 47 48 /** Assert the corresponding logging method has happened. */ assertLoggingFinished()49 public void assertLoggingFinished() throws InterruptedException { 50 assertCalled(); 51 } 52 } 53