The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 20 | import android.content.Intent; |
Michael Jurka | 34c2e6c | 2013-12-13 16:07:45 +0100 | [diff] [blame] | 21 | import android.content.pm.PackageInfo; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 22 | import android.content.pm.PackageManager; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager.NameNotFoundException; |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 24 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 26 | import android.util.Log; |
| 27 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 28 | import java.util.ArrayList; |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 29 | import java.util.HashMap; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 30 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 32 | * Represents an app in AllAppsView. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 34 | public class AppInfo extends ItemInfo { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 35 | private static final String TAG = "Launcher3.AppInfo"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | * The intent used to start the application. |
| 39 | */ |
| 40 | Intent intent; |
| 41 | |
| 42 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 43 | * A bitmap version of the application icon. |
| 44 | */ |
| 45 | Bitmap iconBitmap; |
| 46 | |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 47 | /** |
| 48 | * The time at which the app was first installed. |
| 49 | */ |
| 50 | long firstInstallTime; |
| 51 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 52 | ComponentName componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 54 | static final int DOWNLOADED_FLAG = 1; |
| 55 | static final int UPDATED_SYSTEM_APP_FLAG = 2; |
| 56 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 57 | int flags = 0; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 58 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 59 | AppInfo() { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 60 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 61 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 62 | |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame^] | 63 | public Intent getIntent() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 64 | return intent; |
| 65 | } |
| 66 | |
Chris Wren | b6d4c28 | 2014-01-27 14:17:08 -0500 | [diff] [blame] | 67 | protected Intent getRestoredIntent() { |
| 68 | return null; |
| 69 | } |
| 70 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 71 | /** |
| 72 | * Must not hold the Context. |
| 73 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 74 | public AppInfo(PackageManager pm, ResolveInfo info, IconCache iconCache, |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 75 | HashMap<Object, CharSequence> labelCache) { |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 76 | final String packageName = info.activityInfo.applicationInfo.packageName; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 77 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 78 | this.componentName = new ComponentName(packageName, info.activityInfo.name); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 79 | this.container = ItemInfo.NO_ID; |
| 80 | this.setActivity(componentName, |
| 81 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 82 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 83 | try { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 84 | PackageInfo pi = pm.getPackageInfo(packageName, 0); |
| 85 | flags = initFlags(pi); |
| 86 | firstInstallTime = initFirstInstallTime(pi); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 87 | } catch (NameNotFoundException e) { |
| 88 | Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName); |
| 89 | } |
| 90 | |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 91 | iconCache.getTitleAndIcon(this, info, labelCache); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 92 | } |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 93 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 94 | public static int initFlags(PackageInfo pi) { |
| 95 | int appFlags = pi.applicationInfo.flags; |
| 96 | int flags = 0; |
| 97 | if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 98 | flags |= DOWNLOADED_FLAG; |
| 99 | |
| 100 | if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 101 | flags |= UPDATED_SYSTEM_APP_FLAG; |
| 102 | } |
| 103 | } |
| 104 | return flags; |
| 105 | } |
| 106 | |
| 107 | public static long initFirstInstallTime(PackageInfo pi) { |
| 108 | return pi.firstInstallTime; |
| 109 | } |
| 110 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 111 | public AppInfo(AppInfo info) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 112 | super(info); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 113 | componentName = info.componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 114 | title = info.title.toString(); |
| 115 | intent = new Intent(info.intent); |
Patrick Dubroy | 430c53b | 2010-09-08 16:01:19 -0700 | [diff] [blame] | 116 | flags = info.flags; |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 117 | firstInstallTime = info.firstInstallTime; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Creates the application intent based on a component name and various launch flags. |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 122 | * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 123 | * |
| 124 | * @param className the class name of the component representing the intent |
| 125 | * @param launchFlags the launch flags |
| 126 | */ |
| 127 | final void setActivity(ComponentName className, int launchFlags) { |
| 128 | intent = new Intent(Intent.ACTION_MAIN); |
| 129 | intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 130 | intent.setComponent(className); |
| 131 | intent.setFlags(launchFlags); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 132 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 136 | public String toString() { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 137 | return "ApplicationInfo(title=" + title.toString() + " id=" + this.id |
| 138 | + " type=" + this.itemType + " container=" + this.container |
| 139 | + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY |
| 140 | + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + dropPos + ")"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 142 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 143 | public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 144 | Log.d(tag, label + " size=" + list.size()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 145 | for (AppInfo info: list) { |
Winson Chung | c85ea57 | 2011-07-11 16:02:31 -0700 | [diff] [blame] | 146 | Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" |
| 147 | + info.iconBitmap + " firstInstallTime=" |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 148 | + info.firstInstallTime); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 149 | } |
| 150 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 151 | |
| 152 | public ShortcutInfo makeShortcut() { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 153 | return new ShortcutInfo(this); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 154 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 155 | } |