1 /* 2 * Copyright (C) 2017 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.incallui; 18 19 import android.os.Bundle; 20 import android.support.annotation.NonNull; 21 import android.support.annotation.Nullable; 22 import android.support.v4.app.FragmentActivity; 23 import android.telecom.CallAudioState; 24 import com.android.dialer.logging.DialerImpression; 25 import com.android.dialer.logging.Logger; 26 import com.android.incallui.audiomode.AudioModeProvider; 27 import com.android.incallui.audioroute.AudioRouteSelectorDialogFragment; 28 import com.android.incallui.audioroute.AudioRouteSelectorDialogFragment.AudioRouteSelectorPresenter; 29 import com.android.incallui.call.CallList; 30 import com.android.incallui.call.CallList.Listener; 31 import com.android.incallui.call.DialerCall; 32 import com.android.incallui.call.TelecomAdapter; 33 34 /** Simple activity that just shows the audio route selector fragment */ 35 public class AudioRouteSelectorActivity extends FragmentActivity 36 implements AudioRouteSelectorPresenter, Listener { 37 38 @Override onCreate(@ullable Bundle bundle)39 protected void onCreate(@Nullable Bundle bundle) { 40 super.onCreate(bundle); 41 AudioRouteSelectorDialogFragment.newInstance(AudioModeProvider.getInstance().getAudioState()) 42 .show(getSupportFragmentManager(), AudioRouteSelectorDialogFragment.TAG); 43 44 CallList.getInstance().addListener(this); 45 } 46 47 @Override onAudioRouteSelected(int audioRoute)48 public void onAudioRouteSelected(int audioRoute) { 49 TelecomAdapter.getInstance().setAudioRoute(audioRoute); 50 finish(); 51 52 // Log the select action with audio route and call 53 DialerImpression.Type impressionType = null; 54 if ((audioRoute & CallAudioState.ROUTE_WIRED_OR_EARPIECE) != 0) { 55 impressionType = DialerImpression.Type.BUBBLE_V2_WIRED_OR_EARPIECE; 56 } else if (audioRoute == CallAudioState.ROUTE_SPEAKER) { 57 impressionType = DialerImpression.Type.BUBBLE_V2_SPEAKERPHONE; 58 } else if (audioRoute == CallAudioState.ROUTE_BLUETOOTH) { 59 impressionType = DialerImpression.Type.BUBBLE_V2_BLUETOOTH; 60 } 61 if (impressionType == null) { 62 return; 63 } 64 65 DialerCall call = getCall(); 66 if (call != null) { 67 Logger.get(this) 68 .logCallImpression(impressionType, call.getUniqueCallId(), call.getTimeAddedMs()); 69 } else { 70 Logger.get(this).logImpression(impressionType); 71 } 72 } 73 74 @Override onAudioRouteSelectorDismiss()75 public void onAudioRouteSelectorDismiss() { 76 finish(); 77 } 78 79 @Override onPause()80 protected void onPause() { 81 super.onPause(); 82 AudioRouteSelectorDialogFragment audioRouteSelectorDialogFragment = 83 (AudioRouteSelectorDialogFragment) 84 getSupportFragmentManager().findFragmentByTag(AudioRouteSelectorDialogFragment.TAG); 85 // If Android back button is pressed, the fragment is dismissed and removed. If home button is 86 // pressed, we have to manually dismiss the fragment here. The fragment is also removed when 87 // dismissed. 88 if (audioRouteSelectorDialogFragment != null) { 89 audioRouteSelectorDialogFragment.dismiss(); 90 } 91 // We don't expect the activity to resume, except for orientation change. 92 if (!isChangingConfigurations()) { 93 finish(); 94 } 95 } 96 97 @Override onDestroy()98 protected void onDestroy() { 99 CallList.getInstance().removeListener(this); 100 super.onDestroy(); 101 } 102 getCall()103 private DialerCall getCall() { 104 DialerCall dialerCall = CallList.getInstance().getOutgoingCall(); 105 if (dialerCall == null) { 106 dialerCall = CallList.getInstance().getActiveOrBackgroundCall(); 107 } 108 return dialerCall; 109 } 110 111 @Override onDisconnect(DialerCall call)112 public void onDisconnect(DialerCall call) { 113 if (getCall() == null) { 114 finish(); 115 } 116 } 117 118 @Override onIncomingCall(DialerCall call)119 public void onIncomingCall(DialerCall call) {} 120 121 @Override onUpgradeToVideo(DialerCall call)122 public void onUpgradeToVideo(DialerCall call) {} 123 124 @Override onSessionModificationStateChange(DialerCall call)125 public void onSessionModificationStateChange(DialerCall call) {} 126 127 @Override onCallListChange(CallList callList)128 public void onCallListChange(CallList callList) {} 129 130 @Override onWiFiToLteHandover(DialerCall call)131 public void onWiFiToLteHandover(DialerCall call) {} 132 133 @Override onHandoverToWifiFailed(DialerCall call)134 public void onHandoverToWifiFailed(DialerCall call) {} 135 136 @Override onInternationalCallOnWifi(@onNull DialerCall call)137 public void onInternationalCallOnWifi(@NonNull DialerCall call) {} 138 } 139