1 /* 2 * Copyright (C) 2015 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.tv.receiver; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.media.tv.TvContract; 23 import android.util.Log; 24 import android.view.KeyEvent; 25 26 import com.android.tv.TvApplication; 27 28 /** 29 * Handles global keys. 30 */ 31 public class GlobalKeyReceiver extends BroadcastReceiver { 32 private static final boolean DEBUG = false; 33 private static final String TAG = "GlobalKeyReceiver"; 34 private static final String ACTION_GLOBAL_BUTTON = "android.intent.action.GLOBAL_BUTTON"; 35 36 @Override onReceive(Context context, Intent intent)37 public void onReceive(Context context, Intent intent) { 38 TvApplication.setCurrentRunningProcess(context, true); 39 if (ACTION_GLOBAL_BUTTON.equals(intent.getAction())) { 40 KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); 41 if (DEBUG) Log.d(TAG, "onReceive: " + event); 42 int keyCode = event.getKeyCode(); 43 int action = event.getAction(); 44 if (action == KeyEvent.ACTION_UP) { 45 switch (keyCode) { 46 case KeyEvent.KEYCODE_GUIDE: 47 context.startActivity( 48 new Intent(Intent.ACTION_VIEW, TvContract.Programs.CONTENT_URI)); 49 break; 50 case KeyEvent.KEYCODE_TV: 51 ((TvApplication) context.getApplicationContext()).handleTvKey(); 52 break; 53 case KeyEvent.KEYCODE_TV_INPUT: 54 ((TvApplication) context.getApplicationContext()).handleTvInputKey(); 55 break; 56 default: 57 // Do nothing 58 break; 59 } 60 } 61 } 62 } 63 } 64