blob: bbca664455aefd9c900707647536cdc1438be273 [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;
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 /**
37 * The application name.
38 */
39 CharSequence title;
40
41 /**
42 * The intent used to start the application.
43 */
44 Intent intent;
45
46 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040047 * A bitmap version of the application icon.
48 */
49 Bitmap iconBitmap;
50
Winson Chung78403fe2011-01-21 15:38:02 -080051 /**
52 * The time at which the app was first installed.
53 */
54 long firstInstallTime;
55
Joe Onorato0589f0f2010-02-08 13:44:00 -080056 ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057
Patrick Dubroycd953712011-02-28 15:16:42 -080058 static final int DOWNLOADED_FLAG = 1;
59 static final int UPDATED_SYSTEM_APP_FLAG = 2;
60
Patrick Dubroy3d605d52010-07-29 13:59:29 -070061 int flags = 0;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062
Michael Jurkab60fd0e2011-08-29 14:02:47 -070063 ApplicationInfo(String whereCreated) {
64 super(whereCreated);
Romain Guy73b979d2009-06-09 12:57:21 -070065 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080067
68 /**
69 * Must not hold the Context.
70 */
Winson Chungc3eecff2011-07-11 17:44:15 -070071 public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache,
Michael Jurkab60fd0e2011-08-29 14:02:47 -070072 HashMap<Object, CharSequence> labelCache, String whereCreated) {
73 super(whereCreated);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070074 final String packageName = info.activityInfo.applicationInfo.packageName;
Joe Onorato0589f0f2010-02-08 13:44:00 -080075
Patrick Dubroy3d605d52010-07-29 13:59:29 -070076 this.componentName = new ComponentName(packageName, info.activityInfo.name);
Joe Onorato0589f0f2010-02-08 13:44:00 -080077 this.container = ItemInfo.NO_ID;
78 this.setActivity(componentName,
79 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
80
Patrick Dubroy3d605d52010-07-29 13:59:29 -070081 try {
82 int appFlags = pm.getApplicationInfo(packageName, 0).flags;
83 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
84 flags |= DOWNLOADED_FLAG;
Patrick Dubroycd953712011-02-28 15:16:42 -080085
86 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
87 flags |= UPDATED_SYSTEM_APP_FLAG;
88 }
Patrick Dubroy3d605d52010-07-29 13:59:29 -070089 }
Winson Chung78403fe2011-01-21 15:38:02 -080090 firstInstallTime = pm.getPackageInfo(packageName, 0).firstInstallTime;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070091 } catch (NameNotFoundException e) {
92 Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName);
93 }
94
Winson Chungc3eecff2011-07-11 17:44:15 -070095 iconCache.getTitleAndIcon(this, info, labelCache);
Joe Onorato0589f0f2010-02-08 13:44:00 -080096 }
Winson Chungc3eecff2011-07-11 17:44:15 -070097
Michael Jurkab60fd0e2011-08-29 14:02:47 -070098 public ApplicationInfo(ApplicationInfo info, String whereCreated) {
99 super(info, whereCreated);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800100 componentName = info.componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800101 title = info.title.toString();
102 intent = new Intent(info.intent);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700103 flags = info.flags;
Winson Chung78403fe2011-01-21 15:38:02 -0800104 firstInstallTime = info.firstInstallTime;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800105 }
106
107 /**
108 * Creates the application intent based on a component name and various launch flags.
Romain Guy73b979d2009-06-09 12:57:21 -0700109 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800110 *
111 * @param className the class name of the component representing the intent
112 * @param launchFlags the launch flags
113 */
114 final void setActivity(ComponentName className, int launchFlags) {
115 intent = new Intent(Intent.ACTION_MAIN);
116 intent.addCategory(Intent.CATEGORY_LAUNCHER);
117 intent.setComponent(className);
118 intent.setFlags(launchFlags);
Romain Guy73b979d2009-06-09 12:57:21 -0700119 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120 }
121
122 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123 public String toString() {
Joe Onoratof984e852010-03-25 09:47:45 -0700124 return "ApplicationInfo(title=" + title.toString() + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400126
Joe Onoratobe386092009-11-17 17:32:16 -0800127 public static void dumpApplicationInfoList(String tag, String label,
128 ArrayList<ApplicationInfo> list) {
129 Log.d(tag, label + " size=" + list.size());
130 for (ApplicationInfo info: list) {
Winson Chungc85ea572011-07-11 16:02:31 -0700131 Log.d(tag, " title=\"" + info.title + "\" iconBitmap="
132 + info.iconBitmap + " firstInstallTime="
Winson Chung78403fe2011-01-21 15:38:02 -0800133 + info.firstInstallTime);
Joe Onoratobe386092009-11-17 17:32:16 -0800134 }
135 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800136
137 public ShortcutInfo makeShortcut() {
Michael Jurkab60fd0e2011-08-29 14:02:47 -0700138 return new ShortcutInfo(this, "18");
Joe Onorato0589f0f2010-02-08 13:44:00 -0800139 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140}