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.telephony.ims; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.util.Objects; 28 29 /** 30 * The state of an ongoing SIP dialog. 31 * @hide 32 */ 33 @SystemApi 34 public final class SipDialogState implements Parcelable { 35 36 /**@hide*/ 37 @Retention(RetentionPolicy.SOURCE) 38 @IntDef(prefix = "STATE_", value = {STATE_EARLY, STATE_CONFIRMED, STATE_CLOSED}) 39 public @interface SipDialogStateCode {} 40 /** 41 * The device has sent out a dialog starting event and is awaiting a confirmation. 42 */ 43 public static final int STATE_EARLY = 0; 44 45 /** 46 * The device has received a 2XX response to the early dialog. 47 */ 48 public static final int STATE_CONFIRMED = 1; 49 50 /** 51 * The device has received either a 3XX+ response to a pending dialog request or a BYE 52 * request has been sent on this dialog. 53 */ 54 public static final int STATE_CLOSED = 2; 55 56 private final int mState; 57 58 /** 59 * Builder for {@link SipDialogState}. 60 * @hide 61 */ 62 public static final class Builder { 63 private int mState = STATE_EARLY; 64 65 /** 66 * constructor 67 * @param state The state of SipDialog 68 */ Builder(@ipDialogStateCode int state)69 public Builder(@SipDialogStateCode int state) { 70 mState = state; 71 } 72 73 /** 74 * Build the {@link SipDialogState}. 75 * @return The {@link SipDialogState} instance. 76 */ build()77 public @NonNull SipDialogState build() { 78 return new SipDialogState(this); 79 } 80 } 81 82 /** 83 * set Dialog state 84 */ SipDialogState(@onNull Builder builder)85 private SipDialogState(@NonNull Builder builder) { 86 this.mState = builder.mState; 87 } 88 SipDialogState(Parcel in)89 private SipDialogState(Parcel in) { 90 mState = in.readInt(); 91 } 92 93 /** 94 * @return The state of the SIP dialog 95 */ getState()96 public @SipDialogStateCode int getState() { 97 return mState; 98 } 99 100 public static final @NonNull Creator<SipDialogState> CREATOR = new Creator<SipDialogState>() { 101 @Override 102 public SipDialogState createFromParcel(@NonNull Parcel in) { 103 return new SipDialogState(in); 104 } 105 106 @Override 107 public SipDialogState[] newArray(int size) { 108 return new SipDialogState[size]; 109 } 110 }; 111 112 @Override describeContents()113 public int describeContents() { 114 return 0; 115 } 116 117 @Override writeToParcel(@onNull Parcel dest, int flags)118 public void writeToParcel(@NonNull Parcel dest, int flags) { 119 dest.writeInt(mState); 120 } 121 122 @Override equals(Object o)123 public boolean equals(Object o) { 124 if (this == o) return true; 125 if (o == null || getClass() != o.getClass()) return false; 126 SipDialogState sipDialog = (SipDialogState) o; 127 128 return mState == sipDialog.mState; 129 } 130 131 @Override hashCode()132 public int hashCode() { 133 return Objects.hash(mState); 134 } 135 } 136