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