summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-12-05 06:42:55 -0800
committerRoshan Pius <rpius@google.com>2019-12-06 08:07:05 -0800
commit4cb2e7535b6c05d3e50dfd8a5dc8ab6a1ec3e53f (patch)
treedab8d16fdd5be78b29740405ae445fce6451f9a8
parentf9ae2e78a36e6975171729b5011ae0acd2e1288e (diff)
WifiDiagnostics: Use public API for bugreport collection
This was recently converted to a formal API by the core framework team. Bug: 143494985 Test: atest com.android.server.wifi Change-Id: Ib9d0804628ec78402f4b9daf21ff5aee3f14167d
-rw-r--r--service/java/com/android/server/wifi/WifiDiagnostics.java34
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java21
2 files changed, 14 insertions, 41 deletions
diff --git a/service/java/com/android/server/wifi/WifiDiagnostics.java b/service/java/com/android/server/wifi/WifiDiagnostics.java
index 1e6386716..3e22d863f 100644
--- a/service/java/com/android/server/wifi/WifiDiagnostics.java
+++ b/service/java/com/android/server/wifi/WifiDiagnostics.java
@@ -18,9 +18,8 @@ package com.android.server.wifi;
import android.annotation.NonNull;
import android.content.Context;
-import android.content.Intent;
+import android.os.BugreportManager;
import android.os.BugreportParams;
-import android.os.UserHandle;
import android.util.ArraySet;
import android.util.Base64;
import android.util.Log;
@@ -62,14 +61,6 @@ class WifiDiagnostics extends BaseWifiDiagnostics {
private static final String TAG = "WifiDiags";
private static final boolean DBG = false;
- // TODO (b/143494985): Use formal API instead of sending this intent.
- private static final String INTENT_BUGREPORT_REQUESTED =
- "com.android.internal.intent.action.BUGREPORT_REQUESTED";
- private static final String SHELL_APP_PACKAGE = "com.android.shell";
- private static final String EXTRA_TITLE = "android.intent.extra.TITLE";
- private static final String EXTRA_DESCRIPTION = "android.intent.extra.DESCRIPTION";
- private static final String EXTRA_BUGREPORT_TYPE = "android.intent.extra.BUGREPORT_TYPE";
-
/** log level flags; keep these consistent with wifi_logger.h */
/** No logs whatsoever */
@@ -306,26 +297,11 @@ class WifiDiagnostics extends BaseWifiDiagnostics {
R.bool.config_wifi_diagnostics_bugreport_enabled)) {
return;
}
-
- // TODO (b/143494985): Use formal API instead of sending this intent.
- // The below code snippet is copied from ActivityManager.requestBugReportWithDescription()
- // Create intent to trigger Bugreport API via Shell
- Intent triggerShellBugreport = new Intent();
- triggerShellBugreport.setAction(INTENT_BUGREPORT_REQUESTED);
- triggerShellBugreport.setPackage(SHELL_APP_PACKAGE);
- triggerShellBugreport.putExtra(EXTRA_BUGREPORT_TYPE, BugreportParams.BUGREPORT_MODE_WIFI);
- triggerShellBugreport.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
- triggerShellBugreport.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
- if (bugTitle != null) {
- triggerShellBugreport.putExtra(EXTRA_TITLE, bugTitle);
- }
- if (bugDetail != null) {
- triggerShellBugreport.putExtra(EXTRA_DESCRIPTION, bugDetail);
- }
+ BugreportManager bugreportManager = mContext.getSystemService(BugreportManager.class);
+ BugreportParams params = new BugreportParams(BugreportParams.BUGREPORT_MODE_WIFI);
try {
- // Send broadcast to shell to trigger bugreport using Bugreport API
- mContext.sendBroadcastAsUser(triggerShellBugreport, UserHandle.CURRENT);
- } catch (Exception e) { // diagnostics should never crash system_server
+ bugreportManager.requestBugreport(params, bugTitle, bugDetail);
+ } catch (RuntimeException e) {
mLog.err("error taking bugreport: %").c(e.getClass().getName()).flush();
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
index 27990e738..590db4030 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
@@ -36,8 +36,7 @@ import static org.mockito.Mockito.when;
import android.app.test.MockAnswerUtil.AnswerWithArguments;
import android.content.Context;
-import android.content.Intent;
-import android.os.UserHandle;
+import android.os.BugreportManager;
import androidx.test.filters.SmallTest;
@@ -71,6 +70,7 @@ public class WifiDiagnosticsTest extends WifiBaseTest {
@Mock Process mExternalProcess;
@Mock WifiMetrics mWifiMetrics;
@Mock Clock mClock;
+ @Mock BugreportManager mBugreportManager;
MockResources mResources;
WifiDiagnostics mWifiDiagnostics;
@@ -128,6 +128,7 @@ public class WifiDiagnosticsTest extends WifiBaseTest {
FATAL_FW_ALERT_LIST);
mResources.setBoolean(R.bool.config_wifi_diagnostics_bugreport_enabled, true);
when(mContext.getResources()).thenReturn(mResources);
+ when(mContext.getSystemService(BugreportManager.class)).thenReturn(mBugreportManager);
when(mWifiInjector.makeLog(anyString())).thenReturn(mLog);
when(mWifiInjector.getJavaRuntime()).thenReturn(mJavaRuntime);
when(mWifiInjector.getWifiMetrics()).thenReturn(mWifiMetrics);
@@ -861,26 +862,23 @@ public class WifiDiagnosticsTest extends WifiBaseTest {
public void takeBugReportCallsActivityManagerOnUserDebug() {
when(mBuildProperties.isUserBuild()).thenReturn(false);
mWifiDiagnostics.takeBugReport("", "");
- verify(mContext, times(1)).sendBroadcastAsUser(
- any(Intent.class), any(UserHandle.class));
+ verify(mBugreportManager, times(1)).requestBugreport(any(), any(), any());
}
@Test
public void takeBugReportSwallowsExceptions() {
when(mBuildProperties.isUserBuild()).thenReturn(false);
- doThrow(new RuntimeException()).when(mContext).sendBroadcastAsUser(
- any(Intent.class), any(UserHandle.class));
+ doThrow(new RuntimeException()).when(mBugreportManager).requestBugreport(
+ any(), any(), any());
mWifiDiagnostics.takeBugReport("", "");
- verify(mContext, times(1)).sendBroadcastAsUser(
- any(Intent.class), any(UserHandle.class));
+ verify(mBugreportManager, times(1)).requestBugreport(any(), any(), any());
}
@Test
public void takeBugReportDoesNothingOnUserBuild() {
when(mBuildProperties.isUserBuild()).thenReturn(true);
mWifiDiagnostics.takeBugReport("", "");
- verify(mContext, never()).sendBroadcastAsUser(
- any(Intent.class), any(UserHandle.class));
+ verify(mBugreportManager, never()).requestBugreport(any(), any(), any());
}
@Test
@@ -891,8 +889,7 @@ public class WifiDiagnosticsTest extends WifiBaseTest {
mContext, mWifiInjector, mWifiNative, mBuildProperties, mLastMileLogger, mClock);
mWifiDiagnostics.takeBugReport("", "");
- verify(mContext, never()).sendBroadcastAsUser(
- any(Intent.class), any(UserHandle.class));
+ verify(mBugreportManager, never()).requestBugreport(any(), any(), any());
}
/** Verifies that we flush HAL ringbuffer when capture bugreport. */