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.ComponentName; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.PackageManager; 24 import android.util.Log; 25 26 import com.android.tv.Features; 27 import com.android.tv.TvActivity; 28 import com.android.tv.TvApplication; 29 import com.android.tv.common.feature.CommonFeatures; 30 import com.android.tv.dvr.DvrRecordingService; 31 import com.android.tv.recommendation.NotificationService; 32 import com.android.tv.util.OnboardingUtils; 33 import com.android.tv.util.SetupUtils; 34 35 /** 36 * Boot completed receiver for TV app. 37 * 38 * <p>It's used to 39 * <ul> 40 * <li>start the {@link NotificationService} for recommendation</li> 41 * <li>grant permission to the TIS's </li> 42 * <li>enable {@link TvActivity} if necessary</li> 43 * <li>start the {@link DvrRecordingService} </li> 44 * </ul> 45 */ 46 public class BootCompletedReceiver extends BroadcastReceiver { 47 private static final String TAG = "BootCompletedReceiver"; 48 private static final boolean DEBUG = false; 49 50 @Override onReceive(Context context, Intent intent)51 public void onReceive(Context context, Intent intent) { 52 if (DEBUG) Log.d(TAG, "boot completed " + intent); 53 TvApplication.setCurrentRunningProcess(context, true); 54 // Start {@link NotificationService}. 55 Intent notificationIntent = new Intent(context, NotificationService.class); 56 notificationIntent.setAction(NotificationService.ACTION_SHOW_RECOMMENDATION); 57 context.startService(notificationIntent); 58 59 // Grant permission to already set up packages after the system has finished booting. 60 SetupUtils.grantEpgPermissionToSetUpPackages(context); 61 62 if (Features.UNHIDE.isEnabled(context)) { 63 if (OnboardingUtils.isFirstBoot(context)) { 64 // Enable the application if this is the first "unhide" feature is enabled just in 65 // case when the app has been disabled before. 66 PackageManager pm = context.getPackageManager(); 67 ComponentName name = new ComponentName(context, TvActivity.class); 68 if (pm.getComponentEnabledSetting(name) 69 != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { 70 pm.setComponentEnabledSetting(name, 71 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0); 72 } 73 OnboardingUtils.setFirstBootCompleted(context); 74 } 75 } 76 77 if (CommonFeatures.DVR.isEnabled(context)) { 78 DvrRecordingService.startService(context); 79 } 80 } 81 } 82