use of android.os.IPowerManager in project android_frameworks_base by crdroidandroid.
the class PhoneStatusBar method adjustBrightness.
private void adjustBrightness(int x) {
mBrightnessChanged = true;
float raw = ((float) x) / mScreenWidth;
// Add a padding to the brightness control on both sides to
// make it easier to reach min/max brightness
float padded = Math.min(1.0f - BRIGHTNESS_CONTROL_PADDING, Math.max(BRIGHTNESS_CONTROL_PADDING, raw));
float value = (padded - BRIGHTNESS_CONTROL_PADDING) / (1 - (2.0f * BRIGHTNESS_CONTROL_PADDING));
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (power != null) {
if (mAutomaticBrightness) {
float adj = (2 * value) - 1;
adj = Math.max(adj, -1);
adj = Math.min(adj, 1);
final float val = adj;
power.setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(val);
AsyncTask.execute(new Runnable() {
public void run() {
Settings.System.putFloatForUser(mContext.getContentResolver(), Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, val, UserHandle.USER_CURRENT);
}
});
} else {
int newBrightness = mMinBrightness + (int) Math.round(value * (android.os.PowerManager.BRIGHTNESS_ON - mMinBrightness));
newBrightness = Math.min(newBrightness, android.os.PowerManager.BRIGHTNESS_ON);
newBrightness = Math.max(newBrightness, mMinBrightness);
final int val = newBrightness;
power.setTemporaryScreenBrightnessSettingOverride(val);
AsyncTask.execute(new Runnable() {
@Override
public void run() {
Settings.System.putIntForUser(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, val, UserHandle.USER_CURRENT);
}
});
}
}
} catch (RemoteException e) {
Log.w(TAG, "Setting Brightness failed: " + e);
}
}
use of android.os.IPowerManager in project android_frameworks_base by AOSPA.
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 MetaKeyKeyListener method adjustMetaAfterKeypress.
/**
* Call this method after you handle a keypress so that the meta
* state will be reset to unshifted (if it is not still down)
* or primed to be reset to unshifted (once it is released).
*/
public static void adjustMetaAfterKeypress(Spannable content) {
adjust(content, CAP);
adjust(content, ALT);
adjust(content, SYM);
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (getMetaState(content, META_SHIFT_ON) <= 0)
power.setKeyboardLight(false, 1);
if (getMetaState(content, META_ALT_ON) <= 0)
power.setKeyboardLight(false, 2);
} catch (RemoteException doe) {
}
}
use of android.os.IPowerManager in project android_frameworks_base by DirtyUnicorns.
the class MetaKeyKeyListener method onKeyDown.
/**
* Handles presses of the meta keys.
*/
public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
press(content, CAP);
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
int state = content.getSpanFlags(CAP);
if (state == PRESSED || state == LOCKED) {
power.setKeyboardLight(true, 1);
} else {
power.setKeyboardLight(false, 1);
}
} catch (RemoteException doe) {
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT || keyCode == KeyEvent.KEYCODE_NUM) {
press(content, ALT);
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
int state = content.getSpanFlags(ALT);
if (state == PRESSED || state == LOCKED) {
power.setKeyboardLight(true, 2);
} else {
power.setKeyboardLight(false, 2);
}
} catch (RemoteException doe) {
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_SYM) {
press(content, SYM);
return true;
}
// no super to call through to
return false;
}
use of android.os.IPowerManager in project android_packages_apps_Settings by LineageOS.
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);
}
}
Aggregations