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

Commit fc5d639b authored by Anton Potapov's avatar Anton Potapov Committed by Automerger Merge Worker
Browse files

Merge "Add remove app flow to the home controls panel" into tm-qpr-dev am:...

Merge "Add remove app flow to the home controls panel" into tm-qpr-dev am: 686f8e9d am: bfe65736

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21408653



Change-Id: I424d4bdbe8167eb3a761495d535b7eb70c13fa66
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 828a1729 bfe65736
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2431,6 +2431,10 @@
         panel (embedded activity) instead of controls rendered by SystemUI [CHAR LIMIT=NONE] -->
    <string name="controls_panel_authorization">When you add <xliff:g id="appName" example="My app">%s</xliff:g>, it can add controls and content to this panel. In some apps, you can choose which controls show up here.</string>

    <!-- Shows in a dialog presented to the user to authorize this app removal from a Device
         controls panel [CHAR LIMIT=NONE] -->
    <string name="controls_panel_remove_app_authorization">Remove controls for <xliff:g example="My app" id="appName">%s</xliff:g>?</string>

    <!-- a11y state description for a control that is currently favorited [CHAR LIMIT=NONE] -->
    <string name="accessibility_control_favorite">Favorited</string>
    <!-- a11y state description for a control that is currently favorited with its position [CHAR LIMIT=NONE] -->
@@ -2471,6 +2475,8 @@
    <string name="controls_dialog_title">Add to device controls</string>
    <!-- Controls dialog add to favorites [CHAR LIMIT=40] -->
    <string name="controls_dialog_ok">Add</string>
    <!-- Controls dialog remove app from a panel [CHAR LIMIT=40] -->
    <string name="controls_dialog_remove">Remove</string>
    <!-- Controls dialog message. Indicates app that suggested this control [CHAR LIMIT=NONE] -->
    <string name="controls_dialog_message">Suggested by <xliff:g id="app" example="System UI">%s</xliff:g></string>
    <!-- Controls tile secondary label when device is locked and user does not want access to controls from lockscreen [CHAR LIMIT=20] -->
@@ -2588,6 +2594,8 @@
    <string name="controls_menu_edit">Edit controls</string>
    <!-- Controls menu, add another app [CHAR LIMIT=30] -->
    <string name="controls_menu_add_another_app">Add app</string>
    <!-- Controls menu, remove app [CHAR_LIMIT=30] -->
    <string name="controls_menu_remove">Remove app</string>

    <!-- Title for the media output dialog with media related devices [CHAR LIMIT=50] -->
    <string name="media_output_dialog_add_output">Add outputs</string>
+13 −0
Original line number Diff line number Diff line
@@ -165,6 +165,19 @@ interface ControlsController : UserAwareController {
        controlInfo: ControlInfo
    )

    /**
     * Removes favorites for a given component
     * @param componentName the name of the service that provides the [Control]
     * @return true when favorites is scheduled for deletion
     */
    fun removeFavorites(componentName: ComponentName): Boolean

    /**
     * Checks if the favorites can be removed. You can't remove components from the preferred list.
     * @param componentName the name of the service that provides the [Control]
     */
    fun canRemoveFavorites(componentName: ComponentName): Boolean

    /**
     * Replaces the favorites for the given structure.
     *
+18 −2
Original line number Diff line number Diff line
@@ -499,6 +499,21 @@ class ControlsControllerImpl @Inject constructor (
        }
    }

    override fun canRemoveFavorites(componentName: ComponentName): Boolean =
            !authorizedPanelsRepository.getPreferredPackages().contains(componentName.packageName)

    override fun removeFavorites(componentName: ComponentName): Boolean {
        if (!confirmAvailability()) return false
        if (!canRemoveFavorites(componentName)) return false

        executor.execute {
            Favorites.removeStructures(componentName)
            authorizedPanelsRepository.removeAuthorizedPanels(setOf(componentName.packageName))
            persistenceWrapper.storeFavorites(Favorites.getAllStructures())
        }
        return true
    }

    override fun replaceFavoritesForStructure(structureInfo: StructureInfo) {
        if (!confirmAvailability()) return
        executor.execute {
@@ -657,10 +672,11 @@ private object Favorites {
        return true
    }

    fun removeStructures(componentName: ComponentName) {
    fun removeStructures(componentName: ComponentName): Boolean {
        val newFavMap = favMap.toMutableMap()
        newFavMap.remove(componentName)
        val removed = newFavMap.remove(componentName) != null
        favMap = newFavMap
        return removed
    }

    fun addFavorite(
+8 −0
Original line number Diff line number Diff line
@@ -26,6 +26,14 @@ interface AuthorizedPanelsRepository {
    /** A set of package names that the user has previously authorized to show panels. */
    fun getAuthorizedPanels(): Set<String>

    /** Preferred applications to query controls suggestions from */
    fun getPreferredPackages(): Set<String>

    /** Adds [packageNames] to the set of packages that the user has authorized to show panels. */
    fun addAuthorizedPanels(packageNames: Set<String>)

    /**
     * Removes [packageNames] from the set of packages that the user has authorized to show panels.
     */
    fun removeAuthorizedPanels(packageNames: Set<String>)
}
+11 −9
Original line number Diff line number Diff line
@@ -37,10 +37,20 @@ constructor(
        return getAuthorizedPanelsInternal(instantiateSharedPrefs())
    }

    override fun getPreferredPackages(): Set<String> =
        context.resources.getStringArray(R.array.config_controlsPreferredPackages).toSet()

    override fun addAuthorizedPanels(packageNames: Set<String>) {
        addAuthorizedPanelsInternal(instantiateSharedPrefs(), packageNames)
    }

    override fun removeAuthorizedPanels(packageNames: Set<String>) {
        with(instantiateSharedPrefs()) {
            val currentSet = getAuthorizedPanelsInternal(this)
            edit().putStringSet(KEY, currentSet - packageNames).apply()
        }
    }

    private fun getAuthorizedPanelsInternal(sharedPreferences: SharedPreferences): Set<String> {
        return sharedPreferences.getStringSet(KEY, emptySet())!!
    }
@@ -63,15 +73,7 @@ constructor(

        // If we've never run this (i.e., the key doesn't exist), add the default packages
        if (sharedPref.getStringSet(KEY, null) == null) {
            sharedPref
                .edit()
                .putStringSet(
                    KEY,
                    context.resources
                        .getStringArray(R.array.config_controlsPreferredPackages)
                        .toSet()
                )
                .apply()
            sharedPref.edit().putStringSet(KEY, getPreferredPackages()).apply()
        }
        return sharedPref
    }
Loading