blob: 29f436d9f459180f5240b053ea235ec9f834b536 [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
19import android.annotation.IntDef;
20import android.annotation.NonNull;
Grace Jiaacd4dad2023-01-17 18:14:36 -080021import android.annotation.SystemApi;
Grace Jiaef5a4cc2022-12-13 11:08:55 -080022import android.content.ComponentName;
23import android.net.Uri;
24import android.os.Bundle;
25import android.os.Parcel;
26import android.os.Parcelable;
27
28import java.lang.annotation.Retention;
29import java.lang.annotation.RetentionPolicy;
30
31/**
32 * Represents a voip call requested to stream to another device that the general streaming sender
33 * app should present to the receiver.
Grace Jiaacd4dad2023-01-17 18:14:36 -080034 *
35 * @hide
Grace Jiaef5a4cc2022-12-13 11:08:55 -080036 */
Grace Jiaacd4dad2023-01-17 18:14:36 -080037@SystemApi
Grace Jiaef5a4cc2022-12-13 11:08:55 -080038public final class StreamingCall implements Parcelable {
39 /**
40 * The state of a {@code StreamingCall} when newly created. General streaming sender should
41 * continuously stream call audio to the sender device as long as the {@code StreamingCall} is
42 * in this state.
43 */
44 public static final int STATE_STREAMING = 1;
45
46 /**
47 * The state of a {@code StreamingCall} when in a holding state.
48 */
49 public static final int STATE_HOLDING = 2;
50
51 /**
52 * The state of a {@code StreamingCall} when it's either disconnected or pulled back to the
53 * original device.
54 */
55 public static final int STATE_DISCONNECTED = 3;
56
Grace Jiaacd4dad2023-01-17 18:14:36 -080057 /**
Tyler Gunn8ae42772023-04-26 02:41:41 +000058 * The ID associated with this call. This is the same value as {@link CallControl#getCallId()}.
Tyler Gunn8ae42772023-04-26 02:41:41 +000059 */
60 public static final String EXTRA_CALL_ID = "android.telecom.extra.CALL_ID";
61
62 /**
Grace Jiaacd4dad2023-01-17 18:14:36 -080063 * @hide
64 */
Grace Jiaef5a4cc2022-12-13 11:08:55 -080065 private StreamingCall(@NonNull Parcel in) {
66 mComponentName = in.readParcelable(ComponentName.class.getClassLoader());
Grace Jiaacd4dad2023-01-17 18:14:36 -080067 mDisplayName = in.readCharSequence();
Grace Jiaef5a4cc2022-12-13 11:08:55 -080068 mAddress = in.readParcelable(Uri.class.getClassLoader());
69 mExtras = in.readBundle();
70 mState = in.readInt();
71 }
72
73 @NonNull
74 public static final Creator<StreamingCall> CREATOR = new Creator<>() {
75 @Override
76 public StreamingCall createFromParcel(@NonNull Parcel in) {
77 return new StreamingCall(in);
78 }
79
80 @Override
81 public StreamingCall[] newArray(int size) {
82 return new StreamingCall[size];
83 }
84 };
85
86 @Override
87 public int describeContents() {
88 return 0;
89 }
90
91 @Override
92 public void writeToParcel(@androidx.annotation.NonNull Parcel dest, int flags) {
93 dest.writeParcelable(mComponentName, flags);
Grace Jiaacd4dad2023-01-17 18:14:36 -080094 dest.writeCharSequence(mDisplayName);
Grace Jiaef5a4cc2022-12-13 11:08:55 -080095 dest.writeParcelable(mAddress, flags);
96 dest.writeBundle(mExtras);
97 dest.writeInt(mState);
98 }
99
100 /**
101 * @hide
102 */
103 @IntDef(prefix = { "STATE_" },
104 value = {
105 STATE_STREAMING,
106 STATE_HOLDING,
107 STATE_DISCONNECTED
108 })
109 @Retention(RetentionPolicy.SOURCE)
110 public @interface StreamingCallState {}
111
112 private final ComponentName mComponentName;
Grace Jiaacd4dad2023-01-17 18:14:36 -0800113 private final CharSequence mDisplayName;
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800114 private final Uri mAddress;
115 private final Bundle mExtras;
116 @StreamingCallState
117 private int mState;
118 private StreamingCallAdapter mAdapter = null;
119
Grace Jiaacd4dad2023-01-17 18:14:36 -0800120 public StreamingCall(@NonNull ComponentName componentName, @NonNull CharSequence displayName,
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800121 @NonNull Uri address, @NonNull Bundle extras) {
122 mComponentName = componentName;
123 mDisplayName = displayName;
124 mAddress = address;
125 mExtras = extras;
126 mState = STATE_STREAMING;
127 }
128
129 /**
130 * @hide
131 */
132 public void setAdapter(StreamingCallAdapter adapter) {
133 mAdapter = adapter;
134 }
135
136 /**
137 * @return The {@link ComponentName} to identify the original voip app of this
138 * {@code StreamingCall}. General streaming sender app can use this to query necessary
139 * information (app icon etc.) in order to present notification of the streaming call on the
140 * receiver side.
141 */
142 @NonNull
143 public ComponentName getComponentName() {
144 return mComponentName;
145 }
146
147 /**
148 * @return The display name that the general streaming sender app can use this to present the
149 * {@code StreamingCall} to the receiver side.
150 */
151 @NonNull
Grace Jiaacd4dad2023-01-17 18:14:36 -0800152 public CharSequence getDisplayName() {
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800153 return mDisplayName;
154 }
155
156 /**
157 * @return The address (e.g., phone number) to which the {@code StreamingCall} is currently
158 * connected.
159 */
160 @NonNull
161 public Uri getAddress() {
162 return mAddress;
163 }
164
165 /**
166 * @return The state of this {@code StreamingCall}.
167 */
168 @StreamingCallState
169 public int getState() {
170 return mState;
171 }
172
173 /**
174 * @return The extra info the general streaming app need to stream the call from voip app or
175 * D2DI sdk.
176 */
177 @NonNull
178 public Bundle getExtras() {
179 return mExtras;
180 }
181
182 /**
183 * Sets the state of this {@code StreamingCall}. The general streaming sender app can use this
184 * to request holding, unholding and disconnecting this {@code StreamingCall}.
185 * @param state The current streaming state of the call.
186 */
Grace Jiaefb63a72023-01-19 14:15:25 -0800187 public void requestStreamingState(@StreamingCallState int state) {
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800188 mAdapter.setStreamingState(state);
189 }
190}