Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with PowerManager

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

the class MediaFrameworkTest method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.surface_view);
    mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
    mOverlayView = (ImageView) findViewById(R.id.overlay_layer);
    ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mSurfaceHolder.addCallback(this);
    //Get the midi fd
    midiafd = this.getResources().openRawResourceFd(R.raw.testmidi);
    //Get the mp3 fd
    mp3afd = this.getResources().openRawResourceFd(R.raw.testmp3);
    mOverlayView.setLayoutParams(lp);
    mDestBitmap = Bitmap.createBitmap((int) 640, (int) 480, Bitmap.Config.ARGB_8888);
    mOverlayView.setImageBitmap(mDestBitmap);
    //Acquire the full wake lock to keep the device up
    PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MediaFrameworkTest");
    mWakeLock.acquire();
}
Also used : PowerManager(android.os.PowerManager) ViewGroup(android.view.ViewGroup)

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