Search in sources :

Example 26 with PowerManager

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

the class ConnectivityManagerTestBase method turnScreenOff.

// Turn screen off
protected void turnScreenOff() {
    logv("Turn screen off");
    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    pm.goToSleep(SystemClock.uptimeMillis());
}
Also used : PowerManager(android.os.PowerManager)

Example 27 with PowerManager

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

the class JobServiceContext method onServiceConnected.

/**
     * We acquire/release a wakelock on onServiceConnected/unbindService. This mirrors the work
     * we intend to send to the client - we stop sending work when the service is unbound so until
     * then we keep the wakelock.
     * @param name The concrete component name of the service that has been connected.
     * @param service The IBinder of the Service's communication channel,
     */
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    JobStatus runningJob;
    synchronized (mLock) {
        // This isn't strictly necessary b/c the JobServiceHandler is running on the main
        // looper and at this point we can't get any binder callbacks from the client. Better
        // safe than sorry.
        runningJob = mRunningJob;
    }
    if (runningJob == null || !name.equals(runningJob.getServiceComponent())) {
        mCallbackHandler.obtainMessage(MSG_SHUTDOWN_EXECUTION).sendToTarget();
        return;
    }
    this.service = IJobService.Stub.asInterface(service);
    final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, runningJob.getTag());
    wl.setWorkSource(new WorkSource(runningJob.getSourceUid()));
    wl.setReferenceCounted(false);
    wl.acquire();
    synchronized (mLock) {
        // explicitly fast-forward the release if we're in that situation.
        if (mWakeLock != null) {
            Slog.w(TAG, "Bound new job " + runningJob + " but live wakelock " + mWakeLock + " tag=" + mWakeLock.getTag());
            mWakeLock.release();
        }
        mWakeLock = wl;
    }
    mCallbackHandler.obtainMessage(MSG_SERVICE_BOUND).sendToTarget();
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) PowerManager(android.os.PowerManager) WorkSource(android.os.WorkSource)

Example 28 with PowerManager

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

the class MediaPlayer method setWakeMode.

/**
     * Set the low-level power management behavior for this MediaPlayer.  This
     * can be used when the MediaPlayer is not playing through a SurfaceHolder
     * set with {@link #setDisplay(SurfaceHolder)} and thus can use the
     * high-level {@link #setScreenOnWhilePlaying(boolean)} feature.
     *
     * <p>This function has the MediaPlayer access the low-level power manager
     * service to control the device's power usage while playing is occurring.
     * The parameter is a combination of {@link android.os.PowerManager} wake flags.
     * Use of this method requires {@link android.Manifest.permission#WAKE_LOCK}
     * permission.
     * By default, no attempt is made to keep the device awake during playback.
     *
     * @param context the Context to use
     * @param mode    the power/wake mode to set
     * @see android.os.PowerManager
     */
public void setWakeMode(Context context, int mode) {
    boolean washeld = false;
    /* Disable persistant wakelocks in media player based on property */
    if (SystemProperties.getBoolean("audio.offload.ignore_setawake", false) == true) {
        Log.w(TAG, "IGNORING setWakeMode " + mode);
        return;
    }
    if (mWakeLock != null) {
        if (mWakeLock.isHeld()) {
            washeld = true;
            mWakeLock.release();
        }
        mWakeLock = null;
    }
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, MediaPlayer.class.getName());
    mWakeLock.setReferenceCounted(false);
    if (washeld) {
        mWakeLock.acquire();
    }
}
Also used : PowerManager(android.os.PowerManager)

Example 29 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 30 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)

Aggregations

PowerManager (android.os.PowerManager)598 Context (android.content.Context)112 Handler (android.os.Handler)112 Intent (android.content.Intent)93 IntentFilter (android.content.IntentFilter)72 PendingIntent (android.app.PendingIntent)46 RemoteException (android.os.RemoteException)37 IPowerManager (android.os.IPowerManager)33 SuppressLint (android.annotation.SuppressLint)30 View (android.view.View)27 IOException (java.io.IOException)27 ContentResolver (android.content.ContentResolver)26 HandlerThread (android.os.HandlerThread)26 SharedPreferences (android.content.SharedPreferences)23 KeyguardManager (android.app.KeyguardManager)18 ComponentName (android.content.ComponentName)18 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 PackageManager (android.content.pm.PackageManager)17 Uri (android.net.Uri)16