android.os.IPowerManager Java Examples

The following examples show how to use android.os.IPowerManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    if (service == null) {
        Log.wtf(TAG, "Failed to get power manager service.");
    }
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #2
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    if (service == null) {
        Log.wtf(TAG, "Failed to get power manager service.");
    }
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #3
Source File: Watchdog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Perform a full reboot of the system.
 */
void rebootSystem(String reason) {
    Slog.i(TAG, "Rebooting system because: " + reason);
    IPowerManager pms = (IPowerManager)ServiceManager.getService(Context.POWER_SERVICE);
    try {
        pms.reboot(false, reason, false);
    } catch (RemoteException ex) {
    }
}
 
Example #4
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException {
    IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #5
Source File: SuJavaPlugin.java    From rebootmenu with GNU General Public License v3.0 5 votes vote down vote up
private static void lockScreenWithIPowerManager() {
    Log.v(TAG, "lockScreenWithIPowerManager()");
    IPowerManager iPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
    if (iPowerManager == null) return;
    //Go to sleep reason code: Going to sleep due by application request.
    final int GO_TO_SLEEP_REASON_APPLICATION = 0;
    long uptimeMillis = SystemClock.uptimeMillis();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        iPowerManager.goToSleep(uptimeMillis, GO_TO_SLEEP_REASON_APPLICATION, 0);
    else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        iPowerManager.goToSleep(uptimeMillis, GO_TO_SLEEP_REASON_APPLICATION);
    else
        iPowerManager.goToSleep(uptimeMillis);
}
 
Example #6
Source File: SuJavaPlugin.java    From rebootmenu with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("SameParameterValue")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static void shutdownWithIPowerManager(boolean confirm, boolean wait) {
    Log.v(TAG, "shutdownWithIPowerManager(...)");
    IPowerManager iPowerManager = Objects.requireNonNull(IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        // @param reason code to pass to android_reboot() (e.g. "userrequested"), or null.
        // @hide The value to pass as the 'reason' argument to android_reboot().
        @SuppressWarnings("SpellCheckingInspection") final String SHUTDOWN_USER_REQUESTED = "userrequested";
        iPowerManager.shutdown(confirm, SHUTDOWN_USER_REQUESTED, wait);
        return;
    }
    iPowerManager.shutdown(confirm, wait);
}
 
Example #7
Source File: SettingsHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void setBrightness(int brightness) {
    try {
        IPowerManager power = IPowerManager.Stub.asInterface(
                ServiceManager.getService("power"));
        if (power != null) {
            power.setTemporaryScreenBrightnessSettingOverride(brightness);
        }
    } catch (RemoteException doe) {

    }
}
 
Example #8
Source File: SettingsHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void setBrightness(int brightness) {
    try {
        IPowerManager power = IPowerManager.Stub.asInterface(
                ServiceManager.getService("power"));
        if (power != null) {
            power.setTemporaryScreenBrightnessSettingOverride(brightness);
        }
    } catch (RemoteException doe) {

    }
}
 
Example #9
Source File: CmdGoToSleep.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private static boolean doSleep() {
    try {
        IPowerManager adapter = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); // service list | grep IPowerManager
        adapter.goToSleep(SystemClock.uptimeMillis(), 0, 0);
        return true;
    } catch (Throwable e) {
        //Log.e("CmdGoToSleep.doSleep", Log.getStackTraceString(e));
        PPApplication.recordException(e);
        return false;
    }
}
 
Example #10
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    return new PowerManager(service, ctx.mMainThread.getHandler());
}
 
Example #11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    return new PowerManager(service, ctx.mMainThread.getHandler());
}
 
Example #12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #14
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #15
Source File: PowerManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
PowerManagerShellCommand(IPowerManager service) {
    mInterface = service;
}