Files
MoGoEagleEye/app/src/androidTest/java/com/mogo/functions/test/PatchUtilsTest.kt
2023-05-08 15:10:46 +08:00

89 lines
3.2 KiB
Kotlin

//package com.mogo.functions.test
//
//import androidx.test.core.app.*
//import androidx.test.ext.junit.runners.*
//import androidx.test.filters.*
//import com.mogo.eagle.core.function.hmi.ui.*
//import com.mogo.eagle.core.function.main.*
//import com.mogo.launcher.patch.*
//import com.mogo.launcher.patch.utils.*
//import kotlinx.coroutines.*
//import org.junit.*
//import org.junit.runner.*
//import java.io.*
//import java.util.concurrent.*
//import java.util.concurrent.TimeUnit.MILLISECONDS
//import kotlin.Result
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class PatchUtilsTest {
//
//
// lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun before() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
// }
//
//
// @Test
// fun testGeneratePatchAndMergeThenInstall() = runBlocking {
// val f = ensureMoGoHmiFragmentShow()
// withContext(Dispatchers.Default) {
//
//
// val context = f.context ?: return@withContext
// val oldApkPath = context.let {
// it.packageManager.getPackageInfo(it.packageName, 0)?.applicationInfo?.sourceDir
// } ?: return@withContext
//
// val oldApk = File(oldApkPath)
// if (!oldApk.exists()) {
// throw AssertionError("old apk file is not exist.")
// }
// val oldApkTemp = File(context.getExternalFilesDir(null), "patches/old.apk")
// if (oldApkTemp.exists()) {
// oldApkTemp.delete()
// }
// oldApkTemp.parentFile?.takeIf { !it.exists() }?.also { it.mkdirs() }
//
// oldApk.copyTo(oldApkTemp)
// val patch = File(context.getExternalFilesDir(null), "patches/patch.zip")
// if (!patch.exists()) {
// throw AssertionError("patch file is not exist.")
// }
// val newApk = File(context.getExternalFilesDir(null), "patches/new.apk")
//// PatchUtils.applyPatch(context, File(oldApkPath), patch, newApk)
//// PatchUtils.install(context, newApk)
// }
// delay(TimeUnit.MINUTES.toMillis(1))
// }
//
//
// 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)
// }
// }
//
//}