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

Commit 1153b780 authored by Wu Ahan's avatar Wu Ahan Committed by Android (Google) Code Review
Browse files

Merge "Enable AOD image wallpaper and apply aod mask view."

parents 71839b73 723a80e4
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import android.provider.Settings;
import android.text.TextUtils;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Util class to get feature flag information.
@@ -37,8 +39,11 @@ public class FeatureFlagUtils {
    public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid";
    public static final String SAFETY_HUB = "settings_safety_hub";
    public static final String SCREENRECORD_LONG_PRESS = "settings_screenrecord_long_press";
    public static final String AOD_IMAGEWALLPAPER_ENABLED = "settings_aod_imagewallpaper_enabled";

    private static final Map<String, String> DEFAULT_FLAGS;
    private static final Set<String> OBSERVABLE_FLAGS;

    static {
        DEFAULT_FLAGS = new HashMap<>();
        DEFAULT_FLAGS.put("settings_audio_switcher", "true");
@@ -54,6 +59,10 @@ public class FeatureFlagUtils {
        DEFAULT_FLAGS.put(HEARING_AID_SETTINGS, "false");
        DEFAULT_FLAGS.put(SAFETY_HUB, "false");
        DEFAULT_FLAGS.put(SCREENRECORD_LONG_PRESS, "false");
        DEFAULT_FLAGS.put(AOD_IMAGEWALLPAPER_ENABLED, "false");

        OBSERVABLE_FLAGS = new HashSet<>();
        OBSERVABLE_FLAGS.add(AOD_IMAGEWALLPAPER_ENABLED);
    }

    /**
@@ -90,6 +99,16 @@ public class FeatureFlagUtils {
     */
    public static void setEnabled(Context context, String feature, boolean enabled) {
        SystemProperties.set(FFLAG_OVERRIDE_PREFIX + feature, enabled ? "true" : "false");

        // Also update Settings.Global if needed so that we can observe it via observer.
        if (OBSERVABLE_FLAGS.contains(feature)) {
            setObservableFlag(context, feature, enabled);
        }
    }

    private static void setObservableFlag(Context context, String feature, boolean enabled) {
        Settings.Global.putString(
                context.getContentResolver(), feature, enabled ? "true" : "false");
    }

    /**
+8 −0
Original line number Diff line number Diff line
@@ -43,6 +43,14 @@
                   android:visibility="invisible" />
    </com.android.systemui.statusbar.BackDropView>

    <com.android.systemui.wallpaper.AodMaskView
        android:id="@+id/aod_mask"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:importantForAccessibility="no"
        android:visibility="invisible"
        sysui:ignoreRightInset="true" />

    <com.android.systemui.statusbar.ScrimView
        android:id="@+id/scrim_behind"
        android:layout_width="match_parent"
+5 −0
Original line number Diff line number Diff line
@@ -109,5 +109,10 @@

    <!-- Optional cancel button on Keyguard -->
    <item type="id" name="cancel_button"/>

    <!-- AodMaskView transition tag -->
    <item type="id" name="aod_mask_transition_progress_tag" />
    <item type="id" name="aod_mask_transition_progress_end_tag" />
    <item type="id" name="aod_mask_transition_progress_start_tag" />
</resources>
+8 −0
Original line number Diff line number Diff line
@@ -219,6 +219,14 @@ public enum ScrimState {
    public void prepare(ScrimState previousState) {
    }

    /**
     * Check if lockscreen wallpaper or music album art exists.
     * @return true if lockscreen wallpaper or music album art exists.
     */
    public boolean hasBackdrop() {
        return mHasBackdrop;
    }

    public int getIndex() {
        return mIndex;
    }
+41 −1
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
@@ -98,6 +99,7 @@ import android.service.dreams.IDreamManager;
import android.service.notification.StatusBarNotification;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.FeatureFlagUtils;
import android.util.Log;
import android.util.Slog;
import android.view.Display;
@@ -478,8 +480,13 @@ public class StatusBar extends SystemUI implements DemoMode,
            WallpaperInfo info = wallpaperManager.getWallpaperInfo(UserHandle.USER_CURRENT);
            final boolean deviceSupportsAodWallpaper = mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_dozeSupportsAodWallpaper);
            final boolean aodImageWallpaperEnabled = FeatureFlagUtils.isEnabled(mContext,
                    FeatureFlagUtils.AOD_IMAGEWALLPAPER_ENABLED);
            updateAodMaskVisibility(deviceSupportsAodWallpaper && aodImageWallpaperEnabled);
            // If WallpaperInfo is null, it must be ImageWallpaper.
            final boolean supportsAmbientMode = deviceSupportsAodWallpaper
                    && info != null && info.supportsAmbientMode();
                    && (info == null && aodImageWallpaperEnabled
                        || info != null && info.supportsAmbientMode());

            mStatusBarWindowController.setWallpaperSupportsAmbientMode(supportsAmbientMode);
            mScrimController.setWallpaperSupportsAmbientMode(supportsAmbientMode);
@@ -581,6 +588,7 @@ public class StatusBar extends SystemUI implements DemoMode,
    protected NotificationPresenter mPresenter;
    private NotificationActivityStarter mNotificationActivityStarter;
    private boolean mPulsing;
    private ContentObserver mFeatureFlagObserver;

    @Override
    public void onActiveStateChanged(int code, int uid, String packageName, boolean active) {
@@ -697,6 +705,9 @@ public class StatusBar extends SystemUI implements DemoMode,
        mContext.registerReceiverAsUser(mWallpaperChangedReceiver, UserHandle.ALL,
                wallpaperChangedFilter, null /* broadcastPermission */, null /* scheduler */);
        mWallpaperChangedReceiver.onReceive(mContext, null);
        mFeatureFlagObserver = new FeatureFlagObserver(
                FeatureFlagUtils.AOD_IMAGEWALLPAPER_ENABLED /* feature */,
                () -> mWallpaperChangedReceiver.onReceive(mContext, null) /* callback */);

        // Set up the initial notification state. This needs to happen before CommandQueue.disable()
        setUpPresenter();
@@ -4415,4 +4426,33 @@ public class StatusBar extends SystemUI implements DemoMode,
    public @TransitionMode int getStatusBarMode() {
        return mStatusBarMode;
    }

    private void updateAodMaskVisibility(boolean supportsAodWallpaper) {
        View mask = mStatusBarWindow.findViewById(R.id.aod_mask);
        if (mask != null) {
            mask.setVisibility(supportsAodWallpaper ? View.VISIBLE : View.INVISIBLE);
        }
    }

    private final class FeatureFlagObserver extends ContentObserver {
        private final Runnable mCallback;

        FeatureFlagObserver(String feature, Runnable callback) {
            this(null, feature, callback);
        }

        private FeatureFlagObserver(Handler handler, String feature, Runnable callback) {
            super(handler);
            mCallback = callback;
            mContext.getContentResolver().registerContentObserver(
                    Settings.Global.getUriFor(feature), false, this);
        }

        @Override
        public void onChange(boolean selfChange) {
            if (mCallback != null) {
                mStatusBarWindow.post(mCallback);
            }
        }
    }
}
Loading