| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.telecom; |
| 18 | |
| Grant Menke | 37155c8 | 2023-10-10 14:17:26 -0700 | [diff] [blame] | 19 | import android.annotation.FlaggedApi; |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 20 | import android.annotation.IntDef; |
| 21 | import android.annotation.NonNull; |
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 22 | import android.annotation.SystemApi; |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 23 | import android.content.ComponentName; |
| 24 | import android.net.Uri; |
| 25 | import android.os.Bundle; |
| 26 | import android.os.Parcel; |
| 27 | import android.os.Parcelable; |
| 28 | |
| Grant Menke | 37155c8 | 2023-10-10 14:17:26 -0700 | [diff] [blame] | 29 | import com.android.server.telecom.flags.Flags; |
| 30 | |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 31 | import java.lang.annotation.Retention; |
| 32 | import 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 37 | * |
| 38 | * @hide |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 39 | */ |
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 40 | @SystemApi |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 41 | public 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 60 | /** |
| Tyler Gunn | 8ae4277 | 2023-04-26 02:41:41 +0000 | [diff] [blame] | 61 | * The ID associated with this call. This is the same value as {@link CallControl#getCallId()}. |
| Tyler Gunn | 8ae4277 | 2023-04-26 02:41:41 +0000 | [diff] [blame] | 62 | */ |
| Grant Menke | 37155c8 | 2023-10-10 14:17:26 -0700 | [diff] [blame] | 63 | @FlaggedApi(Flags.FLAG_CALL_DETAILS_ID_CHANGES) |
| Tyler Gunn | 8ae4277 | 2023-04-26 02:41:41 +0000 | [diff] [blame] | 64 | public static final String EXTRA_CALL_ID = "android.telecom.extra.CALL_ID"; |
| 65 | |
| 66 | /** |
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 67 | * @hide |
| 68 | */ |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 69 | private StreamingCall(@NonNull Parcel in) { |
| 70 | mComponentName = in.readParcelable(ComponentName.class.getClassLoader()); |
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 71 | mDisplayName = in.readCharSequence(); |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 72 | 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 98 | dest.writeCharSequence(mDisplayName); |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 99 | 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 117 | private final CharSequence mDisplayName; |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 118 | private final Uri mAddress; |
| 119 | private final Bundle mExtras; |
| 120 | @StreamingCallState |
| 121 | private int mState; |
| 122 | private StreamingCallAdapter mAdapter = null; |
| 123 | |
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 124 | public StreamingCall(@NonNull ComponentName componentName, @NonNull CharSequence displayName, |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 125 | @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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 156 | public CharSequence getDisplayName() { |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 157 | 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 Jia | efb63a7 | 2023-01-19 14:15:25 -0800 | [diff] [blame] | 191 | public void requestStreamingState(@StreamingCallState int state) { |
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 192 | mAdapter.setStreamingState(state); |
| 193 | } |
| 194 | } |