use of android.os.PowerManager in project AndroidChromium by JackyAndroid.
the class PrecacheController method acquirePrecachingWakeLock.
/** Acquires the precaching {@link WakeLock}. */
@VisibleForTesting
void acquirePrecachingWakeLock() {
assert mNonThreadSafe.calledOnValidThread();
Log.v(TAG, "acquiring wake lock");
if (mPrecachingWakeLock == null) {
PowerManager pm = (PowerManager) mAppContext.getSystemService(Context.POWER_SERVICE);
mPrecachingWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
mPrecachingWakeLock.acquire();
}
use of android.os.PowerManager in project wifikeyboard by IvanVolosyuk.
the class WiFiInputMethod method onCreate.
@Override
public void onCreate() {
super.onCreate();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "wifikeyboard");
// Debug.d("WiFiInputMethod started");
serviceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) {
// Debug.d("WiFiInputMethod connected to HttpService.");
try {
remoteKeyboard = RemoteKeyboard.Stub.asInterface(service);
keyboardListener = new RemoteKeyListener.Stub() {
@Override
public void keyEvent(int code, boolean pressed) throws RemoteException {
// Debug.d("got key in WiFiInputMethod");
receivedKey(code, pressed);
}
@Override
public void charEvent(int code) throws RemoteException {
// Debug.d("got key in WiFiInputMethod");
receivedChar(code);
}
@Override
public boolean setText(String text) throws RemoteException {
return WiFiInputMethod.this.setText(text);
}
@Override
public String getText() throws RemoteException {
return WiFiInputMethod.this.getText();
}
};
RemoteKeyboard.Stub.asInterface(service).registerKeyListener(keyboardListener);
} catch (RemoteException e) {
throw new RuntimeException("WiFiInputMethod failed to connected to HttpService.", e);
}
}
//@Override
public void onServiceDisconnected(ComponentName name) {
// Debug.d("WiFiInputMethod disconnected from HttpService.");
}
};
if (this.bindService(new Intent(this, HttpService.class), serviceConnection, BIND_AUTO_CREATE) == false) {
throw new RuntimeException("failed to connect to HttpService");
}
}
use of android.os.PowerManager in project android_frameworks_base by DirtyUnicorns.
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();
}
}
use of android.os.PowerManager in project android_frameworks_base by DirtyUnicorns.
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);
mLog.setTextColor(Color.RED);
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 DirtyUnicorns.
the class NetworkStatsServiceTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
mServiceContext = new BroadcastInterceptingContext(getContext());
mStatsDir = getContext().getFilesDir();
if (mStatsDir.exists()) {
IoUtils.deleteContents(mStatsDir);
}
mNetManager = createMock(INetworkManagementService.class);
// TODO: Mock AlarmManager when migrating this test to Mockito.
AlarmManager alarmManager = (AlarmManager) mServiceContext.getSystemService(Context.ALARM_SERVICE);
mTime = createMock(TrustedTime.class);
mSettings = createMock(NetworkStatsSettings.class);
mConnManager = createMock(IConnectivityManager.class);
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
mService = new NetworkStatsService(mServiceContext, mNetManager, alarmManager, wakeLock, mTime, TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir));
mHandlerThread = new IdleableHandlerThread("HandlerThread");
mHandlerThread.start();
Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService);
mHandler = new Handler(mHandlerThread.getLooper(), callback);
mService.setHandler(mHandler, callback);
mService.bindConnectivityManager(mConnManager);
mElapsedRealtime = 0L;
expectCurrentTime();
expectDefaultSettings();
expectNetworkStatsUidDetail(buildEmptyStats());
expectSystemReady();
// catch INetworkManagementEventObserver during systemReady()
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
mNetManager.registerObserver(capture(networkObserver));
expectLastCall().atLeastOnce();
replay();
mService.systemReady();
mSession = mService.openSession();
verifyAndReset();
mNetworkObserver = networkObserver.getValue();
}
Aggregations