• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.media.tv.interactive.cts;
18 
19 import android.content.Context;
20 import android.graphics.Rect;
21 import android.media.tv.AdRequest;
22 import android.media.tv.AdResponse;
23 import android.media.tv.BroadcastInfoRequest;
24 import android.media.tv.BroadcastInfoResponse;
25 import android.media.tv.TvContentRating;
26 import android.media.tv.TvTrackInfo;
27 import android.media.tv.interactive.AppLinkInfo;
28 import android.media.tv.interactive.TvInteractiveAppManager;
29 import android.media.tv.interactive.TvInteractiveAppService;
30 import android.net.Uri;
31 import android.os.Bundle;
32 import android.view.KeyEvent;
33 import android.view.MotionEvent;
34 import android.view.Surface;
35 import android.view.View;
36 
37 import java.util.List;
38 
39 /**
40  * Stub implementation of (@link android.media.tv.interactive.TvInteractiveAppService}.
41  */
42 public class StubTvInteractiveAppService extends TvInteractiveAppService {
43 
44     public static StubSessionImpl sSession;
45     public static int sType;
46     public static Bundle sAppLinkCommand = null;
47     public static AppLinkInfo sAppLinkInfo = null;
48 
49     @Override
onCreateSession(String iAppServiceId, int type)50     public Session onCreateSession(String iAppServiceId, int type) {
51         sSession = new StubSessionImpl(this);
52         return sSession;
53     }
54 
55     @Override
onAppLinkCommand(Bundle command)56     public void onAppLinkCommand(Bundle command) {
57         super.onAppLinkCommand(command);
58         sAppLinkCommand = command;
59     }
60 
61     @Override
onRegisterAppLinkInfo(AppLinkInfo bundle)62     public void onRegisterAppLinkInfo(AppLinkInfo bundle) {
63         super.onRegisterAppLinkInfo(bundle);
64         sAppLinkInfo = bundle;
65     }
66 
67     @Override
onUnregisterAppLinkInfo(AppLinkInfo bundle)68     public void onUnregisterAppLinkInfo(AppLinkInfo bundle) {
69         super.onUnregisterAppLinkInfo(bundle);
70         sAppLinkInfo = null;
71     }
72 
73     public static class StubSessionImpl extends Session {
74         public int mSetSurfaceCount;
75         public int mSurfaceChangedCount;
76         public int mStartInteractiveAppCount;
77         public int mStopInteractiveAppCount;
78         public int mKeyDownCount;
79         public int mKeyUpCount;
80         public int mKeyMultipleCount;
81         public int mVideoAvailableCount;
82         public int mTunedCount;
83         public int mCreateBiIAppCount;
84         public int mDestroyBiIAppCount;
85         public int mAdResponseCount;
86         public int mBroadcastInfoResponseCount;
87         public int mSigningResultCount;
88         public int mErrorCount;
89 
90         public Integer mKeyDownCode;
91         public Integer mKeyUpCode;
92         public Integer mKeyMultipleCode;
93         public KeyEvent mKeyDownEvent;
94         public KeyEvent mKeyUpEvent;
95         public KeyEvent mKeyMultipleEvent;
96         public Uri mTunedUri;
97         public Uri mCreateBiIAppUri;
98         public Bundle mCreateBiIAppParams;
99         public String mDestroyBiIAppId;
100         public AdResponse mAdResponse;
101         public BroadcastInfoResponse mBroadcastInfoResponse;
102 
StubSessionImpl(Context context)103         StubSessionImpl(Context context) {
104             super(context);
105         }
106 
resetValues()107         public void resetValues() {
108             mSetSurfaceCount = 0;
109             mSurfaceChangedCount = 0;
110             mStartInteractiveAppCount = 0;
111             mStopInteractiveAppCount = 0;
112             mKeyDownCount = 0;
113             mKeyUpCount = 0;
114             mKeyMultipleCount = 0;
115             mVideoAvailableCount = 0;
116             mTunedCount = 0;
117             mCreateBiIAppCount = 0;
118             mDestroyBiIAppCount = 0;
119             mAdResponseCount = 0;
120             mBroadcastInfoResponseCount = 0;
121             mSigningResultCount = 0;
122             mErrorCount = 0;
123 
124             mKeyDownCode = null;
125             mKeyUpCode = null;
126             mKeyMultipleCode = null;
127             mKeyDownEvent = null;
128             mKeyUpEvent = null;
129             mKeyMultipleEvent = null;
130             mTunedUri = null;
131             mCreateBiIAppUri = null;
132             mCreateBiIAppParams = null;
133             mDestroyBiIAppId = null;
134             mAdResponse = null;
135             mBroadcastInfoResponse = null;
136         }
137 
138         @Override
layoutSurface(int left, int top, int right, int bottom)139         public void layoutSurface(int left, int top, int right, int bottom) {
140             super.layoutSurface(left, top, right, bottom);
141         }
142 
143         @Override
notifySessionStateChanged(int state, int err)144         public void notifySessionStateChanged(int state, int err) {
145             super.notifySessionStateChanged(state, err);
146         }
147 
148         @Override
removeBroadcastInfo(int requestId)149         public void removeBroadcastInfo(int requestId) {
150             super.removeBroadcastInfo(requestId);
151         }
152 
153         @Override
requestAd(AdRequest request)154         public void requestAd(AdRequest request) {
155             super.requestAd(request);
156         }
157 
158         @Override
requestBroadcastInfo(BroadcastInfoRequest request)159         public void requestBroadcastInfo(BroadcastInfoRequest request) {
160             super.requestBroadcastInfo(request);
161         }
162 
163         @Override
requestCurrentChannelLcn()164         public void requestCurrentChannelLcn() {
165             super.requestCurrentChannelLcn();
166         }
167 
168         @Override
requestCurrentChannelUri()169         public void requestCurrentChannelUri() {
170             super.requestCurrentChannelUri();
171         }
172 
173         @Override
requestCurrentTvInputId()174         public void requestCurrentTvInputId() {
175             super.requestCurrentTvInputId();
176         }
177 
178         @Override
requestStreamVolume()179         public void requestStreamVolume() {
180             super.requestStreamVolume();
181         }
182 
183         @Override
requestTrackInfoList()184         public void requestTrackInfoList() {
185             super.requestTrackInfoList();
186         }
187 
188         @Override
sendPlaybackCommandRequest(String cmdType, Bundle parameters)189         public void sendPlaybackCommandRequest(String cmdType, Bundle parameters) {
190             super.sendPlaybackCommandRequest(cmdType, parameters);
191         }
192 
193         @Override
setMediaViewEnabled(boolean enable)194         public void setMediaViewEnabled(boolean enable) {
195             super.setMediaViewEnabled(enable);
196         }
197 
198         @Override
setVideoBounds(Rect rect)199         public void setVideoBounds(Rect rect) {
200             super.setVideoBounds(rect);
201         }
202 
203         @Override
onStartInteractiveApp()204         public void onStartInteractiveApp() {
205             super.onStartInteractiveApp();
206             mStartInteractiveAppCount++;
207             notifySessionStateChanged(
208                     TvInteractiveAppManager.INTERACTIVE_APP_STATE_RUNNING,
209                     TvInteractiveAppManager.ERROR_NONE);
210         }
211 
212         @Override
onStopInteractiveApp()213         public void onStopInteractiveApp() {
214             super.onStopInteractiveApp();
215             mStopInteractiveAppCount++;
216         }
217 
218         @Override
onRelease()219         public void onRelease() {
220         }
221 
222         @Override
onSetSurface(Surface surface)223         public boolean onSetSurface(Surface surface) {
224             mSetSurfaceCount++;
225             return false;
226         }
227 
228         @Override
onSurfaceChanged(int format, int width, int height)229         public void onSurfaceChanged(int format, int width, int height) {
230             super.onSurfaceChanged(format, width, height);
231             mSurfaceChangedCount++;
232         }
233 
234         @Override
onKeyDown(int keyCode, KeyEvent event)235         public boolean onKeyDown(int keyCode, KeyEvent event) {
236             super.onKeyDown(keyCode, event);
237             mKeyDownCount++;
238             mKeyDownCode = keyCode;
239             mKeyDownEvent = event;
240             return false;
241         }
242 
243         @Override
onKeyLongPress(int keyCode, KeyEvent event)244         public boolean onKeyLongPress(int keyCode, KeyEvent event) {
245             super.onKeyLongPress(keyCode, event);
246             return false;
247         }
248 
249         @Override
onKeyUp(int keyCode, KeyEvent event)250         public boolean onKeyUp(int keyCode, KeyEvent event) {
251             super.onKeyUp(keyCode, event);
252             mKeyUpCount++;
253             mKeyUpCode = keyCode;
254             mKeyUpEvent = event;
255             return false;
256         }
257 
258         @Override
onKeyMultiple(int keyCode, int count, KeyEvent event)259         public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) {
260             super.onKeyMultiple(keyCode, count, event);
261             mKeyMultipleCount++;
262             mKeyMultipleCode = keyCode;
263             mKeyMultipleEvent = event;
264             return false;
265         }
266 
267         @Override
onCreateBiInteractiveAppRequest(Uri biIAppUri, Bundle params)268         public void onCreateBiInteractiveAppRequest(Uri biIAppUri, Bundle params) {
269             super.onCreateBiInteractiveAppRequest(biIAppUri, params);
270             mCreateBiIAppCount++;
271             mCreateBiIAppUri = biIAppUri;
272             mCreateBiIAppParams = params;
273             notifyBiInteractiveAppCreated(biIAppUri, "biIAppId");
274         }
275 
276         @Override
onDestroyBiInteractiveAppRequest(String biIAppId)277         public void onDestroyBiInteractiveAppRequest(String biIAppId) {
278             super.onDestroyBiInteractiveAppRequest(biIAppId);
279             mDestroyBiIAppCount++;
280             mDestroyBiIAppId = biIAppId;
281         }
282 
283         @Override
onTuned(Uri uri)284         public void onTuned(Uri uri) {
285             super.onTuned(uri);
286             mTunedCount++;
287             mTunedUri = uri;
288         }
289 
290         @Override
onVideoAvailable()291         public void onVideoAvailable() {
292             super.onVideoAvailable();
293             mVideoAvailableCount++;
294         }
295 
296         @Override
onAdResponse(AdResponse response)297         public void onAdResponse(AdResponse response) {
298             super.onAdResponse(response);
299             mAdResponseCount++;
300             mAdResponse = response;
301         }
302 
303         @Override
onBroadcastInfoResponse(BroadcastInfoResponse response)304         public void onBroadcastInfoResponse(BroadcastInfoResponse response) {
305             super.onBroadcastInfoResponse(response);
306             mBroadcastInfoResponseCount++;
307             mBroadcastInfoResponse = response;
308         }
309 
310         @Override
onContentAllowed()311         public void onContentAllowed() {
312             super.onContentAllowed();
313         }
314 
315         @Override
onContentBlocked(TvContentRating rating)316         public void onContentBlocked(TvContentRating rating) {
317             super.onContentBlocked(rating);
318         }
319 
320         @Override
onCreateMediaView()321         public View onCreateMediaView() {
322             super.onCreateMediaView();
323             return null;
324         }
325 
326         @Override
onCurrentChannelLcn(int lcn)327         public void onCurrentChannelLcn(int lcn) {
328             super.onCurrentChannelLcn(lcn);
329         }
330 
331         @Override
onCurrentChannelUri(Uri uri)332         public void onCurrentChannelUri(Uri uri) {
333             super.onCurrentChannelUri(uri);
334         }
335 
336         @Override
onCurrentTvInputId(String id)337         public void onCurrentTvInputId(String id) {
338             super.onCurrentTvInputId(id);
339         }
340 
341         @Override
onGenericMotionEvent(MotionEvent event)342         public boolean onGenericMotionEvent(MotionEvent event) {
343             super.onGenericMotionEvent(event);
344             return false;
345         }
346 
347         @Override
onMediaViewSizeChanged(int w, int h)348         public void onMediaViewSizeChanged(int w, int h) {
349             super.onMediaViewSizeChanged(w, h);
350         }
351 
352         @Override
onResetInteractiveApp()353         public void onResetInteractiveApp() {
354             super.onResetInteractiveApp();
355         }
356 
357         @Override
onSetTeletextAppEnabled(boolean enable)358         public void onSetTeletextAppEnabled(boolean enable) {
359             super.onSetTeletextAppEnabled(enable);
360         }
361 
362         @Override
onSignalStrength(int strength)363         public void onSignalStrength(int strength) {
364             super.onSignalStrength(strength);
365         }
366 
367         @Override
onStreamVolume(float v)368         public void onStreamVolume(float v) {
369             super.onStreamVolume(v);
370         }
371 
372         @Override
onTouchEvent(MotionEvent event)373         public boolean onTouchEvent(MotionEvent event) {
374             super.onTouchEvent(event);
375             return false;
376         }
377 
378         @Override
onTrackInfoList(List<TvTrackInfo> infos)379         public void onTrackInfoList(List<TvTrackInfo> infos) {
380             super.onTrackInfoList(infos);
381         }
382 
383         @Override
onTrackSelected(int type, String id)384         public void onTrackSelected(int type, String id) {
385             super.onTrackSelected(type, id);
386         }
387 
388         @Override
onTrackballEvent(MotionEvent event)389         public boolean onTrackballEvent(MotionEvent event) {
390             super.onTrackballEvent(event);
391             return false;
392         }
393 
394         @Override
onTracksChanged(List<TvTrackInfo> infos)395         public void onTracksChanged(List<TvTrackInfo> infos) {
396             super.onTracksChanged(infos);
397         }
398 
399         @Override
onVideoUnavailable(int reason)400         public void onVideoUnavailable(int reason) {
401             super.onVideoUnavailable(reason);
402         }
403 
404         @Override
onSigningResult(String signingId, byte[] result)405         public void onSigningResult(String signingId, byte[] result) {
406             super.onSigningResult(signingId, result);
407             mSigningResultCount++;
408         }
409 
410         @Override
onError(String errMsg, Bundle params)411         public void onError(String errMsg, Bundle params) {
412             super.onError(errMsg, params);
413             mErrorCount++;
414         }
415     }
416 }
417