1 /*
2  * Copyright (C) 2019 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.server.testutils;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.graphics.ColorSpace;
22 import android.graphics.GraphicBuffer;
23 import android.graphics.Matrix;
24 import android.graphics.Rect;
25 import android.graphics.Region;
26 import android.hardware.HardwareBuffer;
27 import android.os.IBinder;
28 import android.os.Parcel;
29 import android.view.InputWindowHandle;
30 import android.view.Surface;
31 import android.view.SurfaceControl;
32 
33 import com.android.server.testutils.StubTransaction;
34 
35 import java.util.HashSet;
36 import java.util.concurrent.Executor;
37 
38 /**
39  * Stubbed {@link android.view.SurfaceControl.Transaction} class that can be used when unit
40  * testing to avoid calls to native code.
41  */
42 public class StubTransaction extends SurfaceControl.Transaction {
43 
44     private HashSet<Runnable> mWindowInfosReportedListeners = new HashSet<>();
45 
46     @Override
apply()47     public void apply() {
48         for (Runnable listener : mWindowInfosReportedListeners) {
49             listener.run();
50         }
51     }
52 
53     @Override
close()54     public void close() {
55     }
56 
57     @Override
apply(boolean sync)58     public void apply(boolean sync) {
59         apply();
60     }
61 
62     @Override
setVisibility(SurfaceControl sc, boolean visible)63     public SurfaceControl.Transaction setVisibility(SurfaceControl sc, boolean visible) {
64         return this;
65     }
66 
67     @Override
show(SurfaceControl sc)68     public SurfaceControl.Transaction show(SurfaceControl sc) {
69         return this;
70     }
71 
72     @Override
hide(SurfaceControl sc)73     public SurfaceControl.Transaction hide(SurfaceControl sc) {
74         return this;
75     }
76 
77     @Override
setPosition(SurfaceControl sc, float x, float y)78     public SurfaceControl.Transaction setPosition(SurfaceControl sc, float x, float y) {
79         return this;
80     }
81 
82     @Override
setBufferSize(SurfaceControl sc, int w, int h)83     public SurfaceControl.Transaction setBufferSize(SurfaceControl sc,
84             int w, int h) {
85         return this;
86     }
87 
88     @Override
setLayer(SurfaceControl sc, int z)89     public SurfaceControl.Transaction setLayer(SurfaceControl sc, int z) {
90         return this;
91     }
92 
93     @Override
setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z)94     public SurfaceControl.Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo,
95             int z) {
96         return this;
97     }
98 
99     @Override
setTransparentRegionHint(SurfaceControl sc, Region transparentRegion)100     public SurfaceControl.Transaction setTransparentRegionHint(SurfaceControl sc,
101             Region transparentRegion) {
102         return this;
103     }
104 
105     @Override
setAlpha(SurfaceControl sc, float alpha)106     public SurfaceControl.Transaction setAlpha(SurfaceControl sc, float alpha) {
107         return this;
108     }
109 
110     @Override
setInputWindowInfo(SurfaceControl sc, InputWindowHandle handle)111     public SurfaceControl.Transaction setInputWindowInfo(SurfaceControl sc,
112             InputWindowHandle handle) {
113         return this;
114     }
115 
116     @Override
setGeometry(SurfaceControl sc, Rect sourceCrop, Rect destFrame, @Surface.Rotation int orientation)117     public SurfaceControl.Transaction setGeometry(SurfaceControl sc, Rect sourceCrop,
118             Rect destFrame, @Surface.Rotation int orientation) {
119         return this;
120     }
121 
122     @Override
setMatrix(SurfaceControl sc, float dsdx, float dtdx, float dtdy, float dsdy)123     public SurfaceControl.Transaction setMatrix(SurfaceControl sc,
124             float dsdx, float dtdx, float dtdy, float dsdy) {
125         return this;
126     }
127 
128     @Override
setMatrix(SurfaceControl sc, Matrix matrix, float[] float9)129     public SurfaceControl.Transaction setMatrix(SurfaceControl sc, Matrix matrix, float[] float9) {
130         return this;
131     }
132 
133     @Override
setColorTransform(SurfaceControl sc, float[] matrix, float[] translation)134     public SurfaceControl.Transaction setColorTransform(SurfaceControl sc, float[] matrix,
135             float[] translation) {
136         return this;
137     }
138 
139     @Override
setWindowCrop(SurfaceControl sc, Rect crop)140     public SurfaceControl.Transaction setWindowCrop(SurfaceControl sc, Rect crop) {
141         return this;
142     }
143 
144     @Override
setWindowCrop(SurfaceControl sc, int width, int height)145     public SurfaceControl.Transaction setWindowCrop(SurfaceControl sc, int width, int height) {
146         return this;
147     }
148 
149     @Override
150     @NonNull
setCrop(@onNull SurfaceControl sc, @Nullable Rect crop)151     public SurfaceControl.Transaction setCrop(@NonNull SurfaceControl sc, @Nullable Rect crop) {
152         return this;
153     }
154 
155     @Override
setCornerRadius(SurfaceControl sc, float cornerRadius)156     public SurfaceControl.Transaction setCornerRadius(SurfaceControl sc, float cornerRadius) {
157         return this;
158     }
159 
160     @Override
setBackgroundBlurRadius(SurfaceControl sc, int radius)161     public SurfaceControl.Transaction setBackgroundBlurRadius(SurfaceControl sc, int radius) {
162         return this;
163     }
164 
165     @Override
setLayerStack(SurfaceControl sc, int layerStack)166     public SurfaceControl.Transaction setLayerStack(SurfaceControl sc, int layerStack) {
167         return this;
168     }
169 
170     @Override
reparent(SurfaceControl sc, SurfaceControl newParent)171     public SurfaceControl.Transaction reparent(SurfaceControl sc, SurfaceControl newParent) {
172         return this;
173     }
174 
175     @Override
setColor(SurfaceControl sc, float[] color)176     public SurfaceControl.Transaction setColor(SurfaceControl sc, float[] color) {
177         return this;
178     }
179 
180     @Override
setSecure(SurfaceControl sc, boolean isSecure)181     public SurfaceControl.Transaction setSecure(SurfaceControl sc, boolean isSecure) {
182         return this;
183     }
184 
185     @Override
setOpaque(SurfaceControl sc, boolean isOpaque)186     public SurfaceControl.Transaction setOpaque(SurfaceControl sc, boolean isOpaque) {
187         return this;
188     }
189 
190     @Override
setDisplaySurface(IBinder displayToken, Surface surface)191     public SurfaceControl.Transaction setDisplaySurface(IBinder displayToken, Surface surface) {
192         return this;
193     }
194 
195     @Override
setDisplayLayerStack(IBinder displayToken, int layerStack)196     public SurfaceControl.Transaction setDisplayLayerStack(IBinder displayToken, int layerStack) {
197         return this;
198     }
199 
200     @Override
setDisplayFlags(IBinder displayToken, int flags)201     public SurfaceControl.Transaction setDisplayFlags(IBinder displayToken, int flags) {
202         return this;
203     }
204 
205     @Override
setDisplayProjection(IBinder displayToken, int orientation, Rect layerStackRect, Rect displayRect)206     public SurfaceControl.Transaction setDisplayProjection(IBinder displayToken,
207             int orientation, Rect layerStackRect, Rect displayRect) {
208         return this;
209     }
210 
211     @Override
setDisplaySize(IBinder displayToken, int width, int height)212     public SurfaceControl.Transaction setDisplaySize(IBinder displayToken, int width, int height) {
213         return this;
214     }
215 
216     @Override
setAnimationTransaction()217     public SurfaceControl.Transaction setAnimationTransaction() {
218         return this;
219     }
220 
221     @Override
setMetadata(SurfaceControl sc, int key, int data)222     public SurfaceControl.Transaction setMetadata(SurfaceControl sc, int key, int data) {
223         return this;
224     }
225 
226     @Override
setMetadata(SurfaceControl sc, int key, Parcel data)227     public SurfaceControl.Transaction setMetadata(SurfaceControl sc, int key, Parcel data) {
228         return this;
229     }
230 
231     @Override
merge(SurfaceControl.Transaction other)232     public SurfaceControl.Transaction merge(SurfaceControl.Transaction other) {
233         return this;
234     }
235 
236     @Override
remove(SurfaceControl sc)237     public SurfaceControl.Transaction remove(SurfaceControl sc) {
238         return this;
239     }
240 
241     @Override
addTransactionCommittedListener(Executor executor, SurfaceControl.TransactionCommittedListener listener)242     public SurfaceControl.Transaction addTransactionCommittedListener(Executor executor,
243             SurfaceControl.TransactionCommittedListener listener) {
244         return this;
245     }
246 
247     @Override
setColorSpaceAgnostic(SurfaceControl sc, boolean agnostic)248     public SurfaceControl.Transaction setColorSpaceAgnostic(SurfaceControl sc, boolean agnostic) {
249         return this;
250     }
251 
252     @Override
setFrameRateSelectionPriority(SurfaceControl sc, int priority)253     public SurfaceControl.Transaction setFrameRateSelectionPriority(SurfaceControl sc,
254             int priority) {
255         return this;
256     }
257 
258     @Override
setFrameRate(SurfaceControl sc, float frameRate, int compatibility, int changeFrameRateStrategy)259     public SurfaceControl.Transaction setFrameRate(SurfaceControl sc, float frameRate,
260             int compatibility, int changeFrameRateStrategy) {
261         return this;
262     }
263 
264     @Override
unsetColor(SurfaceControl sc)265     public SurfaceControl.Transaction unsetColor(SurfaceControl sc) {
266         return this;
267     }
268 
269     @Override
setShadowRadius(SurfaceControl sc, float shadowRadius)270     public SurfaceControl.Transaction setShadowRadius(SurfaceControl sc, float shadowRadius) {
271         return this;
272     }
273 
274     @Override
setFixedTransformHint(SurfaceControl sc, @Surface.Rotation int transformHint)275     public SurfaceControl.Transaction setFixedTransformHint(SurfaceControl sc,
276             @Surface.Rotation int transformHint) {
277         return this;
278     }
279 
280     @Override
unsetFixedTransformHint(@onNull SurfaceControl sc)281     public SurfaceControl.Transaction unsetFixedTransformHint(@NonNull SurfaceControl sc) {
282         return this;
283     }
284 
285     @Override
setBuffer(SurfaceControl sc, GraphicBuffer buffer)286     public SurfaceControl.Transaction setBuffer(SurfaceControl sc, GraphicBuffer buffer) {
287         return this;
288     }
289 
290     @Override
291     @NonNull
setBuffer(@onNull SurfaceControl sc, @Nullable HardwareBuffer buffer)292     public SurfaceControl.Transaction setBuffer(@NonNull SurfaceControl sc,
293             @Nullable HardwareBuffer buffer) {
294         return this;
295     }
296 
297     @Override
setColorSpace(SurfaceControl sc, ColorSpace colorSpace)298     public SurfaceControl.Transaction setColorSpace(SurfaceControl sc, ColorSpace colorSpace) {
299         return this;
300     }
301 
302     @Override
setTrustedOverlay(SurfaceControl sc, boolean isTrustedOverlay)303     public SurfaceControl.Transaction setTrustedOverlay(SurfaceControl sc,
304             boolean isTrustedOverlay) {
305         return this;
306     }
307 
308     @Override
addWindowInfosReportedListener(@onNull Runnable listener)309     public SurfaceControl.Transaction addWindowInfosReportedListener(@NonNull Runnable listener) {
310         mWindowInfosReportedListeners.add(listener);
311         return this;
312     }
313 }
314