1 /* 2 * Copyright (C) 2022 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.systemui.accessibility; 18 19 import android.os.RemoteException; 20 import android.view.accessibility.IRemoteMagnificationAnimationCallback; 21 22 import java.util.concurrent.CountDownLatch; 23 import java.util.concurrent.atomic.AtomicInteger; 24 25 public class MockMagnificationAnimationCallback extends IRemoteMagnificationAnimationCallback.Stub { 26 27 private final CountDownLatch mCountDownLatch; 28 private final AtomicInteger mSuccessCount; 29 private final AtomicInteger mFailedCount; 30 MockMagnificationAnimationCallback(CountDownLatch countDownLatch)31 MockMagnificationAnimationCallback(CountDownLatch countDownLatch) { 32 mCountDownLatch = countDownLatch; 33 mSuccessCount = new AtomicInteger(); 34 mFailedCount = new AtomicInteger(); 35 } 36 getSuccessCount()37 public int getSuccessCount() { 38 return mSuccessCount.get(); 39 } 40 getFailedCount()41 public int getFailedCount() { 42 return mFailedCount.get(); 43 } 44 45 @Override onResult(boolean success)46 public void onResult(boolean success) throws RemoteException { 47 if (success) { 48 mSuccessCount.getAndIncrement(); 49 } else { 50 mFailedCount.getAndIncrement(); 51 } 52 // It should be put at the last line to avoid making CountDownLatch#await passed without 53 // updating values. 54 mCountDownLatch.countDown(); 55 } 56 } 57