1 /*
2  * Copyright (C) 2010 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 static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
20 import static android.net.wifi.WifiManager.AddNetworkResult.STATUS_ADD_WIFI_CONFIG_FAILURE;
21 import static android.net.wifi.WifiManager.AddNetworkResult.STATUS_SUCCESS;
22 
23 import android.net.wifi.WifiManager;
24 
25 import java.util.Objects;
26 
27 public class NetworkUpdateResult {
28     private final int mNetId;
29     private final boolean mIpChanged;
30     private final boolean mProxyChanged;
31     private final boolean mCredentialChanged;
32     private final boolean mIsNewNetwork;
33     private final @WifiManager.AddNetworkResult.AddNetworkStatusCode int mStatusCode;
34 
NetworkUpdateResult(int netId)35     public NetworkUpdateResult(int netId) {
36         this(netId, netId != INVALID_NETWORK_ID ? STATUS_SUCCESS : STATUS_ADD_WIFI_CONFIG_FAILURE,
37                 false, false, false, false);
38     }
39 
NetworkUpdateResult(int netId, int addNetworkFailureCode)40     public NetworkUpdateResult(int netId, int addNetworkFailureCode) {
41         this(netId, addNetworkFailureCode, false, false, false, false);
42     }
43 
NetworkUpdateResult( int netId, int addNetworkFailureCode, boolean ip, boolean proxy, boolean credential, boolean isNewNetwork)44     public NetworkUpdateResult(
45             int netId,
46             int addNetworkFailureCode,
47             boolean ip,
48             boolean proxy,
49             boolean credential,
50             boolean isNewNetwork) {
51         mNetId = netId;
52         mStatusCode = addNetworkFailureCode;
53         mIpChanged = ip;
54         mProxyChanged = proxy;
55         mCredentialChanged = credential;
56         mIsNewNetwork = isNewNetwork;
57     }
58 
59     /** Make an instance of NetworkUpdateResult whose {@link #isSuccess()} method returns false. */
makeFailed()60     public static NetworkUpdateResult makeFailed() {
61         return new NetworkUpdateResult(INVALID_NETWORK_ID);
62     }
63 
getNetworkId()64     public int getNetworkId() {
65         return mNetId;
66     }
67 
hasIpChanged()68     public boolean hasIpChanged() {
69         return mIpChanged;
70     }
71 
hasProxyChanged()72     public boolean hasProxyChanged() {
73         return mProxyChanged;
74     }
75 
hasCredentialChanged()76     public boolean hasCredentialChanged() {
77         return mCredentialChanged;
78     }
79 
isNewNetwork()80     public boolean isNewNetwork() {
81         return mIsNewNetwork;
82     }
83 
isSuccess()84     public boolean isSuccess() {
85         return mStatusCode == STATUS_SUCCESS;
86     }
87 
getStatusCode()88     public @WifiManager.AddNetworkResult.AddNetworkStatusCode int getStatusCode() {
89         return mStatusCode;
90     }
91 
92     @Override
equals(Object o)93     public boolean equals(Object o) {
94         if (this == o) return true;
95         if (o == null || getClass() != o.getClass()) return false;
96         NetworkUpdateResult that = (NetworkUpdateResult) o;
97         return mNetId == that.mNetId
98                 && mIpChanged == that.mIpChanged
99                 && mProxyChanged == that.mProxyChanged
100                 && mCredentialChanged == that.mCredentialChanged
101                 && mIsNewNetwork == that.mIsNewNetwork;
102     }
103 
104     @Override
hashCode()105     public int hashCode() {
106         return Objects.hash(mNetId, mIpChanged, mProxyChanged, mCredentialChanged, mIsNewNetwork);
107     }
108 
109     @Override
toString()110     public String toString() {
111         return "NetworkUpdateResult{"
112                 + "mNetId=" + mNetId
113                 + ", mIpChanged=" + mIpChanged
114                 + ", mProxyChanged=" + mProxyChanged
115                 + ", mCredentialChanged=" + mCredentialChanged
116                 + ", mIsNewNetwork=" + mIsNewNetwork
117                 + '}';
118     }
119 }
120