blob: bfcad84b37983b677753a21a2986646c19cf02c5 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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 Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
19import android.content.ComponentName;
Kenny Guyed131872014-04-30 03:02:21 +010020import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.content.Intent;
Michael Jurka34c2e6c2013-12-13 16:07:45 +010022import android.content.pm.PackageInfo;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070023import android.content.pm.PackageManager.NameNotFoundException;
Winson Chungc3eecff2011-07-11 17:44:15 -070024import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.graphics.Bitmap;
Joe Onoratobe386092009-11-17 17:32:16 -080026import android.util.Log;
27
Kenny Guyed131872014-04-30 03:02:21 +010028import com.android.launcher3.compat.LauncherActivityInfoCompat;
29import com.android.launcher3.compat.UserManagerCompat;
30import com.android.launcher3.compat.UserHandleCompat;
31
Patrick Dubroy3d605d52010-07-29 13:59:29 -070032import java.util.ArrayList;
Sameer Padalabe3e4102014-04-21 19:36:14 -070033import java.util.Arrays;
Winson Chungc3eecff2011-07-11 17:44:15 -070034import java.util.HashMap;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070035
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036/**
Joe Onorato0589f0f2010-02-08 13:44:00 -080037 * Represents an app in AllAppsView.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038 */
Anjali Koppal7b168a12014-03-04 17:16:11 -080039public class AppInfo extends ItemInfo {
Michael Jurkaeadbfc52013-09-04 00:45:37 +020040 private static final String TAG = "Launcher3.AppInfo";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041
42 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043 * The intent used to start the application.
44 */
45 Intent intent;
46
47 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040048 * A bitmap version of the application icon.
49 */
50 Bitmap iconBitmap;
51
Winson Chung78403fe2011-01-21 15:38:02 -080052 /**
53 * The time at which the app was first installed.
54 */
55 long firstInstallTime;
56
Joe Onorato0589f0f2010-02-08 13:44:00 -080057 ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058
Patrick Dubroycd953712011-02-28 15:16:42 -080059 static final int DOWNLOADED_FLAG = 1;
60 static final int UPDATED_SYSTEM_APP_FLAG = 2;
61
Patrick Dubroy3d605d52010-07-29 13:59:29 -070062 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063
Michael Jurkaeadbfc52013-09-04 00:45:37 +020064 AppInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070065 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080067
Anjali Koppale3e646e2014-03-17 09:34:39 -070068 public Intent getIntent() {
Winson Chung997a9232013-07-24 15:33:46 -070069 return intent;
70 }
71
Chris Wrenb6d4c282014-01-27 14:17:08 -050072 protected Intent getRestoredIntent() {
73 return null;
74 }
75
Joe Onorato0589f0f2010-02-08 13:44:00 -080076 /**
77 * Must not hold the Context.
78 */
Kenny Guyed131872014-04-30 03:02:21 +010079 public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
80 IconCache iconCache, HashMap<Object, CharSequence> labelCache) {
81 this.componentName = info.getComponentName();
Joe Onorato0589f0f2010-02-08 13:44:00 -080082 this.container = ItemInfo.NO_ID;
Joe Onorato0589f0f2010-02-08 13:44:00 -080083
Kenny Guyed131872014-04-30 03:02:21 +010084 flags = initFlags(info);
85 firstInstallTime = info.getFirstInstallTime();
Winson Chungc3eecff2011-07-11 17:44:15 -070086 iconCache.getTitleAndIcon(this, info, labelCache);
Kenny Guyed131872014-04-30 03:02:21 +010087 intent = new Intent(Intent.ACTION_MAIN);
88 intent.addCategory(Intent.CATEGORY_LAUNCHER);
89 intent.setComponent(info.getComponentName());
Kenny Guyb6cc40b2014-05-13 15:58:58 +010090 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Kenny Guyed131872014-04-30 03:02:21 +010091 long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
92 intent.putExtra(EXTRA_PROFILE, serialNumber);
93 this.user = user;
Joe Onorato0589f0f2010-02-08 13:44:00 -080094 }
Winson Chungc3eecff2011-07-11 17:44:15 -070095
Kenny Guyed131872014-04-30 03:02:21 +010096 private static int initFlags(LauncherActivityInfoCompat info) {
Kenny Guyc2bd8102014-06-30 12:30:31 +010097 int appFlags = info.getApplicationInfo().flags;
Michael Jurka1e2f4652013-07-08 18:03:46 -070098 int flags = 0;
99 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
100 flags |= DOWNLOADED_FLAG;
101
102 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
103 flags |= UPDATED_SYSTEM_APP_FLAG;
104 }
105 }
106 return flags;
107 }
108
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200109 public AppInfo(AppInfo info) {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700110 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800111 componentName = info.componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800112 title = info.title.toString();
113 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700114 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -0800115 firstInstallTime = info.firstInstallTime;
Kenny Guyed131872014-04-30 03:02:21 +0100116 iconBitmap = info.iconBitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117 }
118
119 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120 public String toString() {
Winson Chung64359a52013-07-08 17:17:08 -0700121 return "ApplicationInfo(title=" + title.toString() + " id=" + this.id
122 + " type=" + this.itemType + " container=" + this.container
123 + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
Sameer Padalabe3e4102014-04-21 19:36:14 -0700124 + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos)
Kenny Guyed131872014-04-30 03:02:21 +0100125 + " user=" + user + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800126 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400127
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200128 public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) {
Joe Onoratobe386092009-11-17 17:32:16 -0800129 Log.d(tag, label + " size=" + list.size());
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200130 for (AppInfo info: list) {
Winson Chungc85ea572011-07-11 16:02:31 -0700131 Log.d(tag, " title=\"" + info.title + "\" iconBitmap="
132 + info.iconBitmap + " firstInstallTime="
Winson Chung78403fe2011-01-21 15:38:02 -0800133 + info.firstInstallTime);
Joe Onoratobe386092009-11-17 17:32:16 -0800134 }
135 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800136
137 public ShortcutInfo makeShortcut() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700138 return new ShortcutInfo(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800139 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140}