From 90edff826aa7ea6f08421c429aa4a160defcd75e Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 9 May 2023 16:15:29 +0900 Subject: [PATCH] Disable Play auto-update during tests For devices using Play services, disable auto-update during tests, as it may interfere with them. For example, Webview may be killed if it is opened while the update is applied. Bug: 263665773 Test: atest Change-Id: I9613d739ad0763c882a1971879aa743f4541a75c --- .../ConnectivityTestTargetPreparer.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt b/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt index fd837aa1a0..3fc74aa1a4 100644 --- a/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt +++ b/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt @@ -48,6 +48,11 @@ open class ConnectivityTestTargetPreparer : BaseTargetPreparer() { override fun setUp(testInformation: TestInformation) { if (isDisabled) return + disableGmsUpdate(testInformation) + runPreparerApk(testInformation) + } + + private fun runPreparerApk(testInformation: TestInformation) { installer.setCleanApk(true) installer.addTestFileName(CONNECTIVITY_CHECKER_APK) installer.setShouldGrantPermission(true) @@ -90,8 +95,22 @@ open class ConnectivityTestTargetPreparer : BaseTargetPreparer() { testInformation.device.deviceDescriptor) } - override fun tearDown(testInformation: TestInformation?, e: Throwable?) { + private fun disableGmsUpdate(testInformation: TestInformation) { + // This will be a no-op on devices without root (su) or not using gservices, but that's OK. + testInformation.device.executeShellCommand("su 0 am broadcast " + + "-a com.google.gservices.intent.action.GSERVICES_OVERRIDE " + + "-e finsky.play_services_auto_update_enabled false") + } + + private fun clearGmsUpdateOverride(testInformation: TestInformation) { + testInformation.device.executeShellCommand("su 0 am broadcast " + + "-a com.google.gservices.intent.action.GSERVICES_OVERRIDE " + + "--esn finsky.play_services_auto_update_enabled") + } + + override fun tearDown(testInformation: TestInformation, e: Throwable?) { if (isTearDownDisabled) return installer.tearDown(testInformation, e) + clearGmsUpdateOverride(testInformation) } }