summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiDiagnostics.java40
-rw-r--r--service/res/values/config.xml2
-rw-r--r--service/res/values/overlayable.xml1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java43
4 files changed, 67 insertions, 19 deletions
diff --git a/service/java/com/android/server/wifi/WifiDiagnostics.java b/service/java/com/android/server/wifi/WifiDiagnostics.java
index b75b088c7..742581e9d 100644
--- a/service/java/com/android/server/wifi/WifiDiagnostics.java
+++ b/service/java/com/android/server/wifi/WifiDiagnostics.java
@@ -18,6 +18,9 @@ package com.android.server.wifi;
import android.annotation.NonNull;
import android.content.Context;
+import android.content.Intent;
+import android.os.BugreportParams;
+import android.os.UserHandle;
import android.util.ArraySet;
import android.util.Base64;
import android.util.Log;
@@ -60,6 +63,14 @@ 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 */
@@ -117,6 +128,7 @@ class WifiDiagnostics extends BaseWifiDiagnostics {
private boolean mIsLoggingEventHandlerRegistered;
private WifiNative.RingBufferStatus[] mRingBuffers;
private WifiNative.RingBufferStatus mPerPacketRingBuffer;
+ private final Context mContext;
private final BuildProperties mBuildProperties;
private final WifiLog mLog;
private final LastMileLogger mLastMileLogger;
@@ -124,6 +136,7 @@ class WifiDiagnostics extends BaseWifiDiagnostics {
private final WifiMetrics mWifiMetrics;
private int mMaxRingBufferSizeBytes;
private final List<Integer> mFatalFirmwareAlertErrorCodeList;
+ private final boolean mBugreportEnabled;
private WifiInjector mWifiInjector;
private Clock mClock;
@@ -140,7 +153,10 @@ class WifiDiagnostics extends BaseWifiDiagnostics {
R.integer.config_wifi_logger_ring_buffer_verbose_size_limit_kb) * 1024;
int[] fatalFirmwareAlertErrorCodeArray = context.getResources().getIntArray(
R.array.config_wifi_fatal_firmware_alert_error_code_list);
+ mBugreportEnabled = context.getResources().getBoolean(
+ R.bool.config_wifi_diagnostics_bugreport_enabled);
+ mContext = context;
mBuildProperties = buildProperties;
mIsLoggingEventHandlerRegistered = false;
mMaxRingBufferSizeBytes = RING_BUFFER_BYTE_LIMIT_SMALL;
@@ -294,19 +310,33 @@ class WifiDiagnostics extends BaseWifiDiagnostics {
pw.println("--------------------------------------------------------------------");
}
- @Override
/**
* Initiates a system-level bugreport, in a non-blocking fashion.
*/
+ @Override
public void takeBugReport(String bugTitle, String bugDetail) {
- // TODO (b/143494985): Re-enable it once we have a formal API.
- if (true || mBuildProperties.isUserBuild()) {
+ if (mBuildProperties.isUserBuild() || !mBugreportEnabled) {
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);
+ }
try {
- mWifiInjector.getActivityManagerService().requestWifiBugReport(
- bugTitle, bugDetail);
+ // Send broadcast to shell to trigger bugreport using Bugreport API
+ mContext.sendBroadcastAsUser(triggerShellBugreport, UserHandle.CURRENT);
} catch (Exception e) { // diagnostics should never crash system_server
mLog.err("error taking bugreport: %").c(e.getClass().getName()).flush();
}
diff --git a/service/res/values/config.xml b/service/res/values/config.xml
index bc7ef3bb2..ba65ba08c 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -214,4 +214,6 @@
<!-- Do not translate. Default access point SSID used for local only hotspot -->
<string name="wifi_localhotspot_configure_ssid_default" translatable="false">AndroidShare</string>
+ <!-- Indicates that a full bugreport should be triggered when wifi diagnostics detects an error on non-user (i.e debug) builds -->
+ <bool translatable="false" name="config_wifi_diagnostics_bugreport_enabled">false</bool>
</resources>
diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml
index f49e3df3a..581f0be7f 100644
--- a/service/res/values/overlayable.xml
+++ b/service/res/values/overlayable.xml
@@ -94,6 +94,7 @@
<item type="string" name="config_wifi_tcp_buffers" />
<item type="string" name="wifi_tether_configure_ssid_default" />
<item type="string" name="wifi_localhotspot_configure_ssid_default" />
+ <item type="bool" name="config_wifi_diagnostics_bugreport_enabled" />
<!-- Params from config.xml that can be overlayed -->
<!-- Params from strings.xml that can be overlayed -->
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
index 711930912..b85e540c5 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
@@ -36,6 +36,8 @@ 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 androidx.test.filters.SmallTest;
@@ -71,6 +73,7 @@ public class WifiDiagnosticsTest extends WifiBaseTest {
@Mock ActivityManagerService mActivityManagerService;
@Mock WifiMetrics mWifiMetrics;
@Mock Clock mClock;
+ MockResources mResources;
WifiDiagnostics mWifiDiagnostics;
private static final String FAKE_RING_BUFFER_NAME = "fake-ring-buffer";
@@ -118,14 +121,15 @@ public class WifiDiagnosticsTest extends WifiBaseTest {
when(mExternalProcess.getErrorStream()).thenReturn(new ByteArrayInputStream(new byte[0]));
when(mJavaRuntime.exec(anyString())).thenReturn(mExternalProcess);
- MockResources resources = new MockResources();
- resources.setInteger(R.integer.config_wifi_logger_ring_buffer_default_size_limit_kb,
+ mResources = new MockResources();
+ mResources.setInteger(R.integer.config_wifi_logger_ring_buffer_default_size_limit_kb,
SMALL_RING_BUFFER_SIZE_KB);
- resources.setInteger(R.integer.config_wifi_logger_ring_buffer_verbose_size_limit_kb,
+ mResources.setInteger(R.integer.config_wifi_logger_ring_buffer_verbose_size_limit_kb,
LARGE_RING_BUFFER_SIZE_KB);
- resources.setIntArray(R.array.config_wifi_fatal_firmware_alert_error_code_list,
+ mResources.setIntArray(R.array.config_wifi_fatal_firmware_alert_error_code_list,
FATAL_FW_ALERT_LIST);
- when(mContext.getResources()).thenReturn(resources);
+ mResources.setBoolean(R.bool.config_wifi_diagnostics_bugreport_enabled, true);
+ when(mContext.getResources()).thenReturn(mResources);
when(mWifiInjector.makeLog(anyString())).thenReturn(mLog);
when(mWifiInjector.getJavaRuntime()).thenReturn(mJavaRuntime);
when(mWifiInjector.getActivityManagerService()).thenReturn(mActivityManagerService);
@@ -857,30 +861,41 @@ public class WifiDiagnosticsTest extends WifiBaseTest {
}
@Test
- @Ignore("TODO(b/143494985): re-enabled this @Test")
public void takeBugReportCallsActivityManagerOnUserDebug() {
when(mBuildProperties.isUserBuild()).thenReturn(false);
mWifiDiagnostics.takeBugReport("", "");
- verify(mActivityManagerService, times(1)).requestWifiBugReport(
- anyString(), anyString());
+ verify(mContext, times(1)).sendBroadcastAsUser(
+ any(Intent.class), any(UserHandle.class));
}
@Test
- @Ignore("TODO(b/143494985): re-enabled this @Test")
public void takeBugReportSwallowsExceptions() {
when(mBuildProperties.isUserBuild()).thenReturn(false);
- doThrow(new RuntimeException()).when(mActivityManagerService).requestWifiBugReport(
- anyString(), anyString());
+ doThrow(new RuntimeException()).when(mContext).sendBroadcastAsUser(
+ any(Intent.class), any(UserHandle.class));
mWifiDiagnostics.takeBugReport("", "");
- verify(mActivityManagerService, times(1)).requestWifiBugReport(
- anyString(), anyString());
+ verify(mContext, times(1)).sendBroadcastAsUser(
+ any(Intent.class), any(UserHandle.class));
}
@Test
public void takeBugReportDoesNothingOnUserBuild() {
when(mBuildProperties.isUserBuild()).thenReturn(true);
mWifiDiagnostics.takeBugReport("", "");
- verify(mActivityManagerService, never()).requestWifiBugReport(anyString(), anyString());
+ verify(mContext, never()).sendBroadcastAsUser(
+ any(Intent.class), any(UserHandle.class));
+ }
+
+ @Test
+ public void takeBugReportDoesNothingWhenConfigOverlayDisabled() {
+ when(mBuildProperties.isUserBuild()).thenReturn(false);
+ mResources.setBoolean(R.bool.config_wifi_diagnostics_bugreport_enabled, false);
+ mWifiDiagnostics = new WifiDiagnostics(
+ mContext, mWifiInjector, mWifiNative, mBuildProperties, mLastMileLogger, mClock);
+
+ mWifiDiagnostics.takeBugReport("", "");
+ verify(mContext, never()).sendBroadcastAsUser(
+ any(Intent.class), any(UserHandle.class));
}
/** Verifies that we flush HAL ringbuffer when capture bugreport. */