From 7f871799e7233c9cf16def8be78e1926bbc544d5 Mon Sep 17 00:00:00 2001 From: David Su Date: Wed, 20 May 2020 19:56:28 -0700 Subject: WifiDumpsysMetricsTest: ensure that only DUMP permission is needed Only DUMP permission should be needed to run `dumpsys wifi wifiMetricsProto`. No other permission should be necessary. Bug: 157176197 Test: atest MtsWifiTestCases Change-Id: I7f95fec015feda68e1500c0f2900108b22a5ea81 --- tests/mts/AndroidManifest.xml | 3 +++ .../src/android/net/wifi/mts/WifiDumpsysMetricsTest.java | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/mts/AndroidManifest.xml b/tests/mts/AndroidManifest.xml index 7130e6d89..b8b025dc2 100644 --- a/tests/mts/AndroidManifest.xml +++ b/tests/mts/AndroidManifest.xml @@ -19,6 +19,9 @@ package="android.net.wifi.mts" android:targetSandboxVersion="2"> + + + diff --git a/tests/mts/src/android/net/wifi/mts/WifiDumpsysMetricsTest.java b/tests/mts/src/android/net/wifi/mts/WifiDumpsysMetricsTest.java index c548b852c..7fc10ec84 100644 --- a/tests/mts/src/android/net/wifi/mts/WifiDumpsysMetricsTest.java +++ b/tests/mts/src/android/net/wifi/mts/WifiDumpsysMetricsTest.java @@ -17,6 +17,7 @@ package android.net.wifi.mts; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assume.assumeTrue; @@ -26,7 +27,6 @@ import android.util.Base64; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; -import com.android.compatibility.common.util.ShellIdentityUtils; import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiLog; import org.junit.Before; @@ -55,16 +55,20 @@ public class WifiDumpsysMetricsTest { */ @Test public void testWifiDumpMetrics() throws Exception { - String rawDumpOutput = ShellIdentityUtils.invokeWithShellPermissions( - () -> StreamReader.runProcessCommand(WIFI_DUMP_PROTO_CMD)); + // DO NOT run under shell identity. Shell has a lot more permissions. + // `dumpsys wifi wifiMetricsProto` should ONLY need `android.permission.DUMP` + String rawDumpOutput = StreamReader.runProcessCommand(WIFI_DUMP_PROTO_CMD); assertThat(rawDumpOutput).isNotNull(); int protoStart = rawDumpOutput.indexOf(START_TAG); int protoEnd = rawDumpOutput.indexOf(END_TAG); - assertThat(protoStart).isAtLeast(0); - assertThat(protoEnd).isAtLeast(protoStart); + assertWithMessage("Expected to find \"WifiMetrics:\", but instead found: " + rawDumpOutput) + .that(protoStart).isAtLeast(0); + assertWithMessage( + "Expected to find \"EndWifiMetrics\", but instead found: " + rawDumpOutput) + .that(protoEnd).isAtLeast(protoStart); String protoString = rawDumpOutput.substring(protoStart + START_TAG.length(), protoEnd); byte[] protoBytes = Base64.decode(protoString, Base64.DEFAULT); -- cgit v1.2.3