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; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 20 | import android.content.Context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
| 22 | import android.graphics.Bitmap; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 25 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 26 | import com.android.launcher3.compat.UserHandleCompat; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 27 | import com.android.launcher3.compat.UserManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 28 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 29 | import java.util.ArrayList; |
Sameer Padala | be3e410 | 2014-04-21 19:36:14 -0700 | [diff] [blame] | 30 | import java.util.Arrays; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 31 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 33 | * Represents an app in AllAppsView. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 35 | public class AppInfo extends ItemInfo { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 36 | private static final String TAG = "Launcher3.AppInfo"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | * The intent used to start the application. |
| 40 | */ |
| 41 | Intent intent; |
| 42 | |
| 43 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 44 | * A bitmap version of the application icon. |
| 45 | */ |
| 46 | Bitmap iconBitmap; |
| 47 | |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 48 | /** |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 49 | * Indicates whether we're using a low res icon |
| 50 | */ |
| 51 | boolean usingLowResIcon; |
| 52 | |
| 53 | /** |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 54 | * The time at which the app was first installed. |
| 55 | */ |
| 56 | long firstInstallTime; |
| 57 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 58 | ComponentName componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 59 | |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 60 | static final int DOWNLOADED_FLAG = 1; |
| 61 | static final int UPDATED_SYSTEM_APP_FLAG = 2; |
| 62 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 63 | int flags = 0; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 64 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 65 | AppInfo() { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 66 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 67 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 68 | |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 69 | public Intent getIntent() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 70 | return intent; |
| 71 | } |
| 72 | |
Chris Wren | b6d4c28 | 2014-01-27 14:17:08 -0500 | [diff] [blame] | 73 | protected Intent getRestoredIntent() { |
| 74 | return null; |
| 75 | } |
| 76 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Must not hold the Context. |
| 79 | */ |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 80 | public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user, |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 81 | IconCache iconCache) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 82 | this.componentName = info.getComponentName(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 83 | this.container = ItemInfo.NO_ID; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 84 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 85 | flags = initFlags(info); |
| 86 | firstInstallTime = info.getFirstInstallTime(); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 87 | iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */); |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 88 | intent = makeLaunchIntent(context, info, user); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 89 | this.user = user; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 90 | } |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 91 | |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 92 | public static int initFlags(LauncherActivityInfoCompat info) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 93 | int appFlags = info.getApplicationInfo().flags; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 94 | int flags = 0; |
| 95 | if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 96 | flags |= DOWNLOADED_FLAG; |
| 97 | |
| 98 | if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 99 | flags |= UPDATED_SYSTEM_APP_FLAG; |
| 100 | } |
| 101 | } |
| 102 | return flags; |
| 103 | } |
| 104 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 105 | public AppInfo(AppInfo info) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 106 | super(info); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 107 | componentName = info.componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 108 | title = info.title.toString(); |
| 109 | intent = new Intent(info.intent); |
Patrick Dubroy | 430c53b | 2010-09-08 16:01:19 -0700 | [diff] [blame] | 110 | flags = info.flags; |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 111 | firstInstallTime = info.firstInstallTime; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 112 | iconBitmap = info.iconBitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 116 | public String toString() { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 117 | return "ApplicationInfo(title=" + title.toString() + " id=" + this.id |
| 118 | + " type=" + this.itemType + " container=" + this.container |
| 119 | + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY |
Sameer Padala | be3e410 | 2014-04-21 19:36:14 -0700 | [diff] [blame] | 120 | + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 121 | + " user=" + user + ")"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 122 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 123 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 124 | public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 125 | Log.d(tag, label + " size=" + list.size()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 126 | for (AppInfo info: list) { |
Winson Chung | c85ea57 | 2011-07-11 16:02:31 -0700 | [diff] [blame] | 127 | Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" |
| 128 | + info.iconBitmap + " firstInstallTime=" |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 129 | + info.firstInstallTime); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 132 | |
| 133 | public ShortcutInfo makeShortcut() { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 134 | return new ShortcutInfo(this); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 135 | } |
Sunny Goyal | e0f58d7 | 2014-11-10 18:05:31 -0800 | [diff] [blame] | 136 | |
| 137 | public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info, |
| 138 | UserHandleCompat user) { |
| 139 | long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user); |
| 140 | return new Intent(Intent.ACTION_MAIN) |
| 141 | .addCategory(Intent.CATEGORY_LAUNCHER) |
| 142 | .setComponent(info.getComponentName()) |
| 143 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) |
| 144 | .putExtra(EXTRA_PROFILE, serialNumber); |
| 145 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | } |