Merge "Add notification listener using the new shell command." into oc-mr1-dev am: a322dd9920
am: 0f3ddec924
Change-Id: Ibd07f1a78af3c705bdb10d79adcc1580deb8c5a6
This commit is contained in:
@@ -27,12 +27,12 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
@@ -906,19 +906,12 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
|
||||
* notification actions right after the notification is sent.
|
||||
*/
|
||||
protected void registerNotificationListenerService() throws Exception {
|
||||
final StringBuilder listeners = new StringBuilder(getNotificationListenerServices());
|
||||
if (listeners.length() > 0) {
|
||||
listeners.append(":");
|
||||
}
|
||||
listeners.append(MyNotificationListenerService.getId());
|
||||
executeShellCommand("settings put secure enabled_notification_listeners " + listeners);
|
||||
final String newListeners = getNotificationListenerServices();
|
||||
assertEquals("Failed to set 'enabled_notification_listeners'",
|
||||
listeners.toString(), newListeners);
|
||||
}
|
||||
|
||||
private String getNotificationListenerServices() throws Exception {
|
||||
return executeShellCommand("settings get secure enabled_notification_listeners");
|
||||
executeShellCommand("cmd notification allow_listener "
|
||||
+ MyNotificationListenerService.getId());
|
||||
final NotificationManager nm = mContext.getSystemService(NotificationManager.class);
|
||||
final ComponentName listenerComponent = MyNotificationListenerService.getComponentName();
|
||||
assertTrue(listenerComponent + " has not been granted access",
|
||||
nm.isNotificationListenerAccessGranted(listenerComponent));
|
||||
}
|
||||
|
||||
protected void setPendingIntentWhitelistDuration(int durationMs) throws Exception {
|
||||
|
||||
@@ -19,6 +19,7 @@ import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.PendingIntent.CanceledException;
|
||||
import android.app.RemoteInput;
|
||||
import android.content.ComponentName;
|
||||
import android.os.Bundle;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
@@ -74,6 +75,11 @@ public class MyNotificationListenerService extends NotificationListenerService {
|
||||
MyNotificationListenerService.class.getName());
|
||||
}
|
||||
|
||||
static ComponentName getComponentName() {
|
||||
return new ComponentName(MyNotificationListenerService.class.getPackage().getName(),
|
||||
MyNotificationListenerService.class.getName());
|
||||
}
|
||||
|
||||
private static final class PendingIntentSender {
|
||||
private PendingIntent mSentIntent = null;
|
||||
private String mReason = null;
|
||||
|
||||
Reference in New Issue
Block a user