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.tv.setup; 18 19 import android.app.Activity; 20 import android.app.Fragment; 21 import android.content.ActivityNotFoundException; 22 import android.content.ComponentName; 23 import android.content.Intent; 24 import android.media.tv.TvInputInfo; 25 import android.os.Bundle; 26 import android.widget.Toast; 27 import com.android.tv.R; 28 import com.android.tv.SetupPassthroughActivity; 29 import com.android.tv.TvSingletons; 30 import com.android.tv.common.CommonConstants; 31 import com.android.tv.common.ui.setup.SetupActivity; 32 import com.android.tv.common.ui.setup.SetupMultiPaneFragment; 33 import com.android.tv.common.util.CommonUtils; 34 import com.android.tv.onboarding.SetupSourcesFragment; 35 import com.android.tv.util.OnboardingUtils; 36 import com.android.tv.util.SetupUtils; 37 import com.android.tv.util.TvInputManagerHelper; 38 39 /** A activity to start input sources setup fragment for initial setup flow. */ 40 public class SystemSetupActivity extends SetupActivity { 41 private static final String SYSTEM_SETUP = 42 CommonConstants.BASE_PACKAGE + ".action.LAUNCH_SYSTEM_SETUP"; 43 private static final int SHOW_RIPPLE_DURATION_MS = 266; 44 private static final int REQUEST_CODE_START_SETUP_ACTIVITY = 1; 45 46 private TvInputManagerHelper mInputManager; 47 48 @Override onCreate(Bundle savedInstanceState)49 protected void onCreate(Bundle savedInstanceState) { 50 super.onCreate(savedInstanceState); 51 Intent intent = getIntent(); 52 if (!SYSTEM_SETUP.equals(intent.getAction())) { 53 finish(); 54 return; 55 } 56 TvSingletons singletons = TvSingletons.getSingletons(this); 57 mInputManager = singletons.getTvInputManagerHelper(); 58 } 59 60 @Override onCreateInitialFragment()61 protected Fragment onCreateInitialFragment() { 62 return new SetupSourcesFragment(); 63 } 64 showMerchantCollection()65 private void showMerchantCollection() { 66 executeActionWithDelay( 67 new Runnable() { 68 @Override 69 public void run() { 70 startActivity(OnboardingUtils.ONLINE_STORE_INTENT); 71 } 72 }, 73 SHOW_RIPPLE_DURATION_MS); 74 } 75 76 @Override executeAction(String category, int actionId, Bundle params)77 public boolean executeAction(String category, int actionId, Bundle params) { 78 switch (category) { 79 case SetupSourcesFragment.ACTION_CATEGORY: 80 switch (actionId) { 81 case SetupSourcesFragment.ACTION_ONLINE_STORE: 82 showMerchantCollection(); 83 return true; 84 case SetupSourcesFragment.ACTION_SETUP_INPUT: 85 { 86 String inputId = 87 params.getString( 88 SetupSourcesFragment.ACTION_PARAM_KEY_INPUT_ID); 89 TvInputInfo input = mInputManager.getTvInputInfo(inputId); 90 Intent intent = CommonUtils.createSetupIntent(input); 91 if (intent == null) { 92 Toast.makeText( 93 this, 94 R.string.msg_no_setup_activity, 95 Toast.LENGTH_SHORT) 96 .show(); 97 return true; 98 } 99 // Even though other app can handle the intent, the setup launched by 100 // Live 101 // channels should go through Live channels SetupPassthroughActivity. 102 intent.setComponent( 103 new ComponentName(this, SetupPassthroughActivity.class)); 104 try { 105 // Now we know that the user intends to set up this input. Grant 106 // permission for writing EPG data. 107 SetupUtils.grantEpgPermission( 108 this, input.getServiceInfo().packageName); 109 startActivityForResult(intent, REQUEST_CODE_START_SETUP_ACTIVITY); 110 } catch (ActivityNotFoundException e) { 111 Toast.makeText( 112 this, 113 getString( 114 R.string.msg_unable_to_start_setup_activity, 115 input.loadLabel(this)), 116 Toast.LENGTH_SHORT) 117 .show(); 118 } 119 return true; 120 } 121 case SetupMultiPaneFragment.ACTION_DONE: 122 { 123 // To make sure user can finish setup flow, set result as RESULT_OK. 124 setResult(Activity.RESULT_OK); 125 finish(); 126 return true; 127 } 128 } 129 break; 130 } 131 return false; 132 } 133 } 134