1 /* 2 * Copyright (C) 2015 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 package com.android.car.dialer.telecom.embedded; 17 18 import com.android.car.dialer.telecom.UiCall; 19 import com.android.car.dialer.telecom.UiCallList; 20 21 import android.telecom.Call; 22 import android.telecom.DisconnectCause; 23 import android.telecom.GatewayInfo; 24 import android.util.Log; 25 26 /** 27 * Represents a list of {@link UiCall} for underlying {@link android.telecom.Call}. 28 */ 29 public class TelecomUiCallList extends UiCallList<Call> { 30 private final static String TAG = "Em.UiCallList"; 31 32 private volatile static int nextCarPhoneCallId = 0; 33 34 private int getNewCarPhoneCallId() { 35 return nextCarPhoneCallId++; 36 } 37 38 @Override 39 protected UiCall createUiCall(Call telecomCall) { 40 int id = getNewCarPhoneCallId(); 41 42 UiCall uiCall = new UiCall(id); 43 updateCallContainerFromTelecom(uiCall, telecomCall); 44 return uiCall; 45 } 46 47 static void updateCallContainerFromTelecom(UiCall uiCall, Call telecomCall) { 48 if (Log.isLoggable(TAG, Log.DEBUG)) { 49 Log.d(TAG, "updateCallContainerFromTelecom: call: " + uiCall + ", telecomCall: " 50 + telecomCall); 51 } 52 53 uiCall.setState(telecomCall.getState()); 54 uiCall.setHasChildren(!telecomCall.getChildren().isEmpty()); 55 uiCall.setHasParent(telecomCall.getParent() != null); 56 57 Call.Details details = telecomCall.getDetails(); 58 if (details != null) { 59 uiCall.setConnectTimeMillis(details.getConnectTimeMillis()); 60 61 DisconnectCause cause = details.getDisconnectCause(); 62 CharSequence causeLabel = cause == null ? null : cause.getLabel(); 63 uiCall.setDisconnectClause(causeLabel == null ? null : causeLabel.toString()); 64 65 GatewayInfo gatewayInfo = details.getGatewayInfo(); 66 uiCall.setGatewayInfoOriginalAddress( 67 gatewayInfo == null ? null : gatewayInfo.getOriginalAddress()); 68 69 String number = ""; 70 if (gatewayInfo != null) { 71 number = gatewayInfo.getOriginalAddress().getSchemeSpecificPart(); 72 } else if (details.getHandle() != null) { 73 number = details.getHandle().getSchemeSpecificPart(); 74 } 75 uiCall.setNumber(number); 76 } 77 } 78 79 public Call getTelecomCall(UiCall uiCall) { 80 return uiCall != null ? getCall(uiCall.getId()) : null; 81 } 82 } 83