blob: c95d5585a74cfcfa88caec9b46881874bf6d3ada [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;
22import android.graphics.Bitmap;
Joe Onoratobe386092009-11-17 17:32:16 -080023import android.util.Log;
24
Kenny Guyed131872014-04-30 03:02:21 +010025import com.android.launcher3.compat.LauncherActivityInfoCompat;
Kenny Guyed131872014-04-30 03:02:21 +010026import com.android.launcher3.compat.UserHandleCompat;
Sunny Goyal4fbc3822015-02-18 16:46:50 -080027import com.android.launcher3.compat.UserManagerCompat;
Sunny Goyal51832852015-06-16 11:36:19 -070028import com.android.launcher3.util.ComponentKey;
Kenny Guyed131872014-04-30 03:02:21 +010029
Patrick Dubroy3d605d52010-07-29 13:59:29 -070030import java.util.ArrayList;
Sameer Padalabe3e4102014-04-21 19:36:14 -070031import java.util.Arrays;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070032
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033/**
Joe Onorato0589f0f2010-02-08 13:44:00 -080034 * Represents an app in AllAppsView.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035 */
Anjali Koppal7b168a12014-03-04 17:16:11 -080036public class AppInfo extends ItemInfo {
Michael Jurkaeadbfc52013-09-04 00:45:37 +020037 private static final String TAG = "Launcher3.AppInfo";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038
39 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040 * The intent used to start the application.
41 */
Winson Chung5f4e0fd2015-05-22 11:12:27 -070042 public Intent intent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043
44 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040045 * A bitmap version of the application icon.
46 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070047 public Bitmap iconBitmap;
Joe Onorato9c1289c2009-08-17 11:03:03 -040048
Winson Chung78403fe2011-01-21 15:38:02 -080049 /**
Sunny Goyal34b65272015-03-11 16:56:52 -070050 * Indicates whether we're using a low res icon
51 */
52 boolean usingLowResIcon;
53
54 /**
Winson Chung78403fe2011-01-21 15:38:02 -080055 * The time at which the app was first installed.
56 */
57 long firstInstallTime;
58
Hyunyoung Song3f471442015-04-08 19:01:34 -070059 public ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060
Patrick Dubroycd953712011-02-28 15:16:42 -080061 static final int DOWNLOADED_FLAG = 1;
62 static final int UPDATED_SYSTEM_APP_FLAG = 2;
63
Patrick Dubroy3d605d52010-07-29 13:59:29 -070064 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065
Michael Jurkaeadbfc52013-09-04 00:45:37 +020066 AppInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070067 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080069
Anjali Koppale3e646e2014-03-17 09:34:39 -070070 public Intent getIntent() {
Winson Chung997a9232013-07-24 15:33:46 -070071 return intent;
72 }
73
Chris Wrenb6d4c282014-01-27 14:17:08 -050074 protected Intent getRestoredIntent() {
75 return null;
76 }
77
Joe Onorato0589f0f2010-02-08 13:44:00 -080078 /**
79 * Must not hold the Context.
80 */
Kenny Guyed131872014-04-30 03:02:21 +010081 public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
Sunny Goyal4fbc3822015-02-18 16:46:50 -080082 IconCache iconCache) {
Kenny Guyed131872014-04-30 03:02:21 +010083 this.componentName = info.getComponentName();
Joe Onorato0589f0f2010-02-08 13:44:00 -080084 this.container = ItemInfo.NO_ID;
Joe Onorato0589f0f2010-02-08 13:44:00 -080085
Kenny Guyed131872014-04-30 03:02:21 +010086 flags = initFlags(info);
87 firstInstallTime = info.getFirstInstallTime();
Sunny Goyal34b65272015-03-11 16:56:52 -070088 iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
Sunny Goyale0f58d72014-11-10 18:05:31 -080089 intent = makeLaunchIntent(context, info, user);
Kenny Guyed131872014-04-30 03:02:21 +010090 this.user = user;
Joe Onorato0589f0f2010-02-08 13:44:00 -080091 }
Winson Chungc3eecff2011-07-11 17:44:15 -070092
Sunny Goyale0f58d72014-11-10 18:05:31 -080093 public static int initFlags(LauncherActivityInfoCompat info) {
Kenny Guyc2bd8102014-06-30 12:30:31 +010094 int appFlags = info.getApplicationInfo().flags;
Michael Jurka1e2f4652013-07-08 18:03:46 -070095 int flags = 0;
96 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
97 flags |= DOWNLOADED_FLAG;
98
99 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
100 flags |= UPDATED_SYSTEM_APP_FLAG;
101 }
102 }
103 return flags;
104 }
105
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200106 public AppInfo(AppInfo info) {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700107 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800108 componentName = info.componentName;
Winson Chung82b016c2015-05-08 17:00:10 -0700109 title = Utilities.trim(info.title);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800110 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700111 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -0800112 firstInstallTime = info.firstInstallTime;
Kenny Guyed131872014-04-30 03:02:21 +0100113 iconBitmap = info.iconBitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800114 }
115
116 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117 public String toString() {
Winson Chung82b016c2015-05-08 17:00:10 -0700118 return "ApplicationInfo(title=" + title + " id=" + this.id
Winson Chung64359a52013-07-08 17:17:08 -0700119 + " type=" + this.itemType + " container=" + this.container
120 + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
Sameer Padalabe3e4102014-04-21 19:36:14 -0700121 + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos)
Kenny Guyed131872014-04-30 03:02:21 +0100122 + " user=" + user + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400124
Hyunyoung Song3f471442015-04-08 19:01:34 -0700125 /**
126 * Helper method used for debugging.
127 */
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) {
Hyunyoung Song3f471442015-04-08 19:01:34 -0700131 Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
132 + " firstInstallTime=" + info.firstInstallTime
133 + " componentName=" + info.componentName.getPackageName());
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 }
Sunny Goyale0f58d72014-11-10 18:05:31 -0800140
Sunny Goyal51832852015-06-16 11:36:19 -0700141 public ComponentKey toComponentKey() {
142 return new ComponentKey(componentName, user);
143 }
144
Sunny Goyale0f58d72014-11-10 18:05:31 -0800145 public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info,
146 UserHandleCompat user) {
147 long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
148 return new Intent(Intent.ACTION_MAIN)
149 .addCategory(Intent.CATEGORY_LAUNCHER)
150 .setComponent(info.getComponentName())
151 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
152 .putExtra(EXTRA_PROFILE, serialNumber);
153 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154}