blob: 4b27dd6f1e599b56b688be647aed9660dfb237de [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;
21import android.content.ComponentName;
22import android.net.Uri;
23import android.os.Bundle;
24import android.os.Parcel;
25import android.os.Parcelable;
26
27import java.lang.annotation.Retention;
28import java.lang.annotation.RetentionPolicy;
29
30/**
31 * Represents a voip call requested to stream to another device that the general streaming sender
32 * app should present to the receiver.
33 */
34public final class StreamingCall implements Parcelable {
35 /**
36 * The state of a {@code StreamingCall} when newly created. General streaming sender should
37 * continuously stream call audio to the sender device as long as the {@code StreamingCall} is
38 * in this state.
39 */
40 public static final int STATE_STREAMING = 1;
41
42 /**
43 * The state of a {@code StreamingCall} when in a holding state.
44 */
45 public static final int STATE_HOLDING = 2;
46
47 /**
48 * The state of a {@code StreamingCall} when it's either disconnected or pulled back to the
49 * original device.
50 */
51 public static final int STATE_DISCONNECTED = 3;
52
53 private StreamingCall(@NonNull Parcel in) {
54 mComponentName = in.readParcelable(ComponentName.class.getClassLoader());
55 mDisplayName = in.readString16NoHelper();
56 mAddress = in.readParcelable(Uri.class.getClassLoader());
57 mExtras = in.readBundle();
58 mState = in.readInt();
59 }
60
61 @NonNull
62 public static final Creator<StreamingCall> CREATOR = new Creator<>() {
63 @Override
64 public StreamingCall createFromParcel(@NonNull Parcel in) {
65 return new StreamingCall(in);
66 }
67
68 @Override
69 public StreamingCall[] newArray(int size) {
70 return new StreamingCall[size];
71 }
72 };
73
74 @Override
75 public int describeContents() {
76 return 0;
77 }
78
79 @Override
80 public void writeToParcel(@androidx.annotation.NonNull Parcel dest, int flags) {
81 dest.writeParcelable(mComponentName, flags);
82 dest.writeString16NoHelper(mDisplayName);
83 dest.writeParcelable(mAddress, flags);
84 dest.writeBundle(mExtras);
85 dest.writeInt(mState);
86 }
87
88 /**
89 * @hide
90 */
91 @IntDef(prefix = { "STATE_" },
92 value = {
93 STATE_STREAMING,
94 STATE_HOLDING,
95 STATE_DISCONNECTED
96 })
97 @Retention(RetentionPolicy.SOURCE)
98 public @interface StreamingCallState {}
99
100 private final ComponentName mComponentName;
101 private final String mDisplayName;
102 private final Uri mAddress;
103 private final Bundle mExtras;
104 @StreamingCallState
105 private int mState;
106 private StreamingCallAdapter mAdapter = null;
107
108 public StreamingCall(@NonNull ComponentName componentName, @NonNull String displayName,
109 @NonNull Uri address, @NonNull Bundle extras) {
110 mComponentName = componentName;
111 mDisplayName = displayName;
112 mAddress = address;
113 mExtras = extras;
114 mState = STATE_STREAMING;
115 }
116
117 /**
118 * @hide
119 */
120 public void setAdapter(StreamingCallAdapter adapter) {
121 mAdapter = adapter;
122 }
123
124 /**
125 * @return The {@link ComponentName} to identify the original voip app of this
126 * {@code StreamingCall}. General streaming sender app can use this to query necessary
127 * information (app icon etc.) in order to present notification of the streaming call on the
128 * receiver side.
129 */
130 @NonNull
131 public ComponentName getComponentName() {
132 return mComponentName;
133 }
134
135 /**
136 * @return The display name that the general streaming sender app can use this to present the
137 * {@code StreamingCall} to the receiver side.
138 */
139 @NonNull
140 public String getDisplayName() {
141 return mDisplayName;
142 }
143
144 /**
145 * @return The address (e.g., phone number) to which the {@code StreamingCall} is currently
146 * connected.
147 */
148 @NonNull
149 public Uri getAddress() {
150 return mAddress;
151 }
152
153 /**
154 * @return The state of this {@code StreamingCall}.
155 */
156 @StreamingCallState
157 public int getState() {
158 return mState;
159 }
160
161 /**
162 * @return The extra info the general streaming app need to stream the call from voip app or
163 * D2DI sdk.
164 */
165 @NonNull
166 public Bundle getExtras() {
167 return mExtras;
168 }
169
170 /**
171 * Sets the state of this {@code StreamingCall}. The general streaming sender app can use this
172 * to request holding, unholding and disconnecting this {@code StreamingCall}.
173 * @param state The current streaming state of the call.
174 */
Grace Jiaefb63a72023-01-19 14:15:25 -0800175 public void requestStreamingState(@StreamingCallState int state) {
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800176 mAdapter.setStreamingState(state);
177 }
178}