ScoredNetwork.java revision dc960e21ef1005fab5ef145773ddd6f40c802217
1/* 2 * Copyright (C) 2014 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 android.net; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21 22/** 23 * A network identifier along with a score for the quality of that network. 24 * 25 * @hide 26 */ 27public class ScoredNetwork implements Parcelable { 28 29 /** A {@link NetworkKey} uniquely identifying this network. */ 30 public final NetworkKey networkKey; 31 32 /** 33 * The {@link RssiCurve} representing the scores for this network based on the RSSI. 34 * 35 * <p>This field is optional and may be set to null to indicate that no score is available for 36 * this network at this time. Such networks, along with networks for which the scorer has not 37 * responded, are always prioritized below scored networks, regardless of the score. 38 */ 39 public final RssiCurve rssiCurve; 40 41 /** 42 * Construct a new {@link ScoredNetwork}. 43 * 44 * @param networkKey the {@link NetworkKey} uniquely identifying this network. 45 * @param rssiCurve the {@link RssiCurve} representing the scores for this network based on the 46 * RSSI. This field is optional, and may be skipped to represent a network which the scorer 47 * has opted not to score at this time. Passing a null value here is strongly preferred to 48 * not returning any {@link ScoredNetwork} for a given {@link NetworkKey} because it 49 * indicates to the system not to request scores for this network in the future, although 50 * the scorer may choose to issue an out-of-band update at any time. 51 */ 52 public ScoredNetwork(NetworkKey networkKey, RssiCurve rssiCurve) { 53 this.networkKey = networkKey; 54 this.rssiCurve = rssiCurve; 55 } 56 57 private ScoredNetwork(Parcel in) { 58 networkKey = NetworkKey.CREATOR.createFromParcel(in); 59 if (in.readByte() == 1) { 60 rssiCurve = RssiCurve.CREATOR.createFromParcel(in); 61 } else { 62 rssiCurve = null; 63 } 64 } 65 66 @Override 67 public int describeContents() { 68 return 0; 69 } 70 71 @Override 72 public void writeToParcel(Parcel out, int flags) { 73 networkKey.writeToParcel(out, flags); 74 if (rssiCurve != null) { 75 out.writeByte((byte) 1); 76 rssiCurve.writeToParcel(out, flags); 77 } else { 78 out.writeByte((byte) 0); 79 } 80 } 81 82 @Override 83 public String toString() { 84 return "ScoredNetwork[key=" + networkKey + ",score=" + rssiCurve + "]"; 85 } 86 87 public static final Parcelable.Creator<ScoredNetwork> CREATOR = 88 new Parcelable.Creator<ScoredNetwork>() { 89 @Override 90 public ScoredNetwork createFromParcel(Parcel in) { 91 return new ScoredNetwork(in); 92 } 93 94 @Override 95 public ScoredNetwork[] newArray(int size) { 96 return new ScoredNetwork[size]; 97 } 98 }; 99} 100