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);
}
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();
}
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());
}
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);
}
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();
}
}
}
Aggregations