1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * This file is derived in part from code issued under the following license. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 */ 19 package com.android.incallui; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.support.annotation.VisibleForTesting; 24 import com.android.dialer.common.LogUtil; 25 import com.android.incallui.InCallPresenter.InCallState; 26 import com.android.incallui.InCallPresenter.InCallStateListener; 27 import com.android.incallui.InCallPresenter.InCallUiListener; 28 import com.android.incallui.call.CallList; 29 30 /** 31 * Responsible for broadcasting the Intent INCOMING_CALL_VISIBILITY_CHANGED so other processes could 32 * know when the incoming call activity is started or finished. 33 */ 34 public class MotorolaInCallUiNotifier implements InCallUiListener, InCallStateListener { 35 36 @VisibleForTesting static final String EXTRA_VISIBLE_KEY = "visible"; 37 38 @VisibleForTesting 39 static final String ACTION_INCOMING_CALL_VISIBILITY_CHANGED = 40 "com.motorola.incallui.action.INCOMING_CALL_VISIBILITY_CHANGED"; 41 42 @VisibleForTesting 43 static final String PERMISSION_INCOMING_CALL_VISIBILITY_CHANGED = 44 "com.motorola.incallui.permission.INCOMING_CALL_VISIBILITY_CHANGED"; 45 46 private final Context context; 47 48 MotorolaInCallUiNotifier(Context context) { 49 this.context = context; 50 } 51 52 @Override 53 public void onUiShowing(boolean showing) { 54 if (showing && CallList.getInstance().getIncomingCall() != null) { 55 sendInCallUiBroadcast(true); 56 } 57 } 58 59 @Override 60 public void onStateChange(InCallState oldState, InCallState newState, CallList callList) { 61 if (oldState != null 62 && oldState.isConnectingOrConnected() 63 && newState == InCallState.NO_CALLS) { 64 sendInCallUiBroadcast(false); 65 } 66 } 67 68 private void sendInCallUiBroadcast(boolean visible) { 69 LogUtil.d( 70 "MotorolaInCallUiNotifier.sendInCallUiBroadcast", 71 "Send InCallUi Broadcast, visible: " + visible); 72 Intent intent = new Intent(); 73 intent.putExtra(EXTRA_VISIBLE_KEY, visible); 74 intent.setAction(ACTION_INCOMING_CALL_VISIBILITY_CHANGED); 75 context.sendBroadcast(intent, PERMISSION_INCOMING_CALL_VISIBILITY_CHANGED); 76 } 77 } 78