diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java index 35e84c5f19..e65db3197f 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java @@ -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; @@ -898,19 +898,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 { diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyNotificationListenerService.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyNotificationListenerService.java index 0893511071..013253670a 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyNotificationListenerService.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MyNotificationListenerService.java @@ -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;