Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | package android.content.pm; |
| 17 | |
| 18 | import android.annotation.IntDef; |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 21 | import android.annotation.TestApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 22 | import android.annotation.UnsupportedAppUsage; |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 23 | import android.annotation.UserIdInt; |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 24 | import android.app.Person; |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 25 | import android.app.TaskStackBuilder; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 26 | import android.content.ComponentName; |
| 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 29 | import android.content.pm.LauncherApps.ShortcutQuery; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 30 | import android.content.res.Resources; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 31 | import android.content.res.Resources.NotFoundException; |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 32 | import android.graphics.Bitmap; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 33 | import android.graphics.drawable.Icon; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 34 | import android.os.Build; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 35 | import android.os.Bundle; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.Parcelable; |
| 38 | import android.os.PersistableBundle; |
| 39 | import android.os.UserHandle; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 40 | import android.text.TextUtils; |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 41 | import android.util.ArraySet; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 42 | import android.util.Log; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 43 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 44 | import com.android.internal.annotations.VisibleForTesting; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 45 | import com.android.internal.util.Preconditions; |
| 46 | |
| 47 | import java.lang.annotation.Retention; |
| 48 | import java.lang.annotation.RetentionPolicy; |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 49 | import java.util.List; |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 50 | import java.util.Set; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 53 | * Represents a shortcut that can be published via {@link ShortcutManager}. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 54 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 55 | * @see ShortcutManager |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 56 | */ |
Jeff Sharkey | 70168dd | 2016-03-30 21:47:16 -0600 | [diff] [blame] | 57 | public final class ShortcutInfo implements Parcelable { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 58 | static final String TAG = "Shortcut"; |
| 59 | |
| 60 | private static final String RES_TYPE_STRING = "string"; |
| 61 | |
| 62 | private static final String ANDROID_PACKAGE_NAME = "android"; |
| 63 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 64 | private static final int IMPLICIT_RANK_MASK = 0x7fffffff; |
| 65 | |
| 66 | private static final int RANK_CHANGED_BIT = ~IMPLICIT_RANK_MASK; |
| 67 | |
| 68 | /** @hide */ |
| 69 | public static final int RANK_NOT_SET = Integer.MAX_VALUE; |
| 70 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 71 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 72 | public static final int FLAG_DYNAMIC = 1 << 0; |
| 73 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 74 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 75 | public static final int FLAG_PINNED = 1 << 1; |
| 76 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 77 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 78 | public static final int FLAG_HAS_ICON_RES = 1 << 2; |
| 79 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 80 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 81 | public static final int FLAG_HAS_ICON_FILE = 1 << 3; |
| 82 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 83 | /** @hide */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 84 | public static final int FLAG_KEY_FIELDS_ONLY = 1 << 4; |
| 85 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 86 | /** @hide */ |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 87 | public static final int FLAG_MANIFEST = 1 << 5; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 88 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 89 | /** @hide */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 90 | public static final int FLAG_DISABLED = 1 << 6; |
| 91 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 92 | /** @hide */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 93 | public static final int FLAG_STRINGS_RESOLVED = 1 << 7; |
| 94 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 95 | /** @hide */ |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 96 | public static final int FLAG_IMMUTABLE = 1 << 8; |
| 97 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 98 | /** @hide */ |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 99 | public static final int FLAG_ADAPTIVE_BITMAP = 1 << 9; |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 100 | |
| 101 | /** @hide */ |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 102 | public static final int FLAG_RETURNED_BY_SERVICE = 1 << 10; |
| 103 | |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 104 | /** @hide When this is set, the bitmap icon is waiting to be saved. */ |
| 105 | public static final int FLAG_ICON_FILE_PENDING_SAVE = 1 << 11; |
| 106 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 107 | /** |
| 108 | * "Shadow" shortcuts are the ones that are restored, but the owner package hasn't been |
| 109 | * installed yet. |
| 110 | * @hide |
| 111 | */ |
| 112 | public static final int FLAG_SHADOW = 1 << 12; |
| 113 | |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 114 | /** @hide */ |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 115 | public static final int FLAG_LONG_LIVED = 1 << 13; |
| 116 | |
| 117 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 118 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 119 | FLAG_DYNAMIC, |
| 120 | FLAG_PINNED, |
| 121 | FLAG_HAS_ICON_RES, |
| 122 | FLAG_HAS_ICON_FILE, |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 123 | FLAG_KEY_FIELDS_ONLY, |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 124 | FLAG_MANIFEST, |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 125 | FLAG_DISABLED, |
| 126 | FLAG_STRINGS_RESOLVED, |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 127 | FLAG_IMMUTABLE, |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 128 | FLAG_ADAPTIVE_BITMAP, |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 129 | FLAG_RETURNED_BY_SERVICE, |
| 130 | FLAG_ICON_FILE_PENDING_SAVE, |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 131 | FLAG_SHADOW, |
| 132 | FLAG_LONG_LIVED, |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 133 | }) |
| 134 | @Retention(RetentionPolicy.SOURCE) |
| 135 | public @interface ShortcutFlags {} |
| 136 | |
| 137 | // Cloning options. |
| 138 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 139 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 140 | private static final int CLONE_REMOVE_ICON = 1 << 0; |
| 141 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 142 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 143 | private static final int CLONE_REMOVE_INTENT = 1 << 1; |
| 144 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 145 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 146 | public static final int CLONE_REMOVE_NON_KEY_INFO = 1 << 2; |
| 147 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 148 | /** @hide */ |
| 149 | public static final int CLONE_REMOVE_RES_NAMES = 1 << 3; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 150 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 151 | /** @hide */ |
| 152 | public static final int CLONE_REMOVE_FOR_CREATOR = CLONE_REMOVE_ICON | CLONE_REMOVE_RES_NAMES; |
| 153 | |
| 154 | /** @hide */ |
| 155 | public static final int CLONE_REMOVE_FOR_LAUNCHER = CLONE_REMOVE_ICON | CLONE_REMOVE_INTENT |
| 156 | | CLONE_REMOVE_RES_NAMES; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 157 | |
| 158 | /** @hide */ |
Makoto Onuki | a01f4f0 | 2016-12-15 15:58:41 -0800 | [diff] [blame] | 159 | public static final int CLONE_REMOVE_FOR_LAUNCHER_APPROVAL = CLONE_REMOVE_INTENT |
| 160 | | CLONE_REMOVE_RES_NAMES; |
| 161 | |
| 162 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 163 | @IntDef(flag = true, prefix = { "CLONE_" }, value = { |
| 164 | CLONE_REMOVE_ICON, |
| 165 | CLONE_REMOVE_INTENT, |
| 166 | CLONE_REMOVE_NON_KEY_INFO, |
| 167 | CLONE_REMOVE_RES_NAMES, |
| 168 | CLONE_REMOVE_FOR_CREATOR, |
| 169 | CLONE_REMOVE_FOR_LAUNCHER |
| 170 | }) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 171 | @Retention(RetentionPolicy.SOURCE) |
| 172 | public @interface CloneFlags {} |
| 173 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 174 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 175 | * Shortcut is not disabled. |
| 176 | */ |
| 177 | public static final int DISABLED_REASON_NOT_DISABLED = 0; |
| 178 | |
| 179 | /** |
| 180 | * Shortcut has been disabled by the publisher app with the |
| 181 | * {@link ShortcutManager#disableShortcuts(List)} API. |
| 182 | */ |
| 183 | public static final int DISABLED_REASON_BY_APP = 1; |
| 184 | |
| 185 | /** |
| 186 | * Shortcut has been disabled due to changes to the publisher app. (e.g. a manifest shortcut |
| 187 | * no longer exists.) |
| 188 | */ |
| 189 | public static final int DISABLED_REASON_APP_CHANGED = 2; |
| 190 | |
| 191 | /** |
Makoto Onuki | 5482a8e6 | 2018-01-09 10:31:08 -0800 | [diff] [blame] | 192 | * Shortcut is disabled for an unknown reason. |
| 193 | */ |
| 194 | public static final int DISABLED_REASON_UNKNOWN = 3; |
| 195 | |
| 196 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 197 | * A disabled reason that's equal to or bigger than this is due to backup and restore issue. |
| 198 | * A shortcut with such a reason wil be visible to the launcher, but not to the publisher. |
| 199 | * ({@link #isVisibleToPublisher()} will be false.) |
| 200 | */ |
| 201 | private static final int DISABLED_REASON_RESTORE_ISSUE_START = 100; |
| 202 | |
| 203 | /** |
| 204 | * Shortcut has been restored from the previous device, but the publisher app on the current |
| 205 | * device is of a lower version. The shortcut will not be usable until the app is upgraded to |
| 206 | * the same version or higher. |
| 207 | */ |
| 208 | public static final int DISABLED_REASON_VERSION_LOWER = 100; |
| 209 | |
| 210 | /** |
| 211 | * Shortcut has not been restored because the publisher app does not support backup and restore. |
| 212 | */ |
| 213 | public static final int DISABLED_REASON_BACKUP_NOT_SUPPORTED = 101; |
| 214 | |
| 215 | /** |
| 216 | * Shortcut has not been restored because the publisher app's signature has changed. |
| 217 | */ |
| 218 | public static final int DISABLED_REASON_SIGNATURE_MISMATCH = 102; |
| 219 | |
| 220 | /** |
| 221 | * Shortcut has not been restored for unknown reason. |
| 222 | */ |
| 223 | public static final int DISABLED_REASON_OTHER_RESTORE_ISSUE = 103; |
| 224 | |
| 225 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 226 | @IntDef(prefix = { "DISABLED_REASON_" }, value = { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 227 | DISABLED_REASON_NOT_DISABLED, |
| 228 | DISABLED_REASON_BY_APP, |
| 229 | DISABLED_REASON_APP_CHANGED, |
Makoto Onuki | 5482a8e6 | 2018-01-09 10:31:08 -0800 | [diff] [blame] | 230 | DISABLED_REASON_UNKNOWN, |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 231 | DISABLED_REASON_VERSION_LOWER, |
| 232 | DISABLED_REASON_BACKUP_NOT_SUPPORTED, |
| 233 | DISABLED_REASON_SIGNATURE_MISMATCH, |
| 234 | DISABLED_REASON_OTHER_RESTORE_ISSUE, |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 235 | }) |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 236 | @Retention(RetentionPolicy.SOURCE) |
| 237 | public @interface DisabledReason{} |
| 238 | |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 239 | /** |
| 240 | * Return a label for disabled reasons, which are *not* supposed to be shown to the user. |
| 241 | * @hide |
| 242 | */ |
| 243 | public static String getDisabledReasonDebugString(@DisabledReason int disabledReason) { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 244 | switch (disabledReason) { |
| 245 | case DISABLED_REASON_NOT_DISABLED: |
| 246 | return "[Not disabled]"; |
| 247 | case DISABLED_REASON_BY_APP: |
| 248 | return "[Disabled: by app]"; |
| 249 | case DISABLED_REASON_APP_CHANGED: |
| 250 | return "[Disabled: app changed]"; |
| 251 | case DISABLED_REASON_VERSION_LOWER: |
| 252 | return "[Disabled: lower version]"; |
| 253 | case DISABLED_REASON_BACKUP_NOT_SUPPORTED: |
| 254 | return "[Disabled: backup not supported]"; |
| 255 | case DISABLED_REASON_SIGNATURE_MISMATCH: |
| 256 | return "[Disabled: signature mismatch]"; |
| 257 | case DISABLED_REASON_OTHER_RESTORE_ISSUE: |
| 258 | return "[Disabled: unknown restore issue]"; |
| 259 | } |
| 260 | return "[Disabled: unknown reason:" + disabledReason + "]"; |
| 261 | } |
| 262 | |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 263 | /** |
| 264 | * Return a label for a disabled reason for shortcuts that are disabled due to a backup and |
| 265 | * restore issue. If the reason is not due to backup & restore, then it'll return null. |
| 266 | * |
| 267 | * This method returns localized, user-facing strings, which will be returned by |
| 268 | * {@link #getDisabledMessage()}. |
| 269 | * |
| 270 | * @hide |
| 271 | */ |
| 272 | public static String getDisabledReasonForRestoreIssue(Context context, |
| 273 | @DisabledReason int disabledReason) { |
| 274 | final Resources res = context.getResources(); |
| 275 | |
| 276 | switch (disabledReason) { |
| 277 | case DISABLED_REASON_VERSION_LOWER: |
| 278 | return res.getString( |
| 279 | com.android.internal.R.string.shortcut_restored_on_lower_version); |
| 280 | case DISABLED_REASON_BACKUP_NOT_SUPPORTED: |
| 281 | return res.getString( |
| 282 | com.android.internal.R.string.shortcut_restore_not_supported); |
| 283 | case DISABLED_REASON_SIGNATURE_MISMATCH: |
| 284 | return res.getString( |
| 285 | com.android.internal.R.string.shortcut_restore_signature_mismatch); |
| 286 | case DISABLED_REASON_OTHER_RESTORE_ISSUE: |
| 287 | return res.getString( |
| 288 | com.android.internal.R.string.shortcut_restore_unknown_issue); |
Makoto Onuki | 5482a8e6 | 2018-01-09 10:31:08 -0800 | [diff] [blame] | 289 | case DISABLED_REASON_UNKNOWN: |
| 290 | return res.getString( |
| 291 | com.android.internal.R.string.shortcut_disabled_reason_unknown); |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 292 | } |
| 293 | return null; |
| 294 | } |
| 295 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 296 | /** @hide */ |
| 297 | public static boolean isDisabledForRestoreIssue(@DisabledReason int disabledReason) { |
| 298 | return disabledReason >= DISABLED_REASON_RESTORE_ISSUE_START; |
| 299 | } |
| 300 | |
| 301 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 302 | * Shortcut category for messaging related actions, such as chat. |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 303 | */ |
| 304 | public static final String SHORTCUT_CATEGORY_CONVERSATION = "android.shortcut.conversation"; |
| 305 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 306 | private final String mId; |
| 307 | |
| 308 | @NonNull |
| 309 | private final String mPackageName; |
| 310 | |
| 311 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 312 | private ComponentName mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 313 | |
| 314 | @Nullable |
| 315 | private Icon mIcon; |
| 316 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 317 | private int mTitleResId; |
| 318 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 319 | private String mTitleResName; |
| 320 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 321 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 322 | private CharSequence mTitle; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 323 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 324 | private int mTextResId; |
| 325 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 326 | private String mTextResName; |
| 327 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 328 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 329 | private CharSequence mText; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 330 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 331 | private int mDisabledMessageResId; |
| 332 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 333 | private String mDisabledMessageResName; |
| 334 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 335 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 336 | private CharSequence mDisabledMessage; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 337 | |
| 338 | @Nullable |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 339 | private ArraySet<String> mCategories; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 340 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 341 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 342 | * Intents *with extras removed*. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 343 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 344 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 345 | private Intent[] mIntents; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 346 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 347 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 348 | * Extras for the intents. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 349 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 350 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 351 | private PersistableBundle[] mIntentPersistableExtrases; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 352 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 353 | @Nullable |
| 354 | private Person[] mPersons; |
| 355 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 356 | private int mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 357 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 358 | /** |
| 359 | * Internally used for auto-rank-adjustment. |
| 360 | * |
| 361 | * RANK_CHANGED_BIT is used to denote that the rank of a shortcut is changing. |
| 362 | * The rest of the bits are used to denote the order in which shortcuts are passed to |
| 363 | * APIs, which is used to preserve the argument order when ranks are tie. |
| 364 | */ |
| 365 | private int mImplicitRank; |
| 366 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 367 | @Nullable |
| 368 | private PersistableBundle mExtras; |
| 369 | |
| 370 | private long mLastChangedTimestamp; |
| 371 | |
| 372 | // Internal use only. |
| 373 | @ShortcutFlags |
| 374 | private int mFlags; |
| 375 | |
| 376 | // Internal use only. |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 377 | private int mIconResId; |
| 378 | |
| 379 | private String mIconResName; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 380 | |
| 381 | // Internal use only. |
| 382 | @Nullable |
| 383 | private String mBitmapPath; |
| 384 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 385 | private final int mUserId; |
| 386 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 387 | /** @hide */ |
| 388 | public static final int VERSION_CODE_UNKNOWN = -1; |
| 389 | |
| 390 | private int mDisabledReason; |
| 391 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 392 | private ShortcutInfo(Builder b) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 393 | mUserId = b.mContext.getUserId(); |
| 394 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 395 | mId = Preconditions.checkStringNotEmpty(b.mId, "Shortcut ID must be provided"); |
| 396 | |
| 397 | // Note we can't do other null checks here because SM.updateShortcuts() takes partial |
| 398 | // information. |
| 399 | mPackageName = b.mContext.getPackageName(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 400 | mActivity = b.mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 401 | mIcon = b.mIcon; |
| 402 | mTitle = b.mTitle; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 403 | mTitleResId = b.mTitleResId; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 404 | mText = b.mText; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 405 | mTextResId = b.mTextResId; |
| 406 | mDisabledMessage = b.mDisabledMessage; |
| 407 | mDisabledMessageResId = b.mDisabledMessageResId; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 408 | mCategories = cloneCategories(b.mCategories); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 409 | mIntents = cloneIntents(b.mIntents); |
| 410 | fixUpIntentExtras(); |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 411 | mPersons = clonePersons(b.mPersons); |
| 412 | if (b.mIsLongLived) { |
| 413 | setLongLived(); |
| 414 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 415 | mRank = b.mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 416 | mExtras = b.mExtras; |
| 417 | updateTimestamp(); |
| 418 | } |
| 419 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 420 | /** |
| 421 | * Extract extras from {@link #mIntents} and set them to {@link #mIntentPersistableExtrases} |
| 422 | * as {@link PersistableBundle}, and remove extras from the original intents. |
| 423 | */ |
| 424 | private void fixUpIntentExtras() { |
| 425 | if (mIntents == null) { |
| 426 | mIntentPersistableExtrases = null; |
| 427 | return; |
| 428 | } |
| 429 | mIntentPersistableExtrases = new PersistableBundle[mIntents.length]; |
| 430 | for (int i = 0; i < mIntents.length; i++) { |
| 431 | final Intent intent = mIntents[i]; |
| 432 | final Bundle extras = intent.getExtras(); |
| 433 | if (extras == null) { |
| 434 | mIntentPersistableExtrases[i] = null; |
| 435 | } else { |
| 436 | mIntentPersistableExtrases[i] = new PersistableBundle(extras); |
| 437 | intent.replaceExtras((Bundle) null); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | private static ArraySet<String> cloneCategories(Set<String> source) { |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 443 | if (source == null) { |
| 444 | return null; |
| 445 | } |
| 446 | final ArraySet<String> ret = new ArraySet<>(source.size()); |
| 447 | for (CharSequence s : source) { |
| 448 | if (!TextUtils.isEmpty(s)) { |
| 449 | ret.add(s.toString().intern()); |
| 450 | } |
| 451 | } |
| 452 | return ret; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 455 | private static Intent[] cloneIntents(Intent[] intents) { |
| 456 | if (intents == null) { |
| 457 | return null; |
| 458 | } |
| 459 | final Intent[] ret = new Intent[intents.length]; |
| 460 | for (int i = 0; i < ret.length; i++) { |
| 461 | if (intents[i] != null) { |
| 462 | ret[i] = new Intent(intents[i]); |
| 463 | } |
| 464 | } |
| 465 | return ret; |
| 466 | } |
| 467 | |
| 468 | private static PersistableBundle[] clonePersistableBundle(PersistableBundle[] bundle) { |
| 469 | if (bundle == null) { |
| 470 | return null; |
| 471 | } |
| 472 | final PersistableBundle[] ret = new PersistableBundle[bundle.length]; |
| 473 | for (int i = 0; i < ret.length; i++) { |
| 474 | if (bundle[i] != null) { |
| 475 | ret[i] = new PersistableBundle(bundle[i]); |
| 476 | } |
| 477 | } |
| 478 | return ret; |
| 479 | } |
| 480 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 481 | private static Person[] clonePersons(Person[] persons) { |
| 482 | if (persons == null) { |
| 483 | return null; |
| 484 | } |
| 485 | final Person[] ret = new Person[persons.length]; |
| 486 | for (int i = 0; i < ret.length; i++) { |
| 487 | if (persons[i] != null) { |
| 488 | // Don't need to keep the icon, remove it to save space |
| 489 | ret[i] = persons[i].toBuilder().setIcon(null).build(); |
| 490 | } |
| 491 | } |
| 492 | return ret; |
| 493 | } |
| 494 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 495 | /** |
| 496 | * Throws if any of the mandatory fields is not set. |
| 497 | * |
| 498 | * @hide |
| 499 | */ |
Makoto Onuki | 106ff7a | 2016-12-01 10:17:57 -0800 | [diff] [blame] | 500 | public void enforceMandatoryFields(boolean forPinned) { |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 501 | Preconditions.checkStringNotEmpty(mId, "Shortcut ID must be provided"); |
Makoto Onuki | 106ff7a | 2016-12-01 10:17:57 -0800 | [diff] [blame] | 502 | if (!forPinned) { |
| 503 | Preconditions.checkNotNull(mActivity, "Activity must be provided"); |
| 504 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 505 | if (mTitle == null && mTitleResId == 0) { |
Makoto Onuki | a1d38b3 | 2016-06-10 15:32:26 -0700 | [diff] [blame] | 506 | throw new IllegalArgumentException("Short label must be provided"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 507 | } |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 508 | Preconditions.checkNotNull(mIntents, "Shortcut Intent must be provided"); |
| 509 | Preconditions.checkArgument(mIntents.length > 0, "Shortcut Intent must be provided"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /** |
| 513 | * Copy constructor. |
| 514 | */ |
| 515 | private ShortcutInfo(ShortcutInfo source, @CloneFlags int cloneFlags) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 516 | mUserId = source.mUserId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 517 | mId = source.mId; |
| 518 | mPackageName = source.mPackageName; |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 519 | mActivity = source.mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 520 | mFlags = source.mFlags; |
| 521 | mLastChangedTimestamp = source.mLastChangedTimestamp; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 522 | mDisabledReason = source.mDisabledReason; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 523 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 524 | // Just always keep it since it's cheep. |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 525 | mIconResId = source.mIconResId; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 526 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 527 | if ((cloneFlags & CLONE_REMOVE_NON_KEY_INFO) == 0) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 528 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 529 | if ((cloneFlags & CLONE_REMOVE_ICON) == 0) { |
| 530 | mIcon = source.mIcon; |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 531 | mBitmapPath = source.mBitmapPath; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | mTitle = source.mTitle; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 535 | mTitleResId = source.mTitleResId; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 536 | mText = source.mText; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 537 | mTextResId = source.mTextResId; |
| 538 | mDisabledMessage = source.mDisabledMessage; |
| 539 | mDisabledMessageResId = source.mDisabledMessageResId; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 540 | mCategories = cloneCategories(source.mCategories); |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 541 | mPersons = clonePersons(source.mPersons); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 542 | if ((cloneFlags & CLONE_REMOVE_INTENT) == 0) { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 543 | mIntents = cloneIntents(source.mIntents); |
| 544 | mIntentPersistableExtrases = |
| 545 | clonePersistableBundle(source.mIntentPersistableExtrases); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 546 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 547 | mRank = source.mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 548 | mExtras = source.mExtras; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 549 | |
| 550 | if ((cloneFlags & CLONE_REMOVE_RES_NAMES) == 0) { |
| 551 | mTitleResName = source.mTitleResName; |
| 552 | mTextResName = source.mTextResName; |
| 553 | mDisabledMessageResName = source.mDisabledMessageResName; |
| 554 | mIconResName = source.mIconResName; |
| 555 | } |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 556 | } else { |
| 557 | // Set this bit. |
| 558 | mFlags |= FLAG_KEY_FIELDS_ONLY; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 562 | /** |
| 563 | * Load a string resource from the publisher app. |
| 564 | * |
| 565 | * @param resId resource ID |
| 566 | * @param defValue default value to be returned when the specified resource isn't found. |
| 567 | */ |
| 568 | private CharSequence getResourceString(Resources res, int resId, CharSequence defValue) { |
| 569 | try { |
| 570 | return res.getString(resId); |
| 571 | } catch (NotFoundException e) { |
| 572 | Log.e(TAG, "Resource for ID=" + resId + " not found in package " + mPackageName); |
| 573 | return defValue; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * Load the string resources for the text fields and set them to the actual value fields. |
| 579 | * This will set {@link #FLAG_STRINGS_RESOLVED}. |
| 580 | * |
| 581 | * @param res {@link Resources} for the publisher. Must have been loaded with |
| 582 | * {@link PackageManager#getResourcesForApplicationAsUser}. |
| 583 | * |
| 584 | * @hide |
| 585 | */ |
| 586 | public void resolveResourceStrings(@NonNull Resources res) { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 587 | mFlags |= FLAG_STRINGS_RESOLVED; |
| 588 | |
| 589 | if ((mTitleResId == 0) && (mTextResId == 0) && (mDisabledMessageResId == 0)) { |
| 590 | return; // Bail early. |
| 591 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 592 | |
| 593 | if (mTitleResId != 0) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 594 | mTitle = getResourceString(res, mTitleResId, mTitle); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 595 | } |
| 596 | if (mTextResId != 0) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 597 | mText = getResourceString(res, mTextResId, mText); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 598 | } |
| 599 | if (mDisabledMessageResId != 0) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 600 | mDisabledMessage = getResourceString(res, mDisabledMessageResId, mDisabledMessage); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 604 | /** |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 605 | * Look up resource name for a given resource ID. |
| 606 | * |
| 607 | * @return a simple resource name (e.g. "text_1") when {@code withType} is false, or with the |
| 608 | * type (e.g. "string/text_1"). |
| 609 | * |
| 610 | * @hide |
| 611 | */ |
| 612 | @VisibleForTesting |
| 613 | public static String lookUpResourceName(@NonNull Resources res, int resId, boolean withType, |
| 614 | @NonNull String packageName) { |
| 615 | if (resId == 0) { |
| 616 | return null; |
| 617 | } |
| 618 | try { |
| 619 | final String fullName = res.getResourceName(resId); |
| 620 | |
| 621 | if (ANDROID_PACKAGE_NAME.equals(getResourcePackageName(fullName))) { |
| 622 | // If it's a framework resource, the value won't change, so just return the ID |
| 623 | // value as a string. |
| 624 | return String.valueOf(resId); |
| 625 | } |
| 626 | return withType ? getResourceTypeAndEntryName(fullName) |
| 627 | : getResourceEntryName(fullName); |
| 628 | } catch (NotFoundException e) { |
| 629 | Log.e(TAG, "Resource name for ID=" + resId + " not found in package " + packageName |
| 630 | + ". Resource IDs may change when the application is upgraded, and the system" |
| 631 | + " may not be able to find the correct resource."); |
| 632 | return null; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * Extract the package name from a fully-donated resource name. |
| 638 | * e.g. "com.android.app1:drawable/icon1" -> "com.android.app1" |
| 639 | * @hide |
| 640 | */ |
| 641 | @VisibleForTesting |
| 642 | public static String getResourcePackageName(@NonNull String fullResourceName) { |
| 643 | final int p1 = fullResourceName.indexOf(':'); |
| 644 | if (p1 < 0) { |
| 645 | return null; |
| 646 | } |
| 647 | return fullResourceName.substring(0, p1); |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * Extract the type name from a fully-donated resource name. |
| 652 | * e.g. "com.android.app1:drawable/icon1" -> "drawable" |
| 653 | * @hide |
| 654 | */ |
| 655 | @VisibleForTesting |
| 656 | public static String getResourceTypeName(@NonNull String fullResourceName) { |
| 657 | final int p1 = fullResourceName.indexOf(':'); |
| 658 | if (p1 < 0) { |
| 659 | return null; |
| 660 | } |
| 661 | final int p2 = fullResourceName.indexOf('/', p1 + 1); |
| 662 | if (p2 < 0) { |
| 663 | return null; |
| 664 | } |
| 665 | return fullResourceName.substring(p1 + 1, p2); |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Extract the type name + the entry name from a fully-donated resource name. |
| 670 | * e.g. "com.android.app1:drawable/icon1" -> "drawable/icon1" |
| 671 | * @hide |
| 672 | */ |
| 673 | @VisibleForTesting |
| 674 | public static String getResourceTypeAndEntryName(@NonNull String fullResourceName) { |
| 675 | final int p1 = fullResourceName.indexOf(':'); |
| 676 | if (p1 < 0) { |
| 677 | return null; |
| 678 | } |
| 679 | return fullResourceName.substring(p1 + 1); |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * Extract the entry name from a fully-donated resource name. |
| 684 | * e.g. "com.android.app1:drawable/icon1" -> "icon1" |
| 685 | * @hide |
| 686 | */ |
| 687 | @VisibleForTesting |
| 688 | public static String getResourceEntryName(@NonNull String fullResourceName) { |
| 689 | final int p1 = fullResourceName.indexOf('/'); |
| 690 | if (p1 < 0) { |
| 691 | return null; |
| 692 | } |
| 693 | return fullResourceName.substring(p1 + 1); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * Return the resource ID for a given resource ID. |
| 698 | * |
| 699 | * Basically its' a wrapper over {@link Resources#getIdentifier(String, String, String)}, except |
| 700 | * if {@code resourceName} is an integer then it'll just return its value. (Which also the |
| 701 | * aforementioned method would do internally, but not documented, so doing here explicitly.) |
| 702 | * |
| 703 | * @param res {@link Resources} for the publisher. Must have been loaded with |
| 704 | * {@link PackageManager#getResourcesForApplicationAsUser}. |
| 705 | * |
| 706 | * @hide |
| 707 | */ |
| 708 | @VisibleForTesting |
| 709 | public static int lookUpResourceId(@NonNull Resources res, @Nullable String resourceName, |
| 710 | @Nullable String resourceType, String packageName) { |
| 711 | if (resourceName == null) { |
| 712 | return 0; |
| 713 | } |
| 714 | try { |
| 715 | try { |
| 716 | // It the name can be parsed as an integer, just use it. |
| 717 | return Integer.parseInt(resourceName); |
| 718 | } catch (NumberFormatException ignore) { |
| 719 | } |
| 720 | |
| 721 | return res.getIdentifier(resourceName, resourceType, packageName); |
| 722 | } catch (NotFoundException e) { |
| 723 | Log.e(TAG, "Resource ID for name=" + resourceName + " not found in package " |
| 724 | + packageName); |
| 725 | return 0; |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * Look up resource names from the resource IDs for the icon res and the text fields, and fill |
| 731 | * in the resource name fields. |
| 732 | * |
| 733 | * @param res {@link Resources} for the publisher. Must have been loaded with |
| 734 | * {@link PackageManager#getResourcesForApplicationAsUser}. |
| 735 | * |
| 736 | * @hide |
| 737 | */ |
| 738 | public void lookupAndFillInResourceNames(@NonNull Resources res) { |
| 739 | if ((mTitleResId == 0) && (mTextResId == 0) && (mDisabledMessageResId == 0) |
| 740 | && (mIconResId == 0)) { |
| 741 | return; // Bail early. |
| 742 | } |
| 743 | |
| 744 | // We don't need types for strings because their types are always "string". |
| 745 | mTitleResName = lookUpResourceName(res, mTitleResId, /*withType=*/ false, mPackageName); |
| 746 | mTextResName = lookUpResourceName(res, mTextResId, /*withType=*/ false, mPackageName); |
| 747 | mDisabledMessageResName = lookUpResourceName(res, mDisabledMessageResId, |
| 748 | /*withType=*/ false, mPackageName); |
| 749 | |
| 750 | // But icons have multiple possible types, so include the type. |
| 751 | mIconResName = lookUpResourceName(res, mIconResId, /*withType=*/ true, mPackageName); |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Look up resource IDs from the resource names for the icon res and the text fields, and fill |
| 756 | * in the resource ID fields. |
| 757 | * |
| 758 | * This is called when an app is updated. |
| 759 | * |
| 760 | * @hide |
| 761 | */ |
| 762 | public void lookupAndFillInResourceIds(@NonNull Resources res) { |
| 763 | if ((mTitleResName == null) && (mTextResName == null) && (mDisabledMessageResName == null) |
| 764 | && (mIconResName == null)) { |
| 765 | return; // Bail early. |
| 766 | } |
| 767 | |
| 768 | mTitleResId = lookUpResourceId(res, mTitleResName, RES_TYPE_STRING, mPackageName); |
| 769 | mTextResId = lookUpResourceId(res, mTextResName, RES_TYPE_STRING, mPackageName); |
| 770 | mDisabledMessageResId = lookUpResourceId(res, mDisabledMessageResName, RES_TYPE_STRING, |
| 771 | mPackageName); |
| 772 | |
| 773 | // mIconResName already contains the type, so the third argument is not needed. |
| 774 | mIconResId = lookUpResourceId(res, mIconResName, null, mPackageName); |
| 775 | } |
| 776 | |
| 777 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 778 | * Copy a {@link ShortcutInfo}, optionally removing fields. |
| 779 | * @hide |
| 780 | */ |
| 781 | public ShortcutInfo clone(@CloneFlags int cloneFlags) { |
| 782 | return new ShortcutInfo(this, cloneFlags); |
| 783 | } |
| 784 | |
| 785 | /** |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 786 | * @hide |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 787 | * |
| 788 | * @isUpdating set true if it's "update", as opposed to "replace". |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 789 | */ |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 790 | public void ensureUpdatableWith(ShortcutInfo source, boolean isUpdating) { |
| 791 | if (isUpdating) { |
| 792 | Preconditions.checkState(isVisibleToPublisher(), |
| 793 | "[Framework BUG] Invisible shortcuts can't be updated"); |
| 794 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 795 | Preconditions.checkState(mUserId == source.mUserId, "Owner User ID must match"); |
| 796 | Preconditions.checkState(mId.equals(source.mId), "ID must match"); |
| 797 | Preconditions.checkState(mPackageName.equals(source.mPackageName), |
| 798 | "Package name must match"); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 799 | |
| 800 | if (isVisibleToPublisher()) { |
| 801 | // Don't do this check for restore-blocked shortcuts. |
| 802 | Preconditions.checkState(!isImmutable(), "Target ShortcutInfo is immutable"); |
| 803 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 807 | * Copy non-null/zero fields from another {@link ShortcutInfo}. Only "public" information |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 808 | * will be overwritten. The timestamp will *not* be updated to be consistent with other |
| 809 | * setters (and also the clock is not injectable in this file). |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 810 | * |
| 811 | * - Flags will not change |
| 812 | * - mBitmapPath will not change |
| 813 | * - Current time will be set to timestamp |
| 814 | * |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 815 | * @throws IllegalStateException if source is not compatible. |
| 816 | * |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 817 | * @hide |
| 818 | */ |
| 819 | public void copyNonNullFieldsFrom(ShortcutInfo source) { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 820 | ensureUpdatableWith(source, /*isUpdating=*/ true); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 821 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 822 | if (source.mActivity != null) { |
| 823 | mActivity = source.mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | if (source.mIcon != null) { |
| 827 | mIcon = source.mIcon; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 828 | |
| 829 | mIconResId = 0; |
| 830 | mIconResName = null; |
| 831 | mBitmapPath = null; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 832 | } |
| 833 | if (source.mTitle != null) { |
| 834 | mTitle = source.mTitle; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 835 | mTitleResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 836 | mTitleResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 837 | } else if (source.mTitleResId != 0) { |
| 838 | mTitle = null; |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 839 | mTitleResId = source.mTitleResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 840 | mTitleResName = null; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 841 | } |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 842 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 843 | if (source.mText != null) { |
| 844 | mText = source.mText; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 845 | mTextResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 846 | mTextResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 847 | } else if (source.mTextResId != 0) { |
| 848 | mText = null; |
| 849 | mTextResId = source.mTextResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 850 | mTextResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 851 | } |
| 852 | if (source.mDisabledMessage != null) { |
| 853 | mDisabledMessage = source.mDisabledMessage; |
| 854 | mDisabledMessageResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 855 | mDisabledMessageResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 856 | } else if (source.mDisabledMessageResId != 0) { |
| 857 | mDisabledMessage = null; |
| 858 | mDisabledMessageResId = source.mDisabledMessageResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 859 | mDisabledMessageResName = null; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 860 | } |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 861 | if (source.mCategories != null) { |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 862 | mCategories = cloneCategories(source.mCategories); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 863 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 864 | if (source.mPersons != null) { |
| 865 | mPersons = clonePersons(source.mPersons); |
| 866 | } |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 867 | if (source.mIntents != null) { |
| 868 | mIntents = cloneIntents(source.mIntents); |
| 869 | mIntentPersistableExtrases = |
| 870 | clonePersistableBundle(source.mIntentPersistableExtrases); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 871 | } |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 872 | if (source.mRank != RANK_NOT_SET) { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 873 | mRank = source.mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 874 | } |
| 875 | if (source.mExtras != null) { |
| 876 | mExtras = source.mExtras; |
| 877 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /** |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 881 | * @hide |
| 882 | */ |
| 883 | public static Icon validateIcon(Icon icon) { |
| 884 | switch (icon.getType()) { |
| 885 | case Icon.TYPE_RESOURCE: |
| 886 | case Icon.TYPE_BITMAP: |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 887 | case Icon.TYPE_ADAPTIVE_BITMAP: |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 888 | break; // OK |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 889 | default: |
| 890 | throw getInvalidIconException(); |
| 891 | } |
| 892 | if (icon.hasTint()) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 893 | throw new IllegalArgumentException("Icons with tints are not supported"); |
| 894 | } |
| 895 | |
| 896 | return icon; |
| 897 | } |
| 898 | |
| 899 | /** @hide */ |
| 900 | public static IllegalArgumentException getInvalidIconException() { |
| 901 | return new IllegalArgumentException("Unsupported icon type:" |
Makoto Onuki | a97256b | 2016-07-15 13:23:54 -0700 | [diff] [blame] | 902 | +" only the bitmap and resource types are supported"); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 906 | * Builder class for {@link ShortcutInfo} objects. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 907 | * |
| 908 | * @see ShortcutManager |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 909 | */ |
| 910 | public static class Builder { |
| 911 | private final Context mContext; |
| 912 | |
| 913 | private String mId; |
| 914 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 915 | private ComponentName mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 916 | |
| 917 | private Icon mIcon; |
| 918 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 919 | private int mTitleResId; |
| 920 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 921 | private CharSequence mTitle; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 922 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 923 | private int mTextResId; |
| 924 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 925 | private CharSequence mText; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 926 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 927 | private int mDisabledMessageResId; |
| 928 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 929 | private CharSequence mDisabledMessage; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 930 | |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 931 | private Set<String> mCategories; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 932 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 933 | private Intent[] mIntents; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 934 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 935 | private Person[] mPersons; |
| 936 | |
| 937 | private boolean mIsLongLived; |
| 938 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 939 | private int mRank = RANK_NOT_SET; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 940 | |
| 941 | private PersistableBundle mExtras; |
| 942 | |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 943 | /** |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 944 | * Old style constructor. |
| 945 | * @hide |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 946 | */ |
| 947 | @Deprecated |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 948 | public Builder(Context context) { |
| 949 | mContext = context; |
| 950 | } |
| 951 | |
| 952 | /** |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 953 | * Used with the old style constructor, kept for unit tests. |
| 954 | * @hide |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 955 | */ |
| 956 | @NonNull |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 957 | @Deprecated |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 958 | public Builder setId(@NonNull String id) { |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 959 | mId = Preconditions.checkStringNotEmpty(id, "id cannot be empty"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 960 | return this; |
| 961 | } |
| 962 | |
| 963 | /** |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 964 | * Constructor. |
| 965 | * |
| 966 | * @param context Client context. |
| 967 | * @param id ID of the shortcut. |
| 968 | */ |
| 969 | public Builder(Context context, String id) { |
| 970 | mContext = context; |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 971 | mId = Preconditions.checkStringNotEmpty(id, "id cannot be empty"); |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 975 | * Sets the target activity. A shortcut will be shown along with this activity's icon |
| 976 | * on the launcher. |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 977 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 978 | * When selecting a target activity, keep the following in mind: |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 979 | * <ul> |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 980 | * <li>All dynamic shortcuts must have a target activity. When a shortcut with no target |
| 981 | * activity is published using |
| 982 | * {@link ShortcutManager#addDynamicShortcuts(List)} or |
| 983 | * {@link ShortcutManager#setDynamicShortcuts(List)}, |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 984 | * the first main activity defined in the app's <code>AndroidManifest.xml</code> |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 985 | * file is used. |
| 986 | * |
| 987 | * <li>Only "main" activities—ones that define the {@link Intent#ACTION_MAIN} |
| 988 | * and {@link Intent#CATEGORY_LAUNCHER} intent filters—can be target |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 989 | * activities. |
| 990 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 991 | * <li>By default, the first main activity defined in the app's manifest is |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 992 | * the target activity. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 993 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 994 | * <li>A target activity must belong to the publisher app. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 995 | * </ul> |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 996 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 997 | * @see ShortcutInfo#getActivity() |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 998 | */ |
| 999 | @NonNull |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1000 | public Builder setActivity(@NonNull ComponentName activity) { |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1001 | mActivity = Preconditions.checkNotNull(activity, "activity cannot be null"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1002 | return this; |
| 1003 | } |
| 1004 | |
| 1005 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1006 | * Sets an icon of a shortcut. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1007 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1008 | * <p>Icons are not available on {@link ShortcutInfo} instances |
| 1009 | * returned by {@link ShortcutManager} or {@link LauncherApps}. The default launcher |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1010 | * app can use {@link LauncherApps#getShortcutIconDrawable(ShortcutInfo, int)} |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1011 | * or {@link LauncherApps#getShortcutBadgedIconDrawable(ShortcutInfo, int)} to fetch |
| 1012 | * shortcut icons. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1013 | * |
| 1014 | * <p>Tints set with {@link Icon#setTint} or {@link Icon#setTintList} are not supported |
| 1015 | * and will be ignored. |
| 1016 | * |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1017 | * <p>Only icons created with {@link Icon#createWithBitmap(Bitmap)}, |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 1018 | * {@link Icon#createWithAdaptiveBitmap(Bitmap)} |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1019 | * and {@link Icon#createWithResource} are supported. |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1020 | * Other types, such as URI-based icons, are not supported. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1021 | * |
| 1022 | * @see LauncherApps#getShortcutIconDrawable(ShortcutInfo, int) |
| 1023 | * @see LauncherApps#getShortcutBadgedIconDrawable(ShortcutInfo, int) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1024 | */ |
| 1025 | @NonNull |
| 1026 | public Builder setIcon(Icon icon) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1027 | mIcon = validateIcon(icon); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1028 | return this; |
| 1029 | } |
| 1030 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1031 | /** |
| 1032 | * @hide We don't support resource strings for dynamic shortcuts for now. (But unit tests |
| 1033 | * use it.) |
| 1034 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1035 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1036 | public Builder setShortLabelResId(int shortLabelResId) { |
| 1037 | Preconditions.checkState(mTitle == null, "shortLabel already set"); |
| 1038 | mTitleResId = shortLabelResId; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1039 | return this; |
| 1040 | } |
| 1041 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1042 | /** |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1043 | * Sets the short title of a shortcut. |
| 1044 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1045 | * <p>This is a mandatory field when publishing a new shortcut with |
| 1046 | * {@link ShortcutManager#addDynamicShortcuts(List)} or |
| 1047 | * {@link ShortcutManager#setDynamicShortcuts(List)}. |
Makoto Onuki | 0e65d36 | 2016-03-29 14:46:50 -0700 | [diff] [blame] | 1048 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1049 | * <p>This field is intended to be a concise description of a shortcut. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1050 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1051 | * <p>The recommended maximum length is 10 characters. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1052 | * |
| 1053 | * @see ShortcutInfo#getShortLabel() |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1054 | */ |
| 1055 | @NonNull |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1056 | public Builder setShortLabel(@NonNull CharSequence shortLabel) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1057 | Preconditions.checkState(mTitleResId == 0, "shortLabelResId already set"); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1058 | mTitle = Preconditions.checkStringNotEmpty(shortLabel, "shortLabel cannot be empty"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1059 | return this; |
| 1060 | } |
| 1061 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1062 | /** |
| 1063 | * @hide We don't support resource strings for dynamic shortcuts for now. (But unit tests |
| 1064 | * use it.) |
| 1065 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1066 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1067 | public Builder setLongLabelResId(int longLabelResId) { |
| 1068 | Preconditions.checkState(mText == null, "longLabel already set"); |
| 1069 | mTextResId = longLabelResId; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1070 | return this; |
| 1071 | } |
| 1072 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1073 | /** |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1074 | * Sets the text of a shortcut. |
Makoto Onuki | 0e65d36 | 2016-03-29 14:46:50 -0700 | [diff] [blame] | 1075 | * |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1076 | * <p>This field is intended to be more descriptive than the shortcut title. The launcher |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1077 | * shows this instead of the short title when it has enough space. |
| 1078 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1079 | * <p>The recommend maximum length is 25 characters. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1080 | * |
| 1081 | * @see ShortcutInfo#getLongLabel() |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1082 | */ |
| 1083 | @NonNull |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1084 | public Builder setLongLabel(@NonNull CharSequence longLabel) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1085 | Preconditions.checkState(mTextResId == 0, "longLabelResId already set"); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1086 | mText = Preconditions.checkStringNotEmpty(longLabel, "longLabel cannot be empty"); |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1087 | return this; |
| 1088 | } |
| 1089 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1090 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1091 | @Deprecated |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1092 | public Builder setTitle(@NonNull CharSequence value) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1093 | return setShortLabel(value); |
| 1094 | } |
| 1095 | |
| 1096 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1097 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1098 | public Builder setTitleResId(int value) { |
| 1099 | return setShortLabelResId(value); |
| 1100 | } |
| 1101 | |
| 1102 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1103 | @Deprecated |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1104 | public Builder setText(@NonNull CharSequence value) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1105 | return setLongLabel(value); |
| 1106 | } |
| 1107 | |
| 1108 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1109 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1110 | public Builder setTextResId(int value) { |
| 1111 | return setLongLabelResId(value); |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * @hide We don't support resource strings for dynamic shortcuts for now. (But unit tests |
| 1116 | * use it.) |
| 1117 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1118 | @Deprecated |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1119 | public Builder setDisabledMessageResId(int disabledMessageResId) { |
| 1120 | Preconditions.checkState(mDisabledMessage == null, "disabledMessage already set"); |
| 1121 | mDisabledMessageResId = disabledMessageResId; |
| 1122 | return this; |
| 1123 | } |
| 1124 | |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1125 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1126 | * Sets the message that should be shown when the user attempts to start a shortcut that |
| 1127 | * is disabled. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1128 | * |
| 1129 | * @see ShortcutInfo#getDisabledMessage() |
| 1130 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1131 | @NonNull |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1132 | public Builder setDisabledMessage(@NonNull CharSequence disabledMessage) { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1133 | Preconditions.checkState( |
| 1134 | mDisabledMessageResId == 0, "disabledMessageResId already set"); |
| 1135 | mDisabledMessage = |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1136 | Preconditions.checkStringNotEmpty(disabledMessage, |
| 1137 | "disabledMessage cannot be empty"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1138 | return this; |
| 1139 | } |
| 1140 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1141 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1142 | * Sets categories for a shortcut. Launcher apps may use this information to |
| 1143 | * categorize shortcuts. |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1144 | * |
| 1145 | * @see #SHORTCUT_CATEGORY_CONVERSATION |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1146 | * @see ShortcutInfo#getCategories() |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1147 | */ |
| 1148 | @NonNull |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 1149 | public Builder setCategories(Set<String> categories) { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1150 | mCategories = categories; |
| 1151 | return this; |
| 1152 | } |
| 1153 | |
| 1154 | /** |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 1155 | * Sets the intent of a shortcut. Alternatively, {@link #setIntents(Intent[])} can be used |
| 1156 | * to launch an activity with other activities in the back stack. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1157 | * |
| 1158 | * <p>This is a mandatory field when publishing a new shortcut with |
| 1159 | * {@link ShortcutManager#addDynamicShortcuts(List)} or |
| 1160 | * {@link ShortcutManager#setDynamicShortcuts(List)}. |
| 1161 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1162 | * <p>A shortcut can launch any intent that the publisher app has permission to |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1163 | * launch. For example, a shortcut can launch an unexported activity within the publisher |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1164 | * app. A shortcut intent doesn't have to point at the target activity. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1165 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1166 | * <p>The given {@code intent} can contain extras, but these extras must contain values |
| 1167 | * of primitive types in order for the system to persist these values. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1168 | * |
| 1169 | * @see ShortcutInfo#getIntent() |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1170 | * @see #setIntents(Intent[]) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1171 | */ |
| 1172 | @NonNull |
| 1173 | public Builder setIntent(@NonNull Intent intent) { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1174 | return setIntents(new Intent[]{intent}); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | /** |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 1178 | * Sets multiple intents instead of a single intent, in order to launch an activity with |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1179 | * other activities in back stack. Use {@link TaskStackBuilder} to build intents. The |
| 1180 | * last element in the list represents the only intent that doesn't place an activity on |
| 1181 | * the back stack. |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 1182 | * See the {@link ShortcutManager} javadoc for details. |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1183 | * |
| 1184 | * @see Builder#setIntent(Intent) |
| 1185 | * @see ShortcutInfo#getIntents() |
| 1186 | * @see Context#startActivities(Intent[]) |
| 1187 | * @see TaskStackBuilder |
| 1188 | */ |
| 1189 | @NonNull |
| 1190 | public Builder setIntents(@NonNull Intent[] intents) { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1191 | Preconditions.checkNotNull(intents, "intents cannot be null"); |
| 1192 | Preconditions.checkNotNull(intents.length, "intents cannot be empty"); |
| 1193 | for (Intent intent : intents) { |
| 1194 | Preconditions.checkNotNull(intent, "intents cannot contain null"); |
| 1195 | Preconditions.checkNotNull(intent.getAction(), "intent's action must be set"); |
| 1196 | } |
| 1197 | // Make sure always clone incoming intents. |
| 1198 | mIntents = cloneIntents(intents); |
| 1199 | return this; |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | /** |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1203 | * Add a person that is relevant to this shortcut. Alternatively, |
| 1204 | * {@link #setPersons(Person[])} can be used to add multiple persons to a shortcut. |
| 1205 | * |
| 1206 | * <p> This is an optional field, but the addition of person may cause this shortcut to |
| 1207 | * appear more prominently in the user interface (e.g. ShareSheet). |
| 1208 | * |
| 1209 | * <p> A person should usually contain a uri in order to benefit from the ranking boost. |
| 1210 | * However, even if no uri is provided, it's beneficial to provide people in the shortcut, |
| 1211 | * such that listeners and voice only devices can announce and handle them properly. |
| 1212 | * |
| 1213 | * @see Person |
| 1214 | * @see #setPersons(Person[]) |
| 1215 | */ |
| 1216 | @NonNull |
| 1217 | public Builder setPerson(@NonNull Person person) { |
| 1218 | return setPersons(new Person[]{person}); |
| 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * Sets multiple persons instead of a single person. |
| 1223 | * |
| 1224 | * @see Person |
| 1225 | * @see #setPerson(Person) |
| 1226 | */ |
| 1227 | @NonNull |
| 1228 | public Builder setPersons(@NonNull Person[] persons) { |
| 1229 | Preconditions.checkNotNull(persons, "persons cannot be null"); |
| 1230 | Preconditions.checkNotNull(persons.length, "persons cannot be empty"); |
| 1231 | for (Person person : persons) { |
| 1232 | Preconditions.checkNotNull(person, "persons cannot contain null"); |
| 1233 | } |
| 1234 | mPersons = clonePersons(persons); |
| 1235 | return this; |
| 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * Sets if a shortcut would be valid even if it has been unpublished/invisible by the app |
| 1240 | * (as a dynamic or pinned shortcut). If it is long lived, it can be cached by various |
| 1241 | * system services even after it has been unpublished as a dynamic shortcut. |
| 1242 | */ |
| 1243 | @NonNull |
| 1244 | public Builder setLongLived() { |
| 1245 | mIsLongLived = true; |
| 1246 | return this; |
| 1247 | } |
| 1248 | |
| 1249 | /** |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1250 | * "Rank" of a shortcut, which is a non-negative value that's used by the launcher app |
| 1251 | * to sort shortcuts. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1252 | * |
| 1253 | * See {@link ShortcutInfo#getRank()} for details. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1254 | */ |
| 1255 | @NonNull |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1256 | public Builder setRank(int rank) { |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1257 | Preconditions.checkArgument((0 <= rank), |
| 1258 | "Rank cannot be negative or bigger than MAX_RANK"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1259 | mRank = rank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1260 | return this; |
| 1261 | } |
| 1262 | |
| 1263 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1264 | * Extras that the app can set for any purpose. |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1265 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1266 | * <p>Apps can store arbitrary shortcut metadata in extras and retrieve the |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1267 | * metadata later using {@link ShortcutInfo#getExtras()}. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1268 | */ |
| 1269 | @NonNull |
| 1270 | public Builder setExtras(@NonNull PersistableBundle extras) { |
| 1271 | mExtras = extras; |
| 1272 | return this; |
| 1273 | } |
| 1274 | |
Hakan Seyalioglu | 58fc95d | 2016-12-13 15:23:22 -0800 | [diff] [blame] | 1275 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1276 | * Creates a {@link ShortcutInfo} instance. |
| 1277 | */ |
| 1278 | @NonNull |
| 1279 | public ShortcutInfo build() { |
| 1280 | return new ShortcutInfo(this); |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1285 | * Returns the ID of a shortcut. |
| 1286 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1287 | * <p>Shortcut IDs are unique within each publisher app and must be stable across |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1288 | * devices so that shortcuts will still be valid when restored on a different device. |
| 1289 | * See {@link ShortcutManager} for details. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1290 | */ |
| 1291 | @NonNull |
| 1292 | public String getId() { |
| 1293 | return mId; |
| 1294 | } |
| 1295 | |
| 1296 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1297 | * Return the package name of the publisher app. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1298 | */ |
| 1299 | @NonNull |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1300 | public String getPackage() { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1301 | return mPackageName; |
| 1302 | } |
| 1303 | |
| 1304 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1305 | * Return the target activity. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1306 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1307 | * <p>This has nothing to do with the activity that this shortcut will launch. |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1308 | * Launcher apps should show the launcher icon for the returned activity alongside |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1309 | * this shortcut. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1310 | * |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1311 | * @see Builder#setActivity |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1312 | */ |
| 1313 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1314 | public ComponentName getActivity() { |
| 1315 | return mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1318 | /** @hide */ |
| 1319 | public void setActivity(ComponentName activity) { |
| 1320 | mActivity = activity; |
| 1321 | } |
| 1322 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1323 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1324 | * Returns the shortcut icon. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1325 | * |
| 1326 | * @hide |
| 1327 | */ |
| 1328 | @Nullable |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1329 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1330 | public Icon getIcon() { |
| 1331 | return mIcon; |
| 1332 | } |
| 1333 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1334 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1335 | @Nullable |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1336 | @Deprecated |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1337 | public CharSequence getTitle() { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1338 | return mTitle; |
| 1339 | } |
| 1340 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1341 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1342 | @Deprecated |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1343 | public int getTitleResId() { |
| 1344 | return mTitleResId; |
| 1345 | } |
| 1346 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1347 | /** @hide -- old signature, the internal code still uses it. */ |
| 1348 | @Nullable |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1349 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1350 | public CharSequence getText() { |
| 1351 | return mText; |
| 1352 | } |
| 1353 | |
| 1354 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1355 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1356 | public int getTextResId() { |
| 1357 | return mTextResId; |
| 1358 | } |
| 1359 | |
| 1360 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1361 | * Return the short description of a shortcut. |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1362 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1363 | * @see Builder#setShortLabel(CharSequence) |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1364 | */ |
| 1365 | @Nullable |
| 1366 | public CharSequence getShortLabel() { |
| 1367 | return mTitle; |
| 1368 | } |
| 1369 | |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 1370 | /** @hide */ |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1371 | public int getShortLabelResourceId() { |
| 1372 | return mTitleResId; |
| 1373 | } |
| 1374 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1375 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1376 | * Return the long description of a shortcut. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1377 | * |
| 1378 | * @see Builder#setLongLabel(CharSequence) |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1379 | */ |
| 1380 | @Nullable |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1381 | public CharSequence getLongLabel() { |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1382 | return mText; |
| 1383 | } |
| 1384 | |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 1385 | /** @hide */ |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1386 | public int getLongLabelResourceId() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1387 | return mTextResId; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1391 | * Return the message that should be shown when the user attempts to start a shortcut |
| 1392 | * that is disabled. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1393 | * |
| 1394 | * @see Builder#setDisabledMessage(CharSequence) |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1395 | */ |
| 1396 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1397 | public CharSequence getDisabledMessage() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1398 | return mDisabledMessage; |
| 1399 | } |
| 1400 | |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 1401 | /** @hide */ |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1402 | public int getDisabledMessageResourceId() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1403 | return mDisabledMessageResId; |
| 1404 | } |
| 1405 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1406 | /** @hide */ |
| 1407 | public void setDisabledReason(@DisabledReason int reason) { |
| 1408 | mDisabledReason = reason; |
| 1409 | } |
| 1410 | |
| 1411 | /** |
| 1412 | * Returns why a shortcut has been disabled. |
| 1413 | */ |
| 1414 | @DisabledReason |
| 1415 | public int getDisabledReason() { |
| 1416 | return mDisabledReason; |
| 1417 | } |
| 1418 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1419 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1420 | * Return the shortcut's categories. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1421 | * |
| 1422 | * @see Builder#setCategories(Set) |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1423 | */ |
| 1424 | @Nullable |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 1425 | public Set<String> getCategories() { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1426 | return mCategories; |
| 1427 | } |
| 1428 | |
| 1429 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1430 | * Returns the intent that is executed when the user selects this shortcut. |
| 1431 | * If setIntents() was used, then return the last intent in the array. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1432 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1433 | * <p>Launcher apps <b>cannot</b> see the intent. If a {@link ShortcutInfo} is |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1434 | * obtained via {@link LauncherApps}, then this method will always return null. |
| 1435 | * Launchers can only start a shortcut intent with {@link LauncherApps#startShortcut}. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1436 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1437 | * @see Builder#setIntent(Intent) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1438 | */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1439 | @Nullable |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1440 | public Intent getIntent() { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1441 | if (mIntents == null || mIntents.length == 0) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1442 | return null; |
| 1443 | } |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1444 | final int last = mIntents.length - 1; |
| 1445 | final Intent intent = new Intent(mIntents[last]); |
| 1446 | return setIntentExtras(intent, mIntentPersistableExtrases[last]); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | /** |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1450 | * Return the intent set with {@link Builder#setIntents(Intent[])}. |
| 1451 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1452 | * <p>Launcher apps <b>cannot</b> see the intents. If a {@link ShortcutInfo} is |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1453 | * obtained via {@link LauncherApps}, then this method will always return null. |
| 1454 | * Launchers can only start a shortcut intent with {@link LauncherApps#startShortcut}. |
| 1455 | * |
| 1456 | * @see Builder#setIntents(Intent[]) |
| 1457 | */ |
| 1458 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1459 | public Intent[] getIntents() { |
| 1460 | final Intent[] ret = new Intent[mIntents.length]; |
| 1461 | |
| 1462 | for (int i = 0; i < ret.length; i++) { |
| 1463 | ret[i] = new Intent(mIntents[i]); |
| 1464 | setIntentExtras(ret[i], mIntentPersistableExtrases[i]); |
| 1465 | } |
| 1466 | |
| 1467 | return ret; |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1471 | * Return "raw" intents, which is the original intents without the extras. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1472 | * @hide |
| 1473 | */ |
| 1474 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1475 | public Intent[] getIntentsNoExtras() { |
| 1476 | return mIntents; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1477 | } |
| 1478 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1479 | /** |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1480 | * Return the Persons set with {@link Builder#setPersons(Person[])}. |
| 1481 | * |
| 1482 | * @hide |
| 1483 | */ |
| 1484 | @Nullable |
| 1485 | public Person[] getPersons() { |
| 1486 | return clonePersons(mPersons); |
| 1487 | } |
| 1488 | |
| 1489 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1490 | * The extras in the intents. We convert extras into {@link PersistableBundle} so we can |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1491 | * persist them. |
| 1492 | * @hide |
| 1493 | */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1494 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1495 | public PersistableBundle[] getIntentPersistableExtrases() { |
| 1496 | return mIntentPersistableExtrases; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1497 | } |
| 1498 | |
Hakan Seyalioglu | 58fc95d | 2016-12-13 15:23:22 -0800 | [diff] [blame] | 1499 | /** |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1500 | * "Rank" of a shortcut, which is a non-negative, sequential value that's unique for each |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1501 | * {@link #getActivity} for each of the two types of shortcuts (static and dynamic). |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1502 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1503 | * <p>Because static shortcuts and dynamic shortcuts have overlapping ranks, |
| 1504 | * when a launcher app shows shortcuts for an activity, it should first show |
| 1505 | * the static shortcuts, followed by the dynamic shortcuts. Within each of those categories, |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1506 | * shortcuts should be sorted by rank in ascending order. |
| 1507 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1508 | * <p><em>Floating shortcuts</em>, or shortcuts that are neither static nor dynamic, will all |
| 1509 | * have rank 0, because they aren't sorted. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1510 | * |
| 1511 | * See the {@link ShortcutManager}'s class javadoc for details. |
| 1512 | * |
| 1513 | * @see Builder#setRank(int) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1514 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1515 | public int getRank() { |
| 1516 | return mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1517 | } |
| 1518 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1519 | /** @hide */ |
| 1520 | public boolean hasRank() { |
| 1521 | return mRank != RANK_NOT_SET; |
| 1522 | } |
| 1523 | |
| 1524 | /** @hide */ |
| 1525 | public void setRank(int rank) { |
| 1526 | mRank = rank; |
| 1527 | } |
| 1528 | |
| 1529 | /** @hide */ |
| 1530 | public void clearImplicitRankAndRankChangedFlag() { |
| 1531 | mImplicitRank = 0; |
| 1532 | } |
| 1533 | |
| 1534 | /** @hide */ |
| 1535 | public void setImplicitRank(int rank) { |
| 1536 | // Make sure to keep RANK_CHANGED_BIT. |
| 1537 | mImplicitRank = (mImplicitRank & RANK_CHANGED_BIT) | (rank & IMPLICIT_RANK_MASK); |
| 1538 | } |
| 1539 | |
| 1540 | /** @hide */ |
| 1541 | public int getImplicitRank() { |
| 1542 | return mImplicitRank & IMPLICIT_RANK_MASK; |
| 1543 | } |
| 1544 | |
| 1545 | /** @hide */ |
| 1546 | public void setRankChanged() { |
| 1547 | mImplicitRank |= RANK_CHANGED_BIT; |
| 1548 | } |
| 1549 | |
| 1550 | /** @hide */ |
| 1551 | public boolean isRankChanged() { |
| 1552 | return (mImplicitRank & RANK_CHANGED_BIT) != 0; |
| 1553 | } |
| 1554 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1555 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1556 | * Extras that the app can set for any purpose. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1557 | * |
| 1558 | * @see Builder#setExtras(PersistableBundle) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1559 | */ |
| 1560 | @Nullable |
| 1561 | public PersistableBundle getExtras() { |
| 1562 | return mExtras; |
| 1563 | } |
| 1564 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1565 | /** @hide */ |
| 1566 | public int getUserId() { |
| 1567 | return mUserId; |
| 1568 | } |
| 1569 | |
| 1570 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1571 | * {@link UserHandle} on which the publisher created this shortcut. |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1572 | */ |
| 1573 | public UserHandle getUserHandle() { |
| 1574 | return UserHandle.of(mUserId); |
| 1575 | } |
| 1576 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1577 | /** |
| 1578 | * Last time when any of the fields was updated. |
| 1579 | */ |
| 1580 | public long getLastChangedTimestamp() { |
| 1581 | return mLastChangedTimestamp; |
| 1582 | } |
| 1583 | |
| 1584 | /** @hide */ |
| 1585 | @ShortcutFlags |
| 1586 | public int getFlags() { |
| 1587 | return mFlags; |
| 1588 | } |
| 1589 | |
| 1590 | /** @hide*/ |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1591 | public void replaceFlags(@ShortcutFlags int flags) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1592 | mFlags = flags; |
| 1593 | } |
| 1594 | |
| 1595 | /** @hide*/ |
| 1596 | public void addFlags(@ShortcutFlags int flags) { |
| 1597 | mFlags |= flags; |
| 1598 | } |
| 1599 | |
| 1600 | /** @hide*/ |
| 1601 | public void clearFlags(@ShortcutFlags int flags) { |
| 1602 | mFlags &= ~flags; |
| 1603 | } |
| 1604 | |
| 1605 | /** @hide*/ |
| 1606 | public boolean hasFlags(@ShortcutFlags int flags) { |
| 1607 | return (mFlags & flags) == flags; |
| 1608 | } |
| 1609 | |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 1610 | /** @hide */ |
| 1611 | public boolean isReturnedByServer() { |
| 1612 | return hasFlags(FLAG_RETURNED_BY_SERVICE); |
| 1613 | } |
| 1614 | |
| 1615 | /** @hide */ |
| 1616 | public void setReturnedByServer() { |
| 1617 | addFlags(FLAG_RETURNED_BY_SERVICE); |
| 1618 | } |
| 1619 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1620 | /** @hide */ |
| 1621 | public boolean isLongLived() { |
| 1622 | return hasFlags(FLAG_LONG_LIVED); |
| 1623 | } |
| 1624 | |
| 1625 | /** @hide */ |
| 1626 | public void setLongLived() { |
| 1627 | addFlags(FLAG_LONG_LIVED); |
| 1628 | } |
| 1629 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1630 | /** Return whether a shortcut is dynamic. */ |
| 1631 | public boolean isDynamic() { |
| 1632 | return hasFlags(FLAG_DYNAMIC); |
| 1633 | } |
| 1634 | |
| 1635 | /** Return whether a shortcut is pinned. */ |
| 1636 | public boolean isPinned() { |
| 1637 | return hasFlags(FLAG_PINNED); |
| 1638 | } |
| 1639 | |
| 1640 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1641 | * Return whether a shortcut is static; that is, whether a shortcut is |
| 1642 | * published from AndroidManifest.xml. If {@code true}, the shortcut is |
| 1643 | * also {@link #isImmutable()}. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1644 | * |
| 1645 | * <p>When an app is upgraded and a shortcut is no longer published from AndroidManifest.xml, |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1646 | * this will be set to {@code false}. If the shortcut is not pinned, then it'll disappear. |
| 1647 | * However, if it's pinned, it will still be visible, {@link #isEnabled()} will be |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1648 | * {@code false} and {@link #isImmutable()} will be {@code true}. |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1649 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1650 | public boolean isDeclaredInManifest() { |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1651 | return hasFlags(FLAG_MANIFEST); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1654 | /** @hide kept for unit tests */ |
| 1655 | @Deprecated |
| 1656 | public boolean isManifestShortcut() { |
| 1657 | return isDeclaredInManifest(); |
| 1658 | } |
| 1659 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1660 | /** |
Makoto Onuki | 9fd9019 | 2017-01-06 18:31:03 +0000 | [diff] [blame] | 1661 | * @return true if pinned but neither static nor dynamic. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1662 | * @hide |
| 1663 | */ |
| 1664 | public boolean isFloating() { |
| 1665 | return isPinned() && !(isDynamic() || isManifestShortcut()); |
| 1666 | } |
| 1667 | |
| 1668 | /** @hide */ |
| 1669 | public boolean isOriginallyFromManifest() { |
| 1670 | return hasFlags(FLAG_IMMUTABLE); |
| 1671 | } |
| 1672 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1673 | /** @hide */ |
| 1674 | public boolean isDynamicVisible() { |
| 1675 | return isDynamic() && isVisibleToPublisher(); |
| 1676 | } |
| 1677 | |
| 1678 | /** @hide */ |
| 1679 | public boolean isPinnedVisible() { |
| 1680 | return isPinned() && isVisibleToPublisher(); |
| 1681 | } |
| 1682 | |
| 1683 | /** @hide */ |
| 1684 | public boolean isManifestVisible() { |
| 1685 | return isDeclaredInManifest() && isVisibleToPublisher(); |
| 1686 | } |
| 1687 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1688 | /** |
| 1689 | * Return if a shortcut is immutable, in which case it cannot be modified with any of |
| 1690 | * {@link ShortcutManager} APIs. |
| 1691 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1692 | * <p>All static shortcuts are immutable. When a static shortcut is pinned and is then |
| 1693 | * disabled because it doesn't appear in AndroidManifest.xml for a newer version of the |
| 1694 | * app, {@link #isDeclaredInManifest()} returns {@code false}, but the shortcut |
| 1695 | * is still immutable. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1696 | * |
| 1697 | * <p>All shortcuts originally published via the {@link ShortcutManager} APIs |
| 1698 | * are all mutable. |
| 1699 | */ |
| 1700 | public boolean isImmutable() { |
| 1701 | return hasFlags(FLAG_IMMUTABLE); |
| 1702 | } |
| 1703 | |
| 1704 | /** |
| 1705 | * Returns {@code false} if a shortcut is disabled with |
| 1706 | * {@link ShortcutManager#disableShortcuts}. |
| 1707 | */ |
| 1708 | public boolean isEnabled() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1709 | return !hasFlags(FLAG_DISABLED); |
| 1710 | } |
| 1711 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1712 | /** @hide */ |
| 1713 | public boolean isAlive() { |
| 1714 | return hasFlags(FLAG_PINNED) || hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST); |
| 1715 | } |
| 1716 | |
| 1717 | /** @hide */ |
| 1718 | public boolean usesQuota() { |
| 1719 | return hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST); |
| 1720 | } |
| 1721 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1722 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1723 | * Return whether a shortcut's icon is a resource in the owning package. |
| 1724 | * |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1725 | * @hide internal/unit tests only |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1726 | */ |
| 1727 | public boolean hasIconResource() { |
| 1728 | return hasFlags(FLAG_HAS_ICON_RES); |
| 1729 | } |
| 1730 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1731 | /** @hide */ |
| 1732 | public boolean hasStringResources() { |
| 1733 | return (mTitleResId != 0) || (mTextResId != 0) || (mDisabledMessageResId != 0); |
| 1734 | } |
| 1735 | |
| 1736 | /** @hide */ |
| 1737 | public boolean hasAnyResources() { |
| 1738 | return hasIconResource() || hasStringResources(); |
| 1739 | } |
| 1740 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1741 | /** |
| 1742 | * Return whether a shortcut's icon is stored as a file. |
| 1743 | * |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1744 | * @hide internal/unit tests only |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1745 | */ |
| 1746 | public boolean hasIconFile() { |
| 1747 | return hasFlags(FLAG_HAS_ICON_FILE); |
| 1748 | } |
| 1749 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1750 | /** |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 1751 | * Return whether a shortcut's icon is adaptive bitmap following design guideline |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 1752 | * defined in {@link android.graphics.drawable.AdaptiveIconDrawable}. |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1753 | * |
| 1754 | * @hide internal/unit tests only |
| 1755 | */ |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 1756 | public boolean hasAdaptiveBitmap() { |
| 1757 | return hasFlags(FLAG_ADAPTIVE_BITMAP); |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1758 | } |
| 1759 | |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 1760 | /** @hide */ |
| 1761 | public boolean isIconPendingSave() { |
| 1762 | return hasFlags(FLAG_ICON_FILE_PENDING_SAVE); |
| 1763 | } |
| 1764 | |
| 1765 | /** @hide */ |
| 1766 | public void setIconPendingSave() { |
| 1767 | addFlags(FLAG_ICON_FILE_PENDING_SAVE); |
| 1768 | } |
| 1769 | |
| 1770 | /** @hide */ |
| 1771 | public void clearIconPendingSave() { |
| 1772 | clearFlags(FLAG_ICON_FILE_PENDING_SAVE); |
| 1773 | } |
| 1774 | |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1775 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1776 | * When the system wasn't able to restore a shortcut, it'll still be registered to the system |
| 1777 | * but disabled, and such shortcuts will not be visible to the publisher. They're still visible |
| 1778 | * to launchers though. |
| 1779 | * |
| 1780 | * @hide |
| 1781 | */ |
| 1782 | @TestApi |
| 1783 | public boolean isVisibleToPublisher() { |
| 1784 | return !isDisabledForRestoreIssue(mDisabledReason); |
| 1785 | } |
| 1786 | |
| 1787 | /** |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1788 | * Return whether a shortcut only contains "key" information only or not. If true, only the |
| 1789 | * following fields are available. |
| 1790 | * <ul> |
| 1791 | * <li>{@link #getId()} |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1792 | * <li>{@link #getPackage()} |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 1793 | * <li>{@link #getActivity()} |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1794 | * <li>{@link #getLastChangedTimestamp()} |
| 1795 | * <li>{@link #isDynamic()} |
| 1796 | * <li>{@link #isPinned()} |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1797 | * <li>{@link #isDeclaredInManifest()} |
| 1798 | * <li>{@link #isImmutable()} |
| 1799 | * <li>{@link #isEnabled()} |
| 1800 | * <li>{@link #getUserHandle()} |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1801 | * </ul> |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1802 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1803 | * <p>For performance reasons, shortcuts passed to |
| 1804 | * {@link LauncherApps.Callback#onShortcutsChanged(String, List, UserHandle)} as well as those |
| 1805 | * returned from {@link LauncherApps#getShortcuts(ShortcutQuery, UserHandle)} |
| 1806 | * while using the {@link ShortcutQuery#FLAG_GET_KEY_FIELDS_ONLY} option contain only key |
| 1807 | * information. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1808 | */ |
| 1809 | public boolean hasKeyFieldsOnly() { |
| 1810 | return hasFlags(FLAG_KEY_FIELDS_ONLY); |
| 1811 | } |
| 1812 | |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1813 | /** @hide */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1814 | public boolean hasStringResourcesResolved() { |
| 1815 | return hasFlags(FLAG_STRINGS_RESOLVED); |
| 1816 | } |
| 1817 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1818 | /** @hide */ |
| 1819 | public void updateTimestamp() { |
| 1820 | mLastChangedTimestamp = System.currentTimeMillis(); |
| 1821 | } |
| 1822 | |
| 1823 | /** @hide */ |
| 1824 | // VisibleForTesting |
| 1825 | public void setTimestamp(long value) { |
| 1826 | mLastChangedTimestamp = value; |
| 1827 | } |
| 1828 | |
| 1829 | /** @hide */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1830 | public void clearIcon() { |
| 1831 | mIcon = null; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | /** @hide */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1835 | public void setIconResourceId(int iconResourceId) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1836 | if (mIconResId != iconResourceId) { |
| 1837 | mIconResName = null; |
| 1838 | } |
| 1839 | mIconResId = iconResourceId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1840 | } |
| 1841 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1842 | /** |
| 1843 | * Get the resource ID for the icon, valid only when {@link #hasIconResource()} } is true. |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1844 | * @hide internal / tests only. |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1845 | */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1846 | public int getIconResourceId() { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1847 | return mIconResId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1848 | } |
| 1849 | |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 1850 | /** |
| 1851 | * Bitmap path. Note this will be null even if {@link #hasIconFile()} is set when the save |
| 1852 | * is pending. Use {@link #isIconPendingSave()} to check it. |
| 1853 | * |
| 1854 | * @hide |
| 1855 | */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1856 | public String getBitmapPath() { |
| 1857 | return mBitmapPath; |
| 1858 | } |
| 1859 | |
| 1860 | /** @hide */ |
| 1861 | public void setBitmapPath(String bitmapPath) { |
| 1862 | mBitmapPath = bitmapPath; |
| 1863 | } |
| 1864 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1865 | /** @hide */ |
| 1866 | public void setDisabledMessageResId(int disabledMessageResId) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1867 | if (mDisabledMessageResId != disabledMessageResId) { |
| 1868 | mDisabledMessageResName = null; |
| 1869 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1870 | mDisabledMessageResId = disabledMessageResId; |
| 1871 | mDisabledMessage = null; |
| 1872 | } |
| 1873 | |
| 1874 | /** @hide */ |
| 1875 | public void setDisabledMessage(String disabledMessage) { |
| 1876 | mDisabledMessage = disabledMessage; |
| 1877 | mDisabledMessageResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1878 | mDisabledMessageResName = null; |
| 1879 | } |
| 1880 | |
| 1881 | /** @hide */ |
| 1882 | public String getTitleResName() { |
| 1883 | return mTitleResName; |
| 1884 | } |
| 1885 | |
| 1886 | /** @hide */ |
| 1887 | public void setTitleResName(String titleResName) { |
| 1888 | mTitleResName = titleResName; |
| 1889 | } |
| 1890 | |
| 1891 | /** @hide */ |
| 1892 | public String getTextResName() { |
| 1893 | return mTextResName; |
| 1894 | } |
| 1895 | |
| 1896 | /** @hide */ |
| 1897 | public void setTextResName(String textResName) { |
| 1898 | mTextResName = textResName; |
| 1899 | } |
| 1900 | |
| 1901 | /** @hide */ |
| 1902 | public String getDisabledMessageResName() { |
| 1903 | return mDisabledMessageResName; |
| 1904 | } |
| 1905 | |
| 1906 | /** @hide */ |
| 1907 | public void setDisabledMessageResName(String disabledMessageResName) { |
| 1908 | mDisabledMessageResName = disabledMessageResName; |
| 1909 | } |
| 1910 | |
| 1911 | /** @hide */ |
| 1912 | public String getIconResName() { |
| 1913 | return mIconResName; |
| 1914 | } |
| 1915 | |
| 1916 | /** @hide */ |
| 1917 | public void setIconResName(String iconResName) { |
| 1918 | mIconResName = iconResName; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1921 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1922 | * Replaces the intent. |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1923 | * |
| 1924 | * @throws IllegalArgumentException when extra is not compatible with {@link PersistableBundle}. |
| 1925 | * |
| 1926 | * @hide |
| 1927 | */ |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1928 | public void setIntents(Intent[] intents) throws IllegalArgumentException { |
| 1929 | Preconditions.checkNotNull(intents); |
| 1930 | Preconditions.checkArgument(intents.length > 0); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1931 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1932 | mIntents = cloneIntents(intents); |
| 1933 | fixUpIntentExtras(); |
| 1934 | } |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1935 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1936 | /** @hide */ |
| 1937 | public static Intent setIntentExtras(Intent intent, PersistableBundle extras) { |
| 1938 | if (extras == null) { |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1939 | intent.replaceExtras((Bundle) null); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1940 | } else { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1941 | intent.replaceExtras(new Bundle(extras)); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1942 | } |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1943 | return intent; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | /** |
| 1947 | * Replaces the categories. |
| 1948 | * |
| 1949 | * @hide |
| 1950 | */ |
| 1951 | public void setCategories(Set<String> categories) { |
| 1952 | mCategories = cloneCategories(categories); |
| 1953 | } |
| 1954 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1955 | private ShortcutInfo(Parcel source) { |
| 1956 | final ClassLoader cl = getClass().getClassLoader(); |
| 1957 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1958 | mUserId = source.readInt(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1959 | mId = source.readString(); |
| 1960 | mPackageName = source.readString(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1961 | mActivity = source.readParcelable(cl); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 1962 | mFlags = source.readInt(); |
| 1963 | mIconResId = source.readInt(); |
| 1964 | mLastChangedTimestamp = source.readLong(); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1965 | mDisabledReason = source.readInt(); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 1966 | |
| 1967 | if (source.readInt() == 0) { |
| 1968 | return; // key information only. |
| 1969 | } |
| 1970 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1971 | mIcon = source.readParcelable(cl); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1972 | mTitle = source.readCharSequence(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1973 | mTitleResId = source.readInt(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1974 | mText = source.readCharSequence(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1975 | mTextResId = source.readInt(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1976 | mDisabledMessage = source.readCharSequence(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1977 | mDisabledMessageResId = source.readInt(); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1978 | mIntents = source.readParcelableArray(cl, Intent.class); |
| 1979 | mIntentPersistableExtrases = source.readParcelableArray(cl, PersistableBundle.class); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1980 | mRank = source.readInt(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1981 | mExtras = source.readParcelable(cl); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1982 | mBitmapPath = source.readString(); |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 1983 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1984 | mIconResName = source.readString(); |
| 1985 | mTitleResName = source.readString(); |
| 1986 | mTextResName = source.readString(); |
| 1987 | mDisabledMessageResName = source.readString(); |
| 1988 | |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 1989 | int N = source.readInt(); |
| 1990 | if (N == 0) { |
| 1991 | mCategories = null; |
| 1992 | } else { |
| 1993 | mCategories = new ArraySet<>(N); |
| 1994 | for (int i = 0; i < N; i++) { |
| 1995 | mCategories.add(source.readString().intern()); |
| 1996 | } |
| 1997 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1998 | |
| 1999 | mPersons = source.readParcelableArray(cl, Person.class); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | @Override |
| 2003 | public void writeToParcel(Parcel dest, int flags) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 2004 | dest.writeInt(mUserId); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2005 | dest.writeString(mId); |
| 2006 | dest.writeString(mPackageName); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2007 | dest.writeParcelable(mActivity, flags); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 2008 | dest.writeInt(mFlags); |
| 2009 | dest.writeInt(mIconResId); |
| 2010 | dest.writeLong(mLastChangedTimestamp); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2011 | dest.writeInt(mDisabledReason); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 2012 | |
| 2013 | if (hasKeyFieldsOnly()) { |
| 2014 | dest.writeInt(0); |
| 2015 | return; |
| 2016 | } |
| 2017 | dest.writeInt(1); |
| 2018 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2019 | dest.writeParcelable(mIcon, flags); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2020 | dest.writeCharSequence(mTitle); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2021 | dest.writeInt(mTitleResId); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2022 | dest.writeCharSequence(mText); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2023 | dest.writeInt(mTextResId); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2024 | dest.writeCharSequence(mDisabledMessage); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2025 | dest.writeInt(mDisabledMessageResId); |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2026 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2027 | dest.writeParcelableArray(mIntents, flags); |
| 2028 | dest.writeParcelableArray(mIntentPersistableExtrases, flags); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2029 | dest.writeInt(mRank); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2030 | dest.writeParcelable(mExtras, flags); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2031 | dest.writeString(mBitmapPath); |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2032 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2033 | dest.writeString(mIconResName); |
| 2034 | dest.writeString(mTitleResName); |
| 2035 | dest.writeString(mTextResName); |
| 2036 | dest.writeString(mDisabledMessageResName); |
| 2037 | |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2038 | if (mCategories != null) { |
| 2039 | final int N = mCategories.size(); |
| 2040 | dest.writeInt(N); |
| 2041 | for (int i = 0; i < N; i++) { |
| 2042 | dest.writeString(mCategories.valueAt(i)); |
| 2043 | } |
| 2044 | } else { |
| 2045 | dest.writeInt(0); |
| 2046 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 2047 | |
| 2048 | dest.writeParcelableArray(mPersons, flags); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | public static final Creator<ShortcutInfo> CREATOR = |
| 2052 | new Creator<ShortcutInfo>() { |
| 2053 | public ShortcutInfo createFromParcel(Parcel source) { |
| 2054 | return new ShortcutInfo(source); |
| 2055 | } |
| 2056 | public ShortcutInfo[] newArray(int size) { |
| 2057 | return new ShortcutInfo[size]; |
| 2058 | } |
| 2059 | }; |
| 2060 | |
| 2061 | @Override |
| 2062 | public int describeContents() { |
| 2063 | return 0; |
| 2064 | } |
| 2065 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2066 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2067 | /** |
| 2068 | * Return a string representation, intended for logging. Some fields will be retracted. |
| 2069 | */ |
| 2070 | @Override |
| 2071 | public String toString() { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2072 | return toStringInner(/* secure =*/ true, /* includeInternalData =*/ false, |
| 2073 | /*indent=*/ null); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | /** @hide */ |
| 2077 | public String toInsecureString() { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2078 | return toStringInner(/* secure =*/ false, /* includeInternalData =*/ true, |
| 2079 | /*indent=*/ null); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2080 | } |
| 2081 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2082 | /** @hide */ |
| 2083 | public String toDumpString(String indent) { |
| 2084 | return toStringInner(/* secure =*/ false, /* includeInternalData =*/ true, indent); |
| 2085 | } |
| 2086 | |
| 2087 | private void addIndentOrComma(StringBuilder sb, String indent) { |
| 2088 | if (indent != null) { |
| 2089 | sb.append("\n "); |
| 2090 | sb.append(indent); |
| 2091 | } else { |
| 2092 | sb.append(", "); |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | private String toStringInner(boolean secure, boolean includeInternalData, String indent) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2097 | final StringBuilder sb = new StringBuilder(); |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2098 | |
| 2099 | if (indent != null) { |
| 2100 | sb.append(indent); |
| 2101 | } |
| 2102 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2103 | sb.append("ShortcutInfo {"); |
| 2104 | |
| 2105 | sb.append("id="); |
| 2106 | sb.append(secure ? "***" : mId); |
| 2107 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2108 | sb.append(", flags=0x"); |
| 2109 | sb.append(Integer.toHexString(mFlags)); |
| 2110 | sb.append(" ["); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2111 | if ((mFlags & FLAG_SHADOW) != 0) { |
| 2112 | // Note the shadow flag isn't actually used anywhere and it's just for dumpsys, so |
| 2113 | // we don't have an isXxx for this. |
| 2114 | sb.append("Sdw"); |
| 2115 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2116 | if (!isEnabled()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2117 | sb.append("Dis"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2118 | } |
| 2119 | if (isImmutable()) { |
| 2120 | sb.append("Im"); |
| 2121 | } |
| 2122 | if (isManifestShortcut()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2123 | sb.append("Man"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2124 | } |
| 2125 | if (isDynamic()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2126 | sb.append("Dyn"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2127 | } |
| 2128 | if (isPinned()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2129 | sb.append("Pin"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2130 | } |
| 2131 | if (hasIconFile()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2132 | sb.append("Ic-f"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2133 | } |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 2134 | if (isIconPendingSave()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2135 | sb.append("Pens"); |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 2136 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2137 | if (hasIconResource()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2138 | sb.append("Ic-r"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2139 | } |
| 2140 | if (hasKeyFieldsOnly()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2141 | sb.append("Key"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2142 | } |
| 2143 | if (hasStringResourcesResolved()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2144 | sb.append("Str"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2145 | } |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 2146 | if (isReturnedByServer()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2147 | sb.append("Rets"); |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 2148 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 2149 | if (isLongLived()) { |
| 2150 | sb.append("Liv"); |
| 2151 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2152 | sb.append("]"); |
| 2153 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2154 | addIndentOrComma(sb, indent); |
| 2155 | |
| 2156 | sb.append("packageName="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2157 | sb.append(mPackageName); |
| 2158 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2159 | addIndentOrComma(sb, indent); |
| 2160 | |
| 2161 | sb.append("activity="); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2162 | sb.append(mActivity); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2163 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2164 | addIndentOrComma(sb, indent); |
| 2165 | |
| 2166 | sb.append("shortLabel="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2167 | sb.append(secure ? "***" : mTitle); |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 2168 | sb.append(", resId="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2169 | sb.append(mTitleResId); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2170 | sb.append("["); |
| 2171 | sb.append(mTitleResName); |
| 2172 | sb.append("]"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2173 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2174 | addIndentOrComma(sb, indent); |
| 2175 | |
| 2176 | sb.append("longLabel="); |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 2177 | sb.append(secure ? "***" : mText); |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 2178 | sb.append(", resId="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2179 | sb.append(mTextResId); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2180 | sb.append("["); |
| 2181 | sb.append(mTextResName); |
| 2182 | sb.append("]"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2183 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2184 | addIndentOrComma(sb, indent); |
| 2185 | |
| 2186 | sb.append("disabledMessage="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2187 | sb.append(secure ? "***" : mDisabledMessage); |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 2188 | sb.append(", resId="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2189 | sb.append(mDisabledMessageResId); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2190 | sb.append("["); |
| 2191 | sb.append(mDisabledMessageResName); |
| 2192 | sb.append("]"); |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 2193 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2194 | addIndentOrComma(sb, indent); |
| 2195 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2196 | sb.append("disabledReason="); |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 2197 | sb.append(getDisabledReasonDebugString(mDisabledReason)); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2198 | |
| 2199 | addIndentOrComma(sb, indent); |
| 2200 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2201 | sb.append("categories="); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 2202 | sb.append(mCategories); |
| 2203 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2204 | addIndentOrComma(sb, indent); |
| 2205 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 2206 | sb.append("persons="); |
| 2207 | sb.append(mPersons); |
| 2208 | |
| 2209 | addIndentOrComma(sb, indent); |
| 2210 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2211 | sb.append("icon="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2212 | sb.append(mIcon); |
| 2213 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2214 | addIndentOrComma(sb, indent); |
| 2215 | |
| 2216 | sb.append("rank="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2217 | sb.append(mRank); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2218 | |
| 2219 | sb.append(", timestamp="); |
| 2220 | sb.append(mLastChangedTimestamp); |
| 2221 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2222 | addIndentOrComma(sb, indent); |
| 2223 | |
| 2224 | sb.append("intents="); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2225 | if (mIntents == null) { |
| 2226 | sb.append("null"); |
| 2227 | } else { |
| 2228 | if (secure) { |
| 2229 | sb.append("size:"); |
| 2230 | sb.append(mIntents.length); |
| 2231 | } else { |
| 2232 | final int size = mIntents.length; |
| 2233 | sb.append("["); |
| 2234 | String sep = ""; |
| 2235 | for (int i = 0; i < size; i++) { |
| 2236 | sb.append(sep); |
| 2237 | sep = ", "; |
| 2238 | sb.append(mIntents[i]); |
| 2239 | sb.append("/"); |
| 2240 | sb.append(mIntentPersistableExtrases[i]); |
| 2241 | } |
| 2242 | sb.append("]"); |
| 2243 | } |
| 2244 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2245 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2246 | addIndentOrComma(sb, indent); |
| 2247 | |
| 2248 | sb.append("extras="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2249 | sb.append(mExtras); |
| 2250 | |
| 2251 | if (includeInternalData) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2252 | addIndentOrComma(sb, indent); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2253 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2254 | sb.append("iconRes="); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2255 | sb.append(mIconResId); |
| 2256 | sb.append("["); |
| 2257 | sb.append(mIconResName); |
| 2258 | sb.append("]"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2259 | |
| 2260 | sb.append(", bitmapPath="); |
| 2261 | sb.append(mBitmapPath); |
| 2262 | } |
| 2263 | |
| 2264 | sb.append("}"); |
| 2265 | return sb.toString(); |
| 2266 | } |
| 2267 | |
| 2268 | /** @hide */ |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 2269 | public ShortcutInfo( |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2270 | @UserIdInt int userId, String id, String packageName, ComponentName activity, |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2271 | Icon icon, CharSequence title, int titleResId, String titleResName, |
| 2272 | CharSequence text, int textResId, String textResName, |
| 2273 | CharSequence disabledMessage, int disabledMessageResId, String disabledMessageResName, |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2274 | Set<String> categories, Intent[] intentsWithExtras, int rank, PersistableBundle extras, |
| 2275 | long lastChangedTimestamp, |
Mehdi Alizadeh | ebb4b60 | 2019-02-05 15:52:18 -0800 | [diff] [blame] | 2276 | int flags, int iconResId, String iconResName, String bitmapPath, int disabledReason, |
| 2277 | Person[] persons) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 2278 | mUserId = userId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2279 | mId = id; |
| 2280 | mPackageName = packageName; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2281 | mActivity = activity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2282 | mIcon = icon; |
| 2283 | mTitle = title; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2284 | mTitleResId = titleResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2285 | mTitleResName = titleResName; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 2286 | mText = text; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2287 | mTextResId = textResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2288 | mTextResName = textResName; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2289 | mDisabledMessage = disabledMessage; |
| 2290 | mDisabledMessageResId = disabledMessageResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2291 | mDisabledMessageResName = disabledMessageResName; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2292 | mCategories = cloneCategories(categories); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2293 | mIntents = cloneIntents(intentsWithExtras); |
| 2294 | fixUpIntentExtras(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2295 | mRank = rank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2296 | mExtras = extras; |
| 2297 | mLastChangedTimestamp = lastChangedTimestamp; |
| 2298 | mFlags = flags; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2299 | mIconResId = iconResId; |
| 2300 | mIconResName = iconResName; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2301 | mBitmapPath = bitmapPath; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2302 | mDisabledReason = disabledReason; |
Mehdi Alizadeh | ebb4b60 | 2019-02-05 15:52:18 -0800 | [diff] [blame] | 2303 | mPersons = persons; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2304 | } |
| 2305 | } |