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 --")