use of android.os.PowerManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatterySaverModeVoiceActivity method onVoiceSettingInteraction.
@Override
protected boolean onVoiceSettingInteraction(Intent intent) {
if (intent.hasExtra(EXTRA_BATTERY_SAVER_MODE_ENABLED)) {
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (powerManager.setPowerSaveMode(intent.getBooleanExtra(EXTRA_BATTERY_SAVER_MODE_ENABLED, false))) {
notifySuccess(null);
} else {
Log.v(TAG, "Unable to set power mode");
notifyFailure(null);
}
} else {
Log.v(TAG, "Missing battery saver mode extra");
}
return true;
}
use of android.os.PowerManager 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.PowerManager in project android_frameworks_base by ResurrectionRemix.
the class FingerprintManager method addLockoutResetCallback.
/**
* @hide
*/
public void addLockoutResetCallback(final LockoutResetCallback callback) {
if (mService != null) {
try {
final PowerManager powerManager = mContext.getSystemService(PowerManager.class);
mService.addLockoutResetCallback(new IFingerprintServiceLockoutResetCallback.Stub() {
@Override
public void onLockoutReset(long deviceId) throws RemoteException {
final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lockoutResetCallback");
wakeLock.acquire();
mHandler.post(new Runnable() {
@Override
public void run() {
try {
callback.onLockoutReset();
} finally {
wakeLock.release();
}
}
});
}
});
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} else {
Log.w(TAG, "addLockoutResetCallback(): Service not connected!");
}
}
use of android.os.PowerManager in project android_frameworks_base by ResurrectionRemix.
the class GeofenceHardwareImpl method acquireWakeLock.
private void acquireWakeLock() {
if (mWakeLock == null) {
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
mWakeLock.acquire();
}
use of android.os.PowerManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatterySaverCondition method refreshState.
@Override
public void refreshState() {
PowerManager powerManager = mManager.getContext().getSystemService(PowerManager.class);
setActive(powerManager.isPowerSaveMode());
}
Aggregations