Merge "Shortcut integration with AppSearch (part 4)" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-03-05 23:31:59 +00:00
committed by Android (Google) Code Review
5 changed files with 158 additions and 93 deletions

View File

@@ -21,32 +21,34 @@ import android.content.IntentSender;
import android.content.pm.ParceledListSlice;
import android.content.pm.ShortcutInfo;
/**
* {@hide}
*/
import com.android.internal.infra.AndroidFuture;
/** {@hide} */
interface IShortcutService {
boolean setDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
int userId);
oneway void setDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
int userId, in AndroidFuture callback);
boolean addDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
int userId);
oneway void addDynamicShortcuts(String packageName, in ParceledListSlice shortcutInfoList,
int userId, in AndroidFuture callback);
void removeDynamicShortcuts(String packageName, in List shortcutIds, int userId);
oneway void removeDynamicShortcuts(String packageName, in List shortcutIds, int userId);
void removeAllDynamicShortcuts(String packageName, int userId);
oneway void removeAllDynamicShortcuts(String packageName, int userId);
boolean updateShortcuts(String packageName, in ParceledListSlice shortcuts, int userId);
oneway void updateShortcuts(String packageName, in ParceledListSlice shortcuts, int userId,
in AndroidFuture callback);
boolean requestPinShortcut(String packageName, in ShortcutInfo shortcut,
in IntentSender resultIntent, int userId);
oneway void requestPinShortcut(String packageName, in ShortcutInfo shortcut,
in IntentSender resultIntent, int userId, in AndroidFuture callback);
Intent createShortcutResultIntent(String packageName, in ShortcutInfo shortcut, int userId);
oneway void createShortcutResultIntent(String packageName, in ShortcutInfo shortcut,
int userId, in AndroidFuture callback);
void disableShortcuts(String packageName, in List shortcutIds, CharSequence disabledMessage,
int disabledMessageResId, int userId);
oneway void disableShortcuts(String packageName, in List shortcutIds,
CharSequence disabledMessage, int disabledMessageResId, int userId);
void enableShortcuts(String packageName, in List shortcutIds, int userId);
oneway void enableShortcuts(String packageName, in List shortcutIds, int userId);
int getMaxShortcutCountPerActivity(String packageName, int userId);
@@ -56,29 +58,31 @@ interface IShortcutService {
int getIconMaxDimensions(String packageName, int userId);
void reportShortcutUsed(String packageName, String shortcutId, int userId);
oneway void reportShortcutUsed(String packageName, String shortcutId, int userId);
void resetThrottling(); // system only API for developer opsions
oneway void resetThrottling(); // system only API for developer opsions
void onApplicationActive(String packageName, int userId); // system only API for sysUI
oneway void onApplicationActive(String packageName, int userId); // system only API for sysUI
byte[] getBackupPayload(int user);
void applyRestore(in byte[] payload, int user);
oneway void applyRestore(in byte[] payload, int user);
boolean isRequestPinItemSupported(int user, int requestType);
// System API used by framework's ShareSheet (ChooserActivity)
ParceledListSlice getShareTargets(String packageName, in IntentFilter filter, int userId);
oneway void getShareTargets(String packageName, in IntentFilter filter, int userId,
in AndroidFuture<ParceledListSlice> callback);
boolean hasShareTargets(String packageName, String packageToCheck, int userId);
void removeLongLivedShortcuts(String packageName, in List shortcutIds, int userId);
oneway void removeLongLivedShortcuts(String packageName, in List shortcutIds, int userId);
ParceledListSlice getShortcuts(String packageName, int matchFlags, int userId);
oneway void getShortcuts(String packageName, int matchFlags, int userId,
in AndroidFuture<ParceledListSlice<ShortcutInfo>> callback);
void pushDynamicShortcut(String packageName, in ShortcutInfo shortcut, int userId);
oneway void pushDynamicShortcut(String packageName, in ShortcutInfo shortcut, int userId);
void updateShortcutVisibility(String callingPkg, String packageName, in byte[] certificate,
in boolean visible, int userId);
}
oneway void updateShortcutVisibility(String callingPkg, String packageName,
in byte[] certificate, in boolean visible, int userId);
}

View File

@@ -24,6 +24,7 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.annotation.WorkerThread;
import android.app.Notification;
import android.app.usage.UsageStatsManager;
import android.compat.annotation.UnsupportedAppUsage;
@@ -42,10 +43,12 @@ import android.os.ServiceManager;
import android.os.UserHandle;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.infra.AndroidFuture;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* <p><code>ShortcutManager</code> executes operations on an app's set of <i>shortcuts</i>, which
@@ -140,13 +143,16 @@ public class ShortcutManager {
*
* @throws IllegalStateException when the user is locked.
*/
@WorkerThread
public boolean setDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
final AndroidFuture<Boolean> future = new AndroidFuture<>();
try {
return mService.setDynamicShortcuts(mContext.getPackageName(),
new ParceledListSlice(shortcutInfoList), injectMyUserId());
mService.setDynamicShortcuts(mContext.getPackageName(),
new ParceledListSlice(shortcutInfoList), injectMyUserId(), future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future);
}
/**
@@ -158,14 +164,17 @@ public class ShortcutManager {
*
* @throws IllegalStateException when the user is locked.
*/
@WorkerThread
@NonNull
public List<ShortcutInfo> getDynamicShortcuts() {
final AndroidFuture<ParceledListSlice<ShortcutInfo>> future = new AndroidFuture<>();
try {
return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_DYNAMIC,
injectMyUserId()).getList();
mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_DYNAMIC, injectMyUserId(),
future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future).getList();
}
/**
@@ -177,14 +186,17 @@ public class ShortcutManager {
*
* @throws IllegalStateException when the user is locked.
*/
@WorkerThread
@NonNull
public List<ShortcutInfo> getManifestShortcuts() {
final AndroidFuture<ParceledListSlice<ShortcutInfo>> future = new AndroidFuture<>();
try {
return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_MANIFEST,
injectMyUserId()).getList();
mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_MANIFEST, injectMyUserId(),
future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future).getList();
}
/**
@@ -205,14 +217,16 @@ public class ShortcutManager {
*
* @throws IllegalStateException when the user is locked.
*/
@WorkerThread
@NonNull
public List<ShortcutInfo> getShortcuts(@ShortcutMatchFlags int matchFlags) {
final AndroidFuture<ParceledListSlice<ShortcutInfo>> future = new AndroidFuture<>();
try {
return mService.getShortcuts(mContext.getPackageName(), matchFlags, injectMyUserId())
.getList();
mService.getShortcuts(mContext.getPackageName(), matchFlags, injectMyUserId(), future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future).getList();
}
/**
@@ -228,13 +242,16 @@ public class ShortcutManager {
*
* @throws IllegalStateException when the user is locked.
*/
@WorkerThread
public boolean addDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
final AndroidFuture<Boolean> future = new AndroidFuture<>();
try {
return mService.addDynamicShortcuts(mContext.getPackageName(),
new ParceledListSlice(shortcutInfoList), injectMyUserId());
mService.addDynamicShortcuts(mContext.getPackageName(),
new ParceledListSlice(shortcutInfoList), injectMyUserId(), future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future);
}
/**
@@ -287,14 +304,17 @@ public class ShortcutManager {
*
* @throws IllegalStateException when the user is locked.
*/
@WorkerThread
@NonNull
public List<ShortcutInfo> getPinnedShortcuts() {
final AndroidFuture<ParceledListSlice<ShortcutInfo>> future = new AndroidFuture<>();
try {
return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_PINNED,
injectMyUserId()).getList();
mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_PINNED, injectMyUserId(),
future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future).getList();
}
/**
@@ -309,13 +329,16 @@ public class ShortcutManager {
*
* @throws IllegalStateException when the user is locked.
*/
@WorkerThread
public boolean updateShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
final AndroidFuture<Boolean> future = new AndroidFuture<>();
try {
return mService.updateShortcuts(mContext.getPackageName(),
new ParceledListSlice(shortcutInfoList), injectMyUserId());
mService.updateShortcuts(mContext.getPackageName(),
new ParceledListSlice(shortcutInfoList), injectMyUserId(), future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future);
}
/**
@@ -584,14 +607,17 @@ public class ShortcutManager {
* @throws IllegalStateException The caller doesn't have a foreground activity or a foreground
* service, or the device is locked.
*/
@WorkerThread
public boolean requestPinShortcut(@NonNull ShortcutInfo shortcut,
@Nullable IntentSender resultIntent) {
final AndroidFuture<Boolean> future = new AndroidFuture<>();
try {
return mService.requestPinShortcut(mContext.getPackageName(), shortcut,
resultIntent, injectMyUserId());
mService.requestPinShortcut(mContext.getPackageName(), shortcut,
resultIntent, injectMyUserId(), future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future);
}
/**
@@ -611,13 +637,16 @@ public class ShortcutManager {
*
* @throws IllegalArgumentException if a shortcut with the same ID exists and is disabled.
*/
@WorkerThread
public Intent createShortcutResultIntent(@NonNull ShortcutInfo shortcut) {
final AndroidFuture<Intent> future = new AndroidFuture<>();
try {
return mService.createShortcutResultIntent(mContext.getPackageName(), shortcut,
injectMyUserId());
mService.createShortcutResultIntent(mContext.getPackageName(), shortcut,
injectMyUserId(), future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future);
}
/**
@@ -650,16 +679,18 @@ public class ShortcutManager {
* @return List of {@link ShareShortcutInfo}s that match the given IntentFilter.
* @hide
*/
@WorkerThread
@NonNull
@SystemApi
@RequiresPermission(Manifest.permission.MANAGE_APP_PREDICTIONS)
public List<ShareShortcutInfo> getShareTargets(@NonNull IntentFilter filter) {
final AndroidFuture<ParceledListSlice> future = new AndroidFuture<>();
try {
return mService.getShareTargets(mContext.getPackageName(), filter,
injectMyUserId()).getList();
mService.getShareTargets(mContext.getPackageName(), filter, injectMyUserId(), future);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
future.completeExceptionally(e);
}
return getFutureOrThrow(future).getList();
}
/**
@@ -788,4 +819,21 @@ public class ShortcutManager {
throw e.rethrowFromSystemServer();
}
}
private static <T> T getFutureOrThrow(@NonNull AndroidFuture<T> future) {
try {
return future.get();
} catch (Throwable e) {
if (e instanceof ExecutionException) {
e = e.getCause();
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
if (e instanceof Error) {
throw (Error) e;
}
throw new RuntimeException(e);
}
}
}