1 /* 2 * Copyright (C) 2018 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.car.dialer.livedata; 18 19 import android.telecom.Call; 20 import android.telecom.InCallService; 21 22 import androidx.annotation.Nullable; 23 import androidx.lifecycle.LiveData; 24 25 import com.android.car.telephony.common.CallDetail; 26 27 import java.util.List; 28 29 /** 30 * Represents the details of an active phone call. 31 */ 32 public class CallDetailLiveData extends LiveData<CallDetail> { 33 34 private Call mTelecomCall; 35 36 @Override onActive()37 protected void onActive() { 38 super.onActive(); 39 setTelecomCallDetail(mTelecomCall); 40 if (mTelecomCall != null) { 41 mTelecomCall.registerCallback(mCallback); 42 } 43 } 44 45 @Override onInactive()46 protected void onInactive() { 47 super.onInactive(); 48 if (mTelecomCall != null) { 49 mTelecomCall.unregisterCallback(mCallback); 50 } 51 } 52 53 private Call.Callback mCallback = new Call.Callback() { 54 @Override 55 public void onStateChanged(Call telecomCall, int state) { 56 // no ops 57 } 58 59 @Override 60 public void onParentChanged(Call telecomCall, Call parent) { 61 // no ops 62 } 63 64 @Override 65 public void onCallDestroyed(Call telecomCall) { 66 // no ops 67 } 68 69 @Override 70 public void onDetailsChanged(Call telecomCall, Call.Details details) { 71 setTelecomCallDetail(mTelecomCall); 72 } 73 74 @Override 75 public void onVideoCallChanged(Call telecomCall, InCallService.VideoCall videoCall) { 76 // no ops 77 } 78 79 @Override 80 public void onCannedTextResponsesLoaded(Call telecomCall, 81 List<String> cannedTextResponses) { 82 // no ops 83 } 84 85 @Override 86 public void onChildrenChanged(Call telecomCall, List<Call> children) { 87 // no ops 88 } 89 }; 90 91 /** 92 * Sets the {@link Call} of which this live data sources. 93 */ setTelecomCall(Call telecomCall)94 public void setTelecomCall(Call telecomCall) { 95 mTelecomCall = telecomCall; 96 setTelecomCallDetail(mTelecomCall); 97 if (mTelecomCall != null) { 98 mTelecomCall.registerCallback(mCallback); 99 } 100 } 101 setTelecomCallDetail(@ullable Call telecomCall)102 private void setTelecomCallDetail(@Nullable Call telecomCall) { 103 setValue(telecomCall != null ? CallDetail.fromTelecomCallDetail(telecomCall.getDetails()) 104 : null); 105 } 106 } 107