Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2019 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 android.app.notification.legacy29.cts;
     18 
     19 import android.app.NotificationManager;
     20 import android.content.ComponentName;
     21 import android.os.Bundle;
     22 import android.service.notification.Adjustment;
     23 import android.service.notification.NotificationAssistantService;
     24 import android.service.notification.StatusBarNotification;
     25 
     26 import java.util.List;
     27 
     28 public class TestNotificationAssistant extends NotificationAssistantService {
     29     public static final String TAG = "TestNotificationAssistant";
     30     public static final String PKG = "android.app.notification.legacy29.cts";
     31 
     32     private static TestNotificationAssistant sNotificationAssistantInstance = null;
     33     boolean isConnected;
     34     public List<String> currentCapabilities;
     35     private NotificationManager mNotificationManager;
     36 
     37     public static String getId() {
     38         return String.format("%s/%s", TestNotificationAssistant.class.getPackage().getName(),
     39                 TestNotificationAssistant.class.getName());
     40     }
     41 
     42     public static ComponentName getComponentName() {
     43         return new ComponentName(TestNotificationAssistant.class.getPackage().getName(),
     44                 TestNotificationAssistant.class.getName());
     45     }
     46 
     47     @Override
     48     public void onCreate() {
     49         super.onCreate();
     50         mNotificationManager = getSystemService(NotificationManager.class);
     51     }
     52 
     53     @Override
     54     public void onListenerConnected() {
     55         super.onListenerConnected();
     56         sNotificationAssistantInstance = this;
     57         isConnected = true;
     58     }
     59 
     60     @Override
     61     public void onListenerDisconnected() {
     62         isConnected = false;
     63     }
     64 
     65     public static TestNotificationAssistant getInstance() {
     66         return sNotificationAssistantInstance;
     67     }
     68 
     69     @Override
     70     public void onNotificationSnoozedUntilContext(StatusBarNotification statusBarNotification,
     71             String s) {
     72     }
     73 
     74     @Override
     75     public Adjustment onNotificationEnqueued(StatusBarNotification sbn) {
     76         Bundle signals = new Bundle();
     77         signals.putInt(Adjustment.KEY_USER_SENTIMENT, Ranking.USER_SENTIMENT_POSITIVE);
     78         return new Adjustment(sbn.getPackageName(), sbn.getKey(), signals, "",
     79                 sbn.getUser());
     80     }
     81 
     82     @Override
     83     public void onAllowedAdjustmentsChanged() {
     84         currentCapabilities = mNotificationManager.getAllowedAssistantAdjustments();
     85     }
     86 }