• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.cts.verifier.notifications;
18 
19 import static android.app.NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED;
20 import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED;
21 import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED;
22 
23 import android.app.NotificationManager;
24 import android.content.BroadcastReceiver;
25 import android.content.Context;
26 import android.content.Intent;
27 import android.content.SharedPreferences;
28 
29 public class BlockChangeReceiver extends BroadcastReceiver {
30 
31     @Override
onReceive(Context context, Intent intent)32     public void onReceive(Context context, Intent intent) {
33         SharedPreferences prefs = context.getSharedPreferences(
34                 NotificationListenerVerifierActivity.PREFS, Context.MODE_PRIVATE);
35         SharedPreferences.Editor editor = prefs.edit();
36         if (ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED.equals(intent.getAction())) {
37             String id = intent.getStringExtra(
38                     NotificationManager.EXTRA_NOTIFICATION_CHANNEL_GROUP_ID);
39             editor.putBoolean(id,
40                     intent.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false));
41         } else if (ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED.equals(intent.getAction())) {
42             String id = intent.getStringExtra(NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID);
43             editor.putBoolean(id,
44                     intent.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false));
45         } else if (ACTION_APP_BLOCK_STATE_CHANGED.equals(intent.getAction())) {
46             String id = context.getPackageName();
47             editor.putBoolean(id,
48                     intent.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false));
49         }
50         editor.commit();
51     }
52 }
53