blob: 3adea373e7fc2ec222f4a92be114b5314b7b3fff [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 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040041 * A bitmap of the application's text in the bubble.
42 */
43 Bitmap titleBitmap;
44
45 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046 * The intent used to start the application.
47 */
48 Intent intent;
49
50 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040051 * A bitmap version of the application icon.
52 */
53 Bitmap iconBitmap;
54
Winson Chung78403fe2011-01-21 15:38:02 -080055 /**
56 * The time at which the app was first installed.
57 */
58 long firstInstallTime;
59
Joe Onorato0589f0f2010-02-08 13:44:00 -080060 ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061
Patrick Dubroy3d605d52010-07-29 13:59:29 -070062 static final int APP_FLAG = 1;
63 static final int GAME_FLAG = 2;
64 static final int DOWNLOADED_FLAG = 4;
65 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066
67 ApplicationInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070068 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080070
71 /**
72 * Must not hold the Context.
73 */
Patrick Dubroy3d605d52010-07-29 13:59:29 -070074 public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache) {
75 final String packageName = info.activityInfo.applicationInfo.packageName;
Joe Onorato0589f0f2010-02-08 13:44:00 -080076
Patrick Dubroy3d605d52010-07-29 13:59:29 -070077 this.componentName = new ComponentName(packageName, info.activityInfo.name);
Joe Onorato0589f0f2010-02-08 13:44:00 -080078 this.container = ItemInfo.NO_ID;
79 this.setActivity(componentName,
80 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
81
Patrick Dubroy3d605d52010-07-29 13:59:29 -070082 try {
83 int appFlags = pm.getApplicationInfo(packageName, 0).flags;
84 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
85 flags |= DOWNLOADED_FLAG;
86 }
87 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
88 flags |= DOWNLOADED_FLAG;
89 }
Winson Chung78403fe2011-01-21 15:38:02 -080090 firstInstallTime = pm.getPackageInfo(packageName, 0).firstInstallTime;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070091 // TODO: Figure out how to determine what is a game
92
93 // If it's not a game, it's an app
94 if ((flags & GAME_FLAG) == 0) {
95 flags |= APP_FLAG;
96 }
97 } catch (NameNotFoundException e) {
98 Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName);
99 }
100
Joe Onorato0589f0f2010-02-08 13:44:00 -0800101 iconCache.getTitleAndIcon(this, info);
102 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800103
104 public ApplicationInfo(ApplicationInfo info) {
105 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800106 componentName = info.componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107 title = info.title.toString();
108 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700109 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -0800110 firstInstallTime = info.firstInstallTime;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111 }
112
113 /**
114 * Creates the application intent based on a component name and various launch flags.
Romain Guy73b979d2009-06-09 12:57:21 -0700115 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116 *
117 * @param className the class name of the component representing the intent
118 * @param launchFlags the launch flags
119 */
120 final void setActivity(ComponentName className, int launchFlags) {
121 intent = new Intent(Intent.ACTION_MAIN);
122 intent.addCategory(Intent.CATEGORY_LAUNCHER);
123 intent.setComponent(className);
124 intent.setFlags(launchFlags);
Romain Guy73b979d2009-06-09 12:57:21 -0700125 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800126 }
127
128 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129 public String toString() {
Joe Onoratof984e852010-03-25 09:47:45 -0700130 return "ApplicationInfo(title=" + title.toString() + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400132
Joe Onoratobe386092009-11-17 17:32:16 -0800133 public static void dumpApplicationInfoList(String tag, String label,
134 ArrayList<ApplicationInfo> list) {
135 Log.d(tag, label + " size=" + list.size());
136 for (ApplicationInfo info: list) {
137 Log.d(tag, " title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap
Winson Chung78403fe2011-01-21 15:38:02 -0800138 + " iconBitmap=" + info.iconBitmap + " firstInstallTime="
139 + info.firstInstallTime);
Joe Onoratobe386092009-11-17 17:32:16 -0800140 }
141 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800142
143 public ShortcutInfo makeShortcut() {
144 return new ShortcutInfo(this);
145 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146}