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

Commit 940d70b4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "themeservice-flagging" into main

* changes:
  Add contrast listeners and getter methods to server
  Flagging ThemeOverlayController and ThemeManagerService
parents 9c0df703 6b7dc168
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import com.android.systemui.statusbar.notification.InstantAppNotifier
import com.android.systemui.statusbar.notification.headsup.StatusBarHeadsUpChangeListener
import com.android.systemui.stylus.StylusUsiPowerStartable
import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator
import com.android.systemui.theme.ThemeOverlayController
import com.android.systemui.usb.StorageNotification
import com.android.systemui.util.NotificationChannels
import com.android.systemui.wmshell.WMShell
@@ -185,12 +184,6 @@ abstract class SystemUICoreStartableModule {
    @ClassKey(StorageNotification::class)
    abstract fun bindStorageNotification(sysui: StorageNotification): CoreStartable

    /** Inject into ThemeOverlayController. */
    @Binds
    @IntoMap
    @ClassKey(ThemeOverlayController::class)
    abstract fun bindThemeOverlayController(sysui: ThemeOverlayController): CoreStartable

    /** Inject into MediaOutputSwitcherDialogUI. */
    @Binds
    @IntoMap
+24 −1
Original line number Diff line number Diff line
@@ -16,16 +16,23 @@

package com.android.systemui.theme;

import static android.server.Flags.enableThemeService;

import android.content.res.Resources;

import com.android.systemui.CoreStartable;
import com.android.systemui.NoOpCoreStartable;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.res.R;
import com.android.systemui.util.concurrency.SysUIConcurrencyModule;

import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ClassKey;
import dagger.multibindings.IntoMap;

import javax.inject.Named;
import javax.inject.Provider;

/** */
@Module(includes = {SysUIConcurrencyModule.class})
@@ -46,4 +53,20 @@ public class ThemeModule {
    static String provideThemePickerPackage(@Main Resources resources) {
        return resources.getString(R.string.themepicker_overlayable_package);
    }

    /**
     * Injects a {@link CoreStartable} that is responsible for applying theme and color overlays.
     * <p>This will be a {@link ThemeOverlayController} unless the {@code enableThemeService} flag
     * is enabled, in which case it will be a {@link NoOpCoreStartable}.
     */
    @Provides
    @IntoMap
    @ClassKey(ThemeOverlayController.class)
    public CoreStartable provideThemeOverlayController(
            Provider<ThemeOverlayController> themeOverlayControllerProvider) {
        if (enableThemeService()) {
            return new NoOpCoreStartable();
        }
        return themeOverlayControllerProvider.get();
    }
}
 No newline at end of file
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server;

import java.util.concurrent.Executor;

/**
 * UiModeManager local system service interface.
 *
@@ -36,4 +38,15 @@ public abstract class UiModeManagerInternal {

    /** Returns the UI mode for the given display. */
    public abstract int getDisplayUiMode(int displayId);

    /** Returns contrast level for the given user. */
    public abstract float getContrast(int userId);

    public interface ContrastListenerInternal {
        /** Called when the contrast level changes. */
        void onContrastChange(int userId, float contrastLevel);
    }

    /** Adds a contrast listener for all users. */
    public abstract void addContrastListener(ContrastListenerInternal listener, Executor executor);
}
+33 −3
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;

final class UiModeManagerService extends SystemService {
    private static final String TAG = UiModeManager.class.getSimpleName();
@@ -508,25 +509,38 @@ final class UiModeManagerService extends SystemService {
    private final ContentObserver mContrastObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            final SparseArray<Float> usersToNotify = new SparseArray<>();

            synchronized (mLock) {
                if (fixContrastAndForceInvertStateForMultiUser()) {
                    for (int i = 0; i < mUiModeManagerCallbacks.size(); i++) {
                        int userId = mUiModeManagerCallbacks.keyAt(i);
                        if (updateContrastLocked(userId)) {
                            float contrast = getContrastLocked(userId);
                            usersToNotify.append(userId, contrast);
                            mUiModeManagerCallbacks.valueAt(i).broadcast(ignoreRemoteException(
                                    callback -> callback.notifyContrastChanged(contrast)));
                        }
                    }
                    return;
                }
                if (updateContrastLocked()) {
                } else if (updateContrastLocked()) {
                    float contrast = getContrastLocked();
                    usersToNotify.append(mCurrentUser, contrast);
                    mUiModeManagerCallbacks.get(mCurrentUser, new RemoteCallbackList<>())
                            .broadcast(ignoreRemoteException(
                                    callback -> callback.notifyContrastChanged(contrast)));
                }
            }

            for (int i = 0; i < usersToNotify.size(); i++) {
                int userId = usersToNotify.keyAt(i);
                float contrast = usersToNotify.valueAt(i);
                for (Map.Entry<UiModeManagerInternal.ContrastListenerInternal, Executor> entry :
                        mLocalService.mContrastListeners.entrySet()) {
                    UiModeManagerInternal.ContrastListenerInternal listener = entry.getKey();
                    Executor executor = entry.getValue();
                    executor.execute(() -> listener.onContrastChange(userId, contrast));
                }
            }
        }
    };

@@ -2673,6 +2687,8 @@ final class UiModeManagerService extends SystemService {
    }

    public final class LocalService extends UiModeManagerInternal {
        private final HashMap<ContrastListenerInternal, Executor> mContrastListeners =
                new HashMap<>();

        @Override
        public boolean isNightMode(int displayId) {
@@ -2749,6 +2765,20 @@ final class UiModeManagerService extends SystemService {
                return uiMode;
            }
        }

        @Override
        public float getContrast(int userId) {
            synchronized (mLock) {
                return getContrastLocked(userId);
            }
        }

        @Override
        public void addContrastListener(ContrastListenerInternal listener, Executor executor) {
            synchronized (mLock) {
                mContrastListeners.put(listener, executor);
            }
        }
    }

    @VisibleForTesting(otherwise = VisibleForTesting.NONE)
+8 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ import static android.security.Flags.preventIntentRedirect;
import static android.security.Flags.preventIntentRedirectCollectNestedKeysOnServerIfNotCollected;
import static android.security.Flags.preventIntentRedirectShowToastIfNestedKeysNotCollectedRW;
import static android.security.Flags.preventIntentRedirectThrowExceptionIfNestedKeysNotCollected;
import static android.server.Flags.enableThemeService;
import static android.util.FeatureFlagUtils.SETTINGS_ENABLE_MONITOR_PHANTOM_PROCS;
import static android.view.Display.INVALID_DISPLAY;
@@ -5501,6 +5502,13 @@ public class ActivityManagerService extends IActivityManager.Stub
    /** Checks whether the home launch delay feature is enabled. */
    private boolean isHomeLaunchDelayable() {
        // ThemeManagerService is the long term solution to avoid Boot delays or regressions.
        // It replaces ThemeOverlayController and calculates themes early in the server,
        // not waiting for SystemUi
        if (enableThemeService()) {
            return false;
        }
        // This feature is disabled on Auto since it seems to add an unacceptably long boot delay
        // without even solving the underlying issue (it merely hits the timeout).
        // This feature is disabled on TV since the ThemeOverlayController is currently not present
Loading