1 /*
2  * Copyright (C) 2011 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 com.android.server.wifi;
18 
19 import android.annotation.NonNull;
20 import android.net.wifi.SupplicantState;
21 import android.net.wifi.WifiManager;
22 import android.net.wifi.WifiSsid;
23 import android.util.Log;
24 
25 /**
26  * Stores supplicant state change information passed from WifiMonitor to
27  * a state machine. ClientModeImpl, SupplicantStateTracker and WpsStateMachine
28  * are example state machines that handle it.
29  */
30 public class StateChangeResult {
31 
32     private static final String TAG = "StateChangeResult";
StateChangeResult(int networkId, @NonNull WifiSsid wifiSsid, @NonNull String bssid, int frequencyMhz, SupplicantState state)33     StateChangeResult(int networkId, @NonNull WifiSsid wifiSsid, @NonNull String bssid,
34             int frequencyMhz, SupplicantState state) {
35         if (wifiSsid == null) {
36             Log.wtf(TAG, "Null SSID provided");
37             this.wifiSsid = WifiSsid.fromBytes(null);
38         } else {
39             this.wifiSsid = wifiSsid;
40         }
41         if (bssid == null) {
42             Log.wtf(TAG, "Null BSSID provided");
43             this.bssid = WifiManager.ALL_ZEROS_MAC_ADDRESS.toString();
44         } else {
45             this.bssid = bssid;
46         }
47         this.state = state;
48         this.networkId = networkId;
49         this.frequencyMhz = frequencyMhz;
50     }
51 
52     public final int networkId;
53     @NonNull public final WifiSsid wifiSsid;
54     @NonNull public final String bssid;
55     public final int frequencyMhz;
56     public final SupplicantState state;
57 
58     @Override
toString()59     public String toString() {
60         StringBuffer sb = new StringBuffer();
61         sb.append(" ssid: ").append(wifiSsid);
62         sb.append(" bssid: ").append(bssid);
63         sb.append(" nid: ").append(networkId);
64         sb.append(" frequencyMhz: ").append(frequencyMhz);
65         sb.append(" state: ").append(state);
66         return sb.toString();
67     }
68 }
69