Merge "Show warning log when ShortcutInfo is re-published" into oc-dev

am: 9ccb15a351

Change-Id: I7f246f362b6e8d124416db790e4856e52baa21b8
This commit is contained in:
Makoto Onuki
2017-05-05 20:16:49 +00:00
committed by android-build-merger
4 changed files with 90 additions and 4 deletions

View File

@@ -23,7 +23,6 @@ import android.app.TaskStackBuilder;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
@@ -95,6 +94,9 @@ public final class ShortcutInfo implements Parcelable {
/** @hide */
public static final int FLAG_ADAPTIVE_BITMAP = 1 << 9;
/** @hide */
public static final int FLAG_RETURNED_BY_SERVICE = 1 << 10;
/** @hide */
@IntDef(flag = true,
value = {
@@ -108,6 +110,7 @@ public final class ShortcutInfo implements Parcelable {
FLAG_STRINGS_RESOLVED,
FLAG_IMMUTABLE,
FLAG_ADAPTIVE_BITMAP,
FLAG_RETURNED_BY_SERVICE
})
@Retention(RetentionPolicy.SOURCE)
public @interface ShortcutFlags {}
@@ -1343,6 +1346,16 @@ public final class ShortcutInfo implements Parcelable {
return (mFlags & flags) == flags;
}
/** @hide */
public boolean isReturnedByServer() {
return hasFlags(FLAG_RETURNED_BY_SERVICE);
}
/** @hide */
public void setReturnedByServer() {
addFlags(FLAG_RETURNED_BY_SERVICE);
}
/** Return whether a shortcut is dynamic. */
public boolean isDynamic() {
return hasFlags(FLAG_DYNAMIC);
@@ -1450,7 +1463,7 @@ public final class ShortcutInfo implements Parcelable {
/**
* Return whether a shortcut's icon is adaptive bitmap following design guideline
* defined in {@link AdaptiveIconDrawable}.
* defined in {@link android.graphics.drawable.AdaptiveIconDrawable}.
*
* @hide internal/unit tests only
*/
@@ -1776,6 +1789,9 @@ public final class ShortcutInfo implements Parcelable {
if (hasStringResourcesResolved()) {
sb.append("Sr");
}
if (isReturnedByServer()) {
sb.append("V");
}
sb.append("]");
sb.append(", packageName=");

View File

@@ -618,6 +618,10 @@ public class ShortcutManager {
/**
* Return all dynamic shortcuts from the caller app.
*
* <p>This API is intended to be used for examining what shortcuts are currently published.
* Re-publishing returned {@link ShortcutInfo}s via APIs such as
* {@link #setDynamicShortcuts(List)} may cause loss of information such as icons.
*
* @throws IllegalStateException when the user is locked.
*/
@NonNull
@@ -633,6 +637,10 @@ public class ShortcutManager {
/**
* Return all static (manifest) shortcuts from the caller app.
*
* <p>This API is intended to be used for examining what shortcuts are currently published.
* Re-publishing returned {@link ShortcutInfo}s via APIs such as
* {@link #setDynamicShortcuts(List)} may cause loss of information such as icons.
*
* @throws IllegalStateException when the user is locked.
*/
@NonNull
@@ -697,6 +705,10 @@ public class ShortcutManager {
/**
* Return all pinned shortcuts from the caller app.
*
* <p>This API is intended to be used for examining what shortcuts are currently published.
* Re-publishing returned {@link ShortcutInfo}s via APIs such as
* {@link #setDynamicShortcuts(List)} may cause loss of information such as icons.
*
* @throws IllegalStateException when the user is locked.
*/
@NonNull

View File

@@ -1611,6 +1611,11 @@ public class ShortcutService extends IShortcutService.Stub {
*/
private void fixUpIncomingShortcutInfo(@NonNull ShortcutInfo shortcut, boolean forUpdate,
boolean forPinRequest) {
if (shortcut.isReturnedByServer()) {
Log.w(TAG,
"Re-publishing ShortcutInfo returned by server is not supported."
+ " Some information such as icon may lost from shortcut.");
}
Preconditions.checkNotNull(shortcut, "Null shortcut detected");
if (shortcut.getActivity() != null) {
Preconditions.checkState(
@@ -1670,6 +1675,13 @@ public class ShortcutService extends IShortcutService.Stub {
}
}
private List<ShortcutInfo> setReturnedByServer(List<ShortcutInfo> shortcuts) {
for (int i = shortcuts.size() - 1; i >= 0; i--) {
shortcuts.get(i).setReturnedByServer();
}
return shortcuts;
}
// === APIs ===
@Override
@@ -2049,7 +2061,7 @@ public class ShortcutService extends IShortcutService.Stub {
final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);
ps.findAll(ret, query, cloneFlags);
return new ParceledListSlice<>(ret);
return new ParceledListSlice<>(setReturnedByServer(ret));
}
@Override
@@ -2406,7 +2418,7 @@ public class ShortcutService extends IShortcutService.Stub {
});
}
}
return ret;
return setReturnedByServer(ret);
}
private void getShortcutsInnerLocked(int launcherUserId, @NonNull String callingPackage,

View File

@@ -7399,4 +7399,50 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
"s21", "s22");
});
}
public void testReturnedByServer() {
// Package 1 updated, with manifest shortcuts.
addManifestShortcutResource(
new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()),
R.xml.shortcut_1);
updatePackageVersion(CALLING_PACKAGE_1, 1);
mService.mPackageMonitor.onReceive(getTestContext(),
genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
assertWith(mManager.getManifestShortcuts())
.haveIds("ms1")
.forAllShortcuts(si -> assertTrue(si.isReturnedByServer()));
assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1"))));
assertWith(mManager.getDynamicShortcuts())
.haveIds("s1")
.forAllShortcuts(si -> assertTrue(si.isReturnedByServer()));
});
// Pin them.
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
list("ms1", "s1"), getCallingUser());
assertWith(getShortcutAsLauncher(USER_0))
.haveIds("ms1", "s1")
.forAllShortcuts(si -> assertTrue(si.isReturnedByServer()));
});
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
assertWith(mManager.getPinnedShortcuts())
.haveIds("ms1", "s1")
.forAllShortcuts(si -> assertTrue(si.isReturnedByServer()));
});
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
// This shows a warning log, but should still work.
assertTrue(mManager.setDynamicShortcuts(mManager.getDynamicShortcuts()));
assertWith(mManager.getDynamicShortcuts())
.haveIds("s1")
.forAllShortcuts(si -> assertTrue(si.isReturnedByServer()));
});
}
}