1 /* 2 ** Copyright 2015, 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 java.util.ArrayList; 22 import java.util.List; 23 24 /** 25 * Response for querying available cellular networks. 26 * 27 * @hide 28 */ 29 public class CellNetworkScanResult implements Parcelable { 30 31 /** 32 * Possible status values. 33 */ 34 public static final int STATUS_SUCCESS = 1; 35 public static final int STATUS_RADIO_NOT_AVAILABLE = 2; 36 public static final int STATUS_RADIO_GENERIC_FAILURE = 3; 37 public static final int STATUS_UNKNOWN_ERROR = 4; 38 39 private final int mStatus; 40 private final List<OperatorInfo> mOperators; 41 42 /** 43 * Constructor. 44 * 45 * @hide 46 */ 47 public CellNetworkScanResult(int status, List<OperatorInfo> operators) { 48 mStatus = status; 49 mOperators = operators; 50 } 51 52 /** 53 * Construct a CellNetworkScanResult from a given parcel. 54 */ 55 private CellNetworkScanResult(Parcel in) { 56 mStatus = in.readInt(); 57 int len = in.readInt(); 58 if (len > 0) { 59 mOperators = new ArrayList(); 60 for (int i = 0; i < len; ++i) { 61 mOperators.add(OperatorInfo.CREATOR.createFromParcel(in)); 62 } 63 } else { 64 mOperators = null; 65 } 66 } 67 68 /** 69 * @return the status of the command. 70 */ 71 public int getStatus() { 72 return mStatus; 73 } 74 75 /** 76 * @return the operators. 77 */ 78 public List<OperatorInfo> getOperators() { 79 return mOperators; 80 } 81 82 @Override 83 public int describeContents() { 84 return 0; 85 } 86 87 @Override 88 public void writeToParcel(Parcel out, int flags) { 89 out.writeInt(mStatus); 90 if (mOperators != null && mOperators.size() > 0) { 91 out.writeInt(mOperators.size()); 92 for (OperatorInfo network : mOperators) { 93 network.writeToParcel(out, flags); 94 } 95 } else { 96 out.writeInt(0); 97 } 98 } 99 100 @Override 101 public String toString() { 102 StringBuffer sb = new StringBuffer(); 103 sb.append("CellNetworkScanResult: {"); 104 sb.append(" status:").append(mStatus); 105 if (mOperators != null) { 106 for (OperatorInfo network : mOperators) { 107 sb.append(" network:").append(network); 108 } 109 } 110 sb.append("}"); 111 return sb.toString(); 112 } 113 114 public static final Parcelable.Creator<CellNetworkScanResult> CREATOR 115 = new Parcelable.Creator<CellNetworkScanResult>() { 116 117 @Override 118 public CellNetworkScanResult createFromParcel(Parcel in) { 119 return new CellNetworkScanResult(in); 120 } 121 122 public CellNetworkScanResult[] newArray(int size) { 123 return new CellNetworkScanResult[size]; 124 } 125 }; 126 } 127