From 06fbdcac173aea88cb4d02c4806866c83e720307 Mon Sep 17 00:00:00 2001 From: YuutaW <17158086+trumeet@users.noreply.github.com> Date: Sat, 30 Mar 2019 16:19:07 -0700 Subject: feat(app/ci): implement multi user support Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com> --- app/src/debug/AndroidManifest.xml | 12 ++ .../java/moe/yuuta/workmode/debug/DebugActivity.kt | 139 +++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 app/src/debug/AndroidManifest.xml create mode 100644 app/src/debug/java/moe/yuuta/workmode/debug/DebugActivity.kt (limited to 'app/src/debug') diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..92efdb0 --- /dev/null +++ b/app/src/debug/AndroidManifest.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/debug/java/moe/yuuta/workmode/debug/DebugActivity.kt b/app/src/debug/java/moe/yuuta/workmode/debug/DebugActivity.kt new file mode 100644 index 0000000..b8b5af8 --- /dev/null +++ b/app/src/debug/java/moe/yuuta/workmode/debug/DebugActivity.kt @@ -0,0 +1,139 @@ +package moe.yuuta.workmode.debug + +import android.graphics.Typeface +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.text.method.ScrollingMovementMethod +import android.util.Log +import android.view.ViewGroup +import android.widget.Button +import android.widget.LinearLayout +import android.widget.TextView +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import moe.yuuta.ext.HandlerThreadExecutor +import moe.yuuta.workmode.access.DumpResult +import moe.yuuta.workmode.suspend.AsyncSuspender +import moe.yuuta.workmode.suspend.data.TransferableSuspendedApp +import moe.yuuta.workmode.utils.Utils +import java.util.concurrent.CompletableFuture + +class DebugActivity : AppCompatActivity() { + companion object { + private const val TAG = "Debug" + } + + private var mCurrentFuture: CompletableFuture<*>? = null + private lateinit var mLogText: TextView + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + Log.i(TAG, "Starting") + val rootView = LinearLayout(this) + rootView.orientation = LinearLayout.VERTICAL + + mLogText = TextView(this) + mLogText.typeface = Typeface.MONOSPACE + mLogText.movementMethod = ScrollingMovementMethod() + rootView.addView(mLogText) + + registerTestingFunction(rootView, "isSuspended", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).isSuspended(listOf(TransferableSuspendedApp.of("kh.android.dir"), + TransferableSuspendedApp.of("com.android.chrome"))) + } + }) + + registerTestingFunction(rootView, "getSuspendedPackageAppExtras", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).getSuspendedPackageAppExtras(TransferableSuspendedApp.of("com.android.chrome")) + } + }) + + registerTestingFunction(rootView, "getSuspendedPackageLauncherExtras", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).getSuspendedPackageLauncherExtras(TransferableSuspendedApp.of("com.android.chrome")) + } + }) + + registerTestingFunction(rootView, "dump", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).dump(TransferableSuspendedApp.of("com.google.android.dialer", 11)) + } + }) + + registerTestingFunction(rootView, "suspend (true)", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).suspend(listOf(TransferableSuspendedApp.of("kh.android.dir"), + TransferableSuspendedApp.of("com.android.chrome")), true) + } + }) + + registerTestingFunction(rootView, "suspend (false)", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).suspend(listOf(TransferableSuspendedApp.of("kh.android.dir"), + TransferableSuspendedApp.of("com.android.chrome")), false) + } + }) + + registerTestingFunction(rootView, "apply", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).applyFromSettings() + } + }) + + registerTestingFunction(rootView, "getInstalledApplicationsAcrossUser", object : Callback { + override fun call(): CompletableFuture<*> { + return AsyncSuspender(this@DebugActivity).getInstalledApplicationsAcrossUser(0) + } + }) + + Log.d(TAG, "Done, children amount: ${rootView.childCount}") + setContentView(rootView) + } + + private fun registerTestingFunction(rootView: ViewGroup, tag: String, onClickListener: Callback) { + val btn = Button(this) + btn.text = tag + btn.setOnClickListener { + if (mCurrentFuture != null && !(mCurrentFuture as CompletableFuture<*>).isDone) { + Toast.makeText(this, "Current running task is not done yet.", Toast.LENGTH_SHORT).show() + return@setOnClickListener + } + mLogText.text = "" + mLogText.append("Started task.\n") + mCurrentFuture = onClickListener + .call() + /* .exceptionally { + runOnUiThread { + Log.e(TAG, "Exceptionally ${Thread.currentThread().name}", it) + mLogText.append("\n") + mLogText.append("Exceptionally: $it\n") + } + return@exceptionally null + } */ + .handle { result, e -> + // handleAsync() doesn't work + runOnUiThread { + if (result != null && result is DumpResult) { + mLogText.append("DumpResult - Launcher Extras: ${Utils.dumpExtras(result.launcherExtras)}\n") + } + mLogText.append("Done!\n") + mLogText.append("Result: $result\n") + mLogText.append("Error: $e") + } + } + .thenRunAsync(Runnable { + Log.e(TAG, "Then run ${Thread.currentThread().name}") + mLogText.append("\n") + mLogText.append("Run.") + }, HandlerThreadExecutor(Handler(Looper.getMainLooper()))) + } + rootView.addView(btn) + } + + private interface Callback { + fun call(): CompletableFuture<*> + } +} \ No newline at end of file -- cgit v1.2.3