blob: 3319fc117b4d87c192aafe6207d1821e8c017d08 [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()}.
59 * @hide
60 */
61 public static final String EXTRA_CALL_ID = "android.telecom.extra.CALL_ID";
62
63 /**
Grace Jiaacd4dad2023-01-17 18:14:36 -080064 * @hide
65 */
Grace Jiaef5a4cc2022-12-13 11:08:55 -080066 private StreamingCall(@NonNull Parcel in) {
67 mComponentName = in.readParcelable(ComponentName.class.getClassLoader());
Grace Jiaacd4dad2023-01-17 18:14:36 -080068 mDisplayName = in.readCharSequence();
Grace Jiaef5a4cc2022-12-13 11:08:55 -080069 mAddress = in.readParcelable(Uri.class.getClassLoader());
70 mExtras = in.readBundle();
71 mState = in.readInt();
72 }
73
74 @NonNull
75 public static final Creator<StreamingCall> CREATOR = new Creator<>() {
76 @Override
77 public StreamingCall createFromParcel(@NonNull Parcel in) {
78 return new StreamingCall(in);
79 }
80
81 @Override
82 public StreamingCall[] newArray(int size) {
83 return new StreamingCall[size];
84 }
85 };
86
87 @Override
88 public int describeContents() {
89 return 0;
90 }
91
92 @Override
93 public void writeToParcel(@androidx.annotation.NonNull Parcel dest, int flags) {
94 dest.writeParcelable(mComponentName, flags);
Grace Jiaacd4dad2023-01-17 18:14:36 -080095 dest.writeCharSequence(mDisplayName);
Grace Jiaef5a4cc2022-12-13 11:08:55 -080096 dest.writeParcelable(mAddress, flags);
97 dest.writeBundle(mExtras);
98 dest.writeInt(mState);
99 }
100
101 /**
102 * @hide
103 */
104 @IntDef(prefix = { "STATE_" },
105 value = {
106 STATE_STREAMING,
107 STATE_HOLDING,
108 STATE_DISCONNECTED
109 })
110 @Retention(RetentionPolicy.SOURCE)
111 public @interface StreamingCallState {}
112
113 private final ComponentName mComponentName;
Grace Jiaacd4dad2023-01-17 18:14:36 -0800114 private final CharSequence mDisplayName;
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800115 private final Uri mAddress;
116 private final Bundle mExtras;
117 @StreamingCallState
118 private int mState;
119 private StreamingCallAdapter mAdapter = null;
120
Grace Jiaacd4dad2023-01-17 18:14:36 -0800121 public StreamingCall(@NonNull ComponentName componentName, @NonNull CharSequence displayName,
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800122 @NonNull Uri address, @NonNull Bundle extras) {
123 mComponentName = componentName;
124 mDisplayName = displayName;
125 mAddress = address;
126 mExtras = extras;
127 mState = STATE_STREAMING;
128 }
129
130 /**
131 * @hide
132 */
133 public void setAdapter(StreamingCallAdapter adapter) {
134 mAdapter = adapter;
135 }
136
137 /**
138 * @return The {@link ComponentName} to identify the original voip app of this
139 * {@code StreamingCall}. General streaming sender app can use this to query necessary
140 * information (app icon etc.) in order to present notification of the streaming call on the
141 * receiver side.
142 */
143 @NonNull
144 public ComponentName getComponentName() {
145 return mComponentName;
146 }
147
148 /**
149 * @return The display name that the general streaming sender app can use this to present the
150 * {@code StreamingCall} to the receiver side.
151 */
152 @NonNull
Grace Jiaacd4dad2023-01-17 18:14:36 -0800153 public CharSequence getDisplayName() {
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800154 return mDisplayName;
155 }
156
157 /**
158 * @return The address (e.g., phone number) to which the {@code StreamingCall} is currently
159 * connected.
160 */
161 @NonNull
162 public Uri getAddress() {
163 return mAddress;
164 }
165
166 /**
167 * @return The state of this {@code StreamingCall}.
168 */
169 @StreamingCallState
170 public int getState() {
171 return mState;
172 }
173
174 /**
175 * @return The extra info the general streaming app need to stream the call from voip app or
176 * D2DI sdk.
177 */
178 @NonNull
179 public Bundle getExtras() {
180 return mExtras;
181 }
182
183 /**
184 * Sets the state of this {@code StreamingCall}. The general streaming sender app can use this
185 * to request holding, unholding and disconnecting this {@code StreamingCall}.
186 * @param state The current streaming state of the call.
187 */
Grace Jiaefb63a72023-01-19 14:15:25 -0800188 public void requestStreamingState(@StreamingCallState int state) {
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800189 mAdapter.setStreamingState(state);
190 }
191}