blob: 53801d60c347d5e93346bfaac8317341071d43c3 [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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080020import android.content.Intent;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070021import android.content.pm.PackageManager;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070022import android.content.pm.PackageManager.NameNotFoundException;
Winson Chungc3eecff2011-07-11 17:44:15 -070023import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024import android.graphics.Bitmap;
Joe Onoratobe386092009-11-17 17:32:16 -080025import android.util.Log;
26
Patrick Dubroy3d605d52010-07-29 13:59:29 -070027import java.util.ArrayList;
Winson Chungc3eecff2011-07-11 17:44:15 -070028import java.util.HashMap;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070029
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030/**
Joe Onorato0589f0f2010-02-08 13:44:00 -080031 * Represents an app in AllAppsView.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032 */
33class ApplicationInfo extends ItemInfo {
Patrick Dubroy3d605d52010-07-29 13:59:29 -070034 private static final String TAG = "Launcher2.ApplicationInfo";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035
36 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037 * The intent used to start the application.
38 */
39 Intent intent;
40
41 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040042 * A bitmap version of the application icon.
43 */
44 Bitmap iconBitmap;
45
Winson Chung78403fe2011-01-21 15:38:02 -080046 /**
47 * The time at which the app was first installed.
48 */
49 long firstInstallTime;
50
Joe Onorato0589f0f2010-02-08 13:44:00 -080051 ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052
Patrick Dubroycd953712011-02-28 15:16:42 -080053 static final int DOWNLOADED_FLAG = 1;
54 static final int UPDATED_SYSTEM_APP_FLAG = 2;
55
Patrick Dubroy3d605d52010-07-29 13:59:29 -070056 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057
Michael Jurkac9d95c52011-08-29 14:03:34 -070058 ApplicationInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070059 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080061
62 /**
63 * Must not hold the Context.
64 */
Winson Chungc3eecff2011-07-11 17:44:15 -070065 public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache,
Michael Jurkac9d95c52011-08-29 14:03:34 -070066 HashMap<Object, CharSequence> labelCache) {
Patrick Dubroy3d605d52010-07-29 13:59:29 -070067 final String packageName = info.activityInfo.applicationInfo.packageName;
Joe Onorato0589f0f2010-02-08 13:44:00 -080068
Patrick Dubroy3d605d52010-07-29 13:59:29 -070069 this.componentName = new ComponentName(packageName, info.activityInfo.name);
Joe Onorato0589f0f2010-02-08 13:44:00 -080070 this.container = ItemInfo.NO_ID;
71 this.setActivity(componentName,
72 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
73
Patrick Dubroy3d605d52010-07-29 13:59:29 -070074 try {
75 int appFlags = pm.getApplicationInfo(packageName, 0).flags;
76 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
77 flags |= DOWNLOADED_FLAG;
Patrick Dubroycd953712011-02-28 15:16:42 -080078
79 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
80 flags |= UPDATED_SYSTEM_APP_FLAG;
81 }
Patrick Dubroy3d605d52010-07-29 13:59:29 -070082 }
Winson Chung78403fe2011-01-21 15:38:02 -080083 firstInstallTime = pm.getPackageInfo(packageName, 0).firstInstallTime;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070084 } catch (NameNotFoundException e) {
85 Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName);
86 }
87
Winson Chungc3eecff2011-07-11 17:44:15 -070088 iconCache.getTitleAndIcon(this, info, labelCache);
Joe Onorato0589f0f2010-02-08 13:44:00 -080089 }
Winson Chungc3eecff2011-07-11 17:44:15 -070090
Michael Jurkac9d95c52011-08-29 14:03:34 -070091 public ApplicationInfo(ApplicationInfo info) {
92 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -080093 componentName = info.componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094 title = info.title.toString();
95 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -070096 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -080097 firstInstallTime = info.firstInstallTime;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080098 }
99
100 /**
101 * Creates the application intent based on a component name and various launch flags.
Romain Guy73b979d2009-06-09 12:57:21 -0700102 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800103 *
104 * @param className the class name of the component representing the intent
105 * @param launchFlags the launch flags
106 */
107 final void setActivity(ComponentName className, int launchFlags) {
108 intent = new Intent(Intent.ACTION_MAIN);
109 intent.addCategory(Intent.CATEGORY_LAUNCHER);
110 intent.setComponent(className);
111 intent.setFlags(launchFlags);
Romain Guy73b979d2009-06-09 12:57:21 -0700112 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
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 Chung64359a52013-07-08 17:17:08 -0700117 return "ApplicationInfo(title=" + title.toString() + " id=" + this.id
118 + " type=" + this.itemType + " container=" + this.container
119 + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
120 + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + dropPos + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400122
Joe Onoratobe386092009-11-17 17:32:16 -0800123 public static void dumpApplicationInfoList(String tag, String label,
124 ArrayList<ApplicationInfo> list) {
125 Log.d(tag, label + " size=" + list.size());
126 for (ApplicationInfo info: list) {
Winson Chungc85ea572011-07-11 16:02:31 -0700127 Log.d(tag, " title=\"" + info.title + "\" iconBitmap="
128 + info.iconBitmap + " firstInstallTime="
Winson Chung78403fe2011-01-21 15:38:02 -0800129 + info.firstInstallTime);
Joe Onoratobe386092009-11-17 17:32:16 -0800130 }
131 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800132
133 public ShortcutInfo makeShortcut() {
Michael Jurkac9d95c52011-08-29 14:03:34 -0700134 return new ShortcutInfo(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800135 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136}