Merge "Shortcut: Reset throttling upon inline reply" into nyc-mr1-dev
This commit is contained in:
@@ -17,6 +17,7 @@ package android.content.pm;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.TestApi;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
@@ -379,6 +380,22 @@ public class ShortcutManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called internally when an application is considered to have come to foreground
|
||||
* even when technically it's not. This method resets the throttling for this package.
|
||||
* For example, when the user sends an "inline reply" on an notification, the system UI will
|
||||
* call it.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void onApplicationActive(@NonNull String packageName, @UserIdInt int userId) {
|
||||
try {
|
||||
mService.onApplicationActive(packageName, userId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide injection point */
|
||||
@VisibleForTesting
|
||||
protected int injectMyUserId() {
|
||||
|
||||
@@ -165,6 +165,9 @@
|
||||
<!-- the ability to rename notifications posted by other apps -->
|
||||
<uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />
|
||||
|
||||
<!-- shortcut manager -->
|
||||
<uses-permission android:name="android.permission.RESET_SHORTCUT_MANAGER_THROTTLING" />
|
||||
|
||||
<application
|
||||
android:name=".SystemUIApplication"
|
||||
android:persistent="true"
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.app.PendingIntent;
|
||||
import android.app.RemoteInput;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
@@ -132,6 +133,15 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
|
||||
mEditText.mShowImeOnInputConnection = false;
|
||||
mController.remoteInputSent(mEntry);
|
||||
|
||||
// Tell ShortcutManager that this package has been "activated". ShortcutManager
|
||||
// will reset the throttling for this package.
|
||||
// Strictly speaking, the intent receiver may be different from the notification publisher,
|
||||
// but that's an edge case, and also because we can't always know which package will receive
|
||||
// an intent, so we just reset for the publisher.
|
||||
getContext().getSystemService(ShortcutManager.class).onApplicationActive(
|
||||
mEntry.notification.getPackageName(),
|
||||
mEntry.notification.getUser().getIdentifier());
|
||||
|
||||
MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_SEND,
|
||||
mEntry.notification.getPackageName());
|
||||
try {
|
||||
|
||||
@@ -4394,11 +4394,11 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
|
||||
|
||||
public void testOnApplicationActive_permission() {
|
||||
assertExpectException(SecurityException.class, "Missing permission", () ->
|
||||
mService.onApplicationActive(CALLING_PACKAGE_1, USER_0));
|
||||
mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0));
|
||||
|
||||
// Has permission, now it should pass.
|
||||
mCallerPermissions.add(permission.RESET_SHORTCUT_MANAGER_THROTTLING);
|
||||
mService.onApplicationActive(CALLING_PACKAGE_1, USER_0);
|
||||
mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0);
|
||||
}
|
||||
|
||||
public void testDumpsys_crossProfile() {
|
||||
|
||||
@@ -1488,7 +1488,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
|
||||
|
||||
// Simulate a call from sys UI.
|
||||
mCallerPermissions.add(permission.RESET_SHORTCUT_MANAGER_THROTTLING);
|
||||
mService.onApplicationActive(CALLING_PACKAGE_1, USER_0);
|
||||
mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0);
|
||||
|
||||
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
|
||||
assertEquals(3, mManager.getRemainingCallCount());
|
||||
@@ -1509,7 +1509,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
|
||||
MoreAsserts.assertNotEqual(3, mManager.getRemainingCallCount());
|
||||
});
|
||||
|
||||
mService.onApplicationActive(CALLING_PACKAGE_3, USER_0);
|
||||
mManager.onApplicationActive(CALLING_PACKAGE_3, USER_0);
|
||||
|
||||
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
|
||||
assertEquals(3, mManager.getRemainingCallCount());
|
||||
@@ -1530,7 +1530,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
|
||||
MoreAsserts.assertNotEqual(3, mManager.getRemainingCallCount());
|
||||
});
|
||||
|
||||
mService.onApplicationActive(CALLING_PACKAGE_1, USER_10);
|
||||
mManager.onApplicationActive(CALLING_PACKAGE_1, USER_10);
|
||||
|
||||
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
|
||||
assertEquals(3, mManager.getRemainingCallCount());
|
||||
|
||||
Reference in New Issue
Block a user