1 /* 2 * Copyright (C) 2018 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.settings.dashboard.conditional; 18 19 import static android.content.Context.NOTIFICATION_SERVICE; 20 21 import android.app.NotificationManager; 22 import android.graphics.drawable.Drawable; 23 import android.media.AudioManager; 24 import android.provider.Settings; 25 26 import com.android.internal.logging.nano.MetricsProto; 27 import com.android.settings.R; 28 29 public class RingerMutedCondition extends AbnormalRingerConditionBase { 30 31 private final NotificationManager mNotificationManager; 32 RingerMutedCondition(ConditionManager manager)33 RingerMutedCondition(ConditionManager manager) { 34 super(manager); 35 mNotificationManager = 36 (NotificationManager) mManager.getContext().getSystemService(NOTIFICATION_SERVICE); 37 } 38 39 @Override refreshState()40 public void refreshState() { 41 int zen = Settings.Global.ZEN_MODE_OFF; 42 if (mNotificationManager != null) { 43 zen = mNotificationManager.getZenMode(); 44 } 45 final boolean zenModeEnabled = zen != Settings.Global.ZEN_MODE_OFF; 46 final boolean isSilent = 47 mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT; 48 setActive(isSilent && !zenModeEnabled); 49 } 50 51 @Override getMetricsConstant()52 public int getMetricsConstant() { 53 return MetricsProto.MetricsEvent.SETTINGS_CONDITION_DEVICE_MUTED; 54 } 55 56 @Override getIcon()57 public Drawable getIcon() { 58 return mManager.getContext().getDrawable(R.drawable.ic_notifications_off_24dp); 59 } 60 61 @Override getTitle()62 public CharSequence getTitle() { 63 return mManager.getContext().getText(R.string.condition_device_muted_title); 64 } 65 66 @Override getSummary()67 public CharSequence getSummary() { 68 return mManager.getContext().getText(R.string.condition_device_muted_summary); 69 } 70 } 71