Shortcut: Reset throttling upon inline reply

When the user does an "inline reply", we consider the notification
publisher app is "activated" and reset the shortcut throttling.

Bug 28705275

Change-Id: Ic9ffa13635274ead7e9d1e832cd31dea997830aa
This commit is contained in:
Makoto Onuki
2016-06-14 11:17:59 -07:00
parent 3bb4366006
commit d6e1f3bec1
5 changed files with 35 additions and 5 deletions

View File

@@ -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() {

View File

@@ -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"

View File

@@ -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 {

View File

@@ -4384,11 +4384,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() {

View File

@@ -1414,7 +1414,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());
@@ -1435,7 +1435,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());
@@ -1456,7 +1456,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());