summaryrefslogtreecommitdiffstats
path: root/tests/DataIdleTest
diff options
context:
space:
mode:
authorTsu Chiang Chuang <tsu@google.com>2011-09-06 16:37:51 -0700
committerTsu Chiang Chuang <tsu@google.com>2011-09-08 13:50:41 -0700
commit3ae29d455866ce358b42617134610415c04e0d53 (patch)
treebb13fc9c26b7ccef3ada4a673ab5a55afcbc8467 /tests/DataIdleTest
parent1d124d5037644ed66a78c181c4eff13a7da04443 (diff)
downloadframeworks_base-3ae29d455866ce358b42617134610415c04e0d53.zip
frameworks_base-3ae29d455866ce358b42617134610415c04e0d53.tar.gz
frameworks_base-3ae29d455866ce358b42617134610415c04e0d53.tar.bz2
idle test app for bandwidth usage.
Change-Id: Ib35b27617369b360972e653db70bf5cf9303ddf1
Diffstat (limited to 'tests/DataIdleTest')
-rw-r--r--tests/DataIdleTest/Android.mk29
-rw-r--r--tests/DataIdleTest/AndroidManifest.xml32
-rw-r--r--tests/DataIdleTest/src/com/android/tests/dataidle/DataIdleTest.java100
3 files changed, 161 insertions, 0 deletions
diff --git a/tests/DataIdleTest/Android.mk b/tests/DataIdleTest/Android.mk
new file mode 100644
index 0000000..acb46c5
--- /dev/null
+++ b/tests/DataIdleTest/Android.mk
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+# We only want this apk build for tests.
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_PACKAGE_NAME := DataIdleTest
+LOCAL_JAVA_LIBRARIES := android.test.runner
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+# We need to sign it to get access to the network usage history.
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
diff --git a/tests/DataIdleTest/AndroidManifest.xml b/tests/DataIdleTest/AndroidManifest.xml
new file mode 100644
index 0000000..2792eec
--- /dev/null
+++ b/tests/DataIdleTest/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.tests.dataidle"
+ android:sharedUserId="android.uid.system">
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" />
+ <application >
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.tests.dataidle"
+ android:label="Idle Bandwidth Tests" />
+
+</manifest>
diff --git a/tests/DataIdleTest/src/com/android/tests/dataidle/DataIdleTest.java b/tests/DataIdleTest/src/com/android/tests/dataidle/DataIdleTest.java
new file mode 100644
index 0000000..637f0d2
--- /dev/null
+++ b/tests/DataIdleTest/src/com/android/tests/dataidle/DataIdleTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.tests.dataidle;
+
+import android.content.Context;
+import android.net.INetworkStatsService;
+import android.net.NetworkStats.Entry;
+import android.net.NetworkTemplate;
+import android.net.NetworkStats;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.telephony.TelephonyManager;
+import android.test.InstrumentationTestCase;
+import android.test.InstrumentationTestRunner;
+import android.util.Log;
+
+/**
+ * A test that dumps data usage to instrumentation out, used for measuring data usage for idle
+ * devices.
+ */
+public class DataIdleTest extends InstrumentationTestCase {
+
+ private TelephonyManager mTelephonyManager;
+ private INetworkStatsService mStatsService;
+
+ private static final String LOG_TAG = "DataIdleTest";
+ private final static int INSTRUMENTATION_IN_PROGRESS = 2;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Context c = getInstrumentation().getTargetContext();
+ mStatsService = INetworkStatsService.Stub.asInterface(
+ ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
+ mTelephonyManager = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
+ }
+
+ /**
+ * Test that dumps all the data usage metrics for wifi to instrumentation out.
+ */
+ public void testWifiIdle() {
+ NetworkTemplate template = NetworkTemplate.buildTemplateWifi();
+ fetchStats(template);
+ }
+
+ /**
+ * Test that dumps all the data usage metrics for all mobile to instrumentation out.
+ */
+ public void testMobile() {
+ String subscriberId = mTelephonyManager.getSubscriberId();
+ NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
+ fetchStats(template);
+ }
+
+ /**
+ * Helper method that fetches all the network stats available and reports it
+ * to instrumentation out.
+ * @param template {link {@link NetworkTemplate} to match.
+ */
+ private void fetchStats(NetworkTemplate template) {
+ try {
+ NetworkStats stats = mStatsService.getSummaryForAllUid(template, Long.MIN_VALUE,
+ Long.MAX_VALUE, false);
+ reportStats(stats);
+ } catch (RemoteException e) {
+ Log.w(LOG_TAG, "Failed to fetch network stats for wifi.");
+ }
+ }
+
+ /**
+ * Print network data usage stats to instrumentation out
+ * @param stats {@link NetworkorStats} to print
+ */
+ void reportStats(NetworkStats stats) {
+ for (int i = 0; i < stats.size(); ++i) {
+ Entry statsEntry = stats.getValues(i, null);
+ Bundle result = new Bundle();
+ result.putInt("uid", statsEntry.uid);
+ result.putInt("tag", statsEntry.tag);
+ result.putInt("set", statsEntry.set);
+ result.putString("iface", statsEntry.iface);
+ result.putLong("rxBytes", statsEntry.rxBytes);
+ result.putLong("txBytes", statsEntry.txBytes);
+ getInstrumentation().sendStatus(INSTRUMENTATION_IN_PROGRESS, result);
+ }
+ }
+}