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