1 /* 2 * Copyright (C) 2014 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.server.telecom; 18 19 import android.app.StatusBarManager; 20 import android.content.Context; 21 import android.telecom.Log; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 25 // TODO: Needed for move to system service: import com.android.internal.R; 26 27 /** 28 * Manages the special status bar notifications used by the phone app. 29 */ 30 @VisibleForTesting 31 public class StatusBarNotifier extends CallsManagerListenerBase { 32 private static final String SLOT_MUTE = "telecom_mute"; 33 private static final String SLOT_SPEAKERPHONE = "speakerphone"; 34 35 private final Context mContext; 36 private final CallsManager mCallsManager; 37 private final StatusBarManager mStatusBarManager; 38 39 private boolean mIsShowingMute; 40 private boolean mIsShowingSpeakerphone; 41 StatusBarNotifier(Context context, CallsManager callsManager)42 StatusBarNotifier(Context context, CallsManager callsManager) { 43 mContext = context; 44 mCallsManager = callsManager; 45 mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); 46 } 47 48 /** ${inheritDoc} */ 49 @Override onCallRemoved(Call call)50 public void onCallRemoved(Call call) { 51 if (!mCallsManager.hasAnyCalls()) { 52 notifyMute(false); 53 notifySpeakerphone(false); 54 } 55 } 56 57 @VisibleForTesting notifyMute(boolean isMuted)58 public void notifyMute(boolean isMuted) { 59 // Never display anything if there are no calls. 60 if (!mCallsManager.hasAnyCalls()) { 61 isMuted = false; 62 } 63 64 if (mIsShowingMute == isMuted) { 65 return; 66 } 67 68 Log.d(this, "Mute status bar icon being set to %b", isMuted); 69 70 if (isMuted) { 71 mStatusBarManager.setIcon( 72 SLOT_MUTE, 73 android.R.drawable.stat_notify_call_mute, 74 0, /* iconLevel */ 75 mContext.getString(R.string.accessibility_call_muted)); 76 } else { 77 mStatusBarManager.removeIcon(SLOT_MUTE); 78 } 79 mIsShowingMute = isMuted; 80 } 81 82 /** 83 * Update the status bar manager with the new speakerphone state. 84 * 85 * IMPORTANT: DO NOT call into any Telecom code here; this is usually scheduled on an async 86 * executor to save Telecom from blocking on outgoing binder calls. 87 * @param isSpeakerphone 88 */ 89 @VisibleForTesting notifySpeakerphone(boolean isSpeakerphone)90 public void notifySpeakerphone(boolean isSpeakerphone) { 91 if (mIsShowingSpeakerphone == isSpeakerphone) { 92 return; 93 } 94 95 Log.d(this, "Speakerphone status bar icon being set to %b", isSpeakerphone); 96 97 if (isSpeakerphone) { 98 mStatusBarManager.setIcon( 99 SLOT_SPEAKERPHONE, 100 android.R.drawable.stat_sys_speakerphone, 101 0, /* iconLevel */ 102 mContext.getString(R.string.accessibility_speakerphone_enabled)); 103 } else { 104 mStatusBarManager.removeIcon(SLOT_SPEAKERPHONE); 105 } 106 mIsShowingSpeakerphone = isSpeakerphone; 107 } 108 } 109