Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.os;
     18 
     19 import android.view.Display;
     20 
     21 /**
     22  * Power manager local system service interface.
     23  *
     24  * @hide Only for use within the system server.
     25  */
     26 public abstract class PowerManagerInternal {
     27     /**
     28      * Wakefulness: The device is asleep.  It can only be awoken by a call to wakeUp().
     29      * The screen should be off or in the process of being turned off by the display controller.
     30      * The device typically passes through the dozing state first.
     31      */
     32     public static final int WAKEFULNESS_ASLEEP = 0;
     33 
     34     /**
     35      * Wakefulness: The device is fully awake.  It can be put to sleep by a call to goToSleep().
     36      * When the user activity timeout expires, the device may start dreaming or go to sleep.
     37      */
     38     public static final int WAKEFULNESS_AWAKE = 1;
     39 
     40     /**
     41      * Wakefulness: The device is dreaming.  It can be awoken by a call to wakeUp(),
     42      * which ends the dream.  The device goes to sleep when goToSleep() is called, when
     43      * the dream ends or when unplugged.
     44      * User activity may brighten the screen but does not end the dream.
     45      */
     46     public static final int WAKEFULNESS_DREAMING = 2;
     47 
     48     /**
     49      * Wakefulness: The device is dozing.  It is almost asleep but is allowing a special
     50      * low-power "doze" dream to run which keeps the display on but lets the application
     51      * processor be suspended.  It can be awoken by a call to wakeUp() which ends the dream.
     52      * The device fully goes to sleep if the dream cannot be started or ends on its own.
     53      */
     54     public static final int WAKEFULNESS_DOZING = 3;
     55 
     56 
     57     /**
     58      * Power hint:
     59      * Interaction: The user is interacting with the device. The corresponding data field must be
     60      * the expected duration of the fling, or 0 if unknown.
     61      *
     62      * Sustained Performance Mode: Enable/Disables Sustained Performance Mode.
     63      *
     64      * These must be kept in sync with the values in hardware/libhardware/include/hardware/power.h
     65      */
     66     public static final int POWER_HINT_INTERACTION = 2;
     67     public static final int POWER_HINT_SUSTAINED_PERFORMANCE_MODE = 6;
     68 
     69     public static String wakefulnessToString(int wakefulness) {
     70         switch (wakefulness) {
     71             case WAKEFULNESS_ASLEEP:
     72                 return "Asleep";
     73             case WAKEFULNESS_AWAKE:
     74                 return "Awake";
     75             case WAKEFULNESS_DREAMING:
     76                 return "Dreaming";
     77             case WAKEFULNESS_DOZING:
     78                 return "Dozing";
     79             default:
     80                 return Integer.toString(wakefulness);
     81         }
     82     }
     83 
     84     /**
     85      * Returns true if the wakefulness state represents an interactive state
     86      * as defined by {@link android.os.PowerManager#isInteractive}.
     87      */
     88     public static boolean isInteractive(int wakefulness) {
     89         return wakefulness == WAKEFULNESS_AWAKE || wakefulness == WAKEFULNESS_DREAMING;
     90     }
     91 
     92     /**
     93      * Used by the window manager to override the screen brightness based on the
     94      * current foreground activity.
     95      *
     96      * This method must only be called by the window manager.
     97      *
     98      * @param brightness The overridden brightness, or -1 to disable the override.
     99      */
    100     public abstract void setScreenBrightnessOverrideFromWindowManager(int brightness);
    101 
    102     /**
    103      * Used by the window manager to override the button brightness based on the
    104      * current foreground activity.
    105      *
    106      * This method must only be called by the window manager.
    107      *
    108      * @param brightness The overridden brightness, or -1 to disable the override.
    109      */
    110     public abstract void setButtonBrightnessOverrideFromWindowManager(int brightness);
    111 
    112     /**
    113      * Used by the window manager to override the user activity timeout based on the
    114      * current foreground activity.  It can only be used to make the timeout shorter
    115      * than usual, not longer.
    116      *
    117      * This method must only be called by the window manager.
    118      *
    119      * @param timeoutMillis The overridden timeout, or -1 to disable the override.
    120      */
    121     public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);
    122 
    123     /**
    124      * Used by the window manager to tell the power manager that the user is no longer actively
    125      * using the device.
    126      */
    127     public abstract void setUserInactiveOverrideFromWindowManager();
    128 
    129     /**
    130      * Used by device administration to set the maximum screen off timeout.
    131      *
    132      * This method must only be called by the device administration policy manager.
    133      */
    134     public abstract void setMaximumScreenOffTimeoutFromDeviceAdmin(int timeMs);
    135 
    136     /**
    137      * Used by the dream manager to override certain properties while dozing.
    138      *
    139      * @param screenState The overridden screen state, or {@link Display#STATE_UNKNOWN}
    140      * to disable the override.
    141      * @param screenBrightness The overridden screen brightness, or
    142      * {@link PowerManager#BRIGHTNESS_DEFAULT} to disable the override.
    143      */
    144     public abstract void setDozeOverrideFromDreamManager(
    145             int screenState, int screenBrightness);
    146 
    147     public abstract boolean getLowPowerModeEnabled();
    148 
    149     public abstract void registerLowPowerModeObserver(LowPowerModeListener listener);
    150 
    151     public interface LowPowerModeListener {
    152         public void onLowPowerModeChanged(boolean enabled);
    153     }
    154 
    155     public abstract boolean setDeviceIdleMode(boolean enabled);
    156 
    157     public abstract boolean setLightDeviceIdleMode(boolean enabled);
    158 
    159     public abstract void setDeviceIdleWhitelist(int[] appids);
    160 
    161     public abstract void setDeviceIdleTempWhitelist(int[] appids);
    162 
    163     public abstract void updateUidProcState(int uid, int procState);
    164 
    165     public abstract void uidGone(int uid);
    166 
    167     public abstract void powerHint(int hintId, int data);
    168 }
    169