165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/* 265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project 365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License"); 565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License. 665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at 765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * http://www.apache.org/licenses/LICENSE-2.0 965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software 1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS, 1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and 1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License. 1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.device.apps; 1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context; 2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Intent; 2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.pm.PackageManager; 2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/** 2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Handles opening an application. 2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneclass OpenManager { 2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final Context mContext; 296e995161147d9110d77ae1fe38b697e52891d3f2Tony Mantler private final AppInfo mAppInfo; 3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Intent mLaunchIntent; 3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane OpenManager(Context context, AppInfo appInfo) { 3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mContext = context; 3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAppInfo = appInfo; 3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean canOpen() { 385a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler return getLaunchIntent() != null; 395a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler } 405a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler 415a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler public Intent getLaunchIntent() { 425a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler if (mLaunchIntent != null) { 435a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler return mLaunchIntent; 445a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler } 4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane PackageManager pm = mContext.getPackageManager(); 4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLaunchIntent = pm.getLeanbackLaunchIntentForPackage(mAppInfo.getPackageName()); 4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mLaunchIntent == null) { 4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLaunchIntent = pm.getLaunchIntentForPackage(mAppInfo.getPackageName()); 4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 505a4ccb2d0d1084782dbf5c90026402d5453dd0e8Tony Mantler return mLaunchIntent; 5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane} 53