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

Commit 2704e9f6 authored by Darrell Shi's avatar Darrell Shi
Browse files

Implement ComplicationTypesUpdater.

The ComplicationTypesUpdater observes user settings for complication
types shown on the dream overlay, and pushes updates to the
DreamOverlayStateController.

Test: atest ComplicationTypesUpdaterTest
Test: locally on device by observing the complications update during
dream while changing complication types through adb command: adb shell settings put secure screensaver_enabled_complications [1,2,3..]
Fix: 217800355

Change-Id: I2d1e95c42a8092f79ef8db4128e970db96732509
parent dd0811a6
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -31,10 +31,8 @@ import androidx.lifecycle.ViewModelStore;
import com.android.internal.policy.PhoneWindow;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.settingslib.dream.DreamBackend;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.complication.Complication;
import com.android.systemui.dreams.complication.ComplicationUtils;
import com.android.systemui.dreams.dagger.DreamOverlayComponent;
import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;

@@ -59,7 +57,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
    // content area).
    private final DreamOverlayContainerViewController mDreamOverlayContainerViewController;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private final DreamBackend mDreamBackend;

    // A reference to the {@link Window} used to hold the dream overlay.
    private Window mWindow;
@@ -112,7 +109,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        setCurrentState(Lifecycle.State.CREATED);
        mLifecycleRegistry = component.getLifecycleRegistry();
        mDreamOverlayTouchMonitor = component.getDreamOverlayTouchMonitor();
        mDreamBackend = component.getDreamBackend();
        mDreamOverlayTouchMonitor.init();
    }

@@ -136,9 +132,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
    public void onStartDream(@NonNull WindowManager.LayoutParams layoutParams) {
        setCurrentState(Lifecycle.State.STARTED);
        mExecutor.execute(() -> {
            mStateController.setAvailableComplicationTypes(
                    ComplicationUtils.convertComplicationTypes(
                            mDreamBackend.getEnabledComplications()));
            addOverlayWindowLocked(layoutParams);
            setCurrentState(Lifecycle.State.RESUMED);
            mStateController.setOverlayActive(true);
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.systemui.dreams.complication;

import android.content.Context;
import android.database.ContentObserver;
import android.os.UserHandle;
import android.provider.Settings;

import com.android.settingslib.dream.DreamBackend;
import com.android.systemui.CoreStartable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.util.settings.SecureSettings;

import java.util.concurrent.Executor;

import javax.inject.Inject;

/**
 * {@link ComplicationTypesUpdater} observes the state of available complication types set by the
 * user, and pushes updates to {@link DreamOverlayStateController}.
 */
@SysUISingleton
public class ComplicationTypesUpdater extends CoreStartable {
    private final DreamBackend mDreamBackend;
    private final Executor mExecutor;
    private final SecureSettings mSecureSettings;

    private final DreamOverlayStateController mDreamOverlayStateController;

    @Inject
    ComplicationTypesUpdater(Context context,
            DreamBackend dreamBackend,
            @Main Executor executor,
            SecureSettings secureSettings,
            DreamOverlayStateController dreamOverlayStateController) {
        super(context);

        mDreamBackend = dreamBackend;
        mExecutor = executor;
        mSecureSettings = secureSettings;
        mDreamOverlayStateController = dreamOverlayStateController;
    }

    @Override
    public void start() {
        final ContentObserver settingsObserver = new ContentObserver(null /*handler*/) {
            @Override
            public void onChange(boolean selfChange) {
                mExecutor.execute(() -> mDreamOverlayStateController.setAvailableComplicationTypes(
                        getAvailableComplicationTypes()));
            }
        };

        mSecureSettings.registerContentObserverForUser(
                Settings.Secure.SCREENSAVER_ENABLED_COMPLICATIONS,
                settingsObserver,
                UserHandle.myUserId());
        settingsObserver.onChange(false);
    }

    /**
     * Returns complication types that are currently available by user setting.
     */
    @Complication.ComplicationType
    private int getAvailableComplicationTypes() {
        return ComplicationUtils.convertComplicationTypes(mDreamBackend.getEnabledComplications());
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@

package com.android.systemui.dreams.dagger;

import android.content.Context;

import com.android.settingslib.dream.DreamBackend;
import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule;
import com.android.systemui.dreams.touch.dagger.DreamTouchModule;

import dagger.Module;
import dagger.Provides;

/**
 * Dagger Module providing Communal-related functionality.
@@ -32,4 +36,11 @@ import dagger.Module;
            DreamOverlayComponent.class,
        })
public interface DreamModule {
    /**
     * Provides an instance of the dream backend.
     */
    @Provides
    static DreamBackend providesDreamBackend(Context context) {
        return DreamBackend.getInstance(context);
    }
}
 No newline at end of file
+0 −4
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.ViewModelStore;

import com.android.settingslib.dream.DreamBackend;
import com.android.systemui.dreams.DreamOverlayContainerViewController;
import com.android.systemui.dreams.complication.Complication;
import com.android.systemui.dreams.complication.dagger.ComplicationModule;
@@ -69,7 +68,4 @@ public interface DreamOverlayComponent {

    /** Builds a {@link DreamOverlayTouchMonitor} */
    DreamOverlayTouchMonitor getDreamOverlayTouchMonitor();

    /** Builds a ${@link DreamBackend} */
    DreamBackend getDreamBackend();
}
+0 −8
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.dreams.dagger;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.view.LayoutInflater;
@@ -28,7 +27,6 @@ import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;

import com.android.internal.util.Preconditions;
import com.android.settingslib.dream.DreamBackend;
import com.android.systemui.R;
import com.android.systemui.battery.BatteryMeterView;
import com.android.systemui.battery.BatteryMeterViewController;
@@ -149,10 +147,4 @@ public abstract class DreamOverlayModule {
    static Lifecycle providesLifecycle(LifecycleOwner lifecycleOwner) {
        return lifecycleOwner.getLifecycle();
    }

    @Provides
    @DreamOverlayComponent.DreamOverlayScope
    static DreamBackend providesDreamBackend(Context context) {
        return DreamBackend.getInstance(context);
    }
}
Loading