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

Commit ff8308d0 authored by Bryce Lee's avatar Bryce Lee
Browse files

Add TestAPI access to settings through DreamManager.

This changelist provides access to whether dreams are supported and
enabled through the DreamManager. These methods are hidden and part of
the Test API.

Bug: 215744456
Test: atest DreamServiceTest DreamManagerServiceTests
Change-Id: Ie2245429c580ad0f7a3d510b26d4001c26a8ad9c
parent 79718744
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -270,9 +270,12 @@ package android.app {
  }

  public class DreamManager {
    method public boolean areDreamsSupported();
    method @RequiresPermission(android.Manifest.permission.READ_DREAM_STATE) public boolean isDreaming();
    method public boolean isScreensaverEnabled();
    method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void setActiveDream(@Nullable android.content.ComponentName);
    method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void setDreamOverlay(@Nullable android.content.ComponentName);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setScreensaverEnabled(boolean);
    method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void startDream(@NonNull android.content.ComponentName);
    method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void stopDream();
  }
+38 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app;

import static android.Manifest.permission.WRITE_SECURE_SETTINGS;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -26,6 +28,8 @@ import android.content.ComponentName;
import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;

@@ -47,6 +51,40 @@ public class DreamManager {
        mContext = context;
    }

    /**
     * Returns whether Settings.Secure.SCREENSAVER_ENABLED is enabled.
     *
     * @hide
     */
    @TestApi
    public boolean isScreensaverEnabled() {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.SCREENSAVER_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
    }

    /**
     * Sets whether Settings.Secure.SCREENSAVER_ENABLED is enabled.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(WRITE_SECURE_SETTINGS)
    public void setScreensaverEnabled(boolean enabled) {
        Settings.Secure.putIntForUser(mContext.getContentResolver(),
                Settings.Secure.SCREENSAVER_ENABLED, enabled ? 1 : 0, UserHandle.USER_CURRENT);
    }

    /**
     * Returns whether dreams are supported.
     *
     * @hide
     */
    @TestApi
    public boolean areDreamsSupported() {
        return mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_dreamsSupported);
    }

    /**
     * Starts dream service with name "name".
     *