| 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 |  | 
|  | 19 | import android.annotation.IntDef; | 
|  | 20 | import android.annotation.NonNull; | 
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; | 
|  | 23 | import android.net.Uri; | 
|  | 24 | import android.os.Bundle; | 
|  | 25 | import android.os.Parcel; | 
|  | 26 | import android.os.Parcelable; | 
|  | 27 |  | 
|  | 28 | import java.lang.annotation.Retention; | 
|  | 29 | import 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 34 | * | 
|  | 35 | * @hide | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 36 | */ | 
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 37 | @SystemApi | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 38 | public 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 57 | /** | 
|  | 58 | * @hide | 
|  | 59 | */ | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 60 | private StreamingCall(@NonNull Parcel in) { | 
|  | 61 | mComponentName = in.readParcelable(ComponentName.class.getClassLoader()); | 
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 62 | mDisplayName = in.readCharSequence(); | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 63 | 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 89 | dest.writeCharSequence(mDisplayName); | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 90 | 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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 108 | private final CharSequence mDisplayName; | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 109 | private final Uri mAddress; | 
|  | 110 | private final Bundle mExtras; | 
|  | 111 | @StreamingCallState | 
|  | 112 | private int mState; | 
|  | 113 | private StreamingCallAdapter mAdapter = null; | 
|  | 114 |  | 
| Grace Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 115 | public StreamingCall(@NonNull ComponentName componentName, @NonNull CharSequence displayName, | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 116 | @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 Jia | acd4dad | 2023-01-17 18:14:36 -0800 | [diff] [blame] | 147 | public CharSequence getDisplayName() { | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 148 | 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 Jia | efb63a7 | 2023-01-19 14:15:25 -0800 | [diff] [blame] | 182 | public void requestStreamingState(@StreamingCallState int state) { | 
| Grace Jia | ef5a4cc | 2022-12-13 11:08:55 -0800 | [diff] [blame] | 183 | mAdapter.setStreamingState(state); | 
|  | 184 | } | 
|  | 185 | } |