2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-30 13:37:37 -07:00
|
|
|
package com.android.launcher2;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.Intent;
|
2010-07-29 13:59:29 -07:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2011-07-11 17:44:15 -07:00
|
|
|
import android.content.pm.ResolveInfo;
|
2009-03-03 19:32:27 -08:00
|
|
|
import android.graphics.Bitmap;
|
2009-11-17 17:32:16 -08:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
2010-07-29 13:59:29 -07:00
|
|
|
import java.util.ArrayList;
|
2011-07-11 17:44:15 -07:00
|
|
|
import java.util.HashMap;
|
2010-07-29 13:59:29 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
2010-02-08 13:44:00 -08:00
|
|
|
* Represents an app in AllAppsView.
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
|
|
|
|
class ApplicationInfo extends ItemInfo {
|
2010-07-29 13:59:29 -07:00
|
|
|
private static final String TAG = "Launcher2.ApplicationInfo";
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The intent used to start the application.
|
|
|
|
|
*/
|
|
|
|
|
Intent intent;
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* A bitmap version of the application icon.
|
|
|
|
|
*/
|
|
|
|
|
Bitmap iconBitmap;
|
|
|
|
|
|
2011-01-21 15:38:02 -08:00
|
|
|
/**
|
|
|
|
|
* The time at which the app was first installed.
|
|
|
|
|
*/
|
|
|
|
|
long firstInstallTime;
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
ComponentName componentName;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2011-02-28 15:16:42 -08:00
|
|
|
static final int DOWNLOADED_FLAG = 1;
|
|
|
|
|
static final int UPDATED_SYSTEM_APP_FLAG = 2;
|
|
|
|
|
|
2010-07-29 13:59:29 -07:00
|
|
|
int flags = 0;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2011-08-29 14:03:34 -07:00
|
|
|
ApplicationInfo() {
|
2010-02-08 13:44:00 -08:00
|
|
|
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
2010-02-08 13:44:00 -08:00
|
|
|
* Must not hold the Context.
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2011-07-11 17:44:15 -07:00
|
|
|
public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache,
|
2011-08-29 14:03:34 -07:00
|
|
|
HashMap<Object, CharSequence> labelCache) {
|
2010-07-29 13:59:29 -07:00
|
|
|
final String packageName = info.activityInfo.applicationInfo.packageName;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2010-07-29 13:59:29 -07:00
|
|
|
this.componentName = new ComponentName(packageName, info.activityInfo.name);
|
2010-02-08 13:44:00 -08:00
|
|
|
this.container = ItemInfo.NO_ID;
|
|
|
|
|
this.setActivity(componentName,
|
|
|
|
|
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
|
|
|
|
|
2010-07-29 13:59:29 -07:00
|
|
|
try {
|
|
|
|
|
int appFlags = pm.getApplicationInfo(packageName, 0).flags;
|
|
|
|
|
if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
|
|
|
|
|
flags |= DOWNLOADED_FLAG;
|
|
|
|
|
|
2011-02-28 15:16:42 -08:00
|
|
|
if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
|
|
|
|
|
flags |= UPDATED_SYSTEM_APP_FLAG;
|
|
|
|
|
}
|
2010-07-29 13:59:29 -07:00
|
|
|
}
|
2011-02-28 15:16:42 -08:00
|
|
|
firstInstallTime = pm.getPackageInfo(packageName, 0).firstInstallTime;
|
2010-07-29 13:59:29 -07:00
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
|
Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-11 17:44:15 -07:00
|
|
|
iconCache.getTitleAndIcon(this, info, labelCache);
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2011-07-11 17:44:15 -07:00
|
|
|
|
2011-08-29 14:03:34 -07:00
|
|
|
public ApplicationInfo(ApplicationInfo info) {
|
|
|
|
|
super(info);
|
2010-02-08 13:44:00 -08:00
|
|
|
componentName = info.componentName;
|
2009-03-03 19:32:27 -08:00
|
|
|
title = info.title.toString();
|
|
|
|
|
intent = new Intent(info.intent);
|
2010-09-08 16:01:19 -07:00
|
|
|
flags = info.flags;
|
2011-01-21 15:38:02 -08:00
|
|
|
firstInstallTime = info.firstInstallTime;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 10:34:12 -07:00
|
|
|
/** Returns the package name that the shortcut's intent will resolve to, or an empty string if
|
|
|
|
|
* none exists. */
|
|
|
|
|
String getPackageName() {
|
|
|
|
|
return super.getPackageName(intent);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* Creates the application intent based on a component name and various launch flags.
|
2009-06-09 12:57:21 -07:00
|
|
|
* Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
|
2009-03-03 19:32:27 -08:00
|
|
|
*
|
|
|
|
|
* @param className the class name of the component representing the intent
|
|
|
|
|
* @param launchFlags the launch flags
|
|
|
|
|
*/
|
|
|
|
|
final void setActivity(ComponentName className, int launchFlags) {
|
|
|
|
|
intent = new Intent(Intent.ACTION_MAIN);
|
|
|
|
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
|
|
intent.setComponent(className);
|
|
|
|
|
intent.setFlags(launchFlags);
|
2009-06-09 12:57:21 -07:00
|
|
|
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
2010-03-25 09:47:45 -07:00
|
|
|
return "ApplicationInfo(title=" + title.toString() + ")";
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2009-11-17 17:32:16 -08:00
|
|
|
public static void dumpApplicationInfoList(String tag, String label,
|
|
|
|
|
ArrayList<ApplicationInfo> list) {
|
|
|
|
|
Log.d(tag, label + " size=" + list.size());
|
|
|
|
|
for (ApplicationInfo info: list) {
|
2011-07-11 16:02:31 -07:00
|
|
|
Log.d(tag, " title=\"" + info.title + "\" iconBitmap="
|
|
|
|
|
+ info.iconBitmap + " firstInstallTime="
|
2011-01-21 15:38:02 -08:00
|
|
|
+ info.firstInstallTime);
|
2009-11-17 17:32:16 -08:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
|
|
|
|
|
public ShortcutInfo makeShortcut() {
|
2011-08-29 14:03:34 -07:00
|
|
|
return new ShortcutInfo(this);
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|