blob: 455c6d16dce0376252a639984b21501ab7ac91ba [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 */
41 Intent intent;
42
43 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040044 * A bitmap version of the application icon.
45 */
46 Bitmap iconBitmap;
47
Winson Chung78403fe2011-01-21 15:38:02 -080048 /**
49 * The time at which the app was first installed.
50 */
51 long firstInstallTime;
52
Joe Onorato0589f0f2010-02-08 13:44:00 -080053 ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054
Patrick Dubroycd953712011-02-28 15:16:42 -080055 static final int DOWNLOADED_FLAG = 1;
56 static final int UPDATED_SYSTEM_APP_FLAG = 2;
57
Patrick Dubroy3d605d52010-07-29 13:59:29 -070058 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059
Michael Jurkaeadbfc52013-09-04 00:45:37 +020060 AppInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070061 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080063
Anjali Koppale3e646e2014-03-17 09:34:39 -070064 public Intent getIntent() {
Winson Chung997a9232013-07-24 15:33:46 -070065 return intent;
66 }
67
Chris Wrenb6d4c282014-01-27 14:17:08 -050068 protected Intent getRestoredIntent() {
69 return null;
70 }
71
Joe Onorato0589f0f2010-02-08 13:44:00 -080072 /**
73 * Must not hold the Context.
74 */
Kenny Guyed131872014-04-30 03:02:21 +010075 public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
Sunny Goyal4fbc3822015-02-18 16:46:50 -080076 IconCache iconCache) {
Kenny Guyed131872014-04-30 03:02:21 +010077 this.componentName = info.getComponentName();
Joe Onorato0589f0f2010-02-08 13:44:00 -080078 this.container = ItemInfo.NO_ID;
Joe Onorato0589f0f2010-02-08 13:44:00 -080079
Kenny Guyed131872014-04-30 03:02:21 +010080 flags = initFlags(info);
81 firstInstallTime = info.getFirstInstallTime();
Sunny Goyal4fbc3822015-02-18 16:46:50 -080082 iconCache.getTitleAndIcon(this, info);
Sunny Goyale0f58d72014-11-10 18:05:31 -080083 intent = makeLaunchIntent(context, info, user);
Kenny Guyed131872014-04-30 03:02:21 +010084 this.user = user;
Joe Onorato0589f0f2010-02-08 13:44:00 -080085 }
Winson Chungc3eecff2011-07-11 17:44:15 -070086
Sunny Goyale0f58d72014-11-10 18:05:31 -080087 public static int initFlags(LauncherActivityInfoCompat info) {
Kenny Guyc2bd8102014-06-30 12:30:31 +010088 int appFlags = info.getApplicationInfo().flags;
Michael Jurka1e2f4652013-07-08 18:03:46 -070089 int flags = 0;
90 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
91 flags |= DOWNLOADED_FLAG;
92
93 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
94 flags |= UPDATED_SYSTEM_APP_FLAG;
95 }
96 }
97 return flags;
98 }
99
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200100 public AppInfo(AppInfo info) {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700101 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800102 componentName = info.componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800103 title = info.title.toString();
104 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700105 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -0800106 firstInstallTime = info.firstInstallTime;
Kenny Guyed131872014-04-30 03:02:21 +0100107 iconBitmap = info.iconBitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108 }
109
110 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111 public String toString() {
Winson Chung64359a52013-07-08 17:17:08 -0700112 return "ApplicationInfo(title=" + title.toString() + " id=" + this.id
113 + " type=" + this.itemType + " container=" + this.container
114 + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
Sameer Padalabe3e4102014-04-21 19:36:14 -0700115 + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos)
Kenny Guyed131872014-04-30 03:02:21 +0100116 + " user=" + user + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400118
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200119 public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) {
Joe Onoratobe386092009-11-17 17:32:16 -0800120 Log.d(tag, label + " size=" + list.size());
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200121 for (AppInfo info: list) {
Winson Chungc85ea572011-07-11 16:02:31 -0700122 Log.d(tag, " title=\"" + info.title + "\" iconBitmap="
123 + info.iconBitmap + " firstInstallTime="
Winson Chung78403fe2011-01-21 15:38:02 -0800124 + info.firstInstallTime);
Joe Onoratobe386092009-11-17 17:32:16 -0800125 }
126 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800127
128 public ShortcutInfo makeShortcut() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700129 return new ShortcutInfo(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800130 }
Sunny Goyale0f58d72014-11-10 18:05:31 -0800131
132 public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info,
133 UserHandleCompat user) {
134 long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
135 return new Intent(Intent.ACTION_MAIN)
136 .addCategory(Intent.CATEGORY_LAUNCHER)
137 .setComponent(info.getComponentName())
138 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
139 .putExtra(EXTRA_PROFILE, serialNumber);
140 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141}