1 /*
2  * Copyright (C) 2021 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.server.wm.jetpack.utils;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 
22 import android.os.IBinder;
23 
24 import androidx.annotation.NonNull;
25 import androidx.window.sidecar.SidecarDeviceState;
26 import androidx.window.sidecar.SidecarInterface.SidecarCallback;
27 import androidx.window.sidecar.SidecarWindowLayoutInfo;
28 
29 public class SidecarCallbackCounter implements SidecarCallback {
30 
31     private final IBinder mWindowToken;
32     private int mCallbackCount;
33 
SidecarCallbackCounter(IBinder windowToken)34     public SidecarCallbackCounter(IBinder windowToken) {
35         mWindowToken = windowToken;
36     }
37 
38     @Override
onDeviceStateChanged(@onNull SidecarDeviceState sidecarDeviceState)39     public void onDeviceStateChanged(@NonNull SidecarDeviceState sidecarDeviceState) {
40     }
41 
42     @Override
onWindowLayoutChanged(@onNull IBinder iBinder, @NonNull SidecarWindowLayoutInfo sidecarWindowLayoutInfo)43     public void onWindowLayoutChanged(@NonNull IBinder iBinder,
44             @NonNull SidecarWindowLayoutInfo sidecarWindowLayoutInfo) {
45         assertEquals(iBinder, mWindowToken);
46         assertNotNull(sidecarWindowLayoutInfo);
47         mCallbackCount++;
48     }
49 
resetCallbackCount()50     public void resetCallbackCount() {
51         mCallbackCount = 0;
52     }
53 
getCallbackCount()54     public long getCallbackCount() {
55         return mCallbackCount;
56     }
57 }
58