blob: af3493e995ac8f01eac65e1a35c76ce73104c518 [file] [log] [blame]
Santos Cordondeb8c892014-05-30 01:38:03 -07001/*
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
Tyler Gunn7cc70b42014-09-12 22:17:27 -070017package com.android.server.telecom;
Santos Cordondeb8c892014-05-30 01:38:03 -070018
19import android.app.StatusBarManager;
20import android.content.Context;
Brad Ebingera3eccfe2016-10-05 15:45:22 -070021import android.telecom.Log;
Santos Cordondeb8c892014-05-30 01:38:03 -070022
Hall Liuf62630a2015-10-27 14:53:39 -070023import com.android.internal.annotations.VisibleForTesting;
24
Tyler Gunn91d43cf2014-09-17 12:19:39 -070025// TODO: Needed for move to system service: import com.android.internal.R;
26
Santos Cordondeb8c892014-05-30 01:38:03 -070027/**
28 * Manages the special status bar notifications used by the phone app.
29 */
Hall Liuf62630a2015-10-27 14:53:39 -070030@VisibleForTesting
31public class StatusBarNotifier extends CallsManagerListenerBase {
Santos Cordondeb8c892014-05-30 01:38:03 -070032 private static final String SLOT_MUTE = "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
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
50 public void onCallRemoved(Call call) {
51 if (!mCallsManager.hasAnyCalls()) {
52 notifyMute(false);
53 notifySpeakerphone(false);
54 }
55 }
56
Hall Liuf62630a2015-10-27 14:53:39 -070057 @VisibleForTesting
58 public void notifyMute(boolean isMuted) {
Santos Cordondeb8c892014-05-30 01:38:03 -070059 // 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
Hall Liuf62630a2015-10-27 14:53:39 -070082 @VisibleForTesting
83 public void notifySpeakerphone(boolean isSpeakerphone) {
Santos Cordondeb8c892014-05-30 01:38:03 -070084 // Never display anything if there are no calls.
85 if (!mCallsManager.hasAnyCalls()) {
86 isSpeakerphone = false;
87 }
88
89 if (mIsShowingSpeakerphone == isSpeakerphone) {
90 return;
91 }
92
93 Log.d(this, "Speakerphone status bar icon being set to %b", isSpeakerphone);
94
95 if (isSpeakerphone) {
96 mStatusBarManager.setIcon(
97 SLOT_SPEAKERPHONE,
98 android.R.drawable.stat_sys_speakerphone,
99 0, /* iconLevel */
100 mContext.getString(R.string.accessibility_speakerphone_enabled));
101 } else {
102 mStatusBarManager.removeIcon(SLOT_SPEAKERPHONE);
103 }
104 mIsShowingSpeakerphone = isSpeakerphone;
105 }
106}