summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2014-10-28 11:08:15 -0400
committerThe Android Automerger <android-build@google.com>2014-10-29 13:29:42 -0700
commit14628f919d3e574da7588baff22777ffe5ae695e (patch)
tree606d04b67e8aac68895770016412542cce138379
parent04e1702fde3b19cc76343cc7646134da6f21e1a3 (diff)
downloadplatform_cts-android-5.0.0_r4.tar.gz
platform_cts-android-5.0.0_r4.tar.bz2
platform_cts-android-5.0.0_r4.zip
Port CtsVerifier to API 21 Notification Listener API. DO NOT MERGE.android-5.0.0_r5android-5.0.0_r4android-5.0.0_r3android-5.0.0_r2
The cancelNotificaiton method now takes a key, so we have to remember those. This is a back port of changes from lmp-sprout-dev so it should not be mergedd. Bug: 18054058 Change-Id: Icad265ed28a998e7276d8386e9754a63af6e7b04
-rw-r--r--apps/CtsVerifier/src/com/android/cts/verifier/notifications/MockListener.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/MockListener.java b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/MockListener.java
index 3d0e0d707a3..b4863fa551d 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/MockListener.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/MockListener.java
@@ -31,7 +31,9 @@ import org.json.JSONObject;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
public class MockListener extends NotificationListenerService {
static final String TAG = "MockListener";
@@ -67,8 +69,10 @@ public class MockListener extends NotificationListenerService {
private ArrayList<String> mPosted = new ArrayList<String>();
private ArrayMap<String, JSONObject> mNotifications = new ArrayMap<>();
+ private ArrayMap<String, String> mNotificationKeys = new ArrayMap<>();
private ArrayList<String> mRemoved = new ArrayList<String>();
private ArrayList<String> mOrder = new ArrayList<>();
+ private Set<String> mTestPackages = new HashSet<>();
private BroadcastReceiver mReceiver;
private int mDND = -1;
@@ -77,6 +81,8 @@ public class MockListener extends NotificationListenerService {
super.onCreate();
Log.d(TAG, "created");
+ mTestPackages.add("com.android.cts.verifier");
+
mPosted = new ArrayList<String>();
mRemoved = new ArrayList<String>();
@@ -123,10 +129,13 @@ public class MockListener extends NotificationListenerService {
setResultCode(Activity.RESULT_OK);
} else if (SERVICE_CLEAR_ONE.equals(action)) {
Log.d(TAG, "SERVICE_CLEAR_ONE");
- MockListener.this.cancelNotification(
- context.getApplicationInfo().packageName,
- intent.getStringExtra(EXTRA_TAG),
- intent.getIntExtra(EXTRA_CODE, 0));
+ String tag = intent.getStringExtra(EXTRA_TAG);
+ String key = mNotificationKeys.get(tag);
+ if (key != null) {
+ MockListener.this.cancelNotification(key);
+ } else {
+ Log.w(TAG, "Notification does not exist: " + tag);
+ }
} else if (SERVICE_CLEAR_ALL.equals(action)) {
Log.d(TAG, "SERVICE_CLEAR_ALL");
MockListener.this.cancelAllNotifications();
@@ -205,6 +214,7 @@ public class MockListener extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
+ if (!mTestPackages.contains(sbn.getPackageName())) { return; }
Log.d(TAG, "posted: " + sbn.getTag());
mPosted.add(sbn.getTag());
JSONObject notification = new JSONObject();
@@ -216,6 +226,7 @@ public class MockListener extends NotificationListenerService {
notification.put(JSON_ICON, sbn.getNotification().icon);
notification.put(JSON_FLAGS, sbn.getNotification().flags);
mNotifications.put(sbn.getKey(), notification);
+ mNotificationKeys.put(sbn.getTag(), sbn.getKey());
} catch (JSONException e) {
Log.e(TAG, "failed to pack up notification payload", e);
}
@@ -228,6 +239,7 @@ public class MockListener extends NotificationListenerService {
mRemoved.add(sbn.getTag());
mNotifications.remove(sbn.getKey());
onNotificationRankingUpdate(rankingMap);
+ mNotificationKeys.remove(sbn.getTag());
}
public static void resetListenerData(Context context) {