Home | History | Annotate | Download | only in telecom
      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 = "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 
     57     @VisibleForTesting
     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     @VisibleForTesting
     83     public void notifySpeakerphone(boolean isSpeakerphone) {
     84         // 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 }
    107