diff options
Diffstat (limited to 'tests')
16 files changed, 435 insertions, 134 deletions
diff --git a/tests/BatteryStatsPerfTest/src/com/android/internal/os/BatteryUsageStatsPerfTest.java b/tests/BatteryStatsPerfTest/src/com/android/internal/os/BatteryUsageStatsPerfTest.java index 4143f595f9a0..30cc002b4144 100644 --- a/tests/BatteryStatsPerfTest/src/com/android/internal/os/BatteryUsageStatsPerfTest.java +++ b/tests/BatteryStatsPerfTest/src/com/android/internal/os/BatteryUsageStatsPerfTest.java @@ -171,11 +171,11 @@ public class BatteryUsageStatsPerfTest { .setConsumedPower(123) .setConsumedPower( BatteryConsumer.POWER_COMPONENT_CPU, 10100) - .setConsumedPowerForCustomComponent( + .setConsumedPower( BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID, 10200) .setUsageDurationMillis( BatteryConsumer.POWER_COMPONENT_CPU, 10300) - .setUsageDurationForCustomComponentMillis( + .setUsageDurationMillis( BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID, 10400); for (int i = 0; i < 1000; i++) { @@ -191,10 +191,9 @@ public class BatteryUsageStatsPerfTest { consumerBuilder.setUsageDurationMillis(componentId, componentId * 1000); } - consumerBuilder.setConsumedPowerForCustomComponent( - BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID, 1234) - .setUsageDurationForCustomComponentMillis( - BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID, 4321); + consumerBuilder + .setConsumedPower(BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID, 1234) + .setUsageDurationMillis(BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID, 4321); } return builder.build(); } diff --git a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonLandscape.kt b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonLandscape.kt index 8040610c485b..cfc818b6c0e9 100644 --- a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonLandscape.kt +++ b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonLandscape.kt @@ -31,8 +31,7 @@ import org.junit.runner.RunWith @RunWith(FlickerServiceJUnit4ClassRunner::class) class CloseAppBackButton3ButtonLandscape : CloseAppBackButton(NavBar.MODE_3BUTTON, Rotation.ROTATION_90) { - // TODO: Missing CUJ (b/300078127) - @ExpectedScenarios(["ENTIRE_TRACE"]) + @ExpectedScenarios(["APP_CLOSE_TO_HOME"]) @Test override fun closeAppBackButtonTest() = super.closeAppBackButtonTest() diff --git a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonPortrait.kt b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonPortrait.kt index aacccf4e680c..6bf32a8e2083 100644 --- a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonPortrait.kt +++ b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButton3ButtonPortrait.kt @@ -31,8 +31,7 @@ import org.junit.runner.RunWith @RunWith(FlickerServiceJUnit4ClassRunner::class) class CloseAppBackButton3ButtonPortrait : CloseAppBackButton(NavBar.MODE_3BUTTON, Rotation.ROTATION_0) { - // TODO: Missing CUJ (b/300078127) - @ExpectedScenarios(["ENTIRE_TRACE"]) + @ExpectedScenarios(["APP_CLOSE_TO_HOME"]) @Test override fun closeAppBackButtonTest() = super.closeAppBackButtonTest() diff --git a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavLandscape.kt b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavLandscape.kt index 74ee46093f6e..4b6ab773f15e 100644 --- a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavLandscape.kt +++ b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavLandscape.kt @@ -31,8 +31,7 @@ import org.junit.runner.RunWith @RunWith(FlickerServiceJUnit4ClassRunner::class) class CloseAppBackButtonGesturalNavLandscape : CloseAppBackButton(NavBar.MODE_GESTURAL, Rotation.ROTATION_90) { - // TODO: Missing CUJ (b/300078127) - @ExpectedScenarios(["ENTIRE_TRACE"]) + @ExpectedScenarios(["APP_CLOSE_TO_HOME"]) @Test override fun closeAppBackButtonTest() = super.closeAppBackButtonTest() diff --git a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavPortrait.kt b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavPortrait.kt index 57463c33c1fa..7cc9db027e1f 100644 --- a/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavPortrait.kt +++ b/tests/FlickerTests/FlickerService/src/com/android/server/wm/flicker/service/close/flicker/CloseAppBackButtonGesturalNavPortrait.kt @@ -31,8 +31,7 @@ import org.junit.runner.RunWith @RunWith(FlickerServiceJUnit4ClassRunner::class) class CloseAppBackButtonGesturalNavPortrait : CloseAppBackButton(NavBar.MODE_GESTURAL, Rotation.ROTATION_0) { - // TODO: Missing CUJ (b/300078127) - @ExpectedScenarios(["ENTIRE_TRACE"]) + @ExpectedScenarios(["APP_CLOSE_TO_HOME"]) @Test override fun closeAppBackButtonTest() = super.closeAppBackButtonTest() diff --git a/tests/FlickerTests/IME/src/com/android/server/wm/flicker/ime/ShowImeWhileEnteringOverviewTest.kt b/tests/FlickerTests/IME/src/com/android/server/wm/flicker/ime/ShowImeWhileEnteringOverviewTest.kt index 638d594b0a48..eb63e4985a9f 100644 --- a/tests/FlickerTests/IME/src/com/android/server/wm/flicker/ime/ShowImeWhileEnteringOverviewTest.kt +++ b/tests/FlickerTests/IME/src/com/android/server/wm/flicker/ime/ShowImeWhileEnteringOverviewTest.kt @@ -28,6 +28,7 @@ import com.android.server.wm.flicker.BaseTest import com.android.server.wm.flicker.helpers.ImeShownOnAppStartHelper import com.android.server.wm.flicker.navBarLayerIsVisibleAtStartAndEnd import com.android.server.wm.flicker.statusBarLayerIsVisibleAtStartAndEnd +import com.android.server.wm.flicker.taskBarLayerIsVisibleAtStartAndEnd import org.junit.Assume import org.junit.FixMethodOrder import org.junit.Ignore @@ -114,28 +115,28 @@ class ShowImeWhileEnteringOverviewTest(flicker: LegacyFlickerTest) : BaseTest(fl /** * In the legacy transitions, the nav bar is not marked as invisible. In the new transitions - * this is fixed and the nav bar shows as invisible + * this is fixed and the status bar shows as invisible */ @Presubmit @Test fun statusBarLayerIsInvisibleInLandscapePhone() { Assume.assumeTrue(flicker.scenario.isLandscapeOrSeascapeAtStart) Assume.assumeTrue(flicker.scenario.isGesturalNavigation) - Assume.assumeFalse(usesTaskbar) + Assume.assumeFalse(flicker.scenario.isTablet) flicker.assertLayersStart { this.isVisible(ComponentNameMatcher.STATUS_BAR) } flicker.assertLayersEnd { this.isInvisible(ComponentNameMatcher.STATUS_BAR) } } /** * In the legacy transitions, the nav bar is not marked as invisible. In the new transitions - * this is fixed and the nav bar shows as invisible + * this is fixed and the status bar shows as invisible */ @Presubmit @Test fun statusBarLayerIsInvisibleInLandscapeTablet() { Assume.assumeTrue(flicker.scenario.isLandscapeOrSeascapeAtStart) Assume.assumeTrue(flicker.scenario.isGesturalNavigation) - Assume.assumeTrue(usesTaskbar) + Assume.assumeTrue(flicker.scenario.isTablet) flicker.statusBarLayerIsVisibleAtStartAndEnd() } @@ -149,6 +150,10 @@ class ShowImeWhileEnteringOverviewTest(flicker: LegacyFlickerTest) : BaseTest(fl @Ignore("Visibility changes depending on orientation and navigation mode") override fun navBarLayerPositionAtStartAndEnd() {} + @Test + @Ignore("Visibility changes depending on orientation and navigation mode") + override fun taskBarLayerIsVisibleAtStartAndEnd() {} + /** {@inheritDoc} */ @Test @Ignore("Visibility changes depending on orientation and navigation mode") @@ -161,7 +166,10 @@ class ShowImeWhileEnteringOverviewTest(flicker: LegacyFlickerTest) : BaseTest(fl @Presubmit @Test - override fun taskBarLayerIsVisibleAtStartAndEnd() = super.taskBarLayerIsVisibleAtStartAndEnd() + fun taskBarLayerIsVisibleAtStartAndEndForTablets() { + Assume.assumeTrue(flicker.scenario.isTablet) + flicker.taskBarLayerIsVisibleAtStartAndEnd() + } @Presubmit @Test diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt index 70d762e02af5..851ce022bd81 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt @@ -137,8 +137,6 @@ constructor( /** * Checks that the [ComponentNameMatcher.TASK_BAR] window is visible at the start and end of the * transition - * - * Note: Large screen only */ @Presubmit @Test @@ -149,8 +147,6 @@ constructor( /** * Checks that the [ComponentNameMatcher.TASK_BAR] window is visible during the whole transition - * - * Note: Large screen only */ @Presubmit @Test diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt index 8811e00f9661..753cb1ff5dd3 100644 --- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt +++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt @@ -16,12 +16,17 @@ package com.android.server.wm.flicker.helpers +import android.content.Context +import android.graphics.Insets import android.graphics.Rect +import android.graphics.Region import android.platform.uiautomator_helpers.DeviceHelpers import android.tools.device.apphelpers.IStandardAppHelper import android.tools.helpers.SYSTEMUI_PACKAGE import android.tools.traces.parsers.WindowManagerStateHelper import android.tools.traces.wm.WindowingMode +import android.view.WindowInsets +import android.view.WindowManager import androidx.test.uiautomator.By import androidx.test.uiautomator.BySelector import androidx.test.uiautomator.UiDevice @@ -70,9 +75,7 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : // Start dragging a little under the top to prevent dragging the notification shade. val startY = 10 - val displayRect = - wmHelper.currentState.wmState.getDefaultDisplay()?.displayRect - ?: throw IllegalStateException("Default display is null") + val displayRect = getDisplayRect(wmHelper) // The position we want to drag to val endY = displayRect.centerY() / 2 @@ -81,18 +84,61 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : device.drag(startX, startY, startX, endY, 100) } + private fun getMaximizeButtonForTheApp(caption: UiObject2?): UiObject2 { + return caption + ?.children + ?.find { it.resourceName.endsWith(MAXIMIZE_BUTTON_VIEW) } + ?.children + ?.get(0) + ?: error("Unable to find resource $MAXIMIZE_BUTTON_VIEW\n") + } + /** Click maximise button on the app header for the given app. */ fun maximiseDesktopApp(wmHelper: WindowManagerStateHelper, device: UiDevice) { val caption = getCaptionForTheApp(wmHelper, device) - val maximizeButton = - caption - ?.children - ?.find { it.resourceName.endsWith(MAXIMIZE_BUTTON_VIEW) } - ?.children - ?.get(0) - maximizeButton?.click() + val maximizeButton = getMaximizeButtonForTheApp(caption) + maximizeButton.click() wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify() } + + /** Open maximize menu and click snap resize button on the app header for the given app. */ + fun snapResizeDesktopApp( + wmHelper: WindowManagerStateHelper, + device: UiDevice, + context: Context, + toLeft: Boolean + ) { + val caption = getCaptionForTheApp(wmHelper, device) + val maximizeButton = getMaximizeButtonForTheApp(caption) + maximizeButton?.longClick() + wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify() + + val buttonResId = if (toLeft) SNAP_LEFT_BUTTON else SNAP_RIGHT_BUTTON + val maximizeMenu = getDesktopAppViewByRes(MAXIMIZE_MENU) + + val snapResizeButton = + maximizeMenu + ?.wait(Until.findObject(By.res(SYSTEMUI_PACKAGE, buttonResId)), TIMEOUT.toMillis()) + ?: error("Unable to find object with resource id $buttonResId") + snapResizeButton.click() + + val displayRect = getDisplayRect(wmHelper) + val insets = getWindowInsets( + context, WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars()) + displayRect.inset(insets) + + val expectedWidth = displayRect.width() / 2 + val expectedRect = Rect(displayRect).apply { + if (toLeft) right -= expectedWidth else left += expectedWidth + } + + wmHelper + .StateSyncBuilder() + .withAppTransitionIdle() + .withSurfaceVisibleRegion(this, Region(expectedRect)) + .waitForAndVerify() + } + /** Click close button on the app header for the given app. */ fun closeDesktopApp(wmHelper: WindowManagerStateHelper, device: UiDevice) { val caption = getCaptionForTheApp(wmHelper, device) @@ -112,8 +158,7 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : if ( wmHelper.getWindow(innerHelper)?.windowingMode != WindowingMode.WINDOWING_MODE_FREEFORM.value - ) - error("expected a freeform window with caption but window is not in freeform mode") + ) error("expected a freeform window with caption but window is not in freeform mode") val captions = device.wait(Until.findObjects(caption), TIMEOUT.toMillis()) ?: error("Unable to find view $caption\n") @@ -156,6 +201,30 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : .waitForAndVerify() } + /** Drag a window to a snap resize region, found at the left and right edges of the screen. */ + fun dragToSnapResizeRegion( + wmHelper: WindowManagerStateHelper, + device: UiDevice, + isLeft: Boolean, + ) { + val windowRect = wmHelper.getWindowRegion(innerHelper).bounds + // Set start x-coordinate as center of app header. + val startX = windowRect.centerX() + val startY = windowRect.top + + val displayRect = getDisplayRect(wmHelper) + + val endX = if (isLeft) displayRect.left else displayRect.right + val endY = displayRect.centerY() / 2 + + // drag the window to snap resize + device.drag(startX, startY, endX, endY, /* steps= */ 100) + wmHelper + .StateSyncBuilder() + .withAppTransitionIdle() + .waitForAndVerify() + } + private fun getStartCoordinatesForCornerResize( windowRect: Rect, corner: Corners @@ -179,9 +248,7 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : private fun dragAppWindowToTopDragZone(wmHelper: WindowManagerStateHelper, device: UiDevice) { val windowRect = wmHelper.getWindowRegion(innerHelper).bounds - val displayRect = - wmHelper.currentState.wmState.getDefaultDisplay()?.displayRect - ?: throw IllegalStateException("Default display is null") + val displayRect = getDisplayRect(wmHelper) val startX = windowRect.centerX() val endX = displayRect.centerX() @@ -194,7 +261,8 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : fun enterDesktopModeFromAppHandleMenu( wmHelper: WindowManagerStateHelper, - device: UiDevice) { + device: UiDevice + ) { val windowRect = wmHelper.getWindowRegion(innerHelper).bounds val startX = windowRect.centerX() // Click a little under the top to prevent opening the notification shade. @@ -204,7 +272,7 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : device.click(startX, startY) wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify() - val pill = getAppHandlePillForWindow() + val pill = getDesktopAppViewByRes(PILL_CONTAINER) val desktopModeButton = pill ?.children @@ -214,10 +282,13 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify() } - private fun getAppHandlePillForWindow(): UiObject2? { - val pillContainer: BySelector = By.res(SYSTEMUI_PACKAGE, PILL_CONTAINER) - return DeviceHelpers.waitForObj(pillContainer, TIMEOUT) - } + private fun getDesktopAppViewByRes(viewResId: String): UiObject2? = + DeviceHelpers.waitForObj(By.res(SYSTEMUI_PACKAGE, viewResId), TIMEOUT) + + private fun getDisplayRect(wmHelper: WindowManagerStateHelper): Rect = + wmHelper.currentState.wmState.getDefaultDisplay()?.displayRect + ?: throw IllegalStateException("Default display is null") + /** Wait for transition to full screen to finish. */ private fun waitForTransitionToFullscreen(wmHelper: WindowManagerStateHelper) { @@ -228,13 +299,23 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) : .waitForAndVerify() } + private fun getWindowInsets(context: Context, typeMask: Int): Insets { + val wm: WindowManager = context.getSystemService(WindowManager::class.java) + ?: error("Unable to connect to WindowManager service") + val metricInsets = wm.currentWindowMetrics.windowInsets + return metricInsets.getInsetsIgnoringVisibility(typeMask) + } + private companion object { - val TIMEOUT = Duration.ofSeconds(3) - val CAPTION = "desktop_mode_caption" - val MAXIMIZE_BUTTON_VIEW = "maximize_button_view" - val CLOSE_BUTTON = "close_window" - val PILL_CONTAINER = "windowing_pill" - val DESKTOP_MODE_BUTTON = "desktop_button" + val TIMEOUT: Duration = Duration.ofSeconds(3) + const val CAPTION: String = "desktop_mode_caption" + const val MAXIMIZE_BUTTON_VIEW: String = "maximize_button_view" + const val MAXIMIZE_MENU: String = "maximize_menu" + const val CLOSE_BUTTON: String = "close_window" + const val PILL_CONTAINER: String = "windowing_pill" + const val DESKTOP_MODE_BUTTON: String = "desktop_button" + const val SNAP_LEFT_BUTTON: String = "maximize_menu_snap_left_button" + const val SNAP_RIGHT_BUTTON: String = "maximize_menu_snap_right_button" val caption: BySelector get() = By.res(SYSTEMUI_PACKAGE, CAPTION) } diff --git a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt index 3c72498082e4..8829f74f5092 100644 --- a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt +++ b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt @@ -151,6 +151,7 @@ class InputManagerServiceTests { verify(native).setTouchpadNaturalScrollingEnabled(anyBoolean()) verify(native).setTouchpadTapToClickEnabled(anyBoolean()) verify(native).setTouchpadTapDraggingEnabled(anyBoolean()) + verify(native).setShouldNotifyTouchpadHardwareState(anyBoolean()) verify(native).setTouchpadRightClickZoneEnabled(anyBoolean()) verify(native).setShowTouches(anyBoolean()) verify(native).setMotionClassifierEnabled(anyBoolean()) diff --git a/tests/Internal/AndroidTest.xml b/tests/Internal/AndroidTest.xml index 7b67e9ebcced..2d6c650eb2dc 100644 --- a/tests/Internal/AndroidTest.xml +++ b/tests/Internal/AndroidTest.xml @@ -26,4 +26,12 @@ <option name="package" value="com.android.internal.tests" /> <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> </test> + + <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> + <option name="pull-pattern-keys" value="perfetto_file_path"/> + <option name="directory-keys" + value="/data/user/0/com.android.internal.tests/files"/> + <option name="collect-on-run-ended-only" value="true"/> + <option name="clean-up" value="true"/> + </metrics_collector> </configuration>
\ No newline at end of file diff --git a/tests/Internal/src/com/android/internal/protolog/PerfettoProtoLogImplTest.java b/tests/Internal/src/com/android/internal/protolog/PerfettoProtoLogImplTest.java index ecaab12384cf..6db5f8277e52 100644 --- a/tests/Internal/src/com/android/internal/protolog/PerfettoProtoLogImplTest.java +++ b/tests/Internal/src/com/android/internal/protolog/PerfettoProtoLogImplTest.java @@ -29,7 +29,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static java.io.File.createTempFile; -import static java.nio.file.Files.createTempDirectory; import android.content.Context; import android.os.SystemClock; @@ -44,7 +43,7 @@ import android.tools.traces.protolog.ProtoLogTrace; import android.tracing.perfetto.DataSource; import android.util.proto.ProtoInputStream; -import androidx.test.filters.SmallTest; +import androidx.test.platform.app.InstrumentationRegistry; import com.android.internal.protolog.common.IProtoLogGroup; import com.android.internal.protolog.common.LogDataType; @@ -73,11 +72,11 @@ import java.util.concurrent.atomic.AtomicInteger; * Test class for {@link ProtoLogImpl}. */ @SuppressWarnings("ConstantConditions") -@SmallTest @Presubmit @RunWith(JUnit4.class) public class PerfettoProtoLogImplTest { - private final File mTracingDirectory = createTempDirectory("temp").toFile(); + private final File mTracingDirectory = InstrumentationRegistry.getInstrumentation() + .getTargetContext().getFilesDir(); private final ResultWriter mWriter = new ResultWriter() .forScenario(new ScenarioBuilder() @@ -165,8 +164,7 @@ public class PerfettoProtoLogImplTest { mReader = Mockito.spy(new ProtoLogViewerConfigReader(viewerConfigInputStreamProvider)); mProtoLog = new PerfettoProtoLogImpl( viewerConfigInputStreamProvider, mReader, - () -> mCacheUpdater.run()); - mProtoLog.registerGroups(TestProtoLogGroup.values()); + () -> mCacheUpdater.run(), TestProtoLogGroup.values()); } @After @@ -758,6 +756,80 @@ public class PerfettoProtoLogImplTest { .isEqualTo("My null args: 0, 0, false"); } + @Test + public void handlesConcurrentTracingSessions() throws IOException { + PerfettoTraceMonitor traceMonitor1 = + PerfettoTraceMonitor.newBuilder().enableProtoLog(true) + .build(); + + PerfettoTraceMonitor traceMonitor2 = + PerfettoTraceMonitor.newBuilder().enableProtoLog(true) + .build(); + + final ResultWriter writer2 = new ResultWriter() + .forScenario(new ScenarioBuilder() + .forClass(createTempFile("temp", "").getName()).build()) + .withOutputDir(mTracingDirectory) + .setRunComplete(); + + try { + traceMonitor1.start(); + traceMonitor2.start(); + + mProtoLog.log(LogLevel.DEBUG, TestProtoLogGroup.TEST_GROUP, 1, + LogDataType.BOOLEAN, new Object[]{true}); + } finally { + traceMonitor1.stop(mWriter); + traceMonitor2.stop(writer2); + } + + final ResultReader reader = new ResultReader(mWriter.write(), mTraceConfig); + final ProtoLogTrace protologFromMonitor1 = reader.readProtoLogTrace(); + + final ResultReader reader2 = new ResultReader(writer2.write(), mTraceConfig); + final ProtoLogTrace protologFromMonitor2 = reader2.readProtoLogTrace(); + + Truth.assertThat(protologFromMonitor1.messages).hasSize(1); + Truth.assertThat(protologFromMonitor1.messages.get(0).getMessage()) + .isEqualTo("My Test Debug Log Message true"); + + Truth.assertThat(protologFromMonitor2.messages).hasSize(1); + Truth.assertThat(protologFromMonitor2.messages.get(0).getMessage()) + .isEqualTo("My Test Debug Log Message true"); + } + + @Test + public void usesDefaultLogFromLevel() throws IOException { + PerfettoTraceMonitor traceMonitor = + PerfettoTraceMonitor.newBuilder().enableProtoLog(LogLevel.WARN).build(); + try { + traceMonitor.start(); + mProtoLog.log(LogLevel.DEBUG, TestProtoLogGroup.TEST_GROUP, + "This message should not be logged"); + mProtoLog.log(LogLevel.WARN, TestProtoLogGroup.TEST_GROUP, + "This message should logged %d", 123); + mProtoLog.log(LogLevel.ERROR, TestProtoLogGroup.TEST_GROUP, + "This message should also be logged %d", 567); + } finally { + traceMonitor.stop(mWriter); + } + + final ResultReader reader = new ResultReader(mWriter.write(), mTraceConfig); + final ProtoLogTrace protolog = reader.readProtoLogTrace(); + + Truth.assertThat(protolog.messages).hasSize(2); + + Truth.assertThat(protolog.messages.get(0).getLevel()) + .isEqualTo(LogLevel.WARN); + Truth.assertThat(protolog.messages.get(0).getMessage()) + .isEqualTo("This message should logged 123"); + + Truth.assertThat(protolog.messages.get(1).getLevel()) + .isEqualTo(LogLevel.ERROR); + Truth.assertThat(protolog.messages.get(1).getMessage()) + .isEqualTo("This message should also be logged 567"); + } + private enum TestProtoLogGroup implements IProtoLogGroup { TEST_GROUP(true, true, false, "TEST_TAG"); diff --git a/tests/Internal/src/com/android/internal/protolog/ProtoLogCommandHandlerTest.java b/tests/Internal/src/com/android/internal/protolog/ProtoLogCommandHandlerTest.java index e3ec62d5b5a6..aba6722c0813 100644 --- a/tests/Internal/src/com/android/internal/protolog/ProtoLogCommandHandlerTest.java +++ b/tests/Internal/src/com/android/internal/protolog/ProtoLogCommandHandlerTest.java @@ -41,14 +41,14 @@ import java.io.PrintWriter; public class ProtoLogCommandHandlerTest { @Mock - ProtoLogService mProtoLogService; + ProtoLogConfigurationService mProtoLogConfigurationService; @Mock PrintWriter mPrintWriter; @Test public void printsHelpForAllAvailableCommands() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); cmdHandler.onHelp(); validateOnHelpPrinted(); @@ -57,7 +57,7 @@ public class ProtoLogCommandHandlerTest { @Test public void printsHelpIfCommandIsNull() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); cmdHandler.onCommand(null); validateOnHelpPrinted(); @@ -65,13 +65,13 @@ public class ProtoLogCommandHandlerTest { @Test public void handlesGroupListCommand() { - Mockito.when(mProtoLogService.getGroups()) + Mockito.when(mProtoLogConfigurationService.getGroups()) .thenReturn(new String[] {"MY_TEST_GROUP", "MY_OTHER_GROUP"}); final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "groups", "list" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "groups", "list" }); Mockito.verify(mPrintWriter, times(1)) .println(contains("MY_TEST_GROUP")); @@ -82,10 +82,10 @@ public class ProtoLogCommandHandlerTest { @Test public void handlesIncompleteGroupsCommand() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "groups" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "groups" }); Mockito.verify(mPrintWriter, times(1)) .println(contains("Incomplete command")); @@ -93,13 +93,14 @@ public class ProtoLogCommandHandlerTest { @Test public void handlesGroupStatusCommand() { - Mockito.when(mProtoLogService.getGroups()).thenReturn(new String[] {"MY_GROUP"}); - Mockito.when(mProtoLogService.isLoggingToLogcat("MY_GROUP")).thenReturn(true); + Mockito.when(mProtoLogConfigurationService.getGroups()) + .thenReturn(new String[] {"MY_GROUP"}); + Mockito.when(mProtoLogConfigurationService.isLoggingToLogcat("MY_GROUP")).thenReturn(true); final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "groups", "status", "MY_GROUP" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "groups", "status", "MY_GROUP" }); Mockito.verify(mPrintWriter, times(1)) .println(contains("MY_GROUP")); @@ -109,12 +110,12 @@ public class ProtoLogCommandHandlerTest { @Test public void handlesGroupStatusCommandOfUnregisteredGroups() { - Mockito.when(mProtoLogService.getGroups()).thenReturn(new String[] {}); + Mockito.when(mProtoLogConfigurationService.getGroups()).thenReturn(new String[] {}); final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "groups", "status", "MY_GROUP" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "groups", "status", "MY_GROUP" }); Mockito.verify(mPrintWriter, times(1)) .println(contains("MY_GROUP")); @@ -125,10 +126,10 @@ public class ProtoLogCommandHandlerTest { @Test public void handlesGroupStatusCommandWithNoGroups() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "groups", "status" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "groups", "status" }); Mockito.verify(mPrintWriter, times(1)) .println(contains("Incomplete command")); @@ -137,10 +138,10 @@ public class ProtoLogCommandHandlerTest { @Test public void handlesIncompleteLogcatCommand() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "logcat" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "logcat" }); Mockito.verify(mPrintWriter, times(1)) .println(contains("Incomplete command")); @@ -149,50 +150,52 @@ public class ProtoLogCommandHandlerTest { @Test public void handlesLogcatEnableCommand() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "logcat", "enable", "MY_GROUP" }); - Mockito.verify(mProtoLogService).enableProtoLogToLogcat("MY_GROUP"); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "logcat", "enable", "MY_GROUP" }); + Mockito.verify(mProtoLogConfigurationService).enableProtoLogToLogcat("MY_GROUP"); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "logcat", "enable", "MY_GROUP", "MY_OTHER_GROUP" }); - Mockito.verify(mProtoLogService) + Mockito.verify(mProtoLogConfigurationService) .enableProtoLogToLogcat("MY_GROUP", "MY_OTHER_GROUP"); } @Test public void handlesLogcatDisableCommand() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "logcat", "disable", "MY_GROUP" }); - Mockito.verify(mProtoLogService).disableProtoLogToLogcat("MY_GROUP"); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "logcat", "disable", "MY_GROUP" }); + Mockito.verify(mProtoLogConfigurationService).disableProtoLogToLogcat("MY_GROUP"); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "logcat", "disable", "MY_GROUP", "MY_OTHER_GROUP" }); - Mockito.verify(mProtoLogService) + Mockito.verify(mProtoLogConfigurationService) .disableProtoLogToLogcat("MY_GROUP", "MY_OTHER_GROUP"); } @Test public void handlesLogcatEnableCommandWithNoGroups() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "logcat", "enable" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "logcat", "enable" }); Mockito.verify(mPrintWriter).println(contains("Incomplete command")); } @Test public void handlesLogcatDisableCommandWithNoGroups() { final ProtoLogCommandHandler cmdHandler = - new ProtoLogCommandHandler(mProtoLogService, mPrintWriter); + new ProtoLogCommandHandler(mProtoLogConfigurationService, mPrintWriter); - cmdHandler.exec(mProtoLogService, FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, - new String[] { "logcat", "disable" }); + cmdHandler.exec(mProtoLogConfigurationService, FileDescriptor.in, FileDescriptor.out, + FileDescriptor.err, new String[] { "logcat", "disable" }); Mockito.verify(mPrintWriter).println(contains("Incomplete command")); } diff --git a/tests/Internal/src/com/android/internal/protolog/ProtoLogServiceTest.java b/tests/Internal/src/com/android/internal/protolog/ProtoLogConfigurationServiceTest.java index feac59c702ea..e1bdd777dc5f 100644 --- a/tests/Internal/src/com/android/internal/protolog/ProtoLogServiceTest.java +++ b/tests/Internal/src/com/android/internal/protolog/ProtoLogConfigurationServiceTest.java @@ -67,7 +67,7 @@ import java.util.List; */ @Presubmit @RunWith(MockitoJUnitRunner.class) -public class ProtoLogServiceTest { +public class ProtoLogConfigurationServiceTest { private static final String TEST_GROUP = "MY_TEST_GROUP"; private static final String OTHER_TEST_GROUP = "MY_OTHER_TEST_GROUP"; @@ -128,7 +128,7 @@ public class ProtoLogServiceTest { private File mViewerConfigFile; - public ProtoLogServiceTest() throws IOException { + public ProtoLogConfigurationServiceTest() throws IOException { } @Before @@ -150,10 +150,12 @@ public class ProtoLogServiceTest { @Test public void canRegisterClientWithGroupsOnly() throws RemoteException { - final ProtoLogService service = new ProtoLogService(); + final ProtoLogConfigurationService service = new ProtoLogConfigurationService(); - final ProtoLogService.RegisterClientArgs args = new ProtoLogService.RegisterClientArgs() - .setGroups(new ProtoLogService.RegisterClientArgs.GroupConfig(TEST_GROUP, true)); + final ProtoLogConfigurationService.RegisterClientArgs args = + new ProtoLogConfigurationService.RegisterClientArgs() + .setGroups(new ProtoLogConfigurationService.RegisterClientArgs + .GroupConfig(TEST_GROUP, true)); service.registerClient(mMockClient, args); Truth.assertThat(service.isLoggingToLogcat(TEST_GROUP)).isTrue(); @@ -163,11 +165,13 @@ public class ProtoLogServiceTest { @Test public void willDumpViewerConfigOnlyOnceOnTraceStop() throws RemoteException, InvalidProtocolBufferException { - final ProtoLogService service = new ProtoLogService(); + final ProtoLogConfigurationService service = new ProtoLogConfigurationService(); - final ProtoLogService.RegisterClientArgs args = new ProtoLogService.RegisterClientArgs() - .setGroups(new ProtoLogService.RegisterClientArgs.GroupConfig(TEST_GROUP, true)) - .setViewerConfigFile(mViewerConfigFile.getAbsolutePath()); + final ProtoLogConfigurationService.RegisterClientArgs args = + new ProtoLogConfigurationService.RegisterClientArgs() + .setGroups(new ProtoLogConfigurationService.RegisterClientArgs + .GroupConfig(TEST_GROUP, true)) + .setViewerConfigFile(mViewerConfigFile.getAbsolutePath()); service.registerClient(mMockClient, args); service.registerClient(mSecondMockClient, args); @@ -196,14 +200,15 @@ public class ProtoLogServiceTest { @Test public void willDumpViewerConfigOnLastClientDisconnected() throws RemoteException, FileNotFoundException { - final ProtoLogService.ViewerConfigFileTracer tracer = - Mockito.mock(ProtoLogService.ViewerConfigFileTracer.class); - final ProtoLogService service = new ProtoLogService(tracer); - - final ProtoLogService.RegisterClientArgs args = new ProtoLogService.RegisterClientArgs() - .setGroups(new ProtoLogService.RegisterClientArgs.GroupConfig( - TEST_GROUP, true)) - .setViewerConfigFile(mViewerConfigFile.getAbsolutePath()); + final ProtoLogConfigurationService.ViewerConfigFileTracer tracer = + Mockito.mock(ProtoLogConfigurationService.ViewerConfigFileTracer.class); + final ProtoLogConfigurationService service = new ProtoLogConfigurationService(tracer); + + final ProtoLogConfigurationService.RegisterClientArgs args = + new ProtoLogConfigurationService.RegisterClientArgs() + .setGroups(new ProtoLogConfigurationService.RegisterClientArgs + .GroupConfig(TEST_GROUP, true)) + .setViewerConfigFile(mViewerConfigFile.getAbsolutePath()); service.registerClient(mMockClient, args); service.registerClient(mSecondMockClient, args); @@ -220,10 +225,11 @@ public class ProtoLogServiceTest { @Test public void sendEnableLoggingToLogcatToClient() throws RemoteException { - final var service = new ProtoLogService(); + final var service = new ProtoLogConfigurationService(); - final var args = new ProtoLogService.RegisterClientArgs() - .setGroups(new ProtoLogService.RegisterClientArgs.GroupConfig(TEST_GROUP, false)); + final var args = new ProtoLogConfigurationService.RegisterClientArgs() + .setGroups(new ProtoLogConfigurationService.RegisterClientArgs + .GroupConfig(TEST_GROUP, false)); service.registerClient(mMockClient, args); Truth.assertThat(service.isLoggingToLogcat(TEST_GROUP)).isFalse(); @@ -236,10 +242,12 @@ public class ProtoLogServiceTest { @Test public void sendDisableLoggingToLogcatToClient() throws RemoteException { - final ProtoLogService service = new ProtoLogService(); + final ProtoLogConfigurationService service = new ProtoLogConfigurationService(); - final ProtoLogService.RegisterClientArgs args = new ProtoLogService.RegisterClientArgs() - .setGroups(new ProtoLogService.RegisterClientArgs.GroupConfig(TEST_GROUP, true)); + final ProtoLogConfigurationService.RegisterClientArgs args = + new ProtoLogConfigurationService.RegisterClientArgs() + .setGroups(new ProtoLogConfigurationService.RegisterClientArgs + .GroupConfig(TEST_GROUP, true)); service.registerClient(mMockClient, args); Truth.assertThat(service.isLoggingToLogcat(TEST_GROUP)).isTrue(); @@ -252,10 +260,12 @@ public class ProtoLogServiceTest { @Test public void doNotSendLoggingToLogcatToClientWithoutRegisteredGroup() throws RemoteException { - final ProtoLogService service = new ProtoLogService(); + final ProtoLogConfigurationService service = new ProtoLogConfigurationService(); - final ProtoLogService.RegisterClientArgs args = new ProtoLogService.RegisterClientArgs() - .setGroups(new ProtoLogService.RegisterClientArgs.GroupConfig(TEST_GROUP, false)); + final ProtoLogConfigurationService.RegisterClientArgs args = + new ProtoLogConfigurationService.RegisterClientArgs() + .setGroups(new ProtoLogConfigurationService.RegisterClientArgs + .GroupConfig(TEST_GROUP, false)); service.registerClient(mMockClient, args); Truth.assertThat(service.isLoggingToLogcat(TEST_GROUP)).isFalse(); @@ -267,14 +277,16 @@ public class ProtoLogServiceTest { @Test public void handlesToggleToLogcatBeforeClientIsRegistered() throws RemoteException { - final ProtoLogService service = new ProtoLogService(); + final ProtoLogConfigurationService service = new ProtoLogConfigurationService(); Truth.assertThat(service.getGroups()).asList().doesNotContain(TEST_GROUP); service.enableProtoLogToLogcat(TEST_GROUP); Truth.assertThat(service.isLoggingToLogcat(TEST_GROUP)).isTrue(); - final ProtoLogService.RegisterClientArgs args = new ProtoLogService.RegisterClientArgs() - .setGroups(new ProtoLogService.RegisterClientArgs.GroupConfig(TEST_GROUP, false)); + final ProtoLogConfigurationService.RegisterClientArgs args = + new ProtoLogConfigurationService.RegisterClientArgs() + .setGroups(new ProtoLogConfigurationService.RegisterClientArgs + .GroupConfig(TEST_GROUP, false)); service.registerClient(mMockClient, args); Mockito.verify(mMockClient).toggleLogcat(eq(true), diff --git a/tests/Internal/src/com/android/internal/protolog/ProtoLogTest.java b/tests/Internal/src/com/android/internal/protolog/ProtoLogTest.java new file mode 100644 index 000000000000..9d56a92fad52 --- /dev/null +++ b/tests/Internal/src/com/android/internal/protolog/ProtoLogTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.protolog; + +import android.platform.test.annotations.Presubmit; + +import com.android.internal.protolog.common.IProtoLogGroup; + +import com.google.common.truth.Truth; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Test class for {@link ProtoLog}. */ +@SuppressWarnings("ConstantConditions") +@Presubmit +@RunWith(JUnit4.class) +public class ProtoLogTest { + + @Test + public void canRunProtoLogInitMultipleTimes() { + ProtoLog.init(TEST_GROUP_1); + ProtoLog.init(TEST_GROUP_1); + ProtoLog.init(TEST_GROUP_2); + ProtoLog.init(TEST_GROUP_1, TEST_GROUP_2); + + final var instance = ProtoLog.getSingleInstance(); + Truth.assertThat(instance.getRegisteredGroups()) + .containsExactly(TEST_GROUP_1, TEST_GROUP_2); + } + + private static final IProtoLogGroup TEST_GROUP_1 = new ProtoLogGroup("TEST_TAG_1", 1); + private static final IProtoLogGroup TEST_GROUP_2 = new ProtoLogGroup("TEST_TAG_2", 2); + + private static class ProtoLogGroup implements IProtoLogGroup { + private final boolean mEnabled; + private volatile boolean mLogToProto; + private volatile boolean mLogToLogcat; + private final String mTag; + private final int mId; + + ProtoLogGroup(String tag, int id) { + this(true, true, false, tag, id); + } + + ProtoLogGroup( + boolean enabled, boolean logToProto, boolean logToLogcat, String tag, int id) { + this.mEnabled = enabled; + this.mLogToProto = logToProto; + this.mLogToLogcat = logToLogcat; + this.mTag = tag; + this.mId = id; + } + + @Override + public String name() { + return mTag; + } + + @Override + public boolean isEnabled() { + return mEnabled; + } + + @Override + public boolean isLogToProto() { + return mLogToProto; + } + + @Override + public boolean isLogToLogcat() { + return mLogToLogcat; + } + + @Override + public boolean isLogToAny() { + return mLogToLogcat || mLogToProto; + } + + @Override + public String getTag() { + return mTag; + } + + @Override + public void setLogToProto(boolean logToProto) { + this.mLogToProto = logToProto; + } + + @Override + public void setLogToLogcat(boolean logToLogcat) { + this.mLogToLogcat = logToLogcat; + } + + @Override + public int getId() { + return mId; + } + } +} diff --git a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java index ab406ef4632e..5b178250a4c9 100644 --- a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java +++ b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java @@ -1867,7 +1867,7 @@ public class PackageWatchdogTest { return true; } - public String getName() { + public String getUniqueIdentifier() { return mName; } diff --git a/tests/UiBench/src/com/android/test/uibench/ResizeHWLayerActivity.java b/tests/UiBench/src/com/android/test/uibench/ResizeHWLayerActivity.java index 80d495df142c..cb26edcf336c 100644 --- a/tests/UiBench/src/com/android/test/uibench/ResizeHWLayerActivity.java +++ b/tests/UiBench/src/com/android/test/uibench/ResizeHWLayerActivity.java @@ -30,6 +30,8 @@ import android.widget.FrameLayout; */ public class ResizeHWLayerActivity extends AppCompatActivity { + private ValueAnimator mAnimator; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -43,10 +45,10 @@ public class ResizeHWLayerActivity extends AppCompatActivity { PropertyValuesHolder pvhWidth = PropertyValuesHolder.ofInt("width", width, 1); PropertyValuesHolder pvhHeight = PropertyValuesHolder.ofInt("height", height, 1); final LayoutParams params = child.getLayoutParams(); - ValueAnimator animator = ValueAnimator.ofPropertyValuesHolder(pvhWidth, pvhHeight); - animator.setRepeatMode(ValueAnimator.REVERSE); - animator.setRepeatCount(ValueAnimator.INFINITE); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + mAnimator = ValueAnimator.ofPropertyValuesHolder(pvhWidth, pvhHeight); + mAnimator.setRepeatMode(ValueAnimator.REVERSE); + mAnimator.setRepeatCount(ValueAnimator.INFINITE); + mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { params.width = (Integer)valueAnimator.getAnimatedValue("width"); @@ -54,7 +56,15 @@ public class ResizeHWLayerActivity extends AppCompatActivity { child.requestLayout(); } }); - animator.start(); + mAnimator.start(); setContentView(child); } + + @Override + protected void onPause() { + super.onPause(); + if (mAnimator != null) { + mAnimator.cancel(); + } + } } |