Search in sources :

Example 1 with IPowerManager

use of android.os.IPowerManager in project android_frameworks_base by ParanoidAndroid.

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);
    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, false);
                }
            } catch (RemoteException e) {
            }
        }
    };
    thr.start();
    finish();
    // Wait for us to tell the power manager to shutdown.
    try {
        thr.join();
    } catch (InterruptedException e) {
    }
}
Also used : IPowerManager(android.os.IPowerManager) Intent(android.content.Intent) RemoteException(android.os.RemoteException) ShutdownThread(com.android.server.power.ShutdownThread)

Example 2 with IPowerManager

use of android.os.IPowerManager in project android_frameworks_base by ParanoidAndroid.

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

Example 3 with IPowerManager

use of android.os.IPowerManager in project android_frameworks_base by ResurrectionRemix.

the class NightDisplayService method setBrightness.

private void setBrightness(boolean activated) {
    if (activated) {
        updateBrightnessModeValues();
    }
    if (customVal == 0) {
        return;
    }
    try {
        IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
        if (power != null) {
            if (mAutomaticBrightness) {
                power.setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(autoVal);
                AsyncTask.execute(new Runnable() {

                    public void run() {
                        if (activated) {
                            Settings.System.putFloatForUser(getContext().getContentResolver(), Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, autoVal, UserHandle.USER_CURRENT);
                        } else {
                            float userAutoVal = Settings.Secure.getFloatForUser(getContext().getContentResolver(), Settings.Secure.NIGHT_AUTOBRIGHTNESS_USERVALUE, 0, UserHandle.USER_CURRENT);
                            Settings.System.putFloatForUser(getContext().getContentResolver(), Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, userAutoVal, UserHandle.USER_CURRENT);
                        }
                    }
                });
            } else {
                power.setTemporaryScreenBrightnessSettingOverride(manualVal);
                AsyncTask.execute(new Runnable() {

                    @Override
                    public void run() {
                        if (activated) {
                            Settings.System.putIntForUser(getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, manualVal, UserHandle.USER_CURRENT);
                        } else {
                            int userManualVal = Settings.Secure.getIntForUser(getContext().getContentResolver(), Settings.Secure.NIGHT_MANBRIGHTNESS_USERVALUE, 0, UserHandle.USER_CURRENT);
                            Settings.System.putIntForUser(getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, userManualVal, UserHandle.USER_CURRENT);
                        }
                    }
                });
            }
        }
    } catch (RemoteException e) {
        Slog.w(TAG, "Setting Brightness failed: " + e);
    }
}
Also used : IPowerManager(android.os.IPowerManager) RemoteException(android.os.RemoteException)

Example 4 with IPowerManager

use of android.os.IPowerManager in project android_frameworks_base by ResurrectionRemix.

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);
    }
}
Also used : IPowerManager(android.os.IPowerManager) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 5 with IPowerManager

use of android.os.IPowerManager in project android_frameworks_base by ResurrectionRemix.

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

Aggregations

IPowerManager (android.os.IPowerManager)43 RemoteException (android.os.RemoteException)41 ContentResolver (android.content.ContentResolver)8 PowerManager (android.os.PowerManager)7 Settings (android.provider.Settings)7 Intent (android.content.Intent)6 Point (android.graphics.Point)3 ShutdownThread (com.android.server.power.ShutdownThread)1