use of android.os.IPowerManager in project android_frameworks_base by ResurrectionRemix.
the class Watchdog method rebootSystem.
/**
* 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) {
}
}
use of android.os.IPowerManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsAppWidgetProvider method toggleBrightness.
/**
* Increases or decreases the brightness.
*
* @param context
*/
private void toggleBrightness(Context context) {
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (power != null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
ContentResolver cr = context.getContentResolver();
int brightness = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
int brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
//Only get brightness setting if available
if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
brightnessMode = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE);
}
// Technically, not a toggle...
if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
brightness = pm.getMinimumScreenBrightnessSetting();
brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
} else if (brightness < pm.getDefaultScreenBrightnessSetting()) {
brightness = pm.getDefaultScreenBrightnessSetting();
} else if (brightness < pm.getMaximumScreenBrightnessSetting()) {
brightness = pm.getMaximumScreenBrightnessSetting();
} else {
brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
brightness = pm.getMinimumScreenBrightnessSetting();
}
if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
// Set screen brightness mode (automatic or manual)
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, brightnessMode);
} else {
// Make sure we set the brightness if automatic mode isn't available
brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
}
if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
power.setTemporaryScreenBrightnessSettingOverride(brightness);
Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
}
}
} catch (RemoteException e) {
Log.d(TAG, "toggleBrightness: " + e);
} catch (Settings.SettingNotFoundException e) {
Log.d(TAG, "toggleBrightness: " + e);
}
}
use of android.os.IPowerManager in project android_frameworks_base by ResurrectionRemix.
the class ShutdownActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
mReboot = Intent.ACTION_REBOOT.equals(intent.getAction());
mConfirm = intent.getBooleanExtra(Intent.EXTRA_KEY_CONFIRM, false);
mUserRequested = intent.getBooleanExtra(Intent.EXTRA_USER_REQUESTED_SHUTDOWN, false);
Slog.i(TAG, "onCreate(): confirm=" + mConfirm);
Thread thr = new Thread("ShutdownActivity") {
@Override
public void run() {
IPowerManager pm = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
try {
if (mReboot) {
pm.reboot(mConfirm, null, false);
} else {
pm.shutdown(mConfirm, mUserRequested ? PowerManager.SHUTDOWN_USER_REQUESTED : null, false);
}
} catch (RemoteException e) {
}
}
};
thr.start();
finish();
// Wait for us to tell the power manager to shutdown.
try {
thr.join();
} catch (InterruptedException e) {
}
}
use of android.os.IPowerManager in project android_frameworks_base by DirtyUnicorns.
the class ShellUiAutomatorBridge method isScreenOn.
@Override
public boolean isScreenOn() {
IPowerManager pm = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
boolean ret = false;
try {
ret = pm.isInteractive();
} catch (RemoteException e) {
Log.e(LOG_TAG, "Error getting screen status", e);
throw new RuntimeException(e);
}
return ret;
}
use of android.os.IPowerManager in project android_frameworks_base by DirtyUnicorns.
the class BrightnessLimit method onClick.
public void onClick(View v) {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (power != null) {
try {
power.setTemporaryScreenBrightnessSettingOverride(0);
} catch (RemoteException darn) {
}
}
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0);
}
Aggregations