summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlen Kuhne <kuh@google.com>2016-06-13 17:56:11 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-06-13 17:56:11 +0000
commite1b848bb11cc44060328bf53162cb776e3dd54dc (patch)
treeef019eb6f3aaea9dbd4d8a32d2f28ebb801aa3ae
parente8f7d4ab151251991982329f7274f866bb03b3da (diff)
parent622e9ff3874251022ae3c27548bc5a2f77bdc8bc (diff)
Merge \"DO NOT MERGE WifiMetrics: Record capture duration\" into nyc-dev
am: 622e9ff387 Change-Id: Ie7de4f9173a815abe88f91efc5a46893be5270d1
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java4
-rw-r--r--service/java/com/android/server/wifi/WifiMetrics.java36
-rw-r--r--service/proto/wifi.proto3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java31
-rw-r--r--tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java3
5 files changed, 40 insertions, 37 deletions
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index cc4048eb9..6939d4574 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -32,10 +32,10 @@ public class WifiInjector {
return LazyHolder.sInstance;
}
- private final WifiMetrics mWifiMetrics = new WifiMetrics();
+ private final Clock mClock = new Clock();
+ private final WifiMetrics mWifiMetrics = new WifiMetrics(mClock);
private final WifiLastResortWatchdog mWifiLastResortWatchdog =
new WifiLastResortWatchdog(mWifiMetrics);
- private final Clock mClock = new Clock();
private final PropertyService mPropertyService = new SystemPropertyService();
private final BuildProperties mBuildProperties = new SystemBuildProperties();
private final KeyStore mKeyStore = KeyStore.getInstance();
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index f3ab02c24..cc6fe000f 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -18,7 +18,6 @@ package com.android.server.wifi;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
-import android.os.SystemClock;
import android.util.Base64;
import android.util.Log;
import android.util.SparseIntArray;
@@ -45,7 +44,7 @@ public class WifiMetrics {
private static final boolean DBG = false;
private final Object mLock = new Object();
private static final int MAX_CONNECTION_EVENTS = 256;
-
+ private Clock mClock;
private boolean mScreenOn;
private int mWifiState;
/**
@@ -72,6 +71,11 @@ public class WifiMetrics {
* combination. Indexed by WifiLog.WifiState * (1 + screenOn)
*/
private SparseIntArray mWifiSystemStateEntries;
+ /**
+ * Records the elapsedRealtime (in seconds) that represents the beginning of data
+ * capture for for this WifiMetricsProto
+ */
+ private long mRecordStartTimeSec;
class RouterFingerPrint {
private WifiMetricsProto.RouterFingerPrint mRouterFingerPrintProto;
@@ -298,7 +302,8 @@ public class WifiMetrics {
}
}
- public WifiMetrics() {
+ public WifiMetrics(Clock clock) {
+ mClock = clock;
mWifiLogProto = new WifiMetricsProto.WifiLog();
mConnectionEventList = new ArrayList<>();
mScanReturnEntries = new SparseIntArray();
@@ -306,6 +311,7 @@ public class WifiMetrics {
mCurrentConnectionEvent = null;
mScreenOn = true;
mWifiState = WifiMetricsProto.WifiLog.WIFI_DISABLED;
+ mRecordStartTimeSec = mClock.elapsedRealtime() / 1000;
}
// Values used for indexing SystemStateEntries
@@ -348,12 +354,12 @@ public class WifiMetrics {
}
mCurrentConnectionEvent = new ConnectionEvent();
mCurrentConnectionEvent.mConnectionEvent.startTimeMillis =
- System.currentTimeMillis();
+ mClock.currentTimeMillis();
mCurrentConnectionEvent.mConfigBssid = targetBSSID;
mCurrentConnectionEvent.mConnectionEvent.roamType = roamType;
mCurrentConnectionEvent.mRouterFingerPrint.updateFromWifiConfiguration(config);
mCurrentConnectionEvent.mConfigBssid = "any";
- mCurrentConnectionEvent.mRealStartTime = SystemClock.elapsedRealtime();
+ mCurrentConnectionEvent.mRealStartTime = mClock.elapsedRealtime();
mCurrentConnectionEvent.mWifiState = mWifiState;
mCurrentConnectionEvent.mScreenOn = mScreenOn;
mConnectionEventList.add(mCurrentConnectionEvent);
@@ -406,7 +412,7 @@ public class WifiMetrics {
boolean result = (level2FailureCode == 1)
&& (connectivityFailureCode == WifiMetricsProto.ConnectionEvent.HLF_NONE);
mCurrentConnectionEvent.mConnectionEvent.connectionResult = result ? 1 : 0;
- mCurrentConnectionEvent.mRealEndTime = SystemClock.elapsedRealtime();
+ mCurrentConnectionEvent.mRealEndTime = mClock.elapsedRealtime();
mCurrentConnectionEvent.mConnectionEvent.durationTakenToConnectMillis = (int)
(mCurrentConnectionEvent.mRealEndTime
- mCurrentConnectionEvent.mRealStartTime);
@@ -899,6 +905,8 @@ public class WifiMetrics {
+ mWifiLogProto.numLastResortWatchdogTriggersWithBadDhcp);
pw.println("mWifiLogProto.numLastResortWatchdogTriggersWithBadOther="
+ mWifiLogProto.numLastResortWatchdogTriggersWithBadOther);
+ pw.println("mWifiLogProto.recordDurationSec="
+ + ((mClock.elapsedRealtime() / 1000) - mRecordStartTimeSec));
}
}
}
@@ -954,19 +962,8 @@ public class WifiMetrics {
mWifiLogProto.wifiSystemStateEntries[i].isScreenOn =
(mWifiSystemStateEntries.keyAt(i) % 2) > 0;
}
- }
- }
-
- /**
- * Serializes all of WifiMetrics to WifiLog proto, and returns the byte array.
- * Does not count as taking an automatic bug report
- *
- * @return byte array of the deserialized & consolidated Proto
- */
- public byte[] toByteArray() {
- synchronized (mLock) {
- consolidateProto(false);
- return mWifiLogProto.toByteArray(mWifiLogProto);
+ mWifiLogProto.recordDurationSec = (int) ((mClock.elapsedRealtime() / 1000)
+ - mRecordStartTimeSec);
}
}
@@ -981,6 +978,7 @@ public class WifiMetrics {
}
mScanReturnEntries.clear();
mWifiSystemStateEntries.clear();
+ mRecordStartTimeSec = mClock.elapsedRealtime() / 1000;
mWifiLogProto.clear();
}
}
diff --git a/service/proto/wifi.proto b/service/proto/wifi.proto
index 73981afb5..43a4166dc 100644
--- a/service/proto/wifi.proto
+++ b/service/proto/wifi.proto
@@ -183,6 +183,9 @@ message WifiLog {
// Count of times connectivity watchdog found background scan not working
optional int32 num_connectivity_watchdog_background_bad = 33;
+
+ // The time duration represented by this wifi log, from start to end of capture
+ optional int32 record_duration_sec = 34;
}
// Information that gets logged for every WiFi connection.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index 8db4a8c39..530b2180b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -17,8 +17,7 @@ package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
@@ -29,6 +28,8 @@ import com.android.server.wifi.hotspot2.NetworkDetail;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
@@ -43,12 +44,14 @@ public class WifiMetricsTest {
WifiMetrics mWifiMetrics;
WifiMetricsProto.WifiLog mDeserializedWifiMetrics;
-
+ @Mock Clock mClock;
@Before
public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
mDeserializedWifiMetrics = null;
- mWifiMetrics = new WifiMetrics();
+ when(mClock.elapsedRealtime()).thenReturn((long) 0);
+ mWifiMetrics = new WifiMetrics(mClock);
}
/**
@@ -74,6 +77,9 @@ public class WifiMetricsTest {
WifiMetricsProto.ConnectionEvent.ROAM_ENTERPRISE);
}
+ private static final long TEST_RECORD_DURATION_SEC = 12 * 60 * 60;
+ private static final long TEST_RECORD_DURATION_MILLIS = TEST_RECORD_DURATION_SEC * 1000;
+
/**
* Simulate how dumpsys gets the proto from mWifiMetrics, filter the proto bytes out and
* deserialize them into mDeserializedWifiMetrics
@@ -82,6 +88,8 @@ public class WifiMetricsTest {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(stream);
String[] args = new String[0];
+
+ when(mClock.elapsedRealtime()).thenReturn(TEST_RECORD_DURATION_MILLIS);
//Test proto dump, by passing in proto arg option
args = new String[]{WifiMetrics.PROTO_DUMP_ARG};
mWifiMetrics.dump(null, writer, args);
@@ -96,15 +104,6 @@ public class WifiMetricsTest {
mDeserializedWifiMetrics = WifiMetricsProto.WifiLog.parseFrom(protoBytes);
}
- /**
- * Test WifiMetrics can be serialized and de-serialized
- */
- public void serializeDeserialize() throws Exception {
- byte[] serializedWifiMetrics = mWifiMetrics.toByteArray();
- mDeserializedWifiMetrics = WifiMetricsProto.WifiLog.parseFrom(
- serializedWifiMetrics);
- }
-
@Test
public void dumpHumanReadable() throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
@@ -312,6 +311,8 @@ public class WifiMetricsTest {
mDeserializedWifiMetrics.numLastResortWatchdogTriggersWithBadDhcp);
assertEquals(NUM_LAST_RESORT_WATCHDOG_TRIGGERS_WITH_BAD_OTHER,
mDeserializedWifiMetrics.numLastResortWatchdogTriggersWithBadOther);
+ assertEquals(TEST_RECORD_DURATION_SEC,
+ mDeserializedWifiMetrics.recordDurationSec);
}
/**
@@ -349,10 +350,10 @@ public class WifiMetricsTest {
public void setMetricsSerializeDeserializeAssertMetricsSame() throws Exception {
setAndIncrementMetrics();
startAndEndConnectionEventSucceeds();
- serializeDeserialize();
+ dumpProtoAndDeserialize();
assertDeserializedMetricsCorrect();
assertEquals("mDeserializedWifiMetrics.connectionEvent.length",
- 3, mDeserializedWifiMetrics.connectionEvent.length);
+ 2, mDeserializedWifiMetrics.connectionEvent.length);
//<TODO> test individual connectionEvents for correctness,
// check scanReturnEntries & wifiSystemStateEntries counts and individual elements
// pending their implementation</TODO>
diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
index a1bf212c3..62f510526 100644
--- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
@@ -82,6 +82,7 @@ public class WifiScanningServiceTest {
@Mock WifiScannerImpl.WifiScannerImplFactory mWifiScannerImplFactory;
@Mock IBatteryStats mBatteryStats;
@Mock WifiInjector mWifiInjector;
+ @Mock Clock mClock;
WifiMetrics mWifiMetrics;
MockLooper mLooper;
WifiScanningServiceImpl mWifiScanningServiceImpl;
@@ -94,7 +95,7 @@ public class WifiScanningServiceTest {
mAlarmManager = new MockAlarmManager();
when(mContext.getSystemService(Context.ALARM_SERVICE))
.thenReturn(mAlarmManager.getAlarmManager());
- mWifiMetrics = new WifiMetrics();
+ mWifiMetrics = new WifiMetrics(mClock);
ChannelHelper channelHelper = new PresetKnownBandsChannelHelper(
new int[]{2400, 2450},