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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
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; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 22 | import android.content.pm.ResolveInfo; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 27 | import java.util.ArrayList; |
| 28 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 29 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 30 | * Represents an app in AllAppsView. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | */ |
| 32 | class ApplicationInfo extends ItemInfo { |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 33 | private static final String TAG = "Launcher2.ApplicationInfo"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * The application name. |
| 37 | */ |
| 38 | CharSequence title; |
| 39 | |
| 40 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 41 | * A bitmap of the application's text in the bubble. |
| 42 | */ |
| 43 | Bitmap titleBitmap; |
| 44 | |
| 45 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 46 | * The intent used to start the application. |
| 47 | */ |
| 48 | Intent intent; |
| 49 | |
| 50 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 51 | * A bitmap version of the application icon. |
| 52 | */ |
| 53 | Bitmap iconBitmap; |
| 54 | |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 55 | /** |
| 56 | * The time at which the app was first installed. |
| 57 | */ |
| 58 | long firstInstallTime; |
| 59 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 60 | ComponentName componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 61 | |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 62 | static final int DOWNLOADED_FLAG = 1; |
| 63 | static final int UPDATED_SYSTEM_APP_FLAG = 2; |
| 64 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 65 | int flags = 0; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 66 | |
| 67 | ApplicationInfo() { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 68 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Must not hold the Context. |
| 73 | */ |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 74 | public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache) { |
| 75 | final String packageName = info.activityInfo.applicationInfo.packageName; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 76 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 77 | this.componentName = new ComponentName(packageName, info.activityInfo.name); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 78 | this.container = ItemInfo.NO_ID; |
| 79 | this.setActivity(componentName, |
| 80 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 81 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 82 | try { |
| 83 | int appFlags = pm.getApplicationInfo(packageName, 0).flags; |
| 84 | if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 85 | flags |= DOWNLOADED_FLAG; |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 86 | |
| 87 | if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 88 | flags |= UPDATED_SYSTEM_APP_FLAG; |
| 89 | } |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 90 | } |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 91 | firstInstallTime = pm.getPackageInfo(packageName, 0).firstInstallTime; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 92 | } catch (NameNotFoundException e) { |
| 93 | Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName); |
| 94 | } |
| 95 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 96 | iconCache.getTitleAndIcon(this, info); |
| 97 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 98 | |
| 99 | public ApplicationInfo(ApplicationInfo info) { |
| 100 | super(info); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 101 | componentName = info.componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 102 | title = info.title.toString(); |
| 103 | intent = new Intent(info.intent); |
Patrick Dubroy | 430c53b | 2010-09-08 16:01:19 -0700 | [diff] [blame] | 104 | flags = info.flags; |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 105 | firstInstallTime = info.firstInstallTime; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * 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] | 110 | * 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] | 111 | * |
| 112 | * @param className the class name of the component representing the intent |
| 113 | * @param launchFlags the launch flags |
| 114 | */ |
| 115 | final void setActivity(ComponentName className, int launchFlags) { |
| 116 | intent = new Intent(Intent.ACTION_MAIN); |
| 117 | intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 118 | intent.setComponent(className); |
| 119 | intent.setFlags(launchFlags); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 120 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | public String toString() { |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 125 | return "ApplicationInfo(title=" + title.toString() + ")"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 126 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 127 | |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 128 | public static void dumpApplicationInfoList(String tag, String label, |
| 129 | ArrayList<ApplicationInfo> list) { |
| 130 | Log.d(tag, label + " size=" + list.size()); |
| 131 | for (ApplicationInfo info: list) { |
| 132 | Log.d(tag, " title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 133 | + " iconBitmap=" + info.iconBitmap + " firstInstallTime=" |
| 134 | + info.firstInstallTime); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 137 | |
| 138 | public ShortcutInfo makeShortcut() { |
| 139 | return new ShortcutInfo(this); |
| 140 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | } |