Search in sources :

Example 76 with PowerManager

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;
}
Also used : PowerManager(android.os.PowerManager)

Example 77 with PowerManager

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);
    }
}
Also used : PowerManager(android.os.PowerManager) IPowerManager(android.os.IPowerManager) IPowerManager(android.os.IPowerManager) RemoteException(android.os.RemoteException) Settings(android.provider.Settings) ContentResolver(android.content.ContentResolver)

Example 78 with PowerManager

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!");
    }
}
Also used : PowerManager(android.os.PowerManager) RemoteException(android.os.RemoteException)

Example 79 with PowerManager

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();
}
Also used : PowerManager(android.os.PowerManager)

Example 80 with PowerManager

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());
}
Also used : PowerManager(android.os.PowerManager)

Aggregations

PowerManager (android.os.PowerManager)289 IntentFilter (android.content.IntentFilter)50 Intent (android.content.Intent)44 Handler (android.os.Handler)33 RemoteException (android.os.RemoteException)31 PendingIntent (android.app.PendingIntent)29 HandlerThread (android.os.HandlerThread)26 Context (android.content.Context)24 IPowerManager (android.os.IPowerManager)21 View (android.view.View)19 Resources (android.content.res.Resources)15 AlarmManager (android.app.AlarmManager)11 SharedPreferences (android.content.SharedPreferences)11 TextView (android.widget.TextView)11 NotificationCompat (android.support.v4.app.NotificationCompat)10 ComponentName (android.content.ComponentName)9 KeyguardManager (android.app.KeyguardManager)8 Vibrator (android.os.Vibrator)8 MotionEvent (android.view.MotionEvent)8 ContentResolver (android.content.ContentResolver)7