• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.bedstead.nene.notifications;
18 
19 import android.service.notification.NotificationListenerService;
20 import android.service.notification.StatusBarNotification;
21 import android.util.Log;
22 
23 import com.android.bedstead.nene.TestApis;
24 
25 import java.util.concurrent.CountDownLatch;
26 import java.util.concurrent.atomic.AtomicReference;
27 
28 /**
29  * {@link NotificationListenerService} for use with Nene.
30  *
31  * <p>To access this use {@link TestApis#notifications()}.
32  */
33 public final class NeneNotificationListenerService extends NotificationListenerService {
34 
35     private static final String TAG = "NeneNotificationListenerService";
36 
37     private static AtomicReference<NeneNotificationListenerService> sInstance =
38             new AtomicReference<>();
39     private static CountDownLatch sConnectedLatch = new CountDownLatch(1);
40 
41     @Override
onListenerConnected()42     public void onListenerConnected() {
43         Log.d(TAG, "Listener connected");
44         sInstance.set(this);
45         sConnectedLatch.countDown();
46     }
47 
48     @Override
onListenerDisconnected()49     public void onListenerDisconnected() {
50         Log.d(TAG, "Listener disconnected");
51         sInstance.set(null);
52         sConnectedLatch = new CountDownLatch(1);
53     }
54 
55     @Override
onNotificationPosted(StatusBarNotification sbn)56     public void onNotificationPosted(StatusBarNotification sbn) {
57         Notifications.sInstance.onNotificationPosted(sbn);
58     }
59 }
60