• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.internal.telephony;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.telephony.CellInfo;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Objects;
26 
27 /**
28  * Defines the incremental network scan result.
29  *
30  * This class contains the network scan results. When the user starts a new scan, multiple
31  * NetworkScanResult may be returned, containing either the scan result or error. When the user
32  * stops an ongoing scan, only one NetworkScanResult will be returned to indicate either the scan
33  * is now complete or there is some error stopping it.
34  * @hide
35  */
36 public final class NetworkScanResult implements Parcelable {
37 
38     // Contains only part of the scan result and more are coming.
39     public static final int SCAN_STATUS_PARTIAL = 1;
40 
41     // Contains the last part of the scan result and the scan is now complete.
42     public static final int SCAN_STATUS_COMPLETE = 2;
43 
44     // The status of the scan, only valid when scanError = SUCCESS.
45     public int scanStatus;
46 
47     /**
48      * The error code of the scan
49      *
50      * This is the error code returned from the RIL, see {@link RILConstants} for more details
51      */
52     public int scanError;
53 
54     // The scan results, only valid when scanError = SUCCESS.
55     public List<CellInfo> networkInfos;
56 
57     /**
58      * Creates a new NetworkScanResult with scanStatus, scanError and networkInfos
59      *
60      * @param scanStatus The status of the scan.
61      * @param scanError The error code of the scan.
62      * @param networkInfos List of the CellInfo.
63      */
NetworkScanResult(int scanStatus, int scanError, List<CellInfo> networkInfos)64     public NetworkScanResult(int scanStatus, int scanError, List<CellInfo> networkInfos) {
65         this.scanStatus = scanStatus;
66         this.scanError = scanError;
67         this.networkInfos = networkInfos;
68     }
69 
70     @Override
describeContents()71     public int describeContents() {
72         return 0;
73     }
74 
75     @Override
writeToParcel(Parcel dest, int flags)76     public void writeToParcel(Parcel dest, int flags) {
77         dest.writeInt(scanStatus);
78         dest.writeInt(scanError);
79         dest.writeParcelableList(networkInfos, flags);
80     }
81 
NetworkScanResult(Parcel in)82     private NetworkScanResult(Parcel in) {
83         scanStatus = in.readInt();
84         scanError = in.readInt();
85         List<CellInfo> ni = new ArrayList<>();
86         in.readParcelableList(ni, Object.class.getClassLoader());
87         networkInfos = ni;
88     }
89 
90     @Override
equals(Object o)91     public boolean equals (Object o) {
92         NetworkScanResult nsr;
93 
94         try {
95             nsr = (NetworkScanResult) o;
96         } catch (ClassCastException ex) {
97             return false;
98         }
99 
100         if (o == null) {
101             return false;
102         }
103 
104         return (scanStatus == nsr.scanStatus
105                 && scanError == nsr.scanError
106                 && networkInfos.equals(nsr.networkInfos));
107     }
108 
109     @Override
toString()110     public String toString() {
111         return new StringBuilder()
112             .append("{")
113             .append("scanStatus=" + scanStatus)
114             .append(", scanError=" + scanError)
115             .append(", networkInfos=" + networkInfos)
116             .append("}")
117             .toString();
118     }
119 
120     @Override
hashCode()121     public int hashCode () {
122         return ((scanStatus * 31)
123                 + (scanError * 23)
124                 + (Objects.hashCode(networkInfos) * 37));
125     }
126 
127     public static final Creator<NetworkScanResult> CREATOR =
128         new Creator<NetworkScanResult>() {
129             @Override
130             public NetworkScanResult createFromParcel(Parcel in) {
131                 return new NetworkScanResult(in);
132             }
133 
134             @Override
135             public NetworkScanResult[] newArray(int size) {
136                 return new NetworkScanResult[size];
137             }
138         };
139 }
140