[dev_opt_2.15.0] patch升级代码提交
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
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<MainLauncherActivity>
|
||||
|
||||
@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.apk")) { 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user