NetworkScanResult.java revision 26439f5616be0f7894ed37e6952b3a6841d3b164
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 17package com.android.internal.telephony; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21import android.telephony.CellInfo; 22import java.util.Arrays; 23import java.util.ArrayList; 24import java.util.List; 25import 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 */ 36public 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 = 0; 40 41 // Contains the last part of the scan result and the scan is now complete. 42 public static final int SCAN_STATUS_COMPLETE = 1; 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 */ 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 71 public int describeContents() { 72 return 0; 73 } 74 75 @Override 76 public void writeToParcel(Parcel dest, int flags) { 77 dest.writeInt(scanStatus); 78 dest.writeInt(scanError); 79 CellInfo[] ci = networkInfos.toArray(new CellInfo[networkInfos.size()]); 80 dest.writeParcelableArray(ci, flags); 81 } 82 83 private NetworkScanResult(Parcel in) { 84 scanStatus = in.readInt(); 85 scanError = in.readInt(); 86 CellInfo[] ci = (CellInfo[]) in.readParcelableArray( 87 Object.class.getClassLoader(), 88 CellInfo.class); 89 networkInfos = Arrays.asList(ci); 90 } 91 92 @Override 93 public boolean equals (Object o) { 94 NetworkScanResult nsr; 95 96 try { 97 nsr = (NetworkScanResult) o; 98 } catch (ClassCastException ex) { 99 return false; 100 } 101 102 if (o == null) { 103 return false; 104 } 105 106 return (scanStatus == nsr.scanStatus 107 && scanError == nsr.scanError 108 && networkInfos.equals(nsr.networkInfos)); 109 } 110 111 @Override 112 public int hashCode () { 113 return ((scanStatus * 31) 114 + (scanError * 23) 115 + (Objects.hashCode(networkInfos) * 37)); 116 } 117 118 public static final Creator<NetworkScanResult> CREATOR = 119 new Creator<NetworkScanResult>() { 120 @Override 121 public NetworkScanResult createFromParcel(Parcel in) { 122 return new NetworkScanResult(in); 123 } 124 125 @Override 126 public NetworkScanResult[] newArray(int size) { 127 return new NetworkScanResult[size]; 128 } 129 }; 130} 131