[MAP] 高精地图Marker绘制逻辑重构

This commit is contained in:
renwj
2023-05-08 14:46:29 +08:00
parent eecea49493
commit 22cf999031
97 changed files with 3615 additions and 6757 deletions

View File

@@ -1,88 +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.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.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)
// }
// }
//}

View File

@@ -1,148 +1,148 @@
package com.mogo.functions.test
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
import com.mogo.eagle.core.function.hmi.ui.MoGoHmiProvider
import com.mogo.eagle.core.function.main.MainLauncherActivity
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import record_cache.RecordPanelOuterClass
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.random.Random
@RunWith(AndroidJUnit4::class)
@LargeTest
class AutoPilotBadCaseTest {
private lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun launch() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@ExperimentalCoroutinesApi
@Test
fun showBadCaseEntrance1(): Unit = runBlocking(Dispatchers.Main) {
ensureMoGoHmiFragmentShow()
delay(TimeUnit.MILLISECONDS.toSeconds(30))
var index = 0
(1 until 50)
.map { it }
.asFlow()
.onEach {
delay(TimeUnit.SECONDS.toMillis(5))
val builder = RecordPanelOuterClass.RecordPanel.newBuilder()
builder.also {
it.diskFree = (100 + index).toLong()
it.duration = 60.0.toFloat()
it.filename = "/user/general/record_$index.log"
it.id = 10 + index
it.key = index.toLong()
it.stat = 100
it.type = 1
it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
index++
}
// CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
}
.flowOn(Dispatchers.Default)
.collect()
delay(TimeUnit.HOURS.toMillis(2))
}
@ExperimentalCoroutinesApi
@Test
fun showBadCaseEntrance2(): Unit = runBlocking(Dispatchers.Main) {
ensureMoGoHmiFragmentShow()
var index = 0
(1 until 50)
.map { it }
.asFlow()
.onEach {
if (index in 1..4) {
delay(TimeUnit.SECONDS.toMillis(15))
} else {
delay(Random(20).nextLong())
}
val builder = RecordPanelOuterClass.RecordPanel.newBuilder()
builder.also {
it.diskFree = (100 + index).toLong()
it.duration = 60.0.toFloat()
it.filename = "/user/general/record_$index.log"
it.id = 10 + index
it.key = index.toLong()
it.stat = 100
it.type = 1
it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
index++
}
// CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
}
.flowOn(Dispatchers.Default)
.collect()
delay(TimeUnit.HOURS.toMillis(2))
}
@ExperimentalCoroutinesApi
@Test
fun showBadCaseEntrance3(): Unit = runBlocking(Dispatchers.Main) {
var index = 0
(1 until 50)
.map { it }
.asFlow()
.onEach {
delay(TimeUnit.SECONDS.toMillis(20))
val builder = RecordPanelOuterClass.RecordPanel.newBuilder()
builder.also {
it.diskFree = (100 + index).toLong()
it.duration = 60.0.toFloat()
it.filename = "/user/general/record_$index.log"
it.id = 10 + index
it.key = index.toLong()
it.stat = 100
it.type = 1
it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
index++
}
// CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
}
.flowOn(Dispatchers.Default)
.collect()
delay(TimeUnit.HOURS.toMillis(2))
}
private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
launch.onActivity { itx ->
val executor = Executors.newSingleThreadScheduledExecutor()
executor.scheduleAtFixedRate({
var find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
while (find == null) {
find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
}
while (!find.isResumed) {
Thread.sleep(500)
}
it.resumeWith(Result.success(find))
try {
Thread.sleep(500)
executor.shutdownNow()
} catch (e: Throwable) {
e.printStackTrace()
}
}, 50, 500, TimeUnit.MILLISECONDS)
}
}
}
//package com.mogo.functions.test
//
//import androidx.test.core.app.ActivityScenario
//import androidx.test.ext.junit.runners.AndroidJUnit4
//import androidx.test.filters.LargeTest
//import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
//import com.mogo.eagle.core.function.hmi.ui.MoGoHmiProvider
//import com.mogo.eagle.core.function.main.MainLauncherActivity
//import kotlinx.coroutines.*
//import kotlinx.coroutines.flow.*
//import org.junit.Before
//import org.junit.Test
//import org.junit.runner.RunWith
//import record_cache.RecordPanelOuterClass
//import java.text.SimpleDateFormat
//import java.util.*
//import java.util.concurrent.Executors
//import java.util.concurrent.TimeUnit
//import kotlin.random.Random
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class AutoPilotBadCaseTest {
//
// private lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun launch() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
// }
//
// @ExperimentalCoroutinesApi
// @Test
// fun showBadCaseEntrance1(): Unit = runBlocking(Dispatchers.Main) {
// ensureMoGoHmiFragmentShow()
// delay(TimeUnit.MILLISECONDS.toSeconds(30))
// var index = 0
// (1 until 50)
// .map { it }
// .asFlow()
// .onEach {
// delay(TimeUnit.SECONDS.toMillis(5))
// val builder = RecordPanelOuterClass.RecordPanel.newBuilder()
// builder.also {
// it.diskFree = (100 + index).toLong()
// it.duration = 60.0.toFloat()
// it.filename = "/user/general/record_$index.log"
// it.id = 10 + index
// it.key = index.toLong()
// it.stat = 100
// it.type = 1
// it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
// index++
// }
// // CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
// }
// .flowOn(Dispatchers.Default)
// .collect()
// delay(TimeUnit.HOURS.toMillis(2))
// }
//
//
// @ExperimentalCoroutinesApi
// @Test
// fun showBadCaseEntrance2(): Unit = runBlocking(Dispatchers.Main) {
// ensureMoGoHmiFragmentShow()
// var index = 0
// (1 until 50)
// .map { it }
// .asFlow()
// .onEach {
// if (index in 1..4) {
// delay(TimeUnit.SECONDS.toMillis(15))
// } else {
// delay(Random(20).nextLong())
// }
// val builder = RecordPanelOuterClass.RecordPanel.newBuilder()
// builder.also {
// it.diskFree = (100 + index).toLong()
// it.duration = 60.0.toFloat()
// it.filename = "/user/general/record_$index.log"
// it.id = 10 + index
// it.key = index.toLong()
// it.stat = 100
// it.type = 1
// it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
// index++
// }
// // CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
// }
// .flowOn(Dispatchers.Default)
// .collect()
// delay(TimeUnit.HOURS.toMillis(2))
// }
//
// @ExperimentalCoroutinesApi
// @Test
// fun showBadCaseEntrance3(): Unit = runBlocking(Dispatchers.Main) {
// var index = 0
// (1 until 50)
// .map { it }
// .asFlow()
// .onEach {
// delay(TimeUnit.SECONDS.toMillis(20))
// val builder = RecordPanelOuterClass.RecordPanel.newBuilder()
// builder.also {
// it.diskFree = (100 + index).toLong()
// it.duration = 60.0.toFloat()
// it.filename = "/user/general/record_$index.log"
// it.id = 10 + index
// it.key = index.toLong()
// it.stat = 100
// it.type = 1
// it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
// index++
// }
// // CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
// }
// .flowOn(Dispatchers.Default)
// .collect()
// delay(TimeUnit.HOURS.toMillis(2))
// }
//
// private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
// launch.onActivity { itx ->
// val executor = Executors.newSingleThreadScheduledExecutor()
// executor.scheduleAtFixedRate({
// var find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
// while (find == null) {
// find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
//
// }
// while (!find.isResumed) {
// Thread.sleep(500)
// }
// it.resumeWith(Result.success(find))
// try {
// Thread.sleep(500)
// executor.shutdownNow()
// } catch (e: Throwable) {
// e.printStackTrace()
// }
// }, 50, 500, TimeUnit.MILLISECONDS)
// }
// }
//}

View File

@@ -1,57 +1,57 @@
package com.mogo.functions.test
import androidx.lifecycle.coroutineScope
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.function.main.MainLauncherActivity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.TimeUnit
@RunWith(AndroidJUnit4::class)
@LargeTest
class KotlinCoroutineSchedulersTest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@Test
fun testKotlinCoroutineSchedulersIo() = runBlocking {
launch.onActivity {
it.lifecycle.coroutineScope.launchWhenCreated {
repeat(10) {
withContext(Dispatchers.IO) {
assert(Thread.currentThread().name.startsWith("io-pool-"))
}
delay(TimeUnit.SECONDS.toMillis(1))
}
}
}
delay(TimeUnit.SECONDS.toMillis(20))
}
@Test
fun testKotlinCoroutineSchedulersCpu() = runBlocking {
launch.onActivity {
it.lifecycle.coroutineScope.launchWhenCreated {
repeat(10) {
withContext(Dispatchers.Default) {
assert(Thread.currentThread().name.startsWith("cpu-pool-"))
}
delay(TimeUnit.SECONDS.toMillis(1))
}
}
}
delay(TimeUnit.SECONDS.toMillis(20))
}
}
//package com.mogo.functions.test
//
//import androidx.lifecycle.coroutineScope
//import androidx.test.core.app.ActivityScenario
//import androidx.test.ext.junit.runners.AndroidJUnit4
//import androidx.test.filters.LargeTest
//import com.mogo.eagle.core.function.main.MainLauncherActivity
//import kotlinx.coroutines.Dispatchers
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.runBlocking
//import kotlinx.coroutines.withContext
//import org.junit.Before
//import org.junit.Test
//import org.junit.runner.RunWith
//import java.util.concurrent.TimeUnit
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class KotlinCoroutineSchedulersTest {
//
// lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun before() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
// }
//
// @Test
// fun testKotlinCoroutineSchedulersIo() = runBlocking {
// launch.onActivity {
// it.lifecycle.coroutineScope.launchWhenCreated {
// repeat(10) {
// withContext(Dispatchers.IO) {
// assert(Thread.currentThread().name.startsWith("io-pool-"))
// }
// delay(TimeUnit.SECONDS.toMillis(1))
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(20))
// }
//
// @Test
// fun testKotlinCoroutineSchedulersCpu() = runBlocking {
// launch.onActivity {
// it.lifecycle.coroutineScope.launchWhenCreated {
// repeat(10) {
// withContext(Dispatchers.Default) {
// assert(Thread.currentThread().name.startsWith("cpu-pool-"))
// }
// delay(TimeUnit.SECONDS.toMillis(1))
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(20))
// }
//}

View File

@@ -1,62 +1,62 @@
package com.mogo.functions.test
import androidx.annotation.VisibleForTesting
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.function.call.map.CallerMapDataCollectorManager
import com.mogo.eagle.core.function.hmi.ui.MoGoHmiProvider
import com.mogo.eagle.core.function.main.MainLauncherActivity
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeUnit.MILLISECONDS
@RunWith(AndroidJUnit4::class)
@LargeTest
class MapDataCollectTest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@Test
fun testTaskSent() = runBlocking {
ensureMoGoHmiFragmentShow()
delay(TimeUnit.SECONDS.toMillis(3))
CallerMapDataCollectorManager.setIsInit()
delay(TimeUnit.HOURS.toMillis(1))
}
private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
launch.onActivity { itx ->
val executor = Executors.newSingleThreadScheduledExecutor()
executor.scheduleAtFixedRate({
var find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
while (find == null) {
find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
}
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 androidx.annotation.VisibleForTesting
//import androidx.test.core.app.ActivityScenario
//import androidx.test.ext.junit.runners.AndroidJUnit4
//import androidx.test.filters.LargeTest
//import com.mogo.eagle.core.function.call.map.CallerMapDataCollectorManager
//import com.mogo.eagle.core.function.hmi.ui.MoGoHmiProvider
//import com.mogo.eagle.core.function.main.MainLauncherActivity
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.runBlocking
//import kotlinx.coroutines.suspendCancellableCoroutine
//import org.junit.Before
//import org.junit.Test
//import org.junit.runner.RunWith
//import java.util.concurrent.Executors
//import java.util.concurrent.TimeUnit
//import java.util.concurrent.TimeUnit.MILLISECONDS
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class MapDataCollectTest {
//
// lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun before() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
// }
//
// @Test
// fun testTaskSent() = runBlocking {
// ensureMoGoHmiFragmentShow()
// delay(TimeUnit.SECONDS.toMillis(3))
// CallerMapDataCollectorManager.setIsInit()
// delay(TimeUnit.HOURS.toMillis(1))
// }
// private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
// launch.onActivity { itx ->
// val executor = Executors.newSingleThreadScheduledExecutor()
// executor.scheduleAtFixedRate({
// var find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
// while (find == null) {
// find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
//
// }
// 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)
// }
// }
//}

View File

@@ -1,89 +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)
}
}
}
//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)
// }
// }
//
//}

View File

@@ -1,426 +1,426 @@
package com.mogo.functions.test
import android.animation.Animator
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.animation.OvershootInterpolator
import android.widget.PopupWindow
import androidx.core.view.ViewCompat
import androidx.lifecycle.lifecycleScope
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWarningStatusListener
import com.mogo.eagle.core.function.hmi.notification.WarningFloat
import com.mogo.eagle.core.function.hmi.notification.anim.DefaultAnimator
import com.mogo.eagle.core.data.enums.SidePattern
import com.mogo.eagle.core.function.hmi.ui.*
import com.mogo.eagle.core.function.main.MainLauncherActivity
import com.mogo.eagle.core.utilcode.kotlin.shape
import com.mogo.eagle.core.utilcode.reminder.Reminder
import com.mogo.eagle.core.utilcode.reminder.api.impl.ActivityReminder
import com.mogo.eagle.core.utilcode.reminder.api.impl.PopupWindowReminder
import com.mogo.eagle.core.utilcode.reminder.api.impl.ViewReminder
import com.mogo.eagle.core.utilcode.util.AppStateManager
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.Integer.min
import java.util.concurrent.*
import java.util.concurrent.TimeUnit.MILLISECONDS
@RunWith(AndroidJUnit4::class)
@LargeTest
class ReminderTest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@Test
fun testViewReminderNotOverride() = runBlocking(Dispatchers.Main) {
launch.onActivity {
it.lifecycleScope.launchWhenResumed {
for (i in 1..10) {
val reminder = WindowManagerViewUnOverrideReminder(View(it).also { itx -> itx.background = shape(solid = color(i)) }, 300, 300)
Reminder.enqueue(it, reminder)
delay(TimeUnit.SECONDS.toMillis(3))
reminder.hide()
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
return@runBlocking
}
@Test
fun testShowWarningV2x() = runBlocking {
val f = ensureMoGoHmiFragmentShow()
delay(5000)
(1 until 20).map {
it
}.asFlow()
.onEach {
f.showWarningV2X("10006", "test", "测试$it", "$it", null, true, 5000)
}
.flowOn(Dispatchers.Default)
.collect()
delay(3000000)
}
private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
launch.onActivity { itx ->
val executor = Executors.newSingleThreadScheduledExecutor()
executor.scheduleAtFixedRate({
var find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
while (find == null) {
find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
}
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)
}
}
@Test
fun testViewReminderOverride() = runBlocking(Dispatchers.Main) {
launch.onActivity {
it.lifecycleScope.launchWhenCreated {
for (i in 1..10) {
val reminder = WindowManagerViewOverrideReminder(View(it).also { itx -> itx.background = shape(solid = color(i)) }, 300, 300)
Reminder.enqueue(it, reminder)
delay(TimeUnit.SECONDS.toMillis(3))
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
return@runBlocking
}
@Test
fun testViewReminderWhenActivityDestroyed() = runBlocking(Dispatchers.Main) {
launch.onActivity {
it.lifecycleScope.launchWhenCreated {
for (i in 1..10) {
val reminder = WindowManagerViewOverrideReminder(View(it).also { itx -> itx.background = shape(solid = color(i)) }, 300, 300)
Reminder.enqueue(it, reminder)
delay(TimeUnit.SECONDS.toMillis(3))
if (i == 8) {
it.finish()
}
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
}
@Test
fun testWarningFloat() = runBlocking(Dispatchers.Main) {
launch.onActivity {
it.lifecycleScope.launchWhenCreated {
for (i in 1..10) {
val v = View(it).also {
it.background = shape(solid = color(i))
it.layoutParams = WindowManager.LayoutParams().also { itx ->
itx.width = 300
itx.height = 400
}
}
val builder = WarningFloat.with(it).setTag("test${i}").setLayout(v).setSidePattern(SidePattern.RESULT_TOP).setCountDownTime(TimeUnit.SECONDS.toMillis(10)).setGravity(Gravity.CENTER_HORIZONTAL, offsetY = 110).setImmersionStatusBar(true).addWarningStatusListener(object :
IMoGoWarningStatusListener {
override fun onShow() {
}
}).setAnimator(object : DefaultAnimator() {
override fun enterAnim(view: View, params: WindowManager.LayoutParams, windowManager: WindowManager, sidePattern: SidePattern): Animator? = super.enterAnim(view, params, windowManager, sidePattern)?.apply {
interpolator = OvershootInterpolator()
}
override fun exitAnim(view: View, params: WindowManager.LayoutParams, windowManager: WindowManager, sidePattern: SidePattern): Animator? = super.exitAnim(view, params, windowManager, sidePattern)?.setDuration(200)
})
Reminder.enqueue(it, WarningFloatReminder(builder))
delay(TimeUnit.SECONDS.toMillis(3))
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
}
@Test
fun testActivityReminder() = runBlocking(Dispatchers.Main) {
launch.onActivity {
it.lifecycleScope.launchWhenResumed {
for (i in 1..10) {
val reminder = ActivityNameReminder(it, "com.mogo.launcher.TestActivity")
Reminder.enqueue(it, reminder)
delay(TimeUnit.SECONDS.toMillis(6))
reminder.hide()
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
}
@Test
fun testActivityReminderOverride() = runBlocking(Dispatchers.Main) {
launch.onActivity {
it.lifecycleScope.launchWhenResumed {
for (i in 1..10) {
val reminder = ActivityNameOverrideReminder(it, "com.mogo.launcher.TestActivity")
Reminder.enqueue(it, reminder)
delay(TimeUnit.SECONDS.toMillis(6))
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
}
@Test
fun testPopupWindowReminder() = runBlocking {
launch.onActivity {
it.lifecycleScope.launchWhenResumed {
for (i in 1..10) {
val reminder = TestPopupWindowReminder(it.findViewById(android.R.id.content), PopupWindow(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT).also { itx ->
itx.contentView = View(it).also {
xx -> xx.background = shape(solid = color(i))
xx.layoutParams = ViewGroup.LayoutParams(300, 400)
}
})
Reminder.enqueue(it, reminder)
delay(TimeUnit.SECONDS.toMillis(3))
reminder.hide()
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
}
@Test
fun testPopupWindowReminderOverride() = runBlocking {
launch.onActivity {
it.lifecycleScope.launchWhenResumed {
for (i in 1..10) {
val reminder = TestPopupWindowReminderOverride(it.findViewById(android.R.id.content), PopupWindow(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT).also { itx ->
itx.contentView = View(it).also {
xx -> xx.background = shape(solid = color(i))
xx.layoutParams = ViewGroup.LayoutParams(300, 400)
}
})
Reminder.enqueue(it, reminder)
delay(TimeUnit.SECONDS.toMillis(3))
}
}
}
delay(TimeUnit.SECONDS.toMillis(100))
}
@Test
fun testWarningFloatForProject() = runBlocking {
//package com.mogo.functions.test
//
//import android.animation.Animator
//import android.app.Activity
//import android.content.Context
//import android.content.Intent
//import android.graphics.Color
//import android.view.Gravity
//import android.view.View
//import android.view.ViewGroup
//import android.view.WindowManager
//import android.view.animation.OvershootInterpolator
//import android.widget.PopupWindow
//import androidx.core.view.ViewCompat
//import androidx.lifecycle.lifecycleScope
//import androidx.test.core.app.ActivityScenario
//import androidx.test.ext.junit.runners.AndroidJUnit4
//import androidx.test.filters.LargeTest
//import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWarningStatusListener
//import com.mogo.eagle.core.function.hmi.notification.WarningFloat
//import com.mogo.eagle.core.function.hmi.notification.anim.DefaultAnimator
//import com.mogo.eagle.core.data.enums.SidePattern
//import com.mogo.eagle.core.function.hmi.ui.*
//import com.mogo.eagle.core.function.main.MainLauncherActivity
//import com.mogo.eagle.core.utilcode.kotlin.shape
//import com.mogo.eagle.core.utilcode.reminder.Reminder
//import com.mogo.eagle.core.utilcode.reminder.api.impl.ActivityReminder
//import com.mogo.eagle.core.utilcode.reminder.api.impl.PopupWindowReminder
//import com.mogo.eagle.core.utilcode.reminder.api.impl.ViewReminder
//import com.mogo.eagle.core.utilcode.util.AppStateManager
//import kotlinx.coroutines.*
//import kotlinx.coroutines.flow.*
//import org.junit.Before
//import org.junit.Test
//import org.junit.runner.RunWith
//import java.lang.Integer.min
//import java.util.concurrent.*
//import java.util.concurrent.TimeUnit.MILLISECONDS
//
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class ReminderTest {
//
// lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun before() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
// }
//
// @Test
// fun testViewReminderNotOverride() = runBlocking(Dispatchers.Main) {
// launch.onActivity {
// it.lifecycleScope.launchWhenResumed {
// for (i in 1..10) {
// val notificationView = V2XNotificationView(it)
// notificationView.setWarningIcon(EventTypeEnum.getWarningIcon("10003"))
// notificationView.setWarningContent("XXXXXX${i}")
// WarningFloat.with(it)
// .setTag("tag")
// .setLayout(notificationView)
// .setSidePattern(SidePattern.RESULT_TOP)
// .setCountDownTime(5000)
// .setGravity(Gravity.CENTER_HORIZONTAL, offsetY = 110)
// .setImmersionStatusBar(true)
// .addWarningStatusListener(object : IMoGoWarningStatusListener {
// override fun onShow() {
// }
// })
// .setAnimator(object : DefaultAnimator() {
// override fun enterAnim(
// view: View,
// params: WindowManager.LayoutParams,
// windowManager: WindowManager,
// sidePattern: SidePattern
// ): Animator? =
// super.enterAnim(view, params, windowManager, sidePattern)?.apply {
// interpolator = OvershootInterpolator()
// }
//
// override fun exitAnim(
// view: View,
// params: WindowManager.LayoutParams,
// windowManager: WindowManager,
// sidePattern: SidePattern
// ): Animator? =
// super.exitAnim(view, params, windowManager, sidePattern)?.setDuration(200)
// })
// .show()
// delay(2000)
// val reminder = WindowManagerViewUnOverrideReminder(View(it).also { itx -> itx.background = shape(solid = color(i)) }, 300, 300)
// Reminder.enqueue(it, reminder)
// delay(TimeUnit.SECONDS.toMillis(3))
// reminder.hide()
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
}
class WarningFloatReminder(private val builder: WarningFloat.Builder) : ViewReminder(builder.config.layoutView!!) {
override fun show() {
builder.show()
}
override fun hide() {
WarningFloat.dismiss(builder.config.floatTag, false)
}
override fun isOverride(): Boolean {
return true
}
}
class WindowManagerViewUnOverrideReminder(private val content: View, private val width: Int, private val height: Int) : ViewReminder(content) {
private val wm by lazy {
content.context.getSystemService(Activity.WINDOW_SERVICE) as WindowManager
}
private var isAdd = false
override fun show() {
if (!isAdd) {
val params = WindowManager.LayoutParams().also {
it.width = width
it.height = height
}
params.gravity = Gravity.CENTER
wm.addView(content, params)
isAdd = true
}
}
override fun hide() {
if (isAdd && ViewCompat.isAttachedToWindow(content)) {
wm.removeView(content)
isAdd = false
}
}
}
class WindowManagerViewOverrideReminder(private val content: View, private val width: Int, private val height: Int) : ViewReminder(content) {
private val wm by lazy {
content.context.getSystemService(Activity.WINDOW_SERVICE) as WindowManager
}
private var isAdd = false
override fun show() {
if (!isAdd) {
val params = WindowManager.LayoutParams().also {
it.width = width
it.height = height
}
params.gravity = Gravity.CENTER
wm.addView(content, params)
isAdd = true
}
}
override fun hide() {
if (isAdd && ViewCompat.isAttachedToWindow(content)) {
wm.removeView(content)
isAdd = false
}
}
override fun isOverride(): Boolean {
return true
}
}
class ActivityNameReminder(private val context: Context, private val className: String): ActivityReminder(className) {
override fun show() {
Intent(context, Class.forName(className)).also {
context.startActivity(it)
}
}
override fun hide() {
AppStateManager.currentActivity()?.takeIf { it.javaClass.name == className }?.finish()
}
}
class ActivityNameOverrideReminder(private val context: Context, private val className: String): ActivityReminder(className) {
override fun show() {
Intent(context, Class.forName(className)).also {
context.startActivity(it)
}
}
override fun hide() {
AppStateManager.currentActivity()?.takeIf { it.javaClass.name == className }?.finish()
}
override fun isOverride(): Boolean {
return true
}
}
class TestPopupWindowReminder(private val anchor: View, override val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
override fun show() {
popupWindow.showAtLocation(anchor, Gravity.CENTER, 0, 0)
}
}
class TestPopupWindowReminderOverride(private val anchor: View, override val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
override fun show() {
popupWindow.showAtLocation(anchor, Gravity.CENTER, 0, 0)
}
override fun isOverride(): Boolean {
return true
}
}
private fun color(index: Int): Int {
if (index > 10) {
return Color.BLACK
}
val alpha = min(255, 255 - index * 20)
return Color.argb(alpha, Color.red(Color.RED), Color.green(Color.RED), Color.blue(Color.RED))
}
}
// return@runBlocking
// }
//
// @Test
// fun testShowWarningV2x() = runBlocking {
// val f = ensureMoGoHmiFragmentShow()
//
// delay(5000)
// (1 until 20).map {
// it
// }.asFlow()
// .onEach {
// f.showWarningV2X("10006", "test", "测试$it", "$it", null, true, 5000)
// }
// .flowOn(Dispatchers.Default)
// .collect()
// delay(3000000)
// }
//
// private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
// launch.onActivity { itx ->
// val executor = Executors.newSingleThreadScheduledExecutor()
// executor.scheduleAtFixedRate({
// var find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
// while (find == null) {
// find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
// }
// 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)
// }
// }
//
// @Test
// fun testViewReminderOverride() = runBlocking(Dispatchers.Main) {
// launch.onActivity {
// it.lifecycleScope.launchWhenCreated {
// for (i in 1..10) {
// val reminder = WindowManagerViewOverrideReminder(View(it).also { itx -> itx.background = shape(solid = color(i)) }, 300, 300)
// Reminder.enqueue(it, reminder)
// delay(TimeUnit.SECONDS.toMillis(3))
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
// return@runBlocking
// }
//
// @Test
// fun testViewReminderWhenActivityDestroyed() = runBlocking(Dispatchers.Main) {
// launch.onActivity {
// it.lifecycleScope.launchWhenCreated {
// for (i in 1..10) {
// val reminder = WindowManagerViewOverrideReminder(View(it).also { itx -> itx.background = shape(solid = color(i)) }, 300, 300)
// Reminder.enqueue(it, reminder)
// delay(TimeUnit.SECONDS.toMillis(3))
//
// if (i == 8) {
// it.finish()
// }
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
// }
//
// @Test
// fun testWarningFloat() = runBlocking(Dispatchers.Main) {
// launch.onActivity {
// it.lifecycleScope.launchWhenCreated {
// for (i in 1..10) {
// val v = View(it).also {
// it.background = shape(solid = color(i))
// it.layoutParams = WindowManager.LayoutParams().also { itx ->
// itx.width = 300
// itx.height = 400
// }
// }
// val builder = WarningFloat.with(it).setTag("test${i}").setLayout(v).setSidePattern(SidePattern.RESULT_TOP).setCountDownTime(TimeUnit.SECONDS.toMillis(10)).setGravity(Gravity.CENTER_HORIZONTAL, offsetY = 110).setImmersionStatusBar(true).addWarningStatusListener(object :
// IMoGoWarningStatusListener {
// override fun onShow() {
//
// }
// }).setAnimator(object : DefaultAnimator() {
// override fun enterAnim(view: View, params: WindowManager.LayoutParams, windowManager: WindowManager, sidePattern: SidePattern): Animator? = super.enterAnim(view, params, windowManager, sidePattern)?.apply {
// interpolator = OvershootInterpolator()
// }
//
// override fun exitAnim(view: View, params: WindowManager.LayoutParams, windowManager: WindowManager, sidePattern: SidePattern): Animator? = super.exitAnim(view, params, windowManager, sidePattern)?.setDuration(200)
// })
// Reminder.enqueue(it, WarningFloatReminder(builder))
// delay(TimeUnit.SECONDS.toMillis(3))
// }
//
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
// }
//
//
// @Test
// fun testActivityReminder() = runBlocking(Dispatchers.Main) {
// launch.onActivity {
// it.lifecycleScope.launchWhenResumed {
// for (i in 1..10) {
// val reminder = ActivityNameReminder(it, "com.mogo.launcher.TestActivity")
// Reminder.enqueue(it, reminder)
// delay(TimeUnit.SECONDS.toMillis(6))
// reminder.hide()
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
// }
//
// @Test
// fun testActivityReminderOverride() = runBlocking(Dispatchers.Main) {
// launch.onActivity {
// it.lifecycleScope.launchWhenResumed {
// for (i in 1..10) {
// val reminder = ActivityNameOverrideReminder(it, "com.mogo.launcher.TestActivity")
// Reminder.enqueue(it, reminder)
// delay(TimeUnit.SECONDS.toMillis(6))
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
// }
//
//
// @Test
// fun testPopupWindowReminder() = runBlocking {
// launch.onActivity {
// it.lifecycleScope.launchWhenResumed {
// for (i in 1..10) {
//
// val reminder = TestPopupWindowReminder(it.findViewById(android.R.id.content), PopupWindow(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT).also { itx ->
// itx.contentView = View(it).also {
// xx -> xx.background = shape(solid = color(i))
// xx.layoutParams = ViewGroup.LayoutParams(300, 400)
// }
// })
// Reminder.enqueue(it, reminder)
// delay(TimeUnit.SECONDS.toMillis(3))
// reminder.hide()
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
// }
//
// @Test
// fun testPopupWindowReminderOverride() = runBlocking {
// launch.onActivity {
// it.lifecycleScope.launchWhenResumed {
// for (i in 1..10) {
//
// val reminder = TestPopupWindowReminderOverride(it.findViewById(android.R.id.content), PopupWindow(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT).also { itx ->
// itx.contentView = View(it).also {
// xx -> xx.background = shape(solid = color(i))
// xx.layoutParams = ViewGroup.LayoutParams(300, 400)
// }
// })
// Reminder.enqueue(it, reminder)
// delay(TimeUnit.SECONDS.toMillis(3))
// }
// }
// }
// delay(TimeUnit.SECONDS.toMillis(100))
// }
//
// @Test
// fun testWarningFloatForProject() = runBlocking {
//// launch.onActivity {
//// it.lifecycleScope.launchWhenResumed {
//// for (i in 1..10) {
//// val notificationView = V2XNotificationView(it)
//// notificationView.setWarningIcon(EventTypeEnum.getWarningIcon("10003"))
//// notificationView.setWarningContent("XXXXXX${i}")
//// WarningFloat.with(it)
//// .setTag("tag")
//// .setLayout(notificationView)
//// .setSidePattern(SidePattern.RESULT_TOP)
//// .setCountDownTime(5000)
//// .setGravity(Gravity.CENTER_HORIZONTAL, offsetY = 110)
//// .setImmersionStatusBar(true)
//// .addWarningStatusListener(object : IMoGoWarningStatusListener {
//// override fun onShow() {
//// }
//// })
//// .setAnimator(object : DefaultAnimator() {
//// override fun enterAnim(
//// view: View,
//// params: WindowManager.LayoutParams,
//// windowManager: WindowManager,
//// sidePattern: SidePattern
//// ): Animator? =
//// super.enterAnim(view, params, windowManager, sidePattern)?.apply {
//// interpolator = OvershootInterpolator()
//// }
////
//// override fun exitAnim(
//// view: View,
//// params: WindowManager.LayoutParams,
//// windowManager: WindowManager,
//// sidePattern: SidePattern
//// ): Animator? =
//// super.exitAnim(view, params, windowManager, sidePattern)?.setDuration(200)
//// })
//// .show()
//// delay(2000)
//// }
//// }
//// }
//// delay(TimeUnit.SECONDS.toMillis(100))
// }
//
//
// class WarningFloatReminder(private val builder: WarningFloat.Builder) : ViewReminder(builder.config.layoutView!!) {
//
// override fun show() {
// builder.show()
// }
//
// override fun hide() {
// WarningFloat.dismiss(builder.config.floatTag, false)
// }
//
// override fun isOverride(): Boolean {
// return true
// }
// }
//
//
// class WindowManagerViewUnOverrideReminder(private val content: View, private val width: Int, private val height: Int) : ViewReminder(content) {
//
// private val wm by lazy {
// content.context.getSystemService(Activity.WINDOW_SERVICE) as WindowManager
// }
//
// private var isAdd = false
//
// override fun show() {
// if (!isAdd) {
// val params = WindowManager.LayoutParams().also {
// it.width = width
// it.height = height
// }
// params.gravity = Gravity.CENTER
// wm.addView(content, params)
// isAdd = true
// }
// }
//
// override fun hide() {
// if (isAdd && ViewCompat.isAttachedToWindow(content)) {
// wm.removeView(content)
// isAdd = false
// }
// }
// }
//
//
// class WindowManagerViewOverrideReminder(private val content: View, private val width: Int, private val height: Int) : ViewReminder(content) {
//
// private val wm by lazy {
// content.context.getSystemService(Activity.WINDOW_SERVICE) as WindowManager
// }
//
// private var isAdd = false
//
// override fun show() {
// if (!isAdd) {
// val params = WindowManager.LayoutParams().also {
// it.width = width
// it.height = height
// }
// params.gravity = Gravity.CENTER
// wm.addView(content, params)
// isAdd = true
// }
// }
//
// override fun hide() {
// if (isAdd && ViewCompat.isAttachedToWindow(content)) {
// wm.removeView(content)
// isAdd = false
// }
// }
//
// override fun isOverride(): Boolean {
// return true
// }
// }
//
//
// class ActivityNameReminder(private val context: Context, private val className: String): ActivityReminder(className) {
//
// override fun show() {
// Intent(context, Class.forName(className)).also {
// context.startActivity(it)
// }
// }
//
// override fun hide() {
// AppStateManager.currentActivity()?.takeIf { it.javaClass.name == className }?.finish()
// }
// }
//
// class ActivityNameOverrideReminder(private val context: Context, private val className: String): ActivityReminder(className) {
//
// override fun show() {
// Intent(context, Class.forName(className)).also {
// context.startActivity(it)
// }
// }
//
// override fun hide() {
// AppStateManager.currentActivity()?.takeIf { it.javaClass.name == className }?.finish()
// }
//
// override fun isOverride(): Boolean {
// return true
// }
// }
//
// class TestPopupWindowReminder(private val anchor: View, override val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
//
// override fun show() {
// popupWindow.showAtLocation(anchor, Gravity.CENTER, 0, 0)
// }
// }
//
// class TestPopupWindowReminderOverride(private val anchor: View, override val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
//
// override fun show() {
// popupWindow.showAtLocation(anchor, Gravity.CENTER, 0, 0)
// }
//
// override fun isOverride(): Boolean {
// return true
// }
// }
//
// private fun color(index: Int): Int {
// if (index > 10) {
// return Color.BLACK
// }
// val alpha = min(255, 255 - index * 20)
// return Color.argb(alpha, Color.red(Color.RED), Color.green(Color.RED), Color.blue(Color.RED))
// }
//}

File diff suppressed because one or more lines are too long

View File

@@ -1,54 +1,54 @@
package com.mogo.functions.test
import android.os.Debug
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.function.main.MainLauncherActivity
import io.reactivex.Flowable
import io.reactivex.plugins.RxJavaPlugins
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeUnit.MILLISECONDS
@RunWith(AndroidJUnit4::class)
@LargeTest
class RxJavaBackPressureTest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
RxJavaPlugins.setErrorHandler {
}
}
@Test
fun testIntervalBackPressure() = runBlocking(Dispatchers.Default) {
val subscription = Flowable.interval(50, MILLISECONDS).doOnNext {
}.subscribeOn(Schedulers.computation()).observeOn(Schedulers.io()).subscribe {
Thread.sleep(2000)
}
repeat(10) {
delay(TimeUnit.SECONDS.toMillis(5))
try {
Debug.dumpHprofData(Date().toFileName())
} catch (t: Throwable) {
t.printStackTrace()
}
}
delay(TimeUnit.HOURS.toMillis(1))
subscription.dispose()
}
private fun Date.toFileName(): String = SimpleDateFormat("yyyyMMdd_HH_mm_ss", Locale.getDefault()).format(this) + ".hprof"
}
//package com.mogo.functions.test
//
//import android.os.Debug
//import androidx.test.core.app.ActivityScenario
//import androidx.test.ext.junit.runners.AndroidJUnit4
//import androidx.test.filters.LargeTest
//import com.mogo.eagle.core.function.main.MainLauncherActivity
//import io.reactivex.Flowable
//import io.reactivex.plugins.RxJavaPlugins
//import io.reactivex.schedulers.Schedulers
//import kotlinx.coroutines.Dispatchers
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.runBlocking
//import org.junit.Before
//import org.junit.Test
//import org.junit.runner.RunWith
//import java.text.SimpleDateFormat
//import java.util.*
//import java.util.concurrent.TimeUnit
//import java.util.concurrent.TimeUnit.MILLISECONDS
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class RxJavaBackPressureTest {
//
// lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun before() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
// RxJavaPlugins.setErrorHandler {
// }
// }
//
// @Test
// fun testIntervalBackPressure() = runBlocking(Dispatchers.Default) {
// val subscription = Flowable.interval(50, MILLISECONDS).doOnNext {
// }.subscribeOn(Schedulers.computation()).observeOn(Schedulers.io()).subscribe {
// Thread.sleep(2000)
// }
// repeat(10) {
// delay(TimeUnit.SECONDS.toMillis(5))
// try {
// Debug.dumpHprofData(Date().toFileName())
// } catch (t: Throwable) {
// t.printStackTrace()
// }
// }
// delay(TimeUnit.HOURS.toMillis(1))
// subscription.dispose()
// }
//
// private fun Date.toFileName(): String = SimpleDateFormat("yyyyMMdd_HH_mm_ss", Locale.getDefault()).format(this) + ".hprof"
//}

View File

@@ -1,76 +1,76 @@
package com.mogo.functions.test
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.function.main.MainLauncherActivity
import io.reactivex.Observable
import io.reactivex.ObservableOnSubscribe
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.TimeUnit.SECONDS
@RunWith(AndroidJUnit4::class)
@LargeTest
class RxJavaSchedulersTest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@Test
fun testRxJavaIoSchedulers() = runBlocking {
val list = mutableListOf<Int>()
for (i in 1..10) {
list += i
}
val result = Observable.fromIterable(list)
.doOnNext {
assert(Thread.currentThread().name.startsWith("io-pool-"))
}
.subscribeOn(Schedulers.io())
.reduce(0) { adder, toAdd ->
val sum = adder + toAdd
sum
}
.blockingGet()
assert(result == 55)
delay(SECONDS.toMillis(20))
}
@Test
fun testRxJavaCpuSchedulers() = runBlocking {
val result = Observable.create(ObservableOnSubscribe<Int> { emitter ->
for (i in 1..10) {
emitter.onNext(i)
}
assert(Thread.currentThread().name.startsWith("cpu-pool-"))
emitter.onComplete()
}).reduce(0) { adder, toAdd ->
adder + toAdd
}.subscribeOn(Schedulers.computation()).blockingGet()
assert(result == 55)
delay(SECONDS.toMillis(20))
}
@Test
fun testRxJavaIntervalSchedulers() = runBlocking {
var counter = 0
Observable.intervalRange(0, 10, 1, 1 ,SECONDS)
.doOnNext {
counter ++
}
.subscribe()
delay(SECONDS.toMillis(20))
assert(counter == 10)
}
}
//package com.mogo.functions.test
//
//import androidx.test.core.app.ActivityScenario
//import androidx.test.ext.junit.runners.AndroidJUnit4
//import androidx.test.filters.LargeTest
//import com.mogo.eagle.core.function.main.MainLauncherActivity
//import io.reactivex.Observable
//import io.reactivex.ObservableOnSubscribe
//import io.reactivex.schedulers.Schedulers
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.runBlocking
//import org.junit.Before
//import org.junit.Test
//import org.junit.runner.RunWith
//import java.util.concurrent.TimeUnit.SECONDS
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class RxJavaSchedulersTest {
//
// lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun before() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
// }
//
// @Test
// fun testRxJavaIoSchedulers() = runBlocking {
// val list = mutableListOf<Int>()
// for (i in 1..10) {
// list += i
// }
// val result = Observable.fromIterable(list)
// .doOnNext {
// assert(Thread.currentThread().name.startsWith("io-pool-"))
// }
// .subscribeOn(Schedulers.io())
// .reduce(0) { adder, toAdd ->
// val sum = adder + toAdd
// sum
// }
// .blockingGet()
// assert(result == 55)
//
// delay(SECONDS.toMillis(20))
// }
//
// @Test
// fun testRxJavaCpuSchedulers() = runBlocking {
// val result = Observable.create(ObservableOnSubscribe<Int> { emitter ->
// for (i in 1..10) {
// emitter.onNext(i)
// }
// assert(Thread.currentThread().name.startsWith("cpu-pool-"))
// emitter.onComplete()
// }).reduce(0) { adder, toAdd ->
// adder + toAdd
// }.subscribeOn(Schedulers.computation()).blockingGet()
// assert(result == 55)
// delay(SECONDS.toMillis(20))
// }
//
// @Test
// fun testRxJavaIntervalSchedulers() = runBlocking {
// var counter = 0
// Observable.intervalRange(0, 10, 1, 1 ,SECONDS)
// .doOnNext {
// counter ++
// }
// .subscribe()
// delay(SECONDS.toMillis(20))
// assert(counter == 10)
// }
//
//}

View File

@@ -1,71 +1,71 @@
package com.mogo.functions.test
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.function.hmi.ui.MoGoHmiProvider
import com.mogo.eagle.core.function.main.MainLauncherActivity
import com.mogo.eagle.core.utilcode.mogo.toast.TipToast
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeUnit.MILLISECONDS
@RunWith(AndroidJUnit4::class)
@LargeTest
class TipToastLeakTest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@Test
fun test() = runBlocking(Dispatchers.Main) {
val f = ensureMoGoHmiFragmentShow()
var index = 0
while (index < 50) {
delay(TimeUnit.SECONDS.toMillis(4))
TipToast.shortTip("toast-> $index" )
index ++
}
delay(TimeUnit.SECONDS.toMillis(1))
f.activity?.finish()
delay(TimeUnit.SECONDS.toMillis(2))
}
private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
launch.onActivity { itx ->
val executor = Executors.newSingleThreadScheduledExecutor()
executor.scheduleAtFixedRate({
var find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
while (find == null) {
find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
}
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 androidx.test.core.app.ActivityScenario
//import androidx.test.ext.junit.runners.AndroidJUnit4
//import androidx.test.filters.LargeTest
//import com.mogo.eagle.core.function.hmi.ui.MoGoHmiProvider
//import com.mogo.eagle.core.function.main.MainLauncherActivity
//import com.mogo.eagle.core.utilcode.mogo.toast.TipToast
//import kotlinx.coroutines.Dispatchers
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.runBlocking
//import kotlinx.coroutines.suspendCancellableCoroutine
//import org.junit.Before
//import org.junit.Test
//import org.junit.runner.RunWith
//import java.util.concurrent.Executors
//import java.util.concurrent.TimeUnit
//import java.util.concurrent.TimeUnit.MILLISECONDS
//
//@RunWith(AndroidJUnit4::class)
//@LargeTest
//class TipToastLeakTest {
//
//
// lateinit var launch: ActivityScenario<MainLauncherActivity>
//
// @Before
// fun before() {
// launch = ActivityScenario.launch(MainLauncherActivity::class.java)
//
// }
//
// @Test
// fun test() = runBlocking(Dispatchers.Main) {
// val f = ensureMoGoHmiFragmentShow()
// var index = 0
// while (index < 50) {
// delay(TimeUnit.SECONDS.toMillis(4))
// TipToast.shortTip("toast-> $index" )
// index ++
// }
// delay(TimeUnit.SECONDS.toMillis(1))
// f.activity?.finish()
// delay(TimeUnit.SECONDS.toMillis(2))
// }
//
// private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiProvider = suspendCancellableCoroutine {
// launch.onActivity { itx ->
// val executor = Executors.newSingleThreadScheduledExecutor()
// executor.scheduleAtFixedRate({
// var find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
// while (find == null) {
// find =
// itx.supportFragmentManager.fragments.find { it is MoGoHmiProvider } as? MoGoHmiProvider
//
// }
// 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)
// }
// }
//}