[6.3.0][APK安装] 优化APK安装逻辑,适配部分机型由于安装请求被用户拒绝导致鹰眼界面不可点击

This commit is contained in:
renwj
2024-02-22 11:05:03 +08:00
parent 12c548d393
commit d57d07201d
2 changed files with 62 additions and 88 deletions

View File

@@ -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<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.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)
// }
// }
//}
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<MainLauncherActivity>
@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分钟结束....")
}
}

View File

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