use of android.os.IPowerManager in project android_packages_apps_Settings by DirtyUnicorns.
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 PhoneProfilesPlus by henrichg.
the class CmdGoToSleep method run.
private static boolean run() {
try {
IPowerManager adapter = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
adapter.goToSleep(SystemClock.uptimeMillis(), 0, 0);
return true;
} catch (Throwable e) {
return false;
}
}
use of android.os.IPowerManager in project android_packages_apps_Settings by LineageOS.
the class BrightnessButton method toggleState.
/**
* Increases or decreases the brightness.
*
* @param context
*/
public void toggleState(Context context) {
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (power != null) {
int brightness = getNextBrightnessValue(context);
ContentResolver contentResolver = context.getContentResolver();
if (brightness == AUTO_BACKLIGHT) {
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
} else {
if (isAutomaticModeSupported(context)) {
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
}
power.setBacklightBrightness(brightness);
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
}
}
} catch (RemoteException e) {
Log.d(SettingsAppWidgetProvider.TAG, "toggleBrightness: " + e);
}
}
use of android.os.IPowerManager in project platform_frameworks_base by android.
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 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);
}
}
Aggregations