diff options
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/net/ConnectivityManager.java | 53 | ||||
-rw-r--r-- | core/java/android/net/IConnectivityManager.aidl | 3 | ||||
-rw-r--r-- | core/java/android/net/INetworkStatsService.aidl | 10 | ||||
-rw-r--r-- | core/java/android/net/NetworkState.aidl | 19 | ||||
-rw-r--r-- | core/java/android/net/NetworkState.java | 68 | ||||
-rw-r--r-- | core/java/android/net/NetworkStatsHistory.java | 36 | ||||
-rw-r--r-- | core/java/android/net/TrafficStats.java | 36 | ||||
-rw-r--r-- | core/java/com/android/internal/util/Objects.java | 45 | ||||
-rw-r--r-- | core/java/com/android/internal/util/Preconditions.java | 57 |
9 files changed, 278 insertions, 49 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index c72c4b0..21cce44 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -256,10 +256,61 @@ public class ConnectivityManager { private final IConnectivityManager mService; - static public boolean isNetworkTypeValid(int networkType) { + public static boolean isNetworkTypeValid(int networkType) { return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; } + /** {@hide} */ + public static String getNetworkTypeName(int type) { + switch (type) { + case TYPE_MOBILE: + return "MOBILE"; + case TYPE_WIFI: + return "WIFI"; + case TYPE_MOBILE_MMS: + return "MOBILE_MMS"; + case TYPE_MOBILE_SUPL: + return "MOBILE_SUPL"; + case TYPE_MOBILE_DUN: + return "MOBILE_DUN"; + case TYPE_MOBILE_HIPRI: + return "MOBILE_HIPRI"; + case TYPE_WIMAX: + return "WIMAX"; + case TYPE_BLUETOOTH: + return "BLUETOOTH"; + case TYPE_DUMMY: + return "DUMMY"; + case TYPE_ETHERNET: + return "ETHERNET"; + case TYPE_MOBILE_FOTA: + return "MOBILE_FOTA"; + case TYPE_MOBILE_IMS: + return "MOBILE_IMS"; + case TYPE_MOBILE_CBS: + return "MOBILE_CBS"; + default: + return Integer.toString(type); + } + } + + /** {@hide} */ + public static boolean isNetworkTypeMobile(int networkType) { + switch (networkType) { + case TYPE_MOBILE: + case TYPE_MOBILE_MMS: + case TYPE_MOBILE_SUPL: + case TYPE_MOBILE_DUN: + case TYPE_MOBILE_HIPRI: + case TYPE_MOBILE_FOTA: + case TYPE_MOBILE_IMS: + case TYPE_MOBILE_CBS: + return true; + default: + return false; + } + } + public void setNetworkPreference(int preference) { try { mService.setNetworkPreference(preference); diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index 647a60a..07f6cec 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -18,6 +18,7 @@ package android.net; import android.net.LinkProperties; import android.net.NetworkInfo; +import android.net.NetworkState; import android.net.ProxyProperties; import android.os.IBinder; @@ -40,6 +41,8 @@ interface IConnectivityManager LinkProperties getActiveLinkProperties(); LinkProperties getLinkProperties(int networkType); + NetworkState[] getAllNetworkState(); + boolean setRadios(boolean onOff); boolean setRadio(int networkType, boolean turnOn); diff --git a/core/java/android/net/INetworkStatsService.aidl b/core/java/android/net/INetworkStatsService.aidl index 6d57036..d38d16c 100644 --- a/core/java/android/net/INetworkStatsService.aidl +++ b/core/java/android/net/INetworkStatsService.aidl @@ -16,12 +16,18 @@ package android.net; +import android.net.NetworkStats; import android.net.NetworkStatsHistory; /** {@hide} */ interface INetworkStatsService { - NetworkStatsHistory[] getNetworkStatsSummary(int networkType); - NetworkStatsHistory getNetworkStatsUid(int uid); + /** Return historical stats for traffic that matches template. */ + NetworkStatsHistory getHistoryForNetwork(int networkTemplate); + /** Return historical stats for specific UID traffic that matches template. */ + NetworkStatsHistory getHistoryForUid(int uid, int networkTemplate); + + /** Return usage summary per UID for traffic that matches template. */ + NetworkStats getSummaryPerUid(long start, long end, int networkTemplate); } diff --git a/core/java/android/net/NetworkState.aidl b/core/java/android/net/NetworkState.aidl new file mode 100644 index 0000000..c0b6cdc --- /dev/null +++ b/core/java/android/net/NetworkState.aidl @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2011, 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; + +parcelable NetworkState; diff --git a/core/java/android/net/NetworkState.java b/core/java/android/net/NetworkState.java new file mode 100644 index 0000000..749039a --- /dev/null +++ b/core/java/android/net/NetworkState.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2011 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; + +/** + * Snapshot of network state. + * + * @hide + */ +public class NetworkState implements Parcelable { + + public final NetworkInfo networkInfo; + public final LinkProperties linkProperties; + public final LinkCapabilities linkCapabilities; + + public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties, + LinkCapabilities linkCapabilities) { + this.networkInfo = networkInfo; + this.linkProperties = linkProperties; + this.linkCapabilities = linkCapabilities; + } + + public NetworkState(Parcel in) { + networkInfo = in.readParcelable(null); + linkProperties = in.readParcelable(null); + linkCapabilities = in.readParcelable(null); + } + + /** {@inheritDoc} */ + public int describeContents() { + return 0; + } + + /** {@inheritDoc} */ + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(networkInfo, flags); + out.writeParcelable(linkProperties, flags); + out.writeParcelable(linkCapabilities, flags); + } + + public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() { + public NetworkState createFromParcel(Parcel in) { + return new NetworkState(in); + } + + public NetworkState[] newArray(int size) { + return new NetworkState[size]; + } + }; + +} diff --git a/core/java/android/net/NetworkStatsHistory.java b/core/java/android/net/NetworkStatsHistory.java index b16101f..60af475 100644 --- a/core/java/android/net/NetworkStatsHistory.java +++ b/core/java/android/net/NetworkStatsHistory.java @@ -40,26 +40,17 @@ import java.util.Arrays; public class NetworkStatsHistory implements Parcelable { private static final int VERSION = 1; - /** {@link #uid} value when UID details unavailable. */ - public static final int UID_ALL = -1; - // TODO: teach about zigzag encoding to use less disk space // TODO: teach how to convert between bucket sizes - public final int networkType; - public final String identity; - public final int uid; public final long bucketDuration; - int bucketCount; - long[] bucketStart; - long[] rx; - long[] tx; + public int bucketCount; + public long[] bucketStart; + public long[] rx; + public long[] tx; - public NetworkStatsHistory(int networkType, String identity, int uid, long bucketDuration) { - this.networkType = networkType; - this.identity = identity; - this.uid = uid; + public NetworkStatsHistory(long bucketDuration) { this.bucketDuration = bucketDuration; bucketStart = new long[0]; rx = new long[0]; @@ -68,9 +59,6 @@ public class NetworkStatsHistory implements Parcelable { } public NetworkStatsHistory(Parcel in) { - networkType = in.readInt(); - identity = in.readString(); - uid = in.readInt(); bucketDuration = in.readLong(); bucketStart = readLongArray(in); rx = in.createLongArray(); @@ -80,9 +68,6 @@ public class NetworkStatsHistory implements Parcelable { /** {@inheritDoc} */ public void writeToParcel(Parcel out, int flags) { - out.writeInt(networkType); - out.writeString(identity); - out.writeInt(uid); out.writeLong(bucketDuration); writeLongArray(out, bucketStart, bucketCount); writeLongArray(out, rx, bucketCount); @@ -91,9 +76,6 @@ public class NetworkStatsHistory implements Parcelable { public NetworkStatsHistory(DataInputStream in) throws IOException { final int version = in.readInt(); - networkType = in.readInt(); - identity = in.readUTF(); - uid = in.readInt(); bucketDuration = in.readLong(); bucketStart = readLongArray(in); rx = readLongArray(in); @@ -103,9 +85,6 @@ public class NetworkStatsHistory implements Parcelable { public void writeToStream(DataOutputStream out) throws IOException { out.writeInt(VERSION); - out.writeInt(networkType); - out.writeUTF(identity); - out.writeInt(uid); out.writeLong(bucketDuration); writeLongArray(out, bucketStart, bucketCount); writeLongArray(out, rx, bucketCount); @@ -214,11 +193,8 @@ public class NetworkStatsHistory implements Parcelable { } public void dump(String prefix, PrintWriter pw) { - // TODO: consider stripping identity when dumping pw.print(prefix); - pw.print("NetworkStatsHistory: networkType="); pw.print(networkType); - pw.print(" identity="); pw.print(identity); - pw.print(" uid="); pw.println(uid); + pw.println("NetworkStatsHistory:"); for (int i = 0; i < bucketCount; i++) { pw.print(prefix); pw.print(" timestamp="); pw.print(bucketStart[i]); diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java index 8ab64fa..a0738c1 100644 --- a/core/java/android/net/TrafficStats.java +++ b/core/java/android/net/TrafficStats.java @@ -41,6 +41,42 @@ public class TrafficStats { */ public final static int UNSUPPORTED = -1; + // TODO: find better home for these template constants + + /** + * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style + * networks together. Only uses statistics for currently active IMSI. + * + * @hide + */ + public static final int TEMPLATE_MOBILE_ALL = 1; + + /** + * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style + * networks together that roughly meet a "3G" definition, or lower. Only + * uses statistics for currently active IMSI. + * + * @hide + */ + public static final int TEMPLATE_MOBILE_3G_LOWER = 2; + + /** + * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style + * networks together that meet a "4G" definition. Only uses statistics for + * currently active IMSI. + * + * @hide + */ + public static final int TEMPLATE_MOBILE_4G = 3; + + /** + * Template to combine all {@link ConnectivityManager#TYPE_WIFI} style + * networks together. + * + * @hide + */ + public static final int TEMPLATE_WIFI = 4; + /** * Snapshot of {@link NetworkStats} when the currently active profiling * session started, or {@code null} if no session active. diff --git a/core/java/com/android/internal/util/Objects.java b/core/java/com/android/internal/util/Objects.java index 598a079..2664182 100644 --- a/core/java/com/android/internal/util/Objects.java +++ b/core/java/com/android/internal/util/Objects.java @@ -16,34 +16,47 @@ package com.android.internal.util; +import java.util.Arrays; + /** * Object utility methods. */ public class Objects { /** - * Ensures the given object isn't {@code null}. + * Determines whether two possibly-null objects are equal. Returns: + * + * <ul> + * <li>{@code true} if {@code a} and {@code b} are both null. + * <li>{@code true} if {@code a} and {@code b} are both non-null and they are + * equal according to {@link Object#equals(Object)}. + * <li>{@code false} in all other situations. + * </ul> * - * @return the given object - * @throws NullPointerException if the object is null + * <p>This assumes that any non-null objects passed to this function conform + * to the {@code equals()} contract. */ - public static <T> T nonNull(T t) { - if (t == null) { - throw new NullPointerException(); - } - return t; + public static boolean equal(Object a, Object b) { + return a == b || (a != null && a.equals(b)); } /** - * Ensures the given object isn't {@code null}. + * Generates a hash code for multiple values. The hash code is generated by + * calling {@link Arrays#hashCode(Object[])}. * - * @return the given object - * @throws NullPointerException if the object is null + * <p>This is useful for implementing {@link Object#hashCode()}. For example, + * in an object that has three properties, {@code x}, {@code y}, and + * {@code z}, one could write: + * <pre> + * public int hashCode() { + * return Objects.hashCode(getX(), getY(), getZ()); + * }</pre> + * + * <b>Warning</b>: When a single object is supplied, the returned hash code + * does not equal the hash code of that object. */ - public static <T> T nonNull(T t, String message) { - if (t == null) { - throw new NullPointerException(message); - } - return t; + public static int hashCode(Object... objects) { + return Arrays.hashCode(objects); } + } diff --git a/core/java/com/android/internal/util/Preconditions.java b/core/java/com/android/internal/util/Preconditions.java new file mode 100644 index 0000000..a53a9c0 --- /dev/null +++ b/core/java/com/android/internal/util/Preconditions.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011 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 com.android.internal.util; + +/** + * Simple static methods to be called at the start of your own methods to verify + * correct arguments and state. + */ +public class Preconditions { + + /** + * Ensures that an object reference passed as a parameter to the calling + * method is not null. + * + * @param reference an object reference + * @return the non-null reference that was validated + * @throws NullPointerException if {@code reference} is null + */ + public static <T> T checkNotNull(T reference) { + if (reference == null) { + throw new NullPointerException(); + } + return reference; + } + + /** + * Ensures that an object reference passed as a parameter to the calling + * method is not null. + * + * @param reference an object reference + * @param errorMessage the exception message to use if the check fails; will + * be converted to a string using {@link String#valueOf(Object)} + * @return the non-null reference that was validated + * @throws NullPointerException if {@code reference} is null + */ + public static <T> T checkNotNull(T reference, Object errorMessage) { + if (reference == null) { + throw new NullPointerException(String.valueOf(errorMessage)); + } + return reference; + } + +} |