1 /*
2  * Copyright (C) 2016 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.cts.tv.hostside.app2;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 import android.media.tv.TvInputManager;
23 import android.os.Bundle;
24 import android.os.Handler;
25 import android.util.Log;
26 
27 public class TvViewMonitorActivity extends Activity {
28     private static final String TAG = TvViewMonitorActivity.class.getSimpleName();
29     private static final String TEST_STRING = "HOST_SIDE_TEST_TV_INTPUT_IS_UPDATED";
30 
31     private TvInputManager mManager;
32     private LoggingCallback mCallback = new LoggingCallback();
33 
hasTvInputFramework()34     private boolean hasTvInputFramework() {
35         return getPackageManager().hasSystemFeature(PackageManager.FEATURE_LIVE_TV);
36     }
37 
38     @Override
onCreate(Bundle savedInstanceState)39     public void onCreate(Bundle savedInstanceState) {
40         super.onCreate(savedInstanceState);
41         mManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
42         if (hasTvInputFramework()) {
43             mManager.registerCallback(mCallback, new Handler());
44         }
45     }
46 
47     @Override
onDestroy()48     protected void onDestroy() {
49         super.onDestroy();
50         if (hasTvInputFramework()) {
51             mManager.unregisterCallback(mCallback);
52         }
53     }
54 
55     private static class LoggingCallback extends TvInputManager.TvInputCallback {
56         @Override
onInputUpdated(String inputId)57         public void onInputUpdated(String inputId) {
58             Log.i(TAG, TEST_STRING);
59         }
60     }
61 }
62