blob: 9c87ced54d6eca6f89b7e6d5bbfb52b95fd40dbc [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;
Kenny Guyed131872014-04-30 03:02:21 +010028
Patrick Dubroy3d605d52010-07-29 13:59:29 -070029import java.util.ArrayList;
Sameer Padalabe3e4102014-04-21 19:36:14 -070030import java.util.Arrays;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070031
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032/**
Joe Onorato0589f0f2010-02-08 13:44:00 -080033 * Represents an app in AllAppsView.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034 */
Anjali Koppal7b168a12014-03-04 17:16:11 -080035public class AppInfo extends ItemInfo {
Michael Jurkaeadbfc52013-09-04 00:45:37 +020036 private static final String TAG = "Launcher3.AppInfo";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037
38 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039 * The intent used to start the application.
40 */
Winson Chung5f4e0fd2015-05-22 11:12:27 -070041 public Intent intent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042
43 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040044 * A bitmap version of the application icon.
45 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070046 public Bitmap iconBitmap;
Joe Onorato9c1289c2009-08-17 11:03:03 -040047
Winson Chung78403fe2011-01-21 15:38:02 -080048 /**
Sunny Goyal34b65272015-03-11 16:56:52 -070049 * Indicates whether we're using a low res icon
50 */
51 boolean usingLowResIcon;
52
53 /**
Winson Chung78403fe2011-01-21 15:38:02 -080054 * The time at which the app was first installed.
55 */
56 long firstInstallTime;
57
Hyunyoung Song3f471442015-04-08 19:01:34 -070058 public ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059
Patrick Dubroycd953712011-02-28 15:16:42 -080060 static final int DOWNLOADED_FLAG = 1;
61 static final int UPDATED_SYSTEM_APP_FLAG = 2;
62
Patrick Dubroy3d605d52010-07-29 13:59:29 -070063 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064
Michael Jurkaeadbfc52013-09-04 00:45:37 +020065 AppInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070066 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080068
Anjali Koppale3e646e2014-03-17 09:34:39 -070069 public Intent getIntent() {
Winson Chung997a9232013-07-24 15:33:46 -070070 return intent;
71 }
72
Chris Wrenb6d4c282014-01-27 14:17:08 -050073 protected Intent getRestoredIntent() {
74 return null;
75 }
76
Joe Onorato0589f0f2010-02-08 13:44:00 -080077 /**
78 * Must not hold the Context.
79 */
Kenny Guyed131872014-04-30 03:02:21 +010080 public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
Sunny Goyal4fbc3822015-02-18 16:46:50 -080081 IconCache iconCache) {
Kenny Guyed131872014-04-30 03:02:21 +010082 this.componentName = info.getComponentName();
Joe Onorato0589f0f2010-02-08 13:44:00 -080083 this.container = ItemInfo.NO_ID;
Joe Onorato0589f0f2010-02-08 13:44:00 -080084
Kenny Guyed131872014-04-30 03:02:21 +010085 flags = initFlags(info);
86 firstInstallTime = info.getFirstInstallTime();
Sunny Goyal34b65272015-03-11 16:56:52 -070087 iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
Sunny Goyale0f58d72014-11-10 18:05:31 -080088 intent = makeLaunchIntent(context, info, user);
Kenny Guyed131872014-04-30 03:02:21 +010089 this.user = user;
Joe Onorato0589f0f2010-02-08 13:44:00 -080090 }
Winson Chungc3eecff2011-07-11 17:44:15 -070091
Sunny Goyale0f58d72014-11-10 18:05:31 -080092 public static int initFlags(LauncherActivityInfoCompat info) {
Kenny Guyc2bd8102014-06-30 12:30:31 +010093 int appFlags = info.getApplicationInfo().flags;
Michael Jurka1e2f4652013-07-08 18:03:46 -070094 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 Jurkaeadbfc52013-09-04 00:45:37 +0200105 public AppInfo(AppInfo info) {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700106 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800107 componentName = info.componentName;
Winson Chung82b016c2015-05-08 17:00:10 -0700108 title = Utilities.trim(info.title);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700110 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -0800111 firstInstallTime = info.firstInstallTime;
Kenny Guyed131872014-04-30 03:02:21 +0100112 iconBitmap = info.iconBitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800113 }
114
115 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116 public String toString() {
Winson Chung82b016c2015-05-08 17:00:10 -0700117 return "ApplicationInfo(title=" + title + " id=" + this.id
Winson Chung64359a52013-07-08 17:17:08 -0700118 + " type=" + this.itemType + " container=" + this.container
119 + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
Sameer Padalabe3e4102014-04-21 19:36:14 -0700120 + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos)
Kenny Guyed131872014-04-30 03:02:21 +0100121 + " user=" + user + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400123
Hyunyoung Song3f471442015-04-08 19:01:34 -0700124 /**
125 * Helper method used for debugging.
126 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200127 public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) {
Joe Onoratobe386092009-11-17 17:32:16 -0800128 Log.d(tag, label + " size=" + list.size());
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200129 for (AppInfo info: list) {
Hyunyoung Song3f471442015-04-08 19:01:34 -0700130 Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
131 + " firstInstallTime=" + info.firstInstallTime
132 + " componentName=" + info.componentName.getPackageName());
Joe Onoratobe386092009-11-17 17:32:16 -0800133 }
134 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800135
136 public ShortcutInfo makeShortcut() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700137 return new ShortcutInfo(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800138 }
Sunny Goyale0f58d72014-11-10 18:05:31 -0800139
140 public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info,
141 UserHandleCompat user) {
142 long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
143 return new Intent(Intent.ACTION_MAIN)
144 .addCategory(Intent.CATEGORY_LAUNCHER)
145 .setComponent(info.getComponentName())
146 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
147 .putExtra(EXTRA_PROFILE, serialNumber);
148 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149}