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
|
|
|
|
2016-05-19 11:19:39 -07:00
|
|
|
import android.annotation.TargetApi;
|
2013-07-08 18:03:46 -07:00
|
|
|
import android.content.Context;
|
2010-02-08 13:44:00 -08:00
|
|
|
import android.content.Intent;
|
2016-05-19 11:19:39 -07:00
|
|
|
import android.os.Build;
|
|
|
|
|
import android.text.TextUtils;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2015-02-18 16:46:50 -08:00
|
|
|
import com.android.launcher3.LauncherSettings.Favorites;
|
2015-04-08 18:13:46 -07:00
|
|
|
import com.android.launcher3.compat.UserManagerCompat;
|
2016-05-19 11:19:39 -07:00
|
|
|
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
|
2016-11-11 11:45:00 -08:00
|
|
|
import com.android.launcher3.util.ContentWriter;
|
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.
|
|
|
|
|
*/
|
2016-12-15 17:40:07 -08:00
|
|
|
public class ShortcutInfo extends ItemInfoWithIcon {
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
public static final int DEFAULT = 0;
|
2014-02-14 16:59:24 -05:00
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
/**
|
|
|
|
|
* The shortcut was restored from a backup and it not ready to be used. This is automatically
|
|
|
|
|
* set during backup/restore
|
|
|
|
|
*/
|
|
|
|
|
public static final int FLAG_RESTORED_ICON = 1;
|
2014-02-14 16:59:24 -05:00
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
/**
|
|
|
|
|
* The icon was added as an auto-install app, and is not ready to be used. This flag can't
|
|
|
|
|
* be present along with {@link #FLAG_RESTORED_ICON}, and is set during default layout
|
|
|
|
|
* parsing.
|
|
|
|
|
*/
|
2017-03-28 12:23:22 -07:00
|
|
|
public static final int FLAG_AUTOINSTALL_ICON = 2; //0B10;
|
2014-02-14 16:59:24 -05:00
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
/**
|
2017-03-28 12:23:22 -07:00
|
|
|
* The icon is being installed. If {@link #FLAG_RESTORED_ICON} or {@link #FLAG_AUTOINSTALL_ICON}
|
2014-08-29 17:20:55 -07:00
|
|
|
* is set, then the icon is either being installed or is in a broken state.
|
|
|
|
|
*/
|
2015-01-15 12:00:14 -08:00
|
|
|
public static final int FLAG_INSTALL_SESSION_ACTIVE = 4; // 0B100;
|
2014-02-14 16:59:24 -05:00
|
|
|
|
2014-09-18 16:13:58 -07:00
|
|
|
/**
|
|
|
|
|
* Indicates that the widget restore has started.
|
|
|
|
|
*/
|
2015-01-15 12:00:14 -08:00
|
|
|
public static final int FLAG_RESTORE_STARTED = 8; //0B1000;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates if it represents a common type mentioned in {@link CommonAppTypeParser}.
|
|
|
|
|
* Upto 15 different types supported.
|
|
|
|
|
*/
|
2017-01-05 14:03:59 -08:00
|
|
|
@Deprecated
|
2015-01-15 12:00:14 -08:00
|
|
|
public static final int FLAG_RESTORED_APP_TYPE = 0B0011110000;
|
2014-09-18 16:13:58 -07:00
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
/**
|
|
|
|
|
* The intent used to start the application.
|
|
|
|
|
*/
|
2015-08-19 17:55:02 -07:00
|
|
|
public Intent intent;
|
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.
|
|
|
|
|
*/
|
2015-06-25 16:37:44 -07:00
|
|
|
public Intent.ShortcutIconResource iconResource;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2014-10-02 15:58:31 -07:00
|
|
|
/**
|
|
|
|
|
* Indicates that the icon is disabled due to safe mode restrictions.
|
|
|
|
|
*/
|
2016-07-28 10:07:32 -07:00
|
|
|
public static final int FLAG_DISABLED_SAFEMODE = 1 << 0;
|
2014-10-02 15:58:31 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates that the icon is disabled as the app is not available.
|
|
|
|
|
*/
|
2016-07-28 10:07:32 -07:00
|
|
|
public static final int FLAG_DISABLED_NOT_AVAILABLE = 1 << 1;
|
2014-10-02 15:58:31 -07:00
|
|
|
|
2016-01-21 19:50:02 +00:00
|
|
|
/**
|
|
|
|
|
* Indicates that the icon is disabled as the app is suspended
|
|
|
|
|
*/
|
2016-07-28 10:07:32 -07:00
|
|
|
public static final int FLAG_DISABLED_SUSPENDED = 1 << 2;
|
2016-01-21 19:50:02 +00:00
|
|
|
|
2016-01-22 17:48:29 +00:00
|
|
|
/**
|
|
|
|
|
* Indicates that the icon is disabled as the user is in quiet mode.
|
|
|
|
|
*/
|
2016-07-28 10:07:32 -07:00
|
|
|
public static final int FLAG_DISABLED_QUIET_USER = 1 << 3;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates that the icon is disabled as the publisher has disabled the actual shortcut.
|
|
|
|
|
*/
|
|
|
|
|
public static final int FLAG_DISABLED_BY_PUBLISHER = 1 << 4;
|
2016-01-22 17:48:29 +00:00
|
|
|
|
2016-07-28 12:11:54 -07:00
|
|
|
/**
|
|
|
|
|
* Indicates that the icon is disabled as the user partition is currently locked.
|
|
|
|
|
*/
|
|
|
|
|
public static final int FLAG_DISABLED_LOCKED_USER = 1 << 5;
|
|
|
|
|
|
2014-07-14 12:02:01 -07:00
|
|
|
/**
|
|
|
|
|
* Could be disabled, if the the app is installed but unavailable (eg. in safe mode or when
|
|
|
|
|
* sd-card is not available).
|
|
|
|
|
*/
|
2016-09-09 15:47:55 -07:00
|
|
|
public int isDisabled = DEFAULT;
|
2014-07-14 12:02:01 -07:00
|
|
|
|
2016-08-04 16:34:49 -07:00
|
|
|
/**
|
|
|
|
|
* A message to display when the user tries to start a disabled shortcut.
|
|
|
|
|
* This is currently only used for deep shortcuts.
|
|
|
|
|
*/
|
|
|
|
|
CharSequence disabledMessage;
|
|
|
|
|
|
2016-09-09 15:47:55 -07:00
|
|
|
public int status;
|
2014-06-24 18:24:23 -04:00
|
|
|
|
2014-07-22 13:48:29 -07:00
|
|
|
/**
|
|
|
|
|
* The installation progress [0-100] of the package that this shortcut represents.
|
|
|
|
|
*/
|
2014-08-29 17:20:55 -07:00
|
|
|
private int mInstallProgress;
|
2014-07-22 13:48:29 -07:00
|
|
|
|
2016-09-12 14:36:30 -07:00
|
|
|
public ShortcutInfo() {
|
2010-02-08 13:44:00 -08:00
|
|
|
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
|
|
|
|
|
}
|
2013-07-24 15:33:46 -07:00
|
|
|
|
2016-07-20 15:42:44 -07:00
|
|
|
public ShortcutInfo(ShortcutInfo info) {
|
2011-08-29 14:03:34 -07:00
|
|
|
super(info);
|
2016-07-20 15:42:44 -07:00
|
|
|
title = info.title;
|
2010-02-08 13:44:00 -08:00
|
|
|
intent = new Intent(info.intent);
|
2016-07-20 15:42:44 -07:00
|
|
|
iconResource = info.iconResource;
|
2014-08-29 17:20:55 -07:00
|
|
|
status = info.status;
|
2016-07-20 15:42:44 -07:00
|
|
|
mInstallProgress = info.mInstallProgress;
|
|
|
|
|
isDisabled = info.isDisabled;
|
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);
|
2015-05-08 17:00:10 -07:00
|
|
|
title = Utilities.trim(info.title);
|
2010-02-08 13:44:00 -08:00
|
|
|
intent = new Intent(info.intent);
|
2016-01-21 19:50:02 +00:00
|
|
|
isDisabled = info.isDisabled;
|
2016-07-20 15:42:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a {@link ShortcutInfo} from a {@link ShortcutInfoCompat}.
|
|
|
|
|
*/
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.N)
|
|
|
|
|
public ShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
|
|
|
|
|
user = shortcutInfo.getUserHandle();
|
|
|
|
|
itemType = LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
|
|
|
|
|
updateFromDeepShortcutInfo(shortcutInfo, context);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
@Override
|
2017-01-21 01:33:02 -08:00
|
|
|
public void onAddToDatabase(ContentWriter writer) {
|
2016-11-11 11:45:00 -08:00
|
|
|
super.onAddToDatabase(writer);
|
|
|
|
|
writer.put(LauncherSettings.BaseLauncherColumns.TITLE, title)
|
2016-12-15 17:40:07 -08:00
|
|
|
.put(LauncherSettings.BaseLauncherColumns.INTENT, getIntent())
|
2016-11-11 11:45:00 -08:00
|
|
|
.put(LauncherSettings.Favorites.RESTORED, status);
|
|
|
|
|
|
|
|
|
|
if (!usingLowResIcon) {
|
2016-11-09 10:43:58 -08:00
|
|
|
writer.putIcon(iconBitmap, user);
|
2016-04-21 14:30:18 -07:00
|
|
|
}
|
|
|
|
|
if (iconResource != null) {
|
2016-11-11 11:45:00 -08:00
|
|
|
writer.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE, iconResource.packageName)
|
|
|
|
|
.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
|
|
|
|
|
iconResource.resourceName);
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 17:40:07 -08:00
|
|
|
@Override
|
|
|
|
|
public Intent getIntent() {
|
2017-01-12 16:55:36 -08:00
|
|
|
return intent;
|
2014-02-14 16:59:24 -05:00
|
|
|
}
|
|
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
public boolean hasStatusFlag(int flag) {
|
|
|
|
|
return (status & flag) != 0;
|
2014-02-14 16:59:24 -05:00
|
|
|
}
|
2014-06-24 18:24:23 -04:00
|
|
|
|
2014-07-22 13:48:29 -07:00
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
public final boolean isPromise() {
|
2017-03-28 12:23:22 -07:00
|
|
|
return hasStatusFlag(FLAG_RESTORED_ICON | FLAG_AUTOINSTALL_ICON);
|
2014-06-24 18:24:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
public int getInstallProgress() {
|
|
|
|
|
return mInstallProgress;
|
2014-06-24 18:24:23 -04:00
|
|
|
}
|
2014-07-22 13:48:29 -07:00
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
public void setInstallProgress(int progress) {
|
|
|
|
|
mInstallProgress = progress;
|
|
|
|
|
status |= FLAG_INSTALL_SESSION_ACTIVE;
|
2014-07-22 13:48:29 -07:00
|
|
|
}
|
2015-03-11 16:56:52 -07:00
|
|
|
|
2016-06-23 14:17:24 -07:00
|
|
|
public void updateFromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
|
2016-07-28 12:11:54 -07:00
|
|
|
// {@link ShortcutInfoCompat#getActivity} can change during an update. Recreate the intent
|
2017-03-21 15:12:01 -07:00
|
|
|
intent = shortcutInfo.makeIntent();
|
2016-05-19 11:19:39 -07:00
|
|
|
title = shortcutInfo.getShortLabel();
|
|
|
|
|
|
|
|
|
|
CharSequence label = shortcutInfo.getLongLabel();
|
|
|
|
|
if (TextUtils.isEmpty(label)) {
|
|
|
|
|
label = shortcutInfo.getShortLabel();
|
|
|
|
|
}
|
2016-07-12 18:02:37 -07:00
|
|
|
contentDescription = UserManagerCompat.getInstance(context)
|
2016-05-19 11:19:39 -07:00
|
|
|
.getBadgedLabelForUser(label, user);
|
2016-07-28 10:07:32 -07:00
|
|
|
if (shortcutInfo.isEnabled()) {
|
|
|
|
|
isDisabled &= ~FLAG_DISABLED_BY_PUBLISHER;
|
|
|
|
|
} else {
|
|
|
|
|
isDisabled |= FLAG_DISABLED_BY_PUBLISHER;
|
|
|
|
|
}
|
2016-08-04 16:34:49 -07:00
|
|
|
disabledMessage = shortcutInfo.getDisabledMessage();
|
2016-07-20 15:42:44 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-19 11:19:39 -07:00
|
|
|
/** Returns the ShortcutInfo id associated with the deep shortcut. */
|
|
|
|
|
public String getDeepShortcutId() {
|
|
|
|
|
return itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT ?
|
2016-12-15 17:40:07 -08:00
|
|
|
getIntent().getStringExtra(ShortcutInfoCompat.EXTRA_SHORTCUT_ID) : null;
|
2016-05-19 11:19:39 -07:00
|
|
|
}
|
|
|
|
|
|
2016-01-21 19:50:02 +00:00
|
|
|
@Override
|
|
|
|
|
public boolean isDisabled() {
|
|
|
|
|
return isDisabled != 0;
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|