blob: ad1b6f9e766544aa8dbf206674ce56f1f7912ead [file] [log] [blame]
Grace Jiaef5a4cc2022-12-13 11:08:55 -08001/*
2 * Copyright (C) 2022 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
17package android.telecom;
18
Grant Menke37155c82023-10-10 14:17:26 -070019import android.annotation.FlaggedApi;
Grace Jiaef5a4cc2022-12-13 11:08:55 -080020import android.annotation.IntDef;
21import android.annotation.NonNull;
Grace Jiaacd4dad2023-01-17 18:14:36 -080022import android.annotation.SystemApi;
Grace Jiaef5a4cc2022-12-13 11:08:55 -080023import android.content.ComponentName;
24import android.net.Uri;
25import android.os.Bundle;
26import android.os.Parcel;
27import android.os.Parcelable;
28
Grant Menke37155c82023-10-10 14:17:26 -070029import com.android.server.telecom.flags.Flags;
30
Grace Jiaef5a4cc2022-12-13 11:08:55 -080031import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
33
34/**
35 * Represents a voip call requested to stream to another device that the general streaming sender
36 * app should present to the receiver.
Grace Jiaacd4dad2023-01-17 18:14:36 -080037 *
38 * @hide
Grace Jiaef5a4cc2022-12-13 11:08:55 -080039 */
Grace Jiaacd4dad2023-01-17 18:14:36 -080040@SystemApi
Grace Jiaef5a4cc2022-12-13 11:08:55 -080041public final class StreamingCall implements Parcelable {
42 /**
43 * The state of a {@code StreamingCall} when newly created. General streaming sender should
44 * continuously stream call audio to the sender device as long as the {@code StreamingCall} is
45 * in this state.
46 */
47 public static final int STATE_STREAMING = 1;
48
49 /**
50 * The state of a {@code StreamingCall} when in a holding state.
51 */
52 public static final int STATE_HOLDING = 2;
53
54 /**
55 * The state of a {@code StreamingCall} when it's either disconnected or pulled back to the
56 * original device.
57 */
58 public static final int STATE_DISCONNECTED = 3;
59
Grace Jiaacd4dad2023-01-17 18:14:36 -080060 /**
Tyler Gunn8ae42772023-04-26 02:41:41 +000061 * The ID associated with this call. This is the same value as {@link CallControl#getCallId()}.
Tyler Gunn8ae42772023-04-26 02:41:41 +000062 */
Grant Menke37155c82023-10-10 14:17:26 -070063 @FlaggedApi(Flags.FLAG_CALL_DETAILS_ID_CHANGES)
Tyler Gunn8ae42772023-04-26 02:41:41 +000064 public static final String EXTRA_CALL_ID = "android.telecom.extra.CALL_ID";
65
66 /**
Grace Jiaacd4dad2023-01-17 18:14:36 -080067 * @hide
68 */
Grace Jiaef5a4cc2022-12-13 11:08:55 -080069 private StreamingCall(@NonNull Parcel in) {
70 mComponentName = in.readParcelable(ComponentName.class.getClassLoader());
Grace Jiaacd4dad2023-01-17 18:14:36 -080071 mDisplayName = in.readCharSequence();
Grace Jiaef5a4cc2022-12-13 11:08:55 -080072 mAddress = in.readParcelable(Uri.class.getClassLoader());
73 mExtras = in.readBundle();
74 mState = in.readInt();
75 }
76
77 @NonNull
78 public static final Creator<StreamingCall> CREATOR = new Creator<>() {
79 @Override
80 public StreamingCall createFromParcel(@NonNull Parcel in) {
81 return new StreamingCall(in);
82 }
83
84 @Override
85 public StreamingCall[] newArray(int size) {
86 return new StreamingCall[size];
87 }
88 };
89
90 @Override
91 public int describeContents() {
92 return 0;
93 }
94
95 @Override
96 public void writeToParcel(@androidx.annotation.NonNull Parcel dest, int flags) {
97 dest.writeParcelable(mComponentName, flags);
Grace Jiaacd4dad2023-01-17 18:14:36 -080098 dest.writeCharSequence(mDisplayName);
Grace Jiaef5a4cc2022-12-13 11:08:55 -080099 dest.writeParcelable(mAddress, flags);
100 dest.writeBundle(mExtras);
101 dest.writeInt(mState);
102 }
103
104 /**
105 * @hide
106 */
107 @IntDef(prefix = { "STATE_" },
108 value = {
109 STATE_STREAMING,
110 STATE_HOLDING,
111 STATE_DISCONNECTED
112 })
113 @Retention(RetentionPolicy.SOURCE)
114 public @interface StreamingCallState {}
115
116 private final ComponentName mComponentName;
Grace Jiaacd4dad2023-01-17 18:14:36 -0800117 private final CharSequence mDisplayName;
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800118 private final Uri mAddress;
119 private final Bundle mExtras;
120 @StreamingCallState
121 private int mState;
122 private StreamingCallAdapter mAdapter = null;
123
Grace Jiaacd4dad2023-01-17 18:14:36 -0800124 public StreamingCall(@NonNull ComponentName componentName, @NonNull CharSequence displayName,
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800125 @NonNull Uri address, @NonNull Bundle extras) {
126 mComponentName = componentName;
127 mDisplayName = displayName;
128 mAddress = address;
129 mExtras = extras;
130 mState = STATE_STREAMING;
131 }
132
133 /**
134 * @hide
135 */
136 public void setAdapter(StreamingCallAdapter adapter) {
137 mAdapter = adapter;
138 }
139
140 /**
141 * @return The {@link ComponentName} to identify the original voip app of this
142 * {@code StreamingCall}. General streaming sender app can use this to query necessary
143 * information (app icon etc.) in order to present notification of the streaming call on the
144 * receiver side.
145 */
146 @NonNull
147 public ComponentName getComponentName() {
148 return mComponentName;
149 }
150
151 /**
152 * @return The display name that the general streaming sender app can use this to present the
153 * {@code StreamingCall} to the receiver side.
154 */
155 @NonNull
Grace Jiaacd4dad2023-01-17 18:14:36 -0800156 public CharSequence getDisplayName() {
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800157 return mDisplayName;
158 }
159
160 /**
161 * @return The address (e.g., phone number) to which the {@code StreamingCall} is currently
162 * connected.
163 */
164 @NonNull
165 public Uri getAddress() {
166 return mAddress;
167 }
168
169 /**
170 * @return The state of this {@code StreamingCall}.
171 */
172 @StreamingCallState
173 public int getState() {
174 return mState;
175 }
176
177 /**
178 * @return The extra info the general streaming app need to stream the call from voip app or
179 * D2DI sdk.
180 */
181 @NonNull
182 public Bundle getExtras() {
183 return mExtras;
184 }
185
186 /**
187 * Sets the state of this {@code StreamingCall}. The general streaming sender app can use this
188 * to request holding, unholding and disconnecting this {@code StreamingCall}.
189 * @param state The current streaming state of the call.
190 */
Grace Jiaefb63a72023-01-19 14:15:25 -0800191 public void requestStreamingState(@StreamingCallState int state) {
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800192 mAdapter.setStreamingState(state);
193 }
194}