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
This commit is contained in:
@@ -26,29 +26,28 @@ import com.android.internal.infra.AndroidFuture;
|
||||
/** {@hide} */
|
||||
interface IShortcutService {
|
||||
|
||||
AndroidFuture setDynamicShortcuts(String packageName,
|
||||
in ParceledListSlice shortcutInfoList, int userId);
|
||||
|
||||
AndroidFuture addDynamicShortcuts(String packageName,
|
||||
in ParceledListSlice shortcutInfoList, int userId);
|
||||
|
||||
AndroidFuture removeDynamicShortcuts(String packageName, in List shortcutIds, int userId);
|
||||
|
||||
AndroidFuture removeAllDynamicShortcuts(String packageName, int userId);
|
||||
|
||||
AndroidFuture updateShortcuts(String packageName, in ParceledListSlice shortcuts,
|
||||
boolean setDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
|
||||
int userId);
|
||||
|
||||
AndroidFuture requestPinShortcut(String packageName, in ShortcutInfo shortcut,
|
||||
in IntentSender resultIntent, int userId);
|
||||
|
||||
AndroidFuture<Intent> createShortcutResultIntent(String packageName, in ShortcutInfo shortcut,
|
||||
boolean addDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
|
||||
int userId);
|
||||
|
||||
AndroidFuture disableShortcuts(String packageName, in List shortcutIds,
|
||||
void removeDynamicShortcuts(String packageName, in List<String> shortcutIds, int userId);
|
||||
|
||||
void removeAllDynamicShortcuts(String packageName, int userId);
|
||||
|
||||
boolean updateShortcuts(String packageName, in ParceledListSlice shortcuts, int userId);
|
||||
|
||||
void requestPinShortcut(String packageName, in ShortcutInfo shortcut,
|
||||
in IntentSender resultIntent, int userId, in AndroidFuture<String> ret);
|
||||
|
||||
void createShortcutResultIntent(String packageName, in ShortcutInfo shortcut, int userId,
|
||||
in AndroidFuture<Intent> ret);
|
||||
|
||||
void disableShortcuts(String packageName, in List<String> shortcutIds,
|
||||
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);
|
||||
|
||||
@@ -58,27 +57,26 @@ interface IShortcutService {
|
||||
|
||||
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
|
||||
|
||||
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);
|
||||
|
||||
AndroidFuture applyRestore(in byte[] payload, int user);
|
||||
void applyRestore(in byte[] payload, int user);
|
||||
|
||||
boolean isRequestPinItemSupported(int user, int requestType);
|
||||
|
||||
// System API used by framework's ShareSheet (ChooserActivity)
|
||||
AndroidFuture<ParceledListSlice> getShareTargets(String packageName, in IntentFilter filter,
|
||||
int userId);
|
||||
ParceledListSlice getShareTargets(String packageName, in IntentFilter filter, 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);
|
||||
}
|
||||
|
||||
@@ -145,9 +145,8 @@ public class ShortcutManager {
|
||||
@WorkerThread
|
||||
public boolean setDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
|
||||
try {
|
||||
return ((boolean) getFutureOrThrow(mService.setDynamicShortcuts(
|
||||
mContext.getPackageName(), new ParceledListSlice(
|
||||
shortcutInfoList), injectMyUserId())));
|
||||
return mService.setDynamicShortcuts(mContext.getPackageName(), new ParceledListSlice(
|
||||
shortcutInfoList), injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -166,8 +165,8 @@ public class ShortcutManager {
|
||||
@NonNull
|
||||
public List<ShortcutInfo> getDynamicShortcuts() {
|
||||
try {
|
||||
return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(),
|
||||
FLAG_MATCH_DYNAMIC, injectMyUserId())).getList();
|
||||
return mService.getShortcuts(mContext.getPackageName(),
|
||||
FLAG_MATCH_DYNAMIC, injectMyUserId()).getList();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -186,8 +185,8 @@ public class ShortcutManager {
|
||||
@NonNull
|
||||
public List<ShortcutInfo> getManifestShortcuts() {
|
||||
try {
|
||||
return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(),
|
||||
FLAG_MATCH_MANIFEST, injectMyUserId())).getList();
|
||||
return mService.getShortcuts(mContext.getPackageName(),
|
||||
FLAG_MATCH_MANIFEST, injectMyUserId()).getList();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -215,8 +214,8 @@ public class ShortcutManager {
|
||||
@NonNull
|
||||
public List<ShortcutInfo> getShortcuts(@ShortcutMatchFlags int matchFlags) {
|
||||
try {
|
||||
return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(), matchFlags,
|
||||
injectMyUserId())).getList();
|
||||
return mService.getShortcuts(mContext.getPackageName(), matchFlags,
|
||||
injectMyUserId()).getList();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -238,9 +237,8 @@ public class ShortcutManager {
|
||||
@WorkerThread
|
||||
public boolean addDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
|
||||
try {
|
||||
return (boolean) getFutureOrThrow(mService.addDynamicShortcuts(
|
||||
mContext.getPackageName(), new ParceledListSlice(shortcutInfoList),
|
||||
injectMyUserId()));
|
||||
return mService.addDynamicShortcuts(mContext.getPackageName(),
|
||||
new ParceledListSlice(shortcutInfoList), injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -253,8 +251,8 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void removeDynamicShortcuts(@NonNull List<String> shortcutIds) {
|
||||
try {
|
||||
getFutureOrThrow(mService.removeDynamicShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
injectMyUserId()));
|
||||
mService.removeDynamicShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -267,8 +265,7 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void removeAllDynamicShortcuts() {
|
||||
try {
|
||||
getFutureOrThrow(mService.removeAllDynamicShortcuts(mContext.getPackageName(),
|
||||
injectMyUserId()));
|
||||
mService.removeAllDynamicShortcuts(mContext.getPackageName(), injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -281,8 +278,8 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void removeLongLivedShortcuts(@NonNull List<String> shortcutIds) {
|
||||
try {
|
||||
getFutureOrThrow(mService.removeLongLivedShortcuts(mContext.getPackageName(),
|
||||
shortcutIds, injectMyUserId()));
|
||||
mService.removeLongLivedShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -301,8 +298,8 @@ public class ShortcutManager {
|
||||
@NonNull
|
||||
public List<ShortcutInfo> getPinnedShortcuts() {
|
||||
try {
|
||||
return getFutureOrThrow(mService.getShortcuts(mContext.getPackageName(),
|
||||
FLAG_MATCH_PINNED, injectMyUserId())).getList();
|
||||
return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_PINNED,
|
||||
injectMyUserId()).getList();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -323,8 +320,8 @@ public class ShortcutManager {
|
||||
@WorkerThread
|
||||
public boolean updateShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
|
||||
try {
|
||||
return (boolean) getFutureOrThrow(mService.updateShortcuts(mContext.getPackageName(),
|
||||
new ParceledListSlice(shortcutInfoList), injectMyUserId()));
|
||||
return mService.updateShortcuts(mContext.getPackageName(),
|
||||
new ParceledListSlice(shortcutInfoList), injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -341,9 +338,9 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void disableShortcuts(@NonNull List<String> shortcutIds) {
|
||||
try {
|
||||
getFutureOrThrow(mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
/* disabledMessage =*/ null, /* disabledMessageResId =*/ 0,
|
||||
injectMyUserId()));
|
||||
injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -354,9 +351,9 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void disableShortcuts(@NonNull List<String> shortcutIds, int disabledMessageResId) {
|
||||
try {
|
||||
getFutureOrThrow(mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
/* disabledMessage =*/ null, disabledMessageResId,
|
||||
injectMyUserId()));
|
||||
injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -382,9 +379,9 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void disableShortcuts(@NonNull List<String> shortcutIds, CharSequence disabledMessage) {
|
||||
try {
|
||||
getFutureOrThrow(mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
mService.disableShortcuts(mContext.getPackageName(), shortcutIds,
|
||||
disabledMessage, /* disabledMessageResId =*/ 0,
|
||||
injectMyUserId()));
|
||||
injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -400,8 +397,7 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void enableShortcuts(@NonNull List<String> shortcutIds) {
|
||||
try {
|
||||
getFutureOrThrow(mService.enableShortcuts(
|
||||
mContext.getPackageName(), shortcutIds, injectMyUserId()));
|
||||
mService.enableShortcuts(mContext.getPackageName(), shortcutIds, injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -522,8 +518,7 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void reportShortcutUsed(String shortcutId) {
|
||||
try {
|
||||
getFutureOrThrow(mService.reportShortcutUsed(mContext.getPackageName(), shortcutId,
|
||||
injectMyUserId()));
|
||||
mService.reportShortcutUsed(mContext.getPackageName(), shortcutId, injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -601,8 +596,10 @@ public class ShortcutManager {
|
||||
public boolean requestPinShortcut(@NonNull ShortcutInfo shortcut,
|
||||
@Nullable IntentSender resultIntent) {
|
||||
try {
|
||||
return (boolean) getFutureOrThrow(mService.requestPinShortcut(mContext.getPackageName(),
|
||||
shortcut, resultIntent, injectMyUserId()));
|
||||
AndroidFuture<String> ret = new AndroidFuture<>();
|
||||
mService.requestPinShortcut(mContext.getPackageName(), shortcut, resultIntent,
|
||||
injectMyUserId(), ret);
|
||||
return Boolean.parseBoolean(getFutureOrThrow(ret));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -627,9 +624,11 @@ public class ShortcutManager {
|
||||
*/
|
||||
@WorkerThread
|
||||
public Intent createShortcutResultIntent(@NonNull ShortcutInfo shortcut) {
|
||||
final AndroidFuture<Intent> ret = new AndroidFuture<>();
|
||||
try {
|
||||
return getFutureOrThrow(mService.createShortcutResultIntent(mContext.getPackageName(),
|
||||
shortcut, injectMyUserId()));
|
||||
mService.createShortcutResultIntent(mContext.getPackageName(),
|
||||
shortcut, injectMyUserId(), ret);
|
||||
return getFutureOrThrow(ret);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -645,7 +644,7 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void onApplicationActive(@NonNull String packageName, @UserIdInt int userId) {
|
||||
try {
|
||||
getFutureOrThrow(mService.onApplicationActive(packageName, userId));
|
||||
mService.onApplicationActive(packageName, userId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -671,8 +670,8 @@ public class ShortcutManager {
|
||||
@RequiresPermission(Manifest.permission.MANAGE_APP_PREDICTIONS)
|
||||
public List<ShareShortcutInfo> getShareTargets(@NonNull IntentFilter filter) {
|
||||
try {
|
||||
return getFutureOrThrow(mService.getShareTargets(mContext.getPackageName(), filter,
|
||||
injectMyUserId())).getList();
|
||||
return mService.getShareTargets(
|
||||
mContext.getPackageName(), filter, injectMyUserId()).getList();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -782,8 +781,7 @@ public class ShortcutManager {
|
||||
*/
|
||||
public void pushDynamicShortcut(@NonNull ShortcutInfo shortcut) {
|
||||
try {
|
||||
getFutureOrThrow(mService.pushDynamicShortcut(
|
||||
mContext.getPackageName(), shortcut, injectMyUserId()));
|
||||
mService.pushDynamicShortcut(mContext.getPackageName(), shortcut, injectMyUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user