FileDocCategorySizeDatePackage
Sandman.javaAPI DocAndroid 5.1 API4874Thu Mar 12 22:22:10 GMT 2015android.service.dreams

Sandman

public final class Sandman extends Object
Internal helper for launching dreams to ensure consistency between the UiModeManagerService system service and the Somnambulator activity.
hide

Fields Summary
private static final String
TAG
private static final android.content.ComponentName
SOMNAMBULATOR_COMPONENT
Constructors Summary
private Sandman()



    // The sandman is eternal.  No one instantiates him.
      
    
Methods Summary
private static booleanisScreenSaverActivatedOnDock(android.content.Context context)

        int def = context.getResources().getBoolean(
                com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault) ? 1 : 0;
        return Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, def,
                UserHandle.USER_CURRENT) != 0;
    
private static booleanisScreenSaverEnabled(android.content.Context context)

        int def = context.getResources().getBoolean(
                com.android.internal.R.bool.config_dreamsEnabledByDefault) ? 1 : 0;
        return Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.SCREENSAVER_ENABLED, def,
                UserHandle.USER_CURRENT) != 0;
    
public static booleanshouldStartDockApp(android.content.Context context, android.content.Intent intent)
Returns true if the specified dock app intent should be started. False if we should dream instead, if appropriate.

        ComponentName name = intent.resolveActivity(context.getPackageManager());
        return name != null && !name.equals(SOMNAMBULATOR_COMPONENT);
    
private static voidstartDream(android.content.Context context, boolean docked)

        try {
            IDreamManager dreamManagerService = IDreamManager.Stub.asInterface(
                    ServiceManager.getService(DreamService.DREAM_SERVICE));
            if (dreamManagerService != null && !dreamManagerService.isDreaming()) {
                if (docked) {
                    Slog.i(TAG, "Activating dream while docked.");

                    // Wake up.
                    // The power manager will wake up the system automatically when it starts
                    // receiving power from a dock but there is a race between that happening
                    // and the UI mode manager starting a dream.  We want the system to already
                    // be awake by the time this happens.  Otherwise the dream may not start.
                    PowerManager powerManager =
                            (PowerManager)context.getSystemService(Context.POWER_SERVICE);
                    powerManager.wakeUp(SystemClock.uptimeMillis());
                } else {
                    Slog.i(TAG, "Activating dream by user request.");
                }

                // Dream.
                dreamManagerService.dream();
            }
        } catch (RemoteException ex) {
            Slog.e(TAG, "Could not start dream when docked.", ex);
        }
    
public static voidstartDreamByUserRequest(android.content.Context context)
Starts a dream manually.

        startDream(context, false);
    
public static voidstartDreamWhenDockedIfAppropriate(android.content.Context context)
Starts a dream when docked if the system has been configured to do so, otherwise does nothing.

        if (!isScreenSaverEnabled(context)
                || !isScreenSaverActivatedOnDock(context)) {
            Slog.i(TAG, "Dreams currently disabled for docks.");
            return;
        }

        startDream(context, true);