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_AUTOMATIC_ZEN_RULE_STATUS_CHANGED; 20 import static android.app.NotificationManager.AUTOMATIC_RULE_STATUS_UNKNOWN; 21 import static android.app.NotificationManager.EXTRA_AUTOMATIC_ZEN_RULE_STATUS; 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 import android.util.Log; 29 30 public class AutomaticZenRuleStatusReceiver extends BroadcastReceiver { 31 private static final String TAG = "AZRReceiver"; 32 @Override onReceive(Context context, Intent intent)33 public void onReceive(Context context, Intent intent) { 34 SharedPreferences prefs = context.getSharedPreferences( 35 ConditionProviderVerifierActivity.PREFS, Context.MODE_PRIVATE); 36 SharedPreferences.Editor editor = prefs.edit(); 37 if (ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED.equals(intent.getAction())) { 38 String id = intent.getStringExtra( 39 NotificationManager.EXTRA_AUTOMATIC_ZEN_RULE_ID); 40 int status = intent.getIntExtra(EXTRA_AUTOMATIC_ZEN_RULE_STATUS, 41 AUTOMATIC_RULE_STATUS_UNKNOWN); 42 Log.d(TAG, "Got broadcast for rule status change: " + id + " " + status); 43 editor.putInt(id, status); 44 editor.commit(); 45 } 46 } 47 } 48