Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41cce320 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Remove AndroidFuture from ShortcutService's internal api

AndroidFuture is not meant to be used as a return type, this CL removes
the cases where AndroidFuture is used as a return type.

After closely scrutinize some of the api are not required to be async
in system level to support AppSearch integration in the future.

Here's the list of API that can was previously made async at
service-level but could actually stay synchronous:
- setDynamicShortcuts/addDynamicShortcuts: Dynamic shortcuts are stored
in system ram only unless it is also a long-lived shortcut, yet long-lived
shortcuts are persisted into AppSearch in a separate background thread,
client process should not need to wait for writing to AppSearch to finish.

- updateShortcuts: Long-lived shortcuts that lives in AppSearch might
be updated by this api, but similar to
setDynamicShortcuts/addDynamicShortcuts client process is not required
to wait for writing to AppSearch to finish.

- removeDynamicShortcuts/removeAllDynamicShortcuts: The method signature
doesn't return anything in the first place, so client process is not
required to wait for AppSearch.

- disableShortcuts/enableShortcuts: Similarily, since the method
signature doesn't return anything, client process is not required to
wait for AppSearch.

- reportShortcutUsed/onApplicationActive/applyRestore: No return type.

- removeLongLivedShortcut: The operation itself should be async, but
since it has no return type, client process is not required to wait.

API that should become async at service level but remain sync in client
process are:
- requestPinShortcut: To support drag and drop from AllApps+, client
process should be waiting for the pin request to complete since
long-lived shortcuts that doesn't exists in system memory might still
be surfaced in AllApps+. Since read from AppSearch is async, the client
process will need to wait for the read to finish synchrounously.

- createShortcutResultIntent: Similarily, a client process might call
this api to launch a long-lived shortcut that doesn't exists in system
memory. So the client process needs to wait for read from AppSearch to
finish.

API that should be async but is not covered in this CL
- getShareTargets: Sharing shortcuts could be potentially backed up
long-lived shortcuts that doesn't live in system ram, but this api is
already being used by PeopleService, thus should be covered in a
separate CL as it would need to be reviewed by another team.

Bug: 197277083
Test: atest ShortcutManagerTest1 ShortcutManagerTest2 ShortcutManagerTest3 ShortcutManagerTest4 ShortcutManagerTest5 ShortcutManagerTest6 ShortcutManagerTest7 ShortcutManagerTest8 ShortcutManagerTest9 ShortcutManagerTest10 ShortcutManagerTest11
Test: atest CtsShortcutManagerTestCases
Change-Id: I8970cc77073d329fe00a349d9fa190f917b7851d
parent 9d64e822
Loading
Loading
Loading
Loading
+20 −22
Original line number Original line Diff line number Diff line
@@ -26,29 +26,28 @@ import com.android.internal.infra.AndroidFuture;
/** {@hide} */
/** {@hide} */
interface IShortcutService {
interface IShortcutService {


    AndroidFuture setDynamicShortcuts(String packageName,
    boolean setDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
            in ParceledListSlice shortcutInfoList, int userId);
            int userId);


    AndroidFuture addDynamicShortcuts(String packageName,
    boolean addDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
            in ParceledListSlice shortcutInfoList, int userId);
            int userId);


    AndroidFuture removeDynamicShortcuts(String packageName, in List shortcutIds, int userId);
    void removeDynamicShortcuts(String packageName, in List<String> shortcutIds, int userId);


    AndroidFuture removeAllDynamicShortcuts(String packageName, int userId);
    void removeAllDynamicShortcuts(String packageName, int userId);


    AndroidFuture updateShortcuts(String packageName, in ParceledListSlice shortcuts,
    boolean updateShortcuts(String packageName, in ParceledListSlice shortcuts, int userId);
            int userId);


    AndroidFuture requestPinShortcut(String packageName, in ShortcutInfo shortcut,
    void requestPinShortcut(String packageName, in ShortcutInfo shortcut,
            in IntentSender resultIntent, int userId);
            in IntentSender resultIntent, int userId, in AndroidFuture<String> ret);


    AndroidFuture<Intent> createShortcutResultIntent(String packageName, in ShortcutInfo shortcut,
    void createShortcutResultIntent(String packageName, in ShortcutInfo shortcut, int userId,
            int userId);
            in AndroidFuture<Intent> ret);


    AndroidFuture disableShortcuts(String packageName, in List shortcutIds,
    void disableShortcuts(String packageName, in List<String> shortcutIds,
            CharSequence disabledMessage, int disabledMessageResId, int userId);
            CharSequence disabledMessage, int disabledMessageResId, int userId);


    AndroidFuture enableShortcuts(String packageName, in List shortcutIds, int userId);
    void enableShortcuts(String packageName, in List<String> shortcutIds, int userId);


    int getMaxShortcutCountPerActivity(String packageName, int userId);
    int getMaxShortcutCountPerActivity(String packageName, int userId);


@@ -58,27 +57,26 @@ interface IShortcutService {


    int getIconMaxDimensions(String packageName, int userId);
    int getIconMaxDimensions(String packageName, int userId);


    AndroidFuture reportShortcutUsed(String packageName, String shortcutId, int userId);
    void reportShortcutUsed(String packageName, String shortcutId, int userId);


    void resetThrottling(); // system only API for developer opsions
    void resetThrottling(); // system only API for developer opsions


    AndroidFuture onApplicationActive(String packageName, int userId); // system only API for sysUI
    void onApplicationActive(String packageName, int userId); // system only API for sysUI


    byte[] getBackupPayload(int user);
    byte[] getBackupPayload(int user);


    AndroidFuture applyRestore(in byte[] payload, int user);
    void applyRestore(in byte[] payload, int user);


    boolean isRequestPinItemSupported(int user, int requestType);
    boolean isRequestPinItemSupported(int user, int requestType);


    // System API used by framework's ShareSheet (ChooserActivity)
    // System API used by framework's ShareSheet (ChooserActivity)
    AndroidFuture<ParceledListSlice> getShareTargets(String packageName, in IntentFilter filter,
    ParceledListSlice getShareTargets(String packageName, in IntentFilter filter, int userId);
            int userId);


    boolean hasShareTargets(String packageName, String packageToCheck, int userId);
    boolean hasShareTargets(String packageName, String packageToCheck, int userId);


    AndroidFuture removeLongLivedShortcuts(String packageName, in List shortcutIds, int userId);
    void removeLongLivedShortcuts(String packageName, in List<String> shortcutIds, int userId);


    AndroidFuture<ParceledListSlice> getShortcuts(String packageName, int matchFlags, int userId);
    ParceledListSlice getShortcuts(String packageName, int matchFlags, int userId);


    AndroidFuture pushDynamicShortcut(String packageName, in ShortcutInfo shortcut, int userId);
    void pushDynamicShortcut(String packageName, in ShortcutInfo shortcut, int userId);
}
}
+39 −41
Original line number Original line Diff line number Diff line
@@ -145,9 +145,8 @@ public class ShortcutManager {
    @WorkerThread
    @WorkerThread
    public boolean setDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
    public boolean setDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
        try {
        try {
            return ((boolean) getFutureOrThrow(mService.setDynamicShortcuts(
            return mService.setDynamicShortcuts(mContext.getPackageName(), new ParceledListSlice(
                    mContext.getPackageName(), new ParceledListSlice(
                    shortcutInfoList), injectMyUserId());
                            shortcutInfoList), injectMyUserId())));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -166,8 +165,8 @@ public class ShortcutManager {
    @NonNull
    @NonNull
    public List<ShortcutInfo> getDynamicShortcuts() {
    public List<ShortcutInfo> getDynamicShortcuts() {
        try {
        try {
            return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(),
            return mService.getShortcuts(mContext.getPackageName(),
                    FLAG_MATCH_DYNAMIC, injectMyUserId())).getList();
                    FLAG_MATCH_DYNAMIC, injectMyUserId()).getList();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -186,8 +185,8 @@ public class ShortcutManager {
    @NonNull
    @NonNull
    public List<ShortcutInfo> getManifestShortcuts() {
    public List<ShortcutInfo> getManifestShortcuts() {
        try {
        try {
            return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(),
            return mService.getShortcuts(mContext.getPackageName(),
                    FLAG_MATCH_MANIFEST, injectMyUserId())).getList();
                    FLAG_MATCH_MANIFEST, injectMyUserId()).getList();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -215,8 +214,8 @@ public class ShortcutManager {
    @NonNull
    @NonNull
    public List<ShortcutInfo> getShortcuts(@ShortcutMatchFlags int matchFlags) {
    public List<ShortcutInfo> getShortcuts(@ShortcutMatchFlags int matchFlags) {
        try {
        try {
            return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(), matchFlags,
            return mService.getShortcuts(mContext.getPackageName(), matchFlags,
                    injectMyUserId())).getList();
                    injectMyUserId()).getList();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -238,9 +237,8 @@ public class ShortcutManager {
    @WorkerThread
    @WorkerThread
    public boolean addDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
    public boolean addDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
        try {
        try {
            return (boolean) getFutureOrThrow(mService.addDynamicShortcuts(
            return mService.addDynamicShortcuts(mContext.getPackageName(),
                    mContext.getPackageName(), new ParceledListSlice(shortcutInfoList),
                    new ParceledListSlice(shortcutInfoList), injectMyUserId());
                    injectMyUserId()));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -253,8 +251,8 @@ public class ShortcutManager {
     */
     */
    public void removeDynamicShortcuts(@NonNull List<String> shortcutIds) {
    public void removeDynamicShortcuts(@NonNull List<String> shortcutIds) {
        try {
        try {
            getFutureOrThrow(mService.removeDynamicShortcuts(mContext.getPackageName(), shortcutIds,
            mService.removeDynamicShortcuts(mContext.getPackageName(), shortcutIds,
                    injectMyUserId()));
                    injectMyUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -267,8 +265,7 @@ public class ShortcutManager {
     */
     */
    public void removeAllDynamicShortcuts() {
    public void removeAllDynamicShortcuts() {
        try {
        try {
            getFutureOrThrow(mService.removeAllDynamicShortcuts(mContext.getPackageName(),
            mService.removeAllDynamicShortcuts(mContext.getPackageName(), injectMyUserId());
                    injectMyUserId()));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -281,8 +278,8 @@ public class ShortcutManager {
     */
     */
    public void removeLongLivedShortcuts(@NonNull List<String> shortcutIds) {
    public void removeLongLivedShortcuts(@NonNull List<String> shortcutIds) {
        try {
        try {
            getFutureOrThrow(mService.removeLongLivedShortcuts(mContext.getPackageName(),
            mService.removeLongLivedShortcuts(mContext.getPackageName(), shortcutIds,
                    shortcutIds, injectMyUserId()));
                    injectMyUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -301,8 +298,8 @@ public class ShortcutManager {
    @NonNull
    @NonNull
    public List<ShortcutInfo> getPinnedShortcuts() {
    public List<ShortcutInfo> getPinnedShortcuts() {
        try {
        try {
            return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(),
            return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_PINNED,
                    FLAG_MATCH_PINNED, injectMyUserId())).getList();
                    injectMyUserId()).getList();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -323,8 +320,8 @@ public class ShortcutManager {
    @WorkerThread
    @WorkerThread
    public boolean updateShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
    public boolean updateShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
        try {
        try {
            return (boolean) getFutureOrThrow(mService.updateShortcuts(mContext.getPackageName(),
            return mService.updateShortcuts(mContext.getPackageName(),
                    new ParceledListSlice(shortcutInfoList), injectMyUserId()));
                    new ParceledListSlice(shortcutInfoList), injectMyUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -341,9 +338,9 @@ public class ShortcutManager {
     */
     */
    public void disableShortcuts(@NonNull List<String> shortcutIds) {
    public void disableShortcuts(@NonNull List<String> shortcutIds) {
        try {
        try {
            getFutureOrThrow(mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
            mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
                    /* disabledMessage =*/ null, /* disabledMessageResId =*/ 0,
                    /* disabledMessage =*/ null, /* disabledMessageResId =*/ 0,
                    injectMyUserId()));
                    injectMyUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -354,9 +351,9 @@ public class ShortcutManager {
     */
     */
    public void disableShortcuts(@NonNull List<String> shortcutIds, int disabledMessageResId) {
    public void disableShortcuts(@NonNull List<String> shortcutIds, int disabledMessageResId) {
        try {
        try {
            getFutureOrThrow(mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
            mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
                    /* disabledMessage =*/ null, disabledMessageResId,
                    /* disabledMessage =*/ null, disabledMessageResId,
                    injectMyUserId()));
                    injectMyUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -382,9 +379,9 @@ public class ShortcutManager {
     */
     */
    public void disableShortcuts(@NonNull List<String> shortcutIds, CharSequence disabledMessage) {
    public void disableShortcuts(@NonNull List<String> shortcutIds, CharSequence disabledMessage) {
        try {
        try {
            getFutureOrThrow(mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
            mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
                    disabledMessage, /* disabledMessageResId =*/ 0,
                    disabledMessage, /* disabledMessageResId =*/ 0,
                    injectMyUserId()));
                    injectMyUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -400,8 +397,7 @@ public class ShortcutManager {
     */
     */
    public void enableShortcuts(@NonNull List<String> shortcutIds) {
    public void enableShortcuts(@NonNull List<String> shortcutIds) {
        try {
        try {
            getFutureOrThrow(mService.enableShortcuts(
            mService.enableShortcuts(mContext.getPackageName(), shortcutIds, injectMyUserId());
                    mContext.getPackageName(), shortcutIds, injectMyUserId()));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -522,8 +518,7 @@ public class ShortcutManager {
     */
     */
    public void reportShortcutUsed(String shortcutId) {
    public void reportShortcutUsed(String shortcutId) {
        try {
        try {
            getFutureOrThrow(mService.reportShortcutUsed(mContext.getPackageName(), shortcutId,
            mService.reportShortcutUsed(mContext.getPackageName(), shortcutId, injectMyUserId());
                    injectMyUserId()));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -601,8 +596,10 @@ public class ShortcutManager {
    public boolean requestPinShortcut(@NonNull ShortcutInfo shortcut,
    public boolean requestPinShortcut(@NonNull ShortcutInfo shortcut,
            @Nullable IntentSender resultIntent) {
            @Nullable IntentSender resultIntent) {
        try {
        try {
            return (boolean) getFutureOrThrow(mService.requestPinShortcut(mContext.getPackageName(),
            AndroidFuture<String> ret = new AndroidFuture<>();
                    shortcut, resultIntent, injectMyUserId()));
            mService.requestPinShortcut(mContext.getPackageName(), shortcut, resultIntent,
                    injectMyUserId(), ret);
            return Boolean.parseBoolean(getFutureOrThrow(ret));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -627,9 +624,11 @@ public class ShortcutManager {
     */
     */
    @WorkerThread
    @WorkerThread
    public Intent createShortcutResultIntent(@NonNull ShortcutInfo shortcut) {
    public Intent createShortcutResultIntent(@NonNull ShortcutInfo shortcut) {
        final AndroidFuture<Intent> ret = new AndroidFuture<>();
        try {
        try {
            return getFutureOrThrow(mService.createShortcutResultIntent(mContext.getPackageName(),
            mService.createShortcutResultIntent(mContext.getPackageName(),
                    shortcut, injectMyUserId()));
                    shortcut, injectMyUserId(), ret);
            return getFutureOrThrow(ret);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -645,7 +644,7 @@ public class ShortcutManager {
     */
     */
    public void onApplicationActive(@NonNull String packageName, @UserIdInt int userId) {
    public void onApplicationActive(@NonNull String packageName, @UserIdInt int userId) {
        try {
        try {
            getFutureOrThrow(mService.onApplicationActive(packageName, userId));
            mService.onApplicationActive(packageName, userId);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -671,8 +670,8 @@ public class ShortcutManager {
    @RequiresPermission(Manifest.permission.MANAGE_APP_PREDICTIONS)
    @RequiresPermission(Manifest.permission.MANAGE_APP_PREDICTIONS)
    public List<ShareShortcutInfo> getShareTargets(@NonNull IntentFilter filter) {
    public List<ShareShortcutInfo> getShareTargets(@NonNull IntentFilter filter) {
        try {
        try {
            return getFutureOrThrow(mService.getShareTargets(mContext.getPackageName(), filter,
            return mService.getShareTargets(
                    injectMyUserId())).getList();
                    mContext.getPackageName(), filter, injectMyUserId()).getList();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -782,8 +781,7 @@ public class ShortcutManager {
     */
     */
    public void pushDynamicShortcut(@NonNull ShortcutInfo shortcut) {
    public void pushDynamicShortcut(@NonNull ShortcutInfo shortcut) {
        try {
        try {
            getFutureOrThrow(mService.pushDynamicShortcut(
            mService.pushDynamicShortcut(mContext.getPackageName(), shortcut, injectMyUserId());
                    mContext.getPackageName(), shortcut, injectMyUserId()));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+455 −744

File changed.

Preview size limit exceeded, changes collapsed.