Loading libs/WindowManager/Shell/tests/e2e/desktopmode/scenarios/src/com/android/wm/shell/scenarios/StartAppMediaProjectionResizeAndDrag.kt 0 → 100644 +85 −0 Original line number Diff line number Diff line /* * 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.wm.shell.scenarios import android.app.Instrumentation import android.platform.test.annotations.Postsubmit import android.tools.NavBar import android.tools.Rotation import android.tools.device.apphelpers.CalculatorAppHelper import android.tools.traces.parsers.WindowManagerStateHelper import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.server.wm.flicker.helpers.DesktopModeAppHelper import com.android.server.wm.flicker.helpers.DesktopModeAppHelper.Corners.LEFT_TOP import com.android.server.wm.flicker.helpers.StartMediaProjectionAppHelper import com.android.window.flags.Flags import com.android.wm.shell.Utils import org.junit.After import org.junit.Assume import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.BlockJUnit4ClassRunner @RunWith(BlockJUnit4ClassRunner::class) @Postsubmit open class StartAppMediaProjectionResizeAndDrag { private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() private val tapl = LauncherInstrumentation() private val wmHelper = WindowManagerStateHelper(instrumentation) private val device = UiDevice.getInstance(instrumentation) private val targetApp = CalculatorAppHelper(instrumentation) private val mediaProjectionAppHelper = StartMediaProjectionAppHelper(instrumentation) private val testApp = DesktopModeAppHelper(mediaProjectionAppHelper) @Rule @JvmField val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0) @Before fun setup() { Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet) tapl.setEnableRotation(true) tapl.setExpectedRotation(0) testApp.enterDesktopWithDrag(wmHelper, device) } @Test open fun startMediaProjectionAndResize() { mediaProjectionAppHelper.startSingleAppMediaProjection(wmHelper, targetApp) with(DesktopModeAppHelper(targetApp)) { val windowRect = wmHelper.getWindowRegion(this).bounds // Set start x-coordinate as center of app header. val startX = windowRect.centerX() val startY = windowRect.top dragWindow(startX, startY, endX = startX + 150, endY = startY + 150, wmHelper, device) cornerResize(wmHelper, device, LEFT_TOP, -200, -200) } } @After fun teardown() { testApp.exit(wmHelper) targetApp.exit(wmHelper) } } libs/WindowManager/Shell/tests/e2e/desktopmode/scenarios/src/com/android/wm/shell/scenarios/StartAppMediaProjectionWithMaxDesktopWindows.kt 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * 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.wm.shell.scenarios import android.app.Instrumentation import android.platform.test.annotations.Postsubmit import android.tools.NavBar import android.tools.Rotation import android.tools.device.apphelpers.CalculatorAppHelper import android.tools.traces.parsers.WindowManagerStateHelper import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.server.wm.flicker.helpers.DesktopModeAppHelper import com.android.server.wm.flicker.helpers.ImeAppHelper import com.android.server.wm.flicker.helpers.MailAppHelper import com.android.server.wm.flicker.helpers.NewTasksAppHelper import com.android.server.wm.flicker.helpers.SimpleAppHelper import com.android.server.wm.flicker.helpers.StartMediaProjectionAppHelper import com.android.window.flags.Flags import com.android.wm.shell.Utils import org.junit.After import org.junit.Assume import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.BlockJUnit4ClassRunner @RunWith(BlockJUnit4ClassRunner::class) @Postsubmit open class StartAppMediaProjectionWithMaxDesktopWindows { val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() val tapl = LauncherInstrumentation() val wmHelper = WindowManagerStateHelper(instrumentation) val device = UiDevice.getInstance(instrumentation) private val targetApp = CalculatorAppHelper(instrumentation) private val mailApp = MailAppHelper(instrumentation) private val newTasksApp = DesktopModeAppHelper(NewTasksAppHelper(instrumentation)) private val imeApp = DesktopModeAppHelper(ImeAppHelper(instrumentation)) private val simpleApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation)) private val mediaProjectionAppHelper = StartMediaProjectionAppHelper(instrumentation) private val testApp = DesktopModeAppHelper(mediaProjectionAppHelper) @Rule @JvmField val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0) @Before fun setup() { Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet) tapl.setEnableRotation(true) tapl.setExpectedRotation(0) testApp.enterDesktopWithDrag(wmHelper, device) } @Test open fun startMediaProjection() { // TODO(b/366455106) - handle max task Limit mediaProjectionAppHelper.startSingleAppMediaProjection(wmHelper, targetApp) mailApp.launchViaIntent(wmHelper) simpleApp.launchViaIntent(wmHelper) newTasksApp.launchViaIntent(wmHelper) imeApp.launchViaIntent(wmHelper) } @After fun teardown() { mailApp.exit(wmHelper) simpleApp.exit(wmHelper) newTasksApp.exit(wmHelper) imeApp.exit(wmHelper) targetApp.exit(wmHelper) testApp.exit(wmHelper) } } libs/WindowManager/Shell/tests/e2e/desktopmode/scenarios/src/com/android/wm/shell/scenarios/StartScreenMediaProjectionWithMaxDesktopWindows.kt 0 → 100644 +85 −0 Original line number Diff line number Diff line /* * 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.wm.shell.scenarios import android.app.Instrumentation import android.platform.test.annotations.Postsubmit import android.tools.NavBar import android.tools.Rotation import android.tools.traces.parsers.WindowManagerStateHelper import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.server.wm.flicker.helpers.DesktopModeAppHelper import com.android.server.wm.flicker.helpers.ImeAppHelper import com.android.server.wm.flicker.helpers.MailAppHelper import com.android.server.wm.flicker.helpers.NewTasksAppHelper import com.android.server.wm.flicker.helpers.SimpleAppHelper import com.android.server.wm.flicker.helpers.StartMediaProjectionAppHelper import com.android.window.flags.Flags import com.android.wm.shell.Utils import org.junit.After import org.junit.Assume import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.BlockJUnit4ClassRunner @RunWith(BlockJUnit4ClassRunner::class) @Postsubmit open class StartScreenMediaProjectionWithMaxDesktopWindows { private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() private val tapl = LauncherInstrumentation() private val wmHelper = WindowManagerStateHelper(instrumentation) private val device = UiDevice.getInstance(instrumentation) @Rule @JvmField val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0) private val mailApp = DesktopModeAppHelper(MailAppHelper(instrumentation)) private val newTasksApp = DesktopModeAppHelper(NewTasksAppHelper(instrumentation)) private val imeApp = DesktopModeAppHelper(ImeAppHelper(instrumentation)) private val simpleApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation)) private val mediaProjectionAppHelper = StartMediaProjectionAppHelper(instrumentation) private val testApp = DesktopModeAppHelper(mediaProjectionAppHelper) @Before fun setup() { Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet) testApp.enterDesktopWithDrag(wmHelper, device) } @Test open fun startMediaProjection() { mediaProjectionAppHelper.startEntireScreenMediaProjection(wmHelper) simpleApp.launchViaIntent(wmHelper) mailApp.launchViaIntent(wmHelper) newTasksApp.launchViaIntent(wmHelper) imeApp.launchViaIntent(wmHelper) } @After fun teardown() { testApp.exit(wmHelper) simpleApp.exit(wmHelper) mailApp.exit(wmHelper) newTasksApp.exit(wmHelper) imeApp.exit(wmHelper) } } libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/MediaProjectionService.kt 0 → 100644 +110 −0 Original line number Diff line number Diff line /* * 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.wm.shell.flicker.utils import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.Service import android.content.Intent import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.drawable.Icon import android.os.IBinder import android.os.Message import android.os.Messenger import android.os.RemoteException import android.util.Log class MediaProjectionService : Service() { private var mTestBitmap: Bitmap? = null private val notificationId: Int = 1 private val notificationChannelId: String = "MediaProjectionFlickerTest" private val notificationChannelName = "FlickerMediaProjectionService" var mMessenger: Messenger? = null override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { mMessenger = intent.extras?.getParcelable( MediaProjectionUtils.EXTRA_MESSENGER, Messenger::class.java) startForeground() return super.onStartCommand(intent, flags, startId) } override fun onBind(intent: Intent?): IBinder? = null override fun onDestroy() { mTestBitmap?.recycle() mTestBitmap = null sendMessage(MediaProjectionUtils.MSG_SERVICE_DESTROYED) super.onDestroy() } private fun createNotificationIcon(): Icon { Log.d(TAG, "createNotification") mTestBitmap = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888) val canvas = Canvas(mTestBitmap!!) canvas.drawColor(Color.BLUE) return Icon.createWithBitmap(mTestBitmap) } private fun startForeground() { Log.d(TAG, "startForeground") val channel = NotificationChannel( notificationChannelId, notificationChannelName, NotificationManager.IMPORTANCE_NONE ) channel.lockscreenVisibility = Notification.VISIBILITY_PRIVATE val notificationManager: NotificationManager = getSystemService(NotificationManager::class.java) notificationManager.createNotificationChannel(channel) val notificationBuilder: Notification.Builder = Notification.Builder(this, notificationChannelId) val notification = notificationBuilder.setOngoing(true) .setContentTitle("App is running") .setSmallIcon(createNotificationIcon()) .setCategory(Notification.CATEGORY_SERVICE) .setContentText("Context") .build() startForeground(notificationId, notification) sendMessage(MediaProjectionUtils.MSG_START_FOREGROUND_DONE) } fun sendMessage(what: Int) { Log.d(TAG, "sendMessage") with(Message.obtain()) { this.what = what try { mMessenger!!.send(this) } catch (e: RemoteException) { Log.d(TAG, "Unable to send message", e) } } } companion object { private const val TAG: String = "FlickerMediaProjectionService" } } No newline at end of file libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/MediaProjectionUtils.kt 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * 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.wm.shell.flicker.utils object MediaProjectionUtils { const val REQUEST_CODE: Int = 99 const val MSG_START_FOREGROUND_DONE: Int = 1 const val MSG_SERVICE_DESTROYED: Int = 2 const val EXTRA_MESSENGER: String = "messenger" } No newline at end of file Loading
libs/WindowManager/Shell/tests/e2e/desktopmode/scenarios/src/com/android/wm/shell/scenarios/StartAppMediaProjectionResizeAndDrag.kt 0 → 100644 +85 −0 Original line number Diff line number Diff line /* * 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.wm.shell.scenarios import android.app.Instrumentation import android.platform.test.annotations.Postsubmit import android.tools.NavBar import android.tools.Rotation import android.tools.device.apphelpers.CalculatorAppHelper import android.tools.traces.parsers.WindowManagerStateHelper import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.server.wm.flicker.helpers.DesktopModeAppHelper import com.android.server.wm.flicker.helpers.DesktopModeAppHelper.Corners.LEFT_TOP import com.android.server.wm.flicker.helpers.StartMediaProjectionAppHelper import com.android.window.flags.Flags import com.android.wm.shell.Utils import org.junit.After import org.junit.Assume import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.BlockJUnit4ClassRunner @RunWith(BlockJUnit4ClassRunner::class) @Postsubmit open class StartAppMediaProjectionResizeAndDrag { private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() private val tapl = LauncherInstrumentation() private val wmHelper = WindowManagerStateHelper(instrumentation) private val device = UiDevice.getInstance(instrumentation) private val targetApp = CalculatorAppHelper(instrumentation) private val mediaProjectionAppHelper = StartMediaProjectionAppHelper(instrumentation) private val testApp = DesktopModeAppHelper(mediaProjectionAppHelper) @Rule @JvmField val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0) @Before fun setup() { Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet) tapl.setEnableRotation(true) tapl.setExpectedRotation(0) testApp.enterDesktopWithDrag(wmHelper, device) } @Test open fun startMediaProjectionAndResize() { mediaProjectionAppHelper.startSingleAppMediaProjection(wmHelper, targetApp) with(DesktopModeAppHelper(targetApp)) { val windowRect = wmHelper.getWindowRegion(this).bounds // Set start x-coordinate as center of app header. val startX = windowRect.centerX() val startY = windowRect.top dragWindow(startX, startY, endX = startX + 150, endY = startY + 150, wmHelper, device) cornerResize(wmHelper, device, LEFT_TOP, -200, -200) } } @After fun teardown() { testApp.exit(wmHelper) targetApp.exit(wmHelper) } }
libs/WindowManager/Shell/tests/e2e/desktopmode/scenarios/src/com/android/wm/shell/scenarios/StartAppMediaProjectionWithMaxDesktopWindows.kt 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * 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.wm.shell.scenarios import android.app.Instrumentation import android.platform.test.annotations.Postsubmit import android.tools.NavBar import android.tools.Rotation import android.tools.device.apphelpers.CalculatorAppHelper import android.tools.traces.parsers.WindowManagerStateHelper import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.server.wm.flicker.helpers.DesktopModeAppHelper import com.android.server.wm.flicker.helpers.ImeAppHelper import com.android.server.wm.flicker.helpers.MailAppHelper import com.android.server.wm.flicker.helpers.NewTasksAppHelper import com.android.server.wm.flicker.helpers.SimpleAppHelper import com.android.server.wm.flicker.helpers.StartMediaProjectionAppHelper import com.android.window.flags.Flags import com.android.wm.shell.Utils import org.junit.After import org.junit.Assume import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.BlockJUnit4ClassRunner @RunWith(BlockJUnit4ClassRunner::class) @Postsubmit open class StartAppMediaProjectionWithMaxDesktopWindows { val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() val tapl = LauncherInstrumentation() val wmHelper = WindowManagerStateHelper(instrumentation) val device = UiDevice.getInstance(instrumentation) private val targetApp = CalculatorAppHelper(instrumentation) private val mailApp = MailAppHelper(instrumentation) private val newTasksApp = DesktopModeAppHelper(NewTasksAppHelper(instrumentation)) private val imeApp = DesktopModeAppHelper(ImeAppHelper(instrumentation)) private val simpleApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation)) private val mediaProjectionAppHelper = StartMediaProjectionAppHelper(instrumentation) private val testApp = DesktopModeAppHelper(mediaProjectionAppHelper) @Rule @JvmField val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0) @Before fun setup() { Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet) tapl.setEnableRotation(true) tapl.setExpectedRotation(0) testApp.enterDesktopWithDrag(wmHelper, device) } @Test open fun startMediaProjection() { // TODO(b/366455106) - handle max task Limit mediaProjectionAppHelper.startSingleAppMediaProjection(wmHelper, targetApp) mailApp.launchViaIntent(wmHelper) simpleApp.launchViaIntent(wmHelper) newTasksApp.launchViaIntent(wmHelper) imeApp.launchViaIntent(wmHelper) } @After fun teardown() { mailApp.exit(wmHelper) simpleApp.exit(wmHelper) newTasksApp.exit(wmHelper) imeApp.exit(wmHelper) targetApp.exit(wmHelper) testApp.exit(wmHelper) } }
libs/WindowManager/Shell/tests/e2e/desktopmode/scenarios/src/com/android/wm/shell/scenarios/StartScreenMediaProjectionWithMaxDesktopWindows.kt 0 → 100644 +85 −0 Original line number Diff line number Diff line /* * 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.wm.shell.scenarios import android.app.Instrumentation import android.platform.test.annotations.Postsubmit import android.tools.NavBar import android.tools.Rotation import android.tools.traces.parsers.WindowManagerStateHelper import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.server.wm.flicker.helpers.DesktopModeAppHelper import com.android.server.wm.flicker.helpers.ImeAppHelper import com.android.server.wm.flicker.helpers.MailAppHelper import com.android.server.wm.flicker.helpers.NewTasksAppHelper import com.android.server.wm.flicker.helpers.SimpleAppHelper import com.android.server.wm.flicker.helpers.StartMediaProjectionAppHelper import com.android.window.flags.Flags import com.android.wm.shell.Utils import org.junit.After import org.junit.Assume import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.BlockJUnit4ClassRunner @RunWith(BlockJUnit4ClassRunner::class) @Postsubmit open class StartScreenMediaProjectionWithMaxDesktopWindows { private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() private val tapl = LauncherInstrumentation() private val wmHelper = WindowManagerStateHelper(instrumentation) private val device = UiDevice.getInstance(instrumentation) @Rule @JvmField val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0) private val mailApp = DesktopModeAppHelper(MailAppHelper(instrumentation)) private val newTasksApp = DesktopModeAppHelper(NewTasksAppHelper(instrumentation)) private val imeApp = DesktopModeAppHelper(ImeAppHelper(instrumentation)) private val simpleApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation)) private val mediaProjectionAppHelper = StartMediaProjectionAppHelper(instrumentation) private val testApp = DesktopModeAppHelper(mediaProjectionAppHelper) @Before fun setup() { Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet) testApp.enterDesktopWithDrag(wmHelper, device) } @Test open fun startMediaProjection() { mediaProjectionAppHelper.startEntireScreenMediaProjection(wmHelper) simpleApp.launchViaIntent(wmHelper) mailApp.launchViaIntent(wmHelper) newTasksApp.launchViaIntent(wmHelper) imeApp.launchViaIntent(wmHelper) } @After fun teardown() { testApp.exit(wmHelper) simpleApp.exit(wmHelper) mailApp.exit(wmHelper) newTasksApp.exit(wmHelper) imeApp.exit(wmHelper) } }
libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/MediaProjectionService.kt 0 → 100644 +110 −0 Original line number Diff line number Diff line /* * 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.wm.shell.flicker.utils import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.Service import android.content.Intent import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.drawable.Icon import android.os.IBinder import android.os.Message import android.os.Messenger import android.os.RemoteException import android.util.Log class MediaProjectionService : Service() { private var mTestBitmap: Bitmap? = null private val notificationId: Int = 1 private val notificationChannelId: String = "MediaProjectionFlickerTest" private val notificationChannelName = "FlickerMediaProjectionService" var mMessenger: Messenger? = null override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { mMessenger = intent.extras?.getParcelable( MediaProjectionUtils.EXTRA_MESSENGER, Messenger::class.java) startForeground() return super.onStartCommand(intent, flags, startId) } override fun onBind(intent: Intent?): IBinder? = null override fun onDestroy() { mTestBitmap?.recycle() mTestBitmap = null sendMessage(MediaProjectionUtils.MSG_SERVICE_DESTROYED) super.onDestroy() } private fun createNotificationIcon(): Icon { Log.d(TAG, "createNotification") mTestBitmap = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888) val canvas = Canvas(mTestBitmap!!) canvas.drawColor(Color.BLUE) return Icon.createWithBitmap(mTestBitmap) } private fun startForeground() { Log.d(TAG, "startForeground") val channel = NotificationChannel( notificationChannelId, notificationChannelName, NotificationManager.IMPORTANCE_NONE ) channel.lockscreenVisibility = Notification.VISIBILITY_PRIVATE val notificationManager: NotificationManager = getSystemService(NotificationManager::class.java) notificationManager.createNotificationChannel(channel) val notificationBuilder: Notification.Builder = Notification.Builder(this, notificationChannelId) val notification = notificationBuilder.setOngoing(true) .setContentTitle("App is running") .setSmallIcon(createNotificationIcon()) .setCategory(Notification.CATEGORY_SERVICE) .setContentText("Context") .build() startForeground(notificationId, notification) sendMessage(MediaProjectionUtils.MSG_START_FOREGROUND_DONE) } fun sendMessage(what: Int) { Log.d(TAG, "sendMessage") with(Message.obtain()) { this.what = what try { mMessenger!!.send(this) } catch (e: RemoteException) { Log.d(TAG, "Unable to send message", e) } } } companion object { private const val TAG: String = "FlickerMediaProjectionService" } } No newline at end of file
libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/MediaProjectionUtils.kt 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * 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.wm.shell.flicker.utils object MediaProjectionUtils { const val REQUEST_CODE: Int = 99 const val MSG_START_FOREGROUND_DONE: Int = 1 const val MSG_SERVICE_DESTROYED: Int = 2 const val EXTRA_MESSENGER: String = "messenger" } No newline at end of file