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

Commit 16619e7a authored by Prince Donkor's avatar Prince Donkor Committed by Android (Google) Code Review
Browse files

Merge "Adding Dream Category API" into main

parents 82bb8686 ceb4ae4c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3065,6 +3065,7 @@ package android.service.dreams {
  }

  public static final class DreamService.DreamMetadata {
    field @FlaggedApi("android.service.controls.flags.home_panel_dream") @NonNull public final int dreamCategory;
    field @Nullable public final android.graphics.drawable.Drawable previewImage;
    field @Nullable public final android.content.ComponentName settingsActivity;
    field @NonNull public final boolean showComplications;
+51 −4
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package android.service.dreams;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.annotation.FlaggedApi;
import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -47,6 +49,7 @@ import android.os.Looper;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.service.controls.flags.Flags;
import android.util.AttributeSet;
import android.util.Log;
import android.util.MathUtils;
@@ -76,6 +79,8 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.function.Consumer;

/**
@@ -217,6 +222,33 @@ public class DreamService extends Service implements Window.Callback {
     */
    public static final boolean DEFAULT_SHOW_COMPLICATIONS = false;

    /**
     * The default value for dream category
     * @hide
     */
    public static final int DREAM_CATEGORY_DEFAULT = 0;

    /**
     * Dream category for Low Light Dream
     * @hide
     */
    public static final int DREAM_CATEGORY_LOW_LIGHT = 1 << 0;

    /**
     * Dream category for Home Panel Dream
     * @hide
     */
    public static final int DREAM_CATEGORY_HOME_PANEL = 1 << 1;

    /** @hide */
    @IntDef(flag = true, prefix = {"DREAM_CATEGORY"}, value = {
        DREAM_CATEGORY_DEFAULT,
        DREAM_CATEGORY_LOW_LIGHT,
        DREAM_CATEGORY_HOME_PANEL
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface DreamCategory {}

    private final IDreamManager mDreamManager;
    private final Handler mHandler = new Handler(Looper.getMainLooper());
    private IBinder mDreamToken;
@@ -1122,12 +1154,15 @@ public class DreamService extends Service implements Window.Callback {
        try (TypedArray rawMetadata = readMetadata(pm, serviceInfo)) {
            if (rawMetadata == null) return null;
            return new DreamMetadata(
                    convertToComponentName(rawMetadata.getString(
                    convertToComponentName(
                    rawMetadata.getString(
                            com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo),
                    rawMetadata.getDrawable(
                            com.android.internal.R.styleable.Dream_previewImage),
                    rawMetadata.getBoolean(R.styleable.Dream_showClockAndComplications,
                            DEFAULT_SHOW_COMPLICATIONS));
                            DEFAULT_SHOW_COMPLICATIONS),
                    rawMetadata.getInt(R.styleable.Dream_dreamCategory, DREAM_CATEGORY_DEFAULT)
                    );
        }
    }

@@ -1543,11 +1578,23 @@ public class DreamService extends Service implements Window.Callback {
        @NonNull
        public final boolean showComplications;

        DreamMetadata(ComponentName settingsActivity, Drawable previewImage,
                boolean showComplications) {
        @NonNull
        @FlaggedApi(Flags.FLAG_HOME_PANEL_DREAM)
        public final int dreamCategory;

        DreamMetadata(
                ComponentName settingsActivity,
                Drawable previewImage,
                boolean showComplications,
                int dreamCategory) {
            this.settingsActivity = settingsActivity;
            this.previewImage = previewImage;
            this.showComplications = showComplications;
            if (Flags.homePanelDream()) {
                this.dreamCategory = dreamCategory;
            } else {
                this.dreamCategory = DREAM_CATEGORY_DEFAULT;
            }
        }
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -8988,6 +8988,14 @@
        <!-- Whether to show clock and other complications such as weather in the overlay. Default
             to true. Note that the overlay on dreams is currently only supported on tablets. -->
        <attr name="showClockAndComplications" format="boolean" />
        <!-- Dream Category to determine the type of dream. Default to default.
        @hide -->
        <attr name="dreamCategory" format="integer">
            <flag name="none" value="0x0" />
            <flag name="low_light" value="0x1" />
            <flag name="home_panel" value="0x2" />
        </attr>
    </declare-styleable>
    <!--  Use <code>trust-agent</code> as the root tag of the XML resource that
+2 −0
Original line number Diff line number Diff line
@@ -167,6 +167,8 @@
    <public name="shiftDrawingOffsetForStartOverhang" />
    <!-- @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") -->
    <public name="windowIsFrameRatePowerSavingsBalanced"/>
    <!-- @FlaggedApi("android.service.controls.flags.Flags.FLAG_HOME_PANEL_DREAM") -->
    <public name="dreamCategory"/>
  </staging-public-group>

  <staging-public-group type="id" first-id="0x01bc0000">
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class DreamBackend {
        public CharSequence description;
        public Drawable previewImage;
        public boolean supportsComplications = false;
        public int dreamCategory;

        @Override
        public String toString() {
@@ -207,6 +208,7 @@ public class DreamBackend {
                dreamInfo.settingsComponentName = dreamMetadata.settingsActivity;
                dreamInfo.previewImage = dreamMetadata.previewImage;
                dreamInfo.supportsComplications = dreamMetadata.showComplications;
                dreamInfo.dreamCategory = dreamMetadata.dreamCategory;
            }
            dreamInfos.add(dreamInfo);
        }
Loading