| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.net; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 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 |
import java.util.StringJoiner; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public final class VpnProfileState implements Parcelable { |
| 34 |
|
| 35 |
public static final int STATE_DISCONNECTED = 0; |
| 36 |
|
| 37 |
public static final int STATE_CONNECTING = 1; |
| 38 |
|
| 39 |
public static final int STATE_CONNECTED = 2; |
| 40 |
|
| 41 |
public static final int STATE_FAILED = 3; |
| 42 |
|
| 43 |
@Retention(RetentionPolicy.SOURCE) |
| 44 |
@IntDef(prefix = {"STATE_"}, value = { |
| 45 |
STATE_CONNECTED, |
| 46 |
STATE_CONNECTING, |
| 47 |
STATE_DISCONNECTED, |
| 48 |
STATE_FAILED, |
| 49 |
}) |
| 50 |
public @interface State {} |
| 51 |
|
| 52 |
@State private final int mState; |
| 53 |
private final String mSessionKey; |
| 54 |
private final boolean mAlwaysOn; |
| 55 |
private final boolean mLockdown; |
| 56 |
|
| 57 |
public VpnProfileState(@State int state, @Nullable String sessionKey, boolean alwaysOn, |
| 58 |
boolean lockdown) { |
| 59 |
mState = state; |
| 60 |
mSessionKey = sessionKey; |
| 61 |
mAlwaysOn = alwaysOn; |
| 62 |
mLockdown = lockdown; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
@State public int getState() { |
| 72 |
return mState; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@Nullable |
| 86 |
public String getSessionId() { |
| 87 |
return mSessionKey; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public boolean isAlwaysOn() { |
| 102 |
return mAlwaysOn; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public boolean isLockdownEnabled() { |
| 117 |
return mLockdown; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public int describeContents() { |
| 124 |
return 0; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 131 |
out.writeInt(mState); |
| 132 |
out.writeString(mSessionKey); |
| 133 |
out.writeBoolean(mAlwaysOn); |
| 134 |
out.writeBoolean(mLockdown); |
| 135 |
} |
| 136 |
|
| 137 |
@NonNull |
| 138 |
public static final Parcelable.Creator<VpnProfileState> CREATOR = |
| 139 |
new Parcelable.Creator<VpnProfileState>() { |
| 140 |
public VpnProfileState createFromParcel(Parcel in) { |
| 141 |
return new VpnProfileState(in); |
| 142 |
} |
| 143 |
|
| 144 |
public VpnProfileState[] newArray(int size) { |
| 145 |
return new VpnProfileState[size]; |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
private VpnProfileState(Parcel in) { |
| 150 |
mState = in.readInt(); |
| 151 |
mSessionKey = in.readString(); |
| 152 |
mAlwaysOn = in.readBoolean(); |
| 153 |
mLockdown = in.readBoolean(); |
| 154 |
} |
| 155 |
|
| 156 |
private String convertStateToString(@State int state) { |
| 157 |
switch (state) { |
| 158 |
case STATE_CONNECTED: |
| 159 |
return "CONNECTED"; |
| 160 |
case STATE_CONNECTING: |
| 161 |
return "CONNECTING"; |
| 162 |
case STATE_DISCONNECTED: |
| 163 |
return "DISCONNECTED"; |
| 164 |
case STATE_FAILED: |
| 165 |
return "FAILED"; |
| 166 |
default: |
| 167 |
return "UNKNOWN"; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
@Override |
| 172 |
public String toString() { |
| 173 |
final StringJoiner resultJoiner = new StringJoiner(", ", "{", "}"); |
| 174 |
resultJoiner.add("State: " + convertStateToString(getState())); |
| 175 |
resultJoiner.add("SessionId: " + getSessionId()); |
| 176 |
resultJoiner.add("Always-on: " + isAlwaysOn()); |
| 177 |
resultJoiner.add("Lockdown: " + isLockdownEnabled()); |
| 178 |
return resultJoiner.toString(); |
| 179 |
} |
| 180 |
|
| 181 |
@Override |
| 182 |
public boolean equals(@Nullable Object obj) { |
| 183 |
if (!(obj instanceof VpnProfileState)) return false; |
| 184 |
final VpnProfileState that = (VpnProfileState) obj; |
| 185 |
return (getState() == that.getState() |
| 186 |
&& Objects.equals(getSessionId(), that.getSessionId()) |
| 187 |
&& isAlwaysOn() == that.isAlwaysOn() |
| 188 |
&& isLockdownEnabled() == that.isLockdownEnabled()); |
| 189 |
} |
| 190 |
|
| 191 |
@Override |
| 192 |
public int hashCode() { |
| 193 |
return Objects.hash(getState(), getSessionId(), isAlwaysOn(), isLockdownEnabled()); |
| 194 |
} |
| 195 |
} |