blob: eea187f32c935fe2f1e3a0fa925226f1a967eb24 [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
17package com.android.telecomm;
18
19import android.app.StatusBarManager;
20import android.content.Context;
21
22/**
23 * Manages the special status bar notifications used by the phone app.
24 */
25final class StatusBarNotifier extends CallsManagerListenerBase {
26 private static final String SLOT_MUTE = "mute";
27 private static final String SLOT_SPEAKERPHONE = "speakerphone";
28
29 private final Context mContext;
30 private final CallsManager mCallsManager;
31 private final StatusBarManager mStatusBarManager;
32
33 private boolean mIsShowingMute;
34 private boolean mIsShowingSpeakerphone;
35
36 StatusBarNotifier(Context context, CallsManager callsManager) {
37 mContext = context;
38 mCallsManager = callsManager;
39 mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
40 }
41
42 /** ${inheritDoc} */
43 @Override
44 public void onCallRemoved(Call call) {
45 if (!mCallsManager.hasAnyCalls()) {
46 notifyMute(false);
47 notifySpeakerphone(false);
48 }
49 }
50
51 void notifyMute(boolean isMuted) {
52 // Never display anything if there are no calls.
53 if (!mCallsManager.hasAnyCalls()) {
54 isMuted = false;
55 }
56
57 if (mIsShowingMute == isMuted) {
58 return;
59 }
60
61 Log.d(this, "Mute status bar icon being set to %b", isMuted);
62
63 if (isMuted) {
64 mStatusBarManager.setIcon(
65 SLOT_MUTE,
66 android.R.drawable.stat_notify_call_mute,
67 0, /* iconLevel */
68 mContext.getString(R.string.accessibility_call_muted));
69 } else {
70 mStatusBarManager.removeIcon(SLOT_MUTE);
71 }
72 mIsShowingMute = isMuted;
73 }
74
75 void notifySpeakerphone(boolean isSpeakerphone) {
76 // Never display anything if there are no calls.
77 if (!mCallsManager.hasAnyCalls()) {
78 isSpeakerphone = false;
79 }
80
81 if (mIsShowingSpeakerphone == isSpeakerphone) {
82 return;
83 }
84
85 Log.d(this, "Speakerphone status bar icon being set to %b", isSpeakerphone);
86
87 if (isSpeakerphone) {
88 mStatusBarManager.setIcon(
89 SLOT_SPEAKERPHONE,
90 android.R.drawable.stat_sys_speakerphone,
91 0, /* iconLevel */
92 mContext.getString(R.string.accessibility_speakerphone_enabled));
93 } else {
94 mStatusBarManager.removeIcon(SLOT_SPEAKERPHONE);
95 }
96 mIsShowingSpeakerphone = isSpeakerphone;
97 }
98}