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.lifecycle.LiveData;
23 
24 import java.util.List;
25 
26 /**
27  * Represents an active phone call state.
28  */
29 public class CallStateLiveData extends LiveData<Integer> {
30 
31     private final Call mTelecomCall;
32 
CallStateLiveData(Call telecomCall)33     public CallStateLiveData(Call telecomCall) {
34         mTelecomCall = telecomCall;
35     }
36 
37     @Override
onActive()38     protected void onActive() {
39         super.onActive();
40 
41         setValue(mTelecomCall.getState());
42         mTelecomCall.registerCallback(mCallback);
43     }
44 
45     @Override
onInactive()46     protected void onInactive() {
47         super.onInactive();
48         mTelecomCall.unregisterCallback(mCallback);
49     }
50 
51     private Call.Callback mCallback = new Call.Callback() {
52         @Override
53         public void onStateChanged(Call telecomCall, int state) {
54             setValue(state);
55         }
56 
57         @Override
58         public void onParentChanged(Call telecomCall, Call parent) {
59             // no ops
60         }
61 
62         @Override
63         public void onCallDestroyed(Call telecomCall) {
64             // no ops
65         }
66 
67         @Override
68         public void onDetailsChanged(Call telecomCall, Call.Details details) {
69             // no ops
70         }
71 
72         @Override
73         public void onVideoCallChanged(Call telecomCall, InCallService.VideoCall videoCall) {
74             // no ops
75         }
76 
77         @Override
78         public void onCannedTextResponsesLoaded(Call telecomCall,
79                 List<String> cannedTextResponses) {
80             // no ops
81         }
82 
83         @Override
84         public void onChildrenChanged(Call telecomCall, List<Call> children) {
85             // no ops
86         }
87     };
88 }
89