summaryrefslogtreecommitdiffstats
path: root/core/java/android/net/NetworkIdentity.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-06-18 18:34:16 -0700
committerJeff Sharkey <jsharkey@android.com>2011-06-18 22:23:11 -0700
commit1b5a2a96f793211bfbd39aa29cc41031dfa23950 (patch)
tree1922879069937ed56dbea9ec0b217a1e5b045941 /core/java/android/net/NetworkIdentity.java
parent1a81a16a967173729839d3802a5527ff074f9af9 (diff)
downloadframeworks_base-1b5a2a96f793211bfbd39aa29cc41031dfa23950.zip
frameworks_base-1b5a2a96f793211bfbd39aa29cc41031dfa23950.tar.gz
frameworks_base-1b5a2a96f793211bfbd39aa29cc41031dfa23950.tar.bz2
Read "qtaguid" network stats, refactor templates.
Teach NMS to read qtaguid stats from kernel, but fall back to older stats when kernel doesn't support. Add "tags" to NetworkStats entries to support qtaguid. To work around double-reporting bug, subtract tagged stats from TAG_NONE entry. Flesh out stronger NetworkTemplate. All NetworkStatsService requests now require a template, and moved matching logic into template. Record UID stats keyed on complete NetworkIdentitySet definition, similar to how interface stats are stored. Since previous UID stats didn't have iface breakdown, discard during file format upgrade. Change-Id: I0447b5e7d205d73d28e71c889c568e536e91b8e4
Diffstat (limited to 'core/java/android/net/NetworkIdentity.java')
-rw-r--r--core/java/android/net/NetworkIdentity.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java
new file mode 100644
index 0000000..f82d922
--- /dev/null
+++ b/core/java/android/net/NetworkIdentity.java
@@ -0,0 +1,107 @@
+/*
+ * 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 static android.net.ConnectivityManager.isNetworkTypeMobile;
+
+import android.content.Context;
+import android.telephony.TelephonyManager;
+
+import com.android.internal.util.Objects;
+
+/**
+ * Network definition that includes strong identity. Analogous to combining
+ * {@link NetworkInfo} and an IMSI.
+ *
+ * @hide
+ */
+public class NetworkIdentity {
+ final int mType;
+ final int mSubType;
+ final String mSubscriberId;
+
+ public NetworkIdentity(int type, int subType, String subscriberId) {
+ this.mType = type;
+ this.mSubType = subType;
+ this.mSubscriberId = subscriberId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(mType, mSubType, mSubscriberId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof NetworkIdentity) {
+ final NetworkIdentity ident = (NetworkIdentity) obj;
+ return mType == ident.mType && mSubType == ident.mSubType
+ && Objects.equal(mSubscriberId, ident.mSubscriberId);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ final String typeName = ConnectivityManager.getNetworkTypeName(mType);
+ final String subTypeName;
+ if (ConnectivityManager.isNetworkTypeMobile(mType)) {
+ subTypeName = TelephonyManager.getNetworkTypeName(mSubType);
+ } else {
+ subTypeName = Integer.toString(mSubType);
+ }
+
+ final String scrubSubscriberId = mSubscriberId != null ? "valid" : "null";
+ return "[type=" + typeName + ", subType=" + subTypeName + ", subscriberId="
+ + scrubSubscriberId + "]";
+ }
+
+ public int getType() {
+ return mType;
+ }
+
+ public int getSubType() {
+ return mSubType;
+ }
+
+ public String getSubscriberId() {
+ return mSubscriberId;
+ }
+
+ /**
+ * Build a {@link NetworkIdentity} from the given {@link NetworkState},
+ * assuming that any mobile networks are using the current IMSI.
+ */
+ public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state) {
+ final int type = state.networkInfo.getType();
+ final int subType = state.networkInfo.getSubtype();
+
+ // TODO: consider moving subscriberId over to LinkCapabilities, so it
+ // comes from an authoritative source.
+
+ final String subscriberId;
+ if (isNetworkTypeMobile(type)) {
+ final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
+ Context.TELEPHONY_SERVICE);
+ subscriberId = telephony.getSubscriberId();
+ } else {
+ subscriberId = null;
+ }
+ return new NetworkIdentity(type, subType, subscriberId);
+ }
+
+}