Search in sources :

Example 51 with PowerManager

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

the class FrameworkPerfActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set the layout for this activity.  You can find it
    // in res/layout/hello_activity.xml
    setContentView(R.layout.main);
    mFgSpinner = (Spinner) findViewById(R.id.fgspinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mAvailOpLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mFgSpinner.setAdapter(adapter);
    mFgSpinner.setOnItemSelectedListener(this);
    mBgSpinner = (Spinner) findViewById(R.id.bgspinner);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mAvailOpLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mBgSpinner.setAdapter(adapter);
    mBgSpinner.setOnItemSelectedListener(this);
    mLimitSpinner = (Spinner) findViewById(R.id.limitspinner);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mLimitLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLimitSpinner.setAdapter(adapter);
    mLimitSpinner.setOnItemSelectedListener(this);
    mTestTime = (TextView) findViewById(R.id.testtime);
    mLimitLabel = (TextView) findViewById(R.id.limitlabel);
    mStartButton = (Button) findViewById(R.id.start);
    mStartButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startRunning();
        }
    });
    mStopButton = (Button) findViewById(R.id.stop);
    mStopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            stopRunning();
        }
    });
    mStopButton.setEnabled(false);
    mLocalCheckBox = (CheckBox) findViewById(R.id.local);
    mLog = (TextView) findViewById(R.id.log);
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Scheduler");
    mPartialWakeLock.setReferenceCounted(false);
}
Also used : PowerManager(android.os.PowerManager) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 52 with PowerManager

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

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 53 with PowerManager

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

the class ConnectivityManagerTestActivity method turnScreenOn.

// Turn screen on
public void turnScreenOn() {
    log("Turn screen on");
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    pm.wakeUp(SystemClock.uptimeMillis());
}
Also used : PowerManager(android.os.PowerManager) IPowerManager(android.os.IPowerManager)

Example 54 with PowerManager

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

the class AsyncPlayer method setUsesWakeLock.

/**
     * We want to hold a wake lock while we do the prepare and play.  The stop probably is
     * optional, but it won't hurt to have it too.  The problem is that if you start a sound
     * while you're holding a wake lock (e.g. an alarm starting a notification), you want the
     * sound to play, but if the CPU turns off before mThread gets to work, it won't.  The
     * simplest way to deal with this is to make it so there is a wake lock held while the
     * thread is starting or running.  You're going to need the WAKE_LOCK permission if you're
     * going to call this.
     *
     * This must be called before the first time play is called.
     *
     * @hide
     */
public void setUsesWakeLock(Context context) {
    if (mWakeLock != null || mThread != null) {
        // and our releases will be out of sync.
        throw new RuntimeException("assertion failed mWakeLock=" + mWakeLock + " mThread=" + mThread);
    }
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mTag);
}
Also used : PowerManager(android.os.PowerManager)

Example 55 with PowerManager

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

the class AudioService method startVoiceBasedInteractions.

/**
     * Tell the system to start voice-based interactions / voice commands
     */
private void startVoiceBasedInteractions(boolean needWakeLock) {
    Intent voiceIntent = null;
    // select which type of search to launch:
    // - screen on and device unlocked: action is ACTION_WEB_SEARCH
    // - device locked or screen off: action is ACTION_VOICE_SEARCH_HANDS_FREE
    //    with EXTRA_SECURE set to true if the device is securely locked
    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    boolean isLocked = mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
    if (!isLocked && pm.isScreenOn()) {
        voiceIntent = new Intent(android.speech.RecognizerIntent.ACTION_WEB_SEARCH);
        Log.i(TAG, "voice-based interactions: about to use ACTION_WEB_SEARCH");
    } else {
        voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
        voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, isLocked && mKeyguardManager.isKeyguardSecure());
        Log.i(TAG, "voice-based interactions: about to use ACTION_VOICE_SEARCH_HANDS_FREE");
    }
    // start the search activity
    if (needWakeLock) {
        mMediaEventWakeLock.acquire();
    }
    try {
        if (voiceIntent != null) {
            voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            mContext.startActivity(voiceIntent);
        }
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, "No activity for search: " + e);
    } finally {
        if (needWakeLock) {
            mMediaEventWakeLock.release();
        }
    }
}
Also used : PowerManager(android.os.PowerManager) ActivityNotFoundException(android.content.ActivityNotFoundException) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent)

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