From d57d07201d56f4bc20cf68448dc728b367520e49 Mon Sep 17 00:00:00 2001 From: renwj Date: Thu, 22 Feb 2024 11:05:03 +0800 Subject: [PATCH] =?UTF-8?q?[6.3.0][APK=E5=AE=89=E8=A3=85]=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96APK=E5=AE=89=E8=A3=85=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E9=80=82=E9=85=8D=E9=83=A8=E5=88=86=E6=9C=BA=E5=9E=8B=E7=94=B1?= =?UTF-8?q?=E4=BA=8E=E5=AE=89=E8=A3=85=E8=AF=B7=E6=B1=82=E8=A2=AB=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8B=92=E7=BB=9D=E5=AF=BC=E8=87=B4=E9=B9=B0=E7=9C=BC?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=B8=8D=E5=8F=AF=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mogo/functions/test/ApkInstallerTest.kt | 149 +++++++----------- .../eagle/core/utilcode/util/ApkInstaller.kt | 1 + 2 files changed, 62 insertions(+), 88 deletions(-) diff --git a/app/src/androidTest/java/com/mogo/functions/test/ApkInstallerTest.kt b/app/src/androidTest/java/com/mogo/functions/test/ApkInstallerTest.kt index 36a17ae3d6..242ded546d 100644 --- a/app/src/androidTest/java/com/mogo/functions/test/ApkInstallerTest.kt +++ b/app/src/androidTest/java/com/mogo/functions/test/ApkInstallerTest.kt @@ -1,88 +1,61 @@ -//package com.mogo.functions.test -// -//import android.util.* -//import androidx.test.core.app.* -//import androidx.test.ext.junit.runners.* -//import androidx.test.filters.* -//import androidx.test.platform.app.InstrumentationRegistry -//import com.mogo.eagle.core.function.hmi.ui.* -//import com.mogo.eagle.core.function.main.* -//import com.mogo.eagle.core.utilcode.util.* -//import kotlinx.coroutines.* -//import org.junit.* -//import org.junit.runner.* -//import java.util.concurrent.* -//import java.util.concurrent.TimeUnit.MILLISECONDS -//import kotlin.Result -// -//@RunWith(AndroidJUnit4::class) -//@LargeTest -//class ApkInstallerTest { -// -// -// lateinit var launch: ActivityScenario -// -// @Before -// fun before() { -// launch = ActivityScenario.launch(MainLauncherActivity::class.java) -// } -// -// @Test -// fun testInstall(): Unit = runBlocking { -// Log.d("RWJ", "wait fragment show ...") -// val f = ensureMoGoHmiFragmentShow() -// Log.d("RWJ", "fragment showed, delay 10s ...") -// delay(10000) -// -// Log.d("RWJ", "10s end, start install ...") -// val context = InstrumentationRegistry.getInstrumentation().context -// ApkInstaller.installApp(f.requireContext(), context.assets.open("190000013.apk")) { code, msg -> -// Log.d("RWJ", "code: $code, msg: $msg") -// } -// Log.d("RWJ", "开始延时10分钟....") -// delay(TimeUnit.MINUTES.toMillis(10)) -// Log.d("RWJ", "延时10分钟结束....") -// } -// -// -// @Test -// fun testInstall2(): Unit = runBlocking { -// Log.d("RWJ", "wait fragment show ...") -// val f = ensureMoGoHmiFragmentShow() -// Log.d("RWJ", "fragment showed, delay 10s ...") -// delay(10000) -// -// Log.d("RWJ", "10s end, start install ...") -// val context = InstrumentationRegistry.getInstrumentation().context -// ApkInstaller.installApp(f.requireContext(), context.assets.open("HelloActivity.zip")) { code, msg -> -// Log.d("RWJ", "code: $code, msg: $msg") -// } -// Log.d("RWJ", "开始延时10分钟....") -// delay(TimeUnit.MINUTES.toMillis(10)) -// Log.d("RWJ", "延时10分钟结束....") -// } -// -// private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiFragment = suspendCancellableCoroutine { -// launch.onActivity { itx -> -// val executor = Executors.newSingleThreadScheduledExecutor() -// executor.scheduleAtFixedRate({ -// var find = -// itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment -// while (find == null) { -// find = -// itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment -// } -// while (!find.isResumed) { -// Thread.sleep(500) -// } -// it.resumeWith(Result.success(find)) -// try { -// Thread.sleep(500) -// executor.shutdownNow() -// } catch (e: Throwable) { -// e.printStackTrace() -// } -// }, 50, 500, MILLISECONDS) -// } -// } -//} \ No newline at end of file +package com.mogo.functions.test + +import android.util.* +import androidx.test.core.app.* +import androidx.test.ext.junit.runners.* +import androidx.test.filters.* +import androidx.test.platform.app.InstrumentationRegistry +import com.mogo.eagle.core.function.hmi.ui.* +import com.mogo.eagle.core.function.main.* +import com.mogo.eagle.core.utilcode.util.* +import kotlinx.coroutines.* +import org.junit.* +import org.junit.runner.* +import java.io.File +import java.util.concurrent.* + +@RunWith(AndroidJUnit4::class) +@LargeTest +class ApkInstallerTest { + + + lateinit var launch: ActivityScenario + + @Before + fun before() { + launch = ActivityScenario.launch(MainLauncherActivity::class.java) + } + + @Test + fun testInstall(): Unit = runBlocking { + Log.d("RWJ", "wait fragment show ...") + Log.d("RWJ", "fragment showed, delay 10s ...") + delay(10000) + + Log.d("RWJ", "10s end, start install ...") + val context = InstrumentationRegistry.getInstrumentation().context + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext + val outFile = File(targetContext.getExternalFilesDir(null), "temp.apk") + val os = outFile.outputStream() + try { + Log.d("RWJ", "将assets目录下的apk文件,copy到应用私有目录...") + context.assets.open("HelloActivity.zip").use { + it.copyTo(os) + } + Log.d("RWJ", "copy操作完成") + } finally { + try { + os.close() + } catch (t: Throwable) { + t.printStackTrace() + } + } + Log.d("RWJ", "开始安装...") + ApkInstaller.installApp(targetContext, outFile) { code, msg -> + Log.d("RWJ", "code: $code, msg: $msg") + } + Log.d("RWJ", "开始延时10分钟....") + delay(TimeUnit.MINUTES.toMillis(10)) + Log.d("RWJ", "延时10分钟结束....") + } +} \ No newline at end of file diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ApkInstaller.kt b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ApkInstaller.kt index 328d90cb29..9f62ba5619 100644 --- a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ApkInstaller.kt +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ApkInstaller.kt @@ -162,6 +162,7 @@ class InstallApkSessionApi: AppCompatActivity() { // This test app isn't privileged, so the user has to confirm the install. val confirmIntent = extras[Intent.EXTRA_INTENT] as? Intent startActivity(confirmIntent) + finish() } STATUS_SUCCESS -> { Log.i(TAG, "--- InstallApkSessionApi -- install success --")