summaryrefslogtreecommitdiffstats
path: root/core/java/android/net/RssiCurve.java
diff options
context:
space:
mode:
authorJeff Davidson <jpd@google.com>2014-04-07 15:19:44 -0700
committerJeff Davidson <jpd@google.com>2014-04-16 11:28:51 -0700
commitdc960e21ef1005fab5ef145773ddd6f40c802217 (patch)
tree49c7f93420b2d407bdae038a4cd97b48e90eed1a /core/java/android/net/RssiCurve.java
parent14a6d6826cc6253ecd036281a0ede597c8b5bf75 (diff)
downloadframeworks_base-dc960e21ef1005fab5ef145773ddd6f40c802217.zip
frameworks_base-dc960e21ef1005fab5ef145773ddd6f40c802217.tar.gz
frameworks_base-dc960e21ef1005fab5ef145773ddd6f40c802217.tar.bz2
Data structures for communication with network scorer apps.
NetworkKey represents the necessary information to identify a network to be scored. ScoredNetwork contains the key to identify a network as well as a score to be used when evaluating that network (as a curve based on RSSI). Bug: 13767776 Change-Id: I6bfebd105c9381e615513167b4332b767b43a23a
Diffstat (limited to 'core/java/android/net/RssiCurve.java')
-rw-r--r--core/java/android/net/RssiCurve.java129
1 files changed, 129 insertions, 0 deletions
diff --git a/core/java/android/net/RssiCurve.java b/core/java/android/net/RssiCurve.java
new file mode 100644
index 0000000..7af7998
--- /dev/null
+++ b/core/java/android/net/RssiCurve.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package android.net;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * A curve defining the network score over a range of RSSI values.
+ *
+ * <p>For each RSSI bucket, the score may be any byte. Scores have no absolute meaning and are only
+ * considered relative to other scores assigned by the same scorer. Networks with no score are all
+ * considered equivalent and ranked below any network with a score.
+ *
+ * <p>For example, consider a curve starting at -110 dBm with a bucket width of 10 and the
+ * following buckets: {@code [-20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]}.
+ * This represents a linear curve between -110 dBm and 30 dBm. It scores progressively higher at
+ * stronger signal strengths.
+ *
+ * <p>A network can be assigned a fixed score independent of RSSI by setting
+ * {@link #rssiBuckets} to a one-byte array whose element is the fixed score. {@link #start}
+ * should be set to the lowest RSSI value at which this fixed score should apply, and
+ * {@link #bucketWidth} should be set such that {@code start + bucketWidth} is equal to the
+ * highest RSSI value at which this fixed score should apply.
+ *
+ * <p>Note that RSSI values below -110 dBm or above 30 dBm are unlikely to cause any difference
+ * in connectivity behavior from those endpoints. That is, the connectivity framework will treat
+ * a network with a -120 dBm signal exactly as it would treat one with a -110 dBm signal.
+ * Therefore, graphs which specify scores outside this range may be truncated to this range by
+ * the system.
+ *
+ * @see ScoredNetwork
+ * @hide
+ */
+public class RssiCurve implements Parcelable {
+
+ /** The starting dBm of the curve. */
+ public final int start;
+
+ /** The width of each RSSI bucket, in dBm. */
+ public final int bucketWidth;
+
+ /** The score for each RSSI bucket. */
+ public final byte[] rssiBuckets;
+
+ /**
+ * Construct a new {@link RssiCurve}.
+ *
+ * @param start the starting dBm of the curve.
+ * @param bucketWidth the width of each RSSI bucket, in dBm.
+ * @param rssiBuckets the score for each RSSI bucket.
+ */
+ public RssiCurve(int start, int bucketWidth, byte[] rssiBuckets) {
+ this.start = start;
+ this.bucketWidth = bucketWidth;
+ if (rssiBuckets == null || rssiBuckets.length == 0) {
+ throw new IllegalArgumentException("rssiBuckets must be at least one element large.");
+ }
+ this.rssiBuckets = rssiBuckets;
+ }
+
+ private RssiCurve(Parcel in) {
+ start = in.readInt();
+ bucketWidth = in.readInt();
+ int bucketCount = in.readInt();
+ rssiBuckets = new byte[bucketCount];
+ in.readByteArray(rssiBuckets);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(start);
+ out.writeInt(bucketWidth);
+ out.writeInt(rssiBuckets.length);
+ out.writeByteArray(rssiBuckets);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("RssiCurve[start=")
+ .append(start)
+ .append(",bucketWidth=")
+ .append(bucketWidth);
+
+ sb.append(",buckets=");
+ for (int i = 0; i < rssiBuckets.length; i++) {
+ sb.append(rssiBuckets[i]);
+ if (i < rssiBuckets.length - 1) {
+ sb.append(",");
+ }
+ }
+ sb.append("]");
+
+ return sb.toString();
+ }
+
+ public static final Creator<RssiCurve> CREATOR =
+ new Creator<RssiCurve>() {
+ @Override
+ public RssiCurve createFromParcel(Parcel in) {
+ return new RssiCurve(in);
+ }
+
+ @Override
+ public RssiCurve[] newArray(int size) {
+ return new RssiCurve[size];
+ }
+ };
+}