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