summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2020-05-20 19:56:28 -0700
committerDavid Su <dysu@google.com>2020-05-20 19:56:28 -0700
commit7f871799e7233c9cf16def8be78e1926bbc544d5 (patch)
treed5d241dc2a1673c8fbb5591d0f40528dfbbecf4f
parent7f0630204adcc2fddaea25d82457036be404b7f4 (diff)
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
-rw-r--r--tests/mts/AndroidManifest.xml3
-rw-r--r--tests/mts/src/android/net/wifi/mts/WifiDumpsysMetricsTest.java14
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">
+ <!-- Need DUMP permission to call `dumpsys wifi wifiMetricsProto` -->
+ <uses-permission android:name="android.permission.DUMP" />
+
<application android:usesCleartextTraffic="true">
<uses-library android:name="android.test.runner" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />
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);