Home | History | Annotate | Download | only in notifications
      1 package com.android.cts.verifier.notifications;
      2 
      3 import static android.app.NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED;
      4 import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED;
      5 import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED;
      6 
      7 import android.app.NotificationManager;
      8 import android.content.BroadcastReceiver;
      9 import android.content.Context;
     10 import android.content.Intent;
     11 import android.content.SharedPreferences;
     12 
     13 public class BlockChangeReceiver extends BroadcastReceiver {
     14 
     15     @Override
     16     public void onReceive(Context context, Intent intent) {
     17         SharedPreferences prefs = context.getSharedPreferences(
     18                 NotificationListenerVerifierActivity.PREFS, Context.MODE_PRIVATE);
     19         SharedPreferences.Editor editor = prefs.edit();
     20         if (ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED.equals(intent.getAction())) {
     21             String id = intent.getStringExtra(
     22                     NotificationManager.EXTRA_NOTIFICATION_CHANNEL_GROUP_ID);
     23             editor.putBoolean(id,
     24                     intent.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false));
     25         } else if (ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED.equals(intent.getAction())) {
     26             String id = intent.getStringExtra(NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID);
     27             editor.putBoolean(id,
     28                     intent.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false));
     29         } else if (ACTION_APP_BLOCK_STATE_CHANGED.equals(intent.getAction())) {
     30             String id = context.getPackageName();
     31             editor.putBoolean(id,
     32                     intent.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false));
     33         }
     34         editor.commit();
     35     }
     36 }
     37