• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, 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.stream;
17 
18 import android.app.PendingIntent;
19 import android.graphics.Bitmap;
20 import android.os.Bundle;
21 
22 /**
23  * An extension to {@link StreamCard} that holds data specific to current call events.
24  */
25 public class CurrentCallExtension extends StreamCardExtension {
26     private static final int INVALID_CALL_STATE = -1;
27 
28     private static final String MUTE_ACTION_KEY = "mute_action";
29     private static final String UNMUTE_ACTION_KEY = "unmute_action";
30     private static final String ACCEPT_CALL_ACTION_KEY = "accept_call_action";
31     private static final String HANGUP_CALL_ACTION_KEY = "hangup_call_action";
32     private static final String CALL_START_TIME_KEY_KEY = "call_start_time";
33     private static final String CALL_STATE_KEY = "call_state";
34     private static final String IS_MUTED_KEY = "is_muted";
35     private static final String DISPLAY_NAME_KEY = "display_name";
36     private static final String CONTACT_PHOTO_KEY = "contact_photo";
37 
38     private long mCallStartTime;
39     private String mDisplayName;
40     private int mCallState = INVALID_CALL_STATE;
41     private boolean mIsMuted;
42 
43     private Bitmap mContactPhoto;
44 
45     private PendingIntent mMuteAction;
46     private PendingIntent mUnMuteAction;
47     private PendingIntent mAcceptCallAction;
48     private PendingIntent mHangupCallAction;
49 
50     public static final Creator<CurrentCallExtension> CREATOR
51             = new BundleableCreator<>(CurrentCallExtension.class);
52 
CurrentCallExtension()53     public CurrentCallExtension() {}
54 
CurrentCallExtension( long callStartTime, String displayName, int callState, boolean isMuted, Bitmap contactPhoto, PendingIntent muteAction, PendingIntent unMuteAction, PendingIntent acceptCallAction, PendingIntent hangupCallAction)55     public CurrentCallExtension(
56             long callStartTime,
57             String displayName,
58             int callState,
59             boolean isMuted,
60             Bitmap contactPhoto,
61             PendingIntent muteAction,
62             PendingIntent unMuteAction,
63             PendingIntent acceptCallAction,
64             PendingIntent hangupCallAction) {
65         mCallStartTime = callStartTime;
66         mDisplayName = displayName;
67         mCallState = callState;
68         mIsMuted = isMuted;
69         mContactPhoto = contactPhoto;
70         mMuteAction = muteAction;
71         mUnMuteAction = unMuteAction;
72         mAcceptCallAction = acceptCallAction;
73         mHangupCallAction = hangupCallAction;
74     }
75 
76     @Override
writeToBundle(Bundle bundle)77     protected void writeToBundle(Bundle bundle) {
78         bundle.putString(DISPLAY_NAME_KEY, mDisplayName);
79         bundle.putInt(CALL_STATE_KEY, mCallState);
80         bundle.putBoolean(IS_MUTED_KEY, mIsMuted);
81         bundle.putParcelable(CONTACT_PHOTO_KEY, mContactPhoto);
82         bundle.putLong(CALL_START_TIME_KEY_KEY, mCallStartTime);
83 
84         bundle.putParcelable(MUTE_ACTION_KEY, mMuteAction);
85         bundle.putParcelable(UNMUTE_ACTION_KEY, mUnMuteAction);
86         bundle.putParcelable(ACCEPT_CALL_ACTION_KEY, mAcceptCallAction);
87         bundle.putParcelable(HANGUP_CALL_ACTION_KEY, mHangupCallAction);
88     }
89 
90     @Override
readFromBundle(Bundle bundle)91     protected void readFromBundle(Bundle bundle) {
92         mDisplayName = bundle.getString(DISPLAY_NAME_KEY);
93         mCallState = bundle.getInt(CALL_STATE_KEY, INVALID_CALL_STATE);
94 
95         mIsMuted = bundle.getBoolean(IS_MUTED_KEY);
96         mContactPhoto = bundle.getParcelable(CONTACT_PHOTO_KEY);
97         mCallStartTime = bundle.getLong(CALL_START_TIME_KEY_KEY);
98 
99         mMuteAction = bundle.getParcelable(MUTE_ACTION_KEY);
100         mUnMuteAction = bundle.getParcelable(UNMUTE_ACTION_KEY);
101         mAcceptCallAction = bundle.getParcelable(ACCEPT_CALL_ACTION_KEY);
102         mHangupCallAction = bundle.getParcelable(HANGUP_CALL_ACTION_KEY);
103     }
104 
getDisplayName()105     public String getDisplayName() {
106         return mDisplayName;
107     }
108 
getHangupCallAction()109     public PendingIntent getHangupCallAction() {
110         return mHangupCallAction;
111     }
112 
getAcceptCallAction()113     public PendingIntent getAcceptCallAction() {
114         return mAcceptCallAction;
115     }
116 
getUnMuteAction()117     public PendingIntent getUnMuteAction() {
118         return mUnMuteAction;
119     }
120 
getMuteAction()121     public PendingIntent getMuteAction() {
122         return mMuteAction;
123     }
124 
getCallState()125     public int getCallState() {
126         return mCallState;
127     }
128 
getCallStartTime()129     public long getCallStartTime() {
130         return mCallStartTime;
131     }
132 
isMuted()133     public boolean isMuted() {
134         return mIsMuted;
135     }
136 
getContactPhoto()137     public Bitmap getContactPhoto() {
138         return mContactPhoto;
139     }
140 }
141