2010-02-08 13:44:00 -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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.ContentValues;
|
2013-07-08 18:03:46 -07:00
|
|
|
import android.content.Context;
|
2010-02-08 13:44:00 -08:00
|
|
|
import android.content.Intent;
|
2013-12-13 16:07:45 +01:00
|
|
|
import android.content.pm.PackageInfo;
|
2013-07-08 18:03:46 -07:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2010-02-08 13:44:00 -08:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
import com.android.launcher3.compat.UserHandleCompat;
|
|
|
|
|
|
2013-07-08 18:03:46 -07:00
|
|
|
import java.util.ArrayList;
|
2014-04-21 19:36:14 -07:00
|
|
|
import java.util.Arrays;
|
2013-07-08 18:03:46 -07:00
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
/**
|
|
|
|
|
* Represents a launchable icon on the workspaces and in folders.
|
|
|
|
|
*/
|
2014-03-04 17:16:11 -08:00
|
|
|
public class ShortcutInfo extends ItemInfo {
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2014-06-24 18:24:23 -04:00
|
|
|
/** {@link #mState} meaning this package is not installed, and there is no other information. */
|
2014-02-14 16:59:24 -05:00
|
|
|
public static final int PACKAGE_STATE_UNKNOWN = -2;
|
|
|
|
|
|
2014-06-24 18:24:23 -04:00
|
|
|
/** {@link #mState} meaning this package is not installed, because installation failed. */
|
2014-02-14 16:59:24 -05:00
|
|
|
public static final int PACKAGE_STATE_ERROR = -1;
|
|
|
|
|
|
2014-06-24 18:24:23 -04:00
|
|
|
/** {@link #mState} meaning this package is installed. This is the typical case. */
|
2014-02-14 16:59:24 -05:00
|
|
|
public static final int PACKAGE_STATE_DEFAULT = 0;
|
|
|
|
|
|
2014-06-24 18:24:23 -04:00
|
|
|
/** {@link #mState} meaning some external entity has promised to install this package. */
|
2014-02-14 16:59:24 -05:00
|
|
|
public static final int PACKAGE_STATE_ENQUEUED = 1;
|
|
|
|
|
|
2014-06-24 18:24:23 -04:00
|
|
|
/** {@link #mState} meaning but some external entity is downloading this package. */
|
2014-02-14 16:59:24 -05:00
|
|
|
public static final int PACKAGE_STATE_DOWNLOADING = 2;
|
|
|
|
|
|
2014-06-24 18:24:23 -04:00
|
|
|
/** {@link #mState} meaning some external entity is installing this package. */
|
2014-02-14 16:59:24 -05:00
|
|
|
public static final int PACKAGE_STATE_INSTALLING = 3;
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
/**
|
|
|
|
|
* The intent used to start the application.
|
|
|
|
|
*/
|
|
|
|
|
Intent intent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates whether the icon comes from an application's resource (if false)
|
|
|
|
|
* or from a custom Bitmap (if true.)
|
|
|
|
|
*/
|
|
|
|
|
boolean customIcon;
|
|
|
|
|
|
2010-03-07 14:32:10 -05:00
|
|
|
/**
|
|
|
|
|
* Indicates whether we're using the default fallback icon instead of something from the
|
|
|
|
|
* app.
|
|
|
|
|
*/
|
|
|
|
|
boolean usingFallbackIcon;
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
/**
|
|
|
|
|
* If isShortcut=true and customIcon=false, this contains a reference to the
|
|
|
|
|
* shortcut icon as an application's resource.
|
|
|
|
|
*/
|
|
|
|
|
Intent.ShortcutIconResource iconResource;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The application icon.
|
|
|
|
|
*/
|
|
|
|
|
private Bitmap mIcon;
|
|
|
|
|
|
2014-06-24 18:24:23 -04:00
|
|
|
/**
|
|
|
|
|
* The installation state of the package that this shortcut represents.
|
|
|
|
|
*/
|
|
|
|
|
protected int mState;
|
|
|
|
|
|
2013-07-08 18:03:46 -07:00
|
|
|
long firstInstallTime;
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
2014-01-27 14:17:08 -05:00
|
|
|
/**
|
|
|
|
|
* If this shortcut is a placeholder, then intent will be a market intent for the package, and
|
|
|
|
|
* this will hold the original intent from the database. Otherwise, null.
|
|
|
|
|
*/
|
|
|
|
|
Intent restoredIntent;
|
|
|
|
|
|
2011-08-29 14:03:34 -07:00
|
|
|
ShortcutInfo() {
|
2010-02-08 13:44:00 -08:00
|
|
|
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
|
|
|
|
|
}
|
2013-07-24 15:33:46 -07:00
|
|
|
|
2014-03-17 09:34:39 -07:00
|
|
|
public Intent getIntent() {
|
2013-07-24 15:33:46 -07:00
|
|
|
return intent;
|
|
|
|
|
}
|
2013-11-19 15:45:07 +00:00
|
|
|
|
2014-01-27 14:17:08 -05:00
|
|
|
protected Intent getRestoredIntent() {
|
|
|
|
|
return restoredIntent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Overwrite placeholder data with restored data, or do nothing if this is not a placeholder.
|
|
|
|
|
*/
|
|
|
|
|
public void restore() {
|
|
|
|
|
if (restoredIntent != null) {
|
|
|
|
|
intent = restoredIntent;
|
|
|
|
|
restoredIntent = null;
|
2014-06-24 18:24:23 -04:00
|
|
|
mState = PACKAGE_STATE_DEFAULT;
|
2014-01-27 14:17:08 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 12:30:31 +01:00
|
|
|
ShortcutInfo(Intent intent, CharSequence title, String contentDescrition,
|
|
|
|
|
Bitmap icon, UserHandleCompat user) {
|
2013-11-19 15:45:07 +00:00
|
|
|
this();
|
|
|
|
|
this.intent = intent;
|
|
|
|
|
this.title = title;
|
2014-06-30 12:30:31 +01:00
|
|
|
this.contentDescription = contentDescription;
|
2013-11-19 15:45:07 +00:00
|
|
|
mIcon = icon;
|
2014-04-30 03:02:21 +01:00
|
|
|
this.user = user;
|
2013-11-19 15:45:07 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-08 18:03:46 -07:00
|
|
|
public ShortcutInfo(Context context, ShortcutInfo info) {
|
2011-08-29 14:03:34 -07:00
|
|
|
super(info);
|
2010-02-08 13:44:00 -08:00
|
|
|
title = info.title.toString();
|
|
|
|
|
intent = new Intent(info.intent);
|
|
|
|
|
if (info.iconResource != null) {
|
|
|
|
|
iconResource = new Intent.ShortcutIconResource();
|
|
|
|
|
iconResource.packageName = info.iconResource.packageName;
|
|
|
|
|
iconResource.resourceName = info.iconResource.resourceName;
|
|
|
|
|
}
|
|
|
|
|
mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all
|
|
|
|
|
customIcon = info.customIcon;
|
2014-04-30 03:02:21 +01:00
|
|
|
flags = info.flags;
|
|
|
|
|
firstInstallTime = info.firstInstallTime;
|
|
|
|
|
user = info.user;
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** TODO: Remove this. It's only called by ApplicationInfo.makeShortcut. */
|
2013-09-04 00:45:37 +02:00
|
|
|
public ShortcutInfo(AppInfo info) {
|
2011-08-29 14:03:34 -07:00
|
|
|
super(info);
|
2010-02-08 13:44:00 -08:00
|
|
|
title = info.title.toString();
|
|
|
|
|
intent = new Intent(info.intent);
|
|
|
|
|
customIcon = false;
|
2013-07-08 18:03:46 -07:00
|
|
|
flags = info.flags;
|
|
|
|
|
firstInstallTime = info.firstInstallTime;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
public void setIcon(Bitmap b) {
|
|
|
|
|
mIcon = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Bitmap getIcon(IconCache iconCache) {
|
|
|
|
|
if (mIcon == null) {
|
2012-03-09 15:59:25 -08:00
|
|
|
updateIcon(iconCache);
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
return mIcon;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-09 15:59:25 -08:00
|
|
|
public void updateIcon(IconCache iconCache) {
|
2014-04-30 03:02:21 +01:00
|
|
|
mIcon = iconCache.getIcon(intent, user);
|
|
|
|
|
usingFallbackIcon = iconCache.isDefaultIcon(mIcon, user);
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-04-30 03:02:21 +01:00
|
|
|
void onAddToDatabase(Context context, ContentValues values) {
|
|
|
|
|
super.onAddToDatabase(context, values);
|
2010-02-08 13:44:00 -08:00
|
|
|
|
|
|
|
|
String titleStr = title != null ? title.toString() : null;
|
|
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr);
|
|
|
|
|
|
|
|
|
|
String uri = intent != null ? intent.toUri(0) : null;
|
|
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri);
|
|
|
|
|
|
|
|
|
|
if (customIcon) {
|
|
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
|
|
|
|
|
LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP);
|
2010-03-07 14:32:10 -05:00
|
|
|
writeBitmap(values, mIcon);
|
2010-02-08 13:44:00 -08:00
|
|
|
} else {
|
2010-08-30 18:30:15 -07:00
|
|
|
if (!usingFallbackIcon) {
|
2010-03-07 14:32:10 -05:00
|
|
|
writeBitmap(values, mIcon);
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
|
|
|
|
|
LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE);
|
|
|
|
|
if (iconResource != null) {
|
|
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
|
|
|
|
|
iconResource.packageName);
|
|
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
|
|
|
|
|
iconResource.resourceName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
2014-04-30 03:02:21 +01:00
|
|
|
return "ShortcutInfo(title=" + title + "intent=" + intent + "id=" + this.id
|
2013-06-18 13:13:40 -07:00
|
|
|
+ " type=" + this.itemType + " container=" + this.container + " screen=" + screenId
|
2012-04-03 14:08:41 -07:00
|
|
|
+ " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX + " spanY=" + spanY
|
2014-04-30 03:02:21 +01:00
|
|
|
+ " dropPos=" + Arrays.toString(dropPos) + " user=" + user + ")";
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void dumpShortcutInfoList(String tag, String label,
|
|
|
|
|
ArrayList<ShortcutInfo> list) {
|
|
|
|
|
Log.d(tag, label + " size=" + list.size());
|
|
|
|
|
for (ShortcutInfo info: list) {
|
|
|
|
|
Log.d(tag, " title=\"" + info.title + " icon=" + info.mIcon
|
|
|
|
|
+ " customIcon=" + info.customIcon);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-14 16:59:24 -05:00
|
|
|
|
|
|
|
|
public boolean isPromise() {
|
|
|
|
|
return restoredIntent != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isPromiseFor(String pkgName) {
|
|
|
|
|
return restoredIntent != null
|
|
|
|
|
&& pkgName != null
|
|
|
|
|
&& pkgName.equals(restoredIntent.getComponent().getPackageName());
|
|
|
|
|
}
|
2014-06-24 18:24:23 -04:00
|
|
|
|
|
|
|
|
public boolean isAbandoned() {
|
|
|
|
|
return isPromise()
|
|
|
|
|
&& (mState == ShortcutInfo.PACKAGE_STATE_ERROR
|
|
|
|
|
|| mState == ShortcutInfo.PACKAGE_STATE_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getState() {
|
|
|
|
|
return mState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setState(int state) {
|
|
|
|
|
mState = state;
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
|