1 /* 2 * Copyright (C) 2021 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.net.wifi; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * A class representing the session information of a connected Wi-Fi network for external Wi-Fi 26 * scorer to identify the Wi-Fi network. 27 * 28 * @hide 29 */ 30 @SystemApi 31 public final class WifiConnectedSessionInfo implements Parcelable { 32 private final int mSessionId; 33 private final boolean mIsUserSelected; 34 35 /** Create a new WifiConnectedSessionInfo object */ WifiConnectedSessionInfo(int sessionId, boolean isUserSelected)36 private WifiConnectedSessionInfo(int sessionId, boolean isUserSelected) { 37 mSessionId = sessionId; 38 mIsUserSelected = isUserSelected; 39 } 40 41 /** Builder for WifiConnectedSessionInfo */ 42 public static final class Builder { 43 private final int mSessionId; 44 private boolean mIsUserSelected = false; 45 46 /** Create a new builder */ Builder(int sessionId)47 public Builder(int sessionId) { 48 mSessionId = sessionId; 49 } 50 51 /** Set whether this network is user selected */ setUserSelected(boolean isUserSelected)52 @NonNull public Builder setUserSelected(boolean isUserSelected) { 53 mIsUserSelected = isUserSelected; 54 return this; 55 } 56 57 /** Build the WifiConnectedSessionInfo object represented by this builder */ build()58 @NonNull public WifiConnectedSessionInfo build() { 59 return new WifiConnectedSessionInfo(mSessionId, mIsUserSelected); 60 } 61 } 62 63 @Override describeContents()64 public int describeContents() { 65 return 0; 66 } 67 68 @Override writeToParcel(@onNull Parcel dest, int flags)69 public void writeToParcel(@NonNull Parcel dest, int flags) { 70 dest.writeInt(mSessionId); 71 dest.writeBoolean(mIsUserSelected); 72 } 73 74 /** Implement the Parcelable interface */ 75 public static final @NonNull Creator<WifiConnectedSessionInfo> CREATOR = 76 new Creator<WifiConnectedSessionInfo>() { 77 public WifiConnectedSessionInfo createFromParcel(Parcel in) { 78 return new WifiConnectedSessionInfo(in.readInt(), in.readBoolean()); 79 } 80 81 public WifiConnectedSessionInfo[] newArray(int size) { 82 return new WifiConnectedSessionInfo[size]; 83 } 84 }; 85 86 /** The ID to indicate current Wi-Fi network connection */ getSessionId()87 public int getSessionId() { 88 return mSessionId; 89 } 90 91 /** Indicate whether current Wi-Fi network is selected by the user */ isUserSelected()92 public boolean isUserSelected() { 93 return mIsUserSelected; 94 } 95 } 96