blob: ac571eaba5d945a54485be6022a87bd1f51167cf [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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
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;
Joe Onorato0589f0f2010-02-08 13:44:00 -080022import android.content.pm.ResolveInfo;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070023import android.content.pm.PackageManager.NameNotFoundException;
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;
28
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029/**
Joe Onorato0589f0f2010-02-08 13:44:00 -080030 * Represents an app in AllAppsView.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031 */
32class ApplicationInfo extends ItemInfo {
Patrick Dubroy3d605d52010-07-29 13:59:29 -070033 private static final String TAG = "Launcher2.ApplicationInfo";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034
35 /**
36 * The application name.
37 */
38 CharSequence title;
39
40 /**
41 * The intent used to start the application.
42 */
43 Intent intent;
44
45 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040046 * A bitmap version of the application icon.
47 */
48 Bitmap iconBitmap;
49
Winson Chung78403fe2011-01-21 15:38:02 -080050 /**
51 * The time at which the app was first installed.
52 */
53 long firstInstallTime;
54
Joe Onorato0589f0f2010-02-08 13:44:00 -080055 ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056
Patrick Dubroycd953712011-02-28 15:16:42 -080057 static final int DOWNLOADED_FLAG = 1;
58 static final int UPDATED_SYSTEM_APP_FLAG = 2;
59
Patrick Dubroy3d605d52010-07-29 13:59:29 -070060 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061
62 ApplicationInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070063 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080065
66 /**
67 * Must not hold the Context.
68 */
Patrick Dubroy3d605d52010-07-29 13:59:29 -070069 public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache) {
70 final String packageName = info.activityInfo.applicationInfo.packageName;
Joe Onorato0589f0f2010-02-08 13:44:00 -080071
Patrick Dubroy3d605d52010-07-29 13:59:29 -070072 this.componentName = new ComponentName(packageName, info.activityInfo.name);
Joe Onorato0589f0f2010-02-08 13:44:00 -080073 this.container = ItemInfo.NO_ID;
74 this.setActivity(componentName,
75 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
76
Patrick Dubroy3d605d52010-07-29 13:59:29 -070077 try {
78 int appFlags = pm.getApplicationInfo(packageName, 0).flags;
79 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
80 flags |= DOWNLOADED_FLAG;
Patrick Dubroycd953712011-02-28 15:16:42 -080081
82 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
83 flags |= UPDATED_SYSTEM_APP_FLAG;
84 }
Patrick Dubroy3d605d52010-07-29 13:59:29 -070085 }
Winson Chung78403fe2011-01-21 15:38:02 -080086 firstInstallTime = pm.getPackageInfo(packageName, 0).firstInstallTime;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070087 } catch (NameNotFoundException e) {
88 Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName);
89 }
90
Joe Onorato0589f0f2010-02-08 13:44:00 -080091 iconCache.getTitleAndIcon(this, info);
92 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093
94 public ApplicationInfo(ApplicationInfo info) {
95 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -080096 componentName = info.componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097 title = info.title.toString();
98 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -070099 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -0800100 firstInstallTime = info.firstInstallTime;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800101 }
102
103 /**
104 * Creates the application intent based on a component name and various launch flags.
Romain Guy73b979d2009-06-09 12:57:21 -0700105 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106 *
107 * @param className the class name of the component representing the intent
108 * @param launchFlags the launch flags
109 */
110 final void setActivity(ComponentName className, int launchFlags) {
111 intent = new Intent(Intent.ACTION_MAIN);
112 intent.addCategory(Intent.CATEGORY_LAUNCHER);
113 intent.setComponent(className);
114 intent.setFlags(launchFlags);
Romain Guy73b979d2009-06-09 12:57:21 -0700115 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116 }
117
118 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119 public String toString() {
Joe Onoratof984e852010-03-25 09:47:45 -0700120 return "ApplicationInfo(title=" + title.toString() + ")";
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() {
134 return new ShortcutInfo(this);
135 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136}