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

Commit 51982c54 authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[3/n] CompatUIRepository definition" into main

parents 29bad4ea 2a216e3a
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.api

/**
 * Abstraction for the repository of all the available CompatUISpec
 */
interface CompatUIRepository {
    /**
     * Adds a {@link CompatUISpec} to the repository
     * @throws IllegalStateException in case of illegal spec
     */
    fun addSpec(spec: CompatUISpec)

    /**
     * Iterates on the list of available {@link CompatUISpec} invoking
     * fn for each of them.
     */
    fun iterateOn(fn: (CompatUISpec) -> Unit)

    /**
     * Returns the {@link CompatUISpec} for a given key
     */
    fun findSpec(name: String): CompatUISpec?
}
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.api

/**
 * Describes each compat ui component to the framework.
 */
data class CompatUISpec(
    // Unique name for the component. It's used for debug and for generating the
    // unique component identifier in the system.
    val name: String
)
 No newline at end of file
+4 −1
Original line number Diff line number Diff line
@@ -19,12 +19,15 @@ package com.android.wm.shell.compatui.impl
import com.android.wm.shell.compatui.api.CompatUIEvent
import com.android.wm.shell.compatui.api.CompatUIHandler
import com.android.wm.shell.compatui.api.CompatUIInfo
import com.android.wm.shell.compatui.api.CompatUIRepository
import java.util.function.Consumer

/**
 * Default implementation of {@link CompatUIHandler} to handle CompatUI components
 */
class DefaultCompatUIHandler : CompatUIHandler {
class DefaultCompatUIHandler(
    private val compatUIRepository: CompatUIRepository
) : CompatUIHandler {

    private var compatUIEventSender: Consumer<CompatUIEvent>? = null
    override fun onCompatInfoChanged(compatUIInfo: CompatUIInfo) {
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.impl

import com.android.wm.shell.compatui.api.CompatUIRepository
import com.android.wm.shell.compatui.api.CompatUISpec

/**
 * Default {@link CompatUIRepository} implementation
 */
class DefaultCompatUIRepository : CompatUIRepository {

    private val allSpecs = mutableMapOf<String, CompatUISpec>()

    override fun addSpec(spec: CompatUISpec) {
        if (allSpecs[spec.name] != null) {
            throw IllegalStateException("Spec with id:${spec.name} already present")
        }
        allSpecs[spec.name] = spec
    }

    override fun iterateOn(fn: (CompatUISpec) -> Unit) =
        allSpecs.values.forEach(fn)

    override fun findSpec(name: String): CompatUISpec? =
        allSpecs[name]
}
 No newline at end of file
+11 −2
Original line number Diff line number Diff line
@@ -72,7 +72,9 @@ import com.android.wm.shell.compatui.CompatUIConfiguration;
import com.android.wm.shell.compatui.CompatUIController;
import com.android.wm.shell.compatui.CompatUIShellCommandHandler;
import com.android.wm.shell.compatui.api.CompatUIHandler;
import com.android.wm.shell.compatui.api.CompatUIRepository;
import com.android.wm.shell.compatui.impl.DefaultCompatUIHandler;
import com.android.wm.shell.compatui.impl.DefaultCompatUIRepository;
import com.android.wm.shell.desktopmode.DesktopMode;
import com.android.wm.shell.desktopmode.DesktopModeTaskRepository;
import com.android.wm.shell.desktopmode.DesktopTasksController;
@@ -245,12 +247,13 @@ public abstract class WMShellBaseModule {
            Lazy<DockStateReader> dockStateReader,
            Lazy<CompatUIConfiguration> compatUIConfiguration,
            Lazy<CompatUIShellCommandHandler> compatUIShellCommandHandler,
            Lazy<AccessibilityManager> accessibilityManager) {
            Lazy<AccessibilityManager> accessibilityManager,
            CompatUIRepository compatUIRepository) {
        if (!context.getResources().getBoolean(R.bool.config_enableCompatUIController)) {
            return Optional.empty();
        }
        if (Flags.appCompatUiFramework()) {
            return Optional.of(new DefaultCompatUIHandler());
            return Optional.of(new DefaultCompatUIHandler(compatUIRepository));
        }
        return Optional.of(
                new CompatUIController(
@@ -269,6 +272,12 @@ public abstract class WMShellBaseModule {
                        accessibilityManager.get()));
    }

    @WMSingleton
    @Provides
    static CompatUIRepository provideCompatUIRepository() {
        return new DefaultCompatUIRepository();
    }

    @WMSingleton
    @Provides
    static SyncTransactionQueue provideSyncTransactionQueue(TransactionPool pool,
Loading