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

Commit 395ff008 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Read "showClockAndComplications" metadata."

parents d965b9f5 30711f85
Loading
Loading
Loading
Loading
+40 −4
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent;

import com.android.internal.R;
import com.android.internal.util.DumpUtils;

import org.xmlpull.v1.XmlPullParser;
@@ -257,13 +258,16 @@ public class DreamService extends Service implements Window.Callback {
            mRequests = new ArrayDeque<>();
        }

        public void bind(Context context, @Nullable ComponentName overlayService) {
        public void bind(Context context, @Nullable ComponentName overlayService,
                ComponentName dreamService) {
            if (overlayService == null) {
                return;
            }

            final Intent overlayIntent = new Intent();
            overlayIntent.setComponent(overlayService);
            overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
                    fetchShouldShowComplications(context, dreamService));

            context.bindService(overlayIntent,
                    this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
@@ -985,7 +989,8 @@ public class DreamService extends Service implements Window.Callback {

        // Connect to the overlay service if present.
        if (!mWindowless) {
            mOverlayConnection.bind(this, intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT));
            mOverlayConnection.bind(this, intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT),
                    new ComponentName(this, getClass()));
        }

        return mDreamServiceWrapper;
@@ -1117,7 +1122,9 @@ public class DreamService extends Service implements Window.Callback {
                convertToComponentName(rawMetadata.getString(
                        com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo),
                rawMetadata.getDrawable(
                        com.android.internal.R.styleable.Dream_previewImage));
                        com.android.internal.R.styleable.Dream_previewImage),
                rawMetadata.getBoolean(R.styleable.Dream_showClockAndComplications,
                        DEFAULT_SHOW_COMPLICATIONS));
        rawMetadata.recycle();
        return metadata;
    }
@@ -1336,6 +1343,30 @@ public class DreamService extends Service implements Window.Callback {
        return (oldFlags&~mask) | (flags&mask);
    }

    /**
     * Fetches metadata of the dream indicated by the ${@link ComponentName}, and returns whether
     * the dream should show complications on the overlay. If not defined, returns
     * ${@link DreamService#DEFAULT_SHOW_COMPLICATIONS}.
     */
    private static boolean fetchShouldShowComplications(Context context,
            ComponentName componentName) {
        final PackageManager pm = context.getPackageManager();

        try {
            final ServiceInfo si = pm.getServiceInfo(componentName,
                    PackageManager.ComponentInfoFlags.of(PackageManager.GET_META_DATA));
            final DreamMetadata metadata = getDreamMetadata(context, si);

            if (metadata != null) {
                return metadata.showComplications;
            }
        } catch (PackageManager.NameNotFoundException e) {
            if (DEBUG) Log.w(TAG, "cannot find component " + componentName.flattenToShortString());
        }

        return DEFAULT_SHOW_COMPLICATIONS;
    }

    @Override
    protected void dump(final FileDescriptor fd, PrintWriter pw, final String[] args) {
        DumpUtils.dumpAsync(mHandler, (pw1, prefix) -> dumpOnHandler(fd, pw1, args), pw, "", 1000);
@@ -1409,9 +1440,14 @@ public class DreamService extends Service implements Window.Callback {
        @Nullable
        public final Drawable previewImage;

        DreamMetadata(ComponentName settingsActivity, Drawable previewImage) {
        @Nullable
        public final boolean showComplications;

        DreamMetadata(ComponentName settingsActivity, Drawable previewImage,
                boolean showComplications) {
            this.settingsActivity = settingsActivity;
            this.previewImage = previewImage;
            this.showComplications = showComplications;
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -15,4 +15,5 @@
  -->

<dream xmlns:android="http://schemas.android.com/apk/res/android"
       android:settingsActivity="com.android.server.dreams/.TestDreamSettingsActivity" />
       android:settingsActivity="com.android.server.dreams/.TestDreamSettingsActivity"
       android:showClockAndComplications="false" />
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.dreams;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import android.content.ComponentName;
import android.content.Context;
@@ -49,6 +50,7 @@ public class DreamServiceTest {

            assertEquals(0, metadata.settingsActivity.compareTo(
                    ComponentName.unflattenFromString(testSettingsActivity)));
            assertFalse(metadata.showComplications);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }