Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 462af0dd authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Exclude setup wizard for desktop mode home condition

This avoids a timing that ACTION_PREFERRED_ACTIVITY_CHANGED is
on the way (right after setup wizard disabled) but a new task
of next home is launched. The task should be still considered as
a part of home and app handle should not show on it.

Bug: 404425629
Bug: 402779100
Flag: EXEMPT bugfix
Test: No app handle on last step of SUW with desktop mode.
Change-Id: Ia54b3a1a8923a0adb1fe5f87f1a2d5cc684c3316
parent 440faf35
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.os.Handler
import com.android.wm.shell.shared.annotations.ShellMainThread
import com.android.wm.shell.sysui.ShellInit
@@ -28,6 +29,7 @@ import java.util.function.Supplier
/**
 * This supplies the package name of default home in an efficient way. The query to package manager
 * only executes on initialization and when the preferred activity (e.g. default home) is changed.
 * Note that this returns null package name if the default home is setup wizard.
 */
class DefaultHomePackageSupplier(
    private val context: Context,
@@ -36,6 +38,7 @@ class DefaultHomePackageSupplier(
) : BroadcastReceiver(), Supplier<String?> {

    private var defaultHomePackage: String? = null
    private var isSetupWizard: Boolean = false

    init {
        shellInit.addInitCallback({ onInit() }, this)
@@ -52,6 +55,14 @@ class DefaultHomePackageSupplier(

    private fun updateDefaultHomePackage(): String? {
        defaultHomePackage = context.packageManager.getHomeActivities(ArrayList())?.packageName
        isSetupWizard =
            defaultHomePackage != null &&
                context.packageManager.resolveActivity(
                    Intent()
                        .setPackage(defaultHomePackage)
                        .addCategory(Intent.CATEGORY_SETUP_WIZARD),
                    PackageManager.MATCH_SYSTEM_ONLY,
                ) != null
        return defaultHomePackage
    }

@@ -60,6 +71,7 @@ class DefaultHomePackageSupplier(
    }

    override fun get(): String? {
        if (isSetupWizard) return null
        return defaultHomePackage ?: updateDefaultHomePackage()
    }
}