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();
}
use of android.os.PowerManager in project android-uploader by nightscout.
the class SyncingService method handleActionSync.
/**
* Handle action Sync in the provided background thread with the provided
* parameters.
*/
protected void handleActionSync(int numOfPages, Context context, DeviceTransport serialDriver) {
boolean broadcastSent = false;
AndroidPreferences preferences = new AndroidPreferences(context);
Tracker tracker = ((Nightscout) context).getTracker();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NSDownload");
wl.acquire();
if (serialDriver != null) {
AbstractUploaderDevice uploaderDevice = AndroidUploaderDevice.getUploaderDevice(context);
AbstractDevice device = new DexcomG4(serialDriver, preferences, uploaderDevice);
((DexcomG4) device).setNumOfPages(numOfPages);
((CdcAcmSerialDriver) serialDriver).setPowerManagementEnabled(preferences.isRootEnabled());
try {
DownloadResults results = device.download();
G4Download download = results.getDownload();
Uploader uploader = new Uploader(context, preferences);
boolean uploadStatus;
if (numOfPages < 20) {
uploadStatus = uploader.upload(results, 1);
} else {
uploadStatus = uploader.upload(results);
}
EGVRecord recentEGV;
if (download.download_status == DownloadStatus.SUCCESS) {
recentEGV = new EGVRecord(download.sgv.get(download.sgv.size() - 1));
} else {
recentEGV = new EGVRecord(-1, TrendArrow.NONE, new Date(), new Date(), G4Noise.NOISE_NONE);
}
broadcastSGVToUI(recentEGV, uploadStatus, results.getNextUploadTime() + TIME_SYNC_OFFSET, results.getDisplayTime(), results.getResultArray(), download.receiver_battery);
broadcastSent = true;
} catch (ArrayIndexOutOfBoundsException e) {
Log.wtf("Unable to read from the dexcom, maybe it will work next time", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Array Index out of bounds").setFatal(false).build());
} catch (NegativeArraySizeException e) {
Log.wtf("Negative array exception from receiver", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Negative Array size").setFatal(false).build());
} catch (IndexOutOfBoundsException e) {
Log.wtf("IndexOutOfBounds exception from receiver", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("IndexOutOfBoundsException").setFatal(false).build());
} catch (CRCFailError e) {
// FIXME: may consider localizing this catch at a lower level (like ReadData) so that
// if the CRC check fails on one type of record we can capture the values if it
// doesn't fail on other types of records. This means we'd need to broadcast back
// partial results to the UI. Adding it to a lower level could make the ReadData class
// more difficult to maintain - needs discussion.
Log.wtf("CRC failed", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("CRC Failed").setFatal(false).build());
} catch (Exception e) {
Log.wtf("Unhandled exception caught", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Catch all exception in handleActionSync").setFatal(false).build());
}
}
if (!broadcastSent)
broadcastSGVToUI();
wl.release();
}
use of android.os.PowerManager in project KeepScore by nolanlawson.
the class GameActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
createGame();
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, getPackageName());
setContentView(R.layout.game);
setUpWidgets();
scheduleAutomaticBackup();
}
use of android.os.PowerManager in project AndEngine by nicolasgramlich.
the class BaseGameActivity method acquireWakeLock.
private void acquireWakeLock(final WakeLockOptions pWakeLockOptions) {
if (pWakeLockOptions == WakeLockOptions.SCREEN_ON) {
ActivityUtils.keepScreenOn(this);
} else {
final PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(pWakeLockOptions.getFlag() | PowerManager.ON_AFTER_RELEASE, Constants.DEBUGTAG);
try {
this.mWakeLock.acquire();
} catch (final SecurityException pSecurityException) {
Debug.e("You have to add\n\t<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>\nto your AndroidManifest.xml !", pSecurityException);
}
}
}
use of android.os.PowerManager in project Timber by naman14.
the class MusicService method onCreate.
@Override
public void onCreate() {
if (D)
Log.d(TAG, "Creating service");
super.onCreate();
mNotificationManager = NotificationManagerCompat.from(this);
// gets a pointer to the playback state store
mPlaybackStateStore = MusicPlaybackState.getInstance(this);
mSongPlayCount = SongPlayCount.getInstance(this);
mRecentStore = RecentStore.getInstance(this);
mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
setUpMediaSession();
mPreferences = getSharedPreferences("Service", 0);
mCardId = getCardId();
registerExternalStorageListener();
mPlayer = new MultiPlayer(this);
mPlayer.setHandler(mPlayerHandler);
// Initialize the intent filter and each action
final IntentFilter filter = new IntentFilter();
filter.addAction(SERVICECMD);
filter.addAction(TOGGLEPAUSE_ACTION);
filter.addAction(PAUSE_ACTION);
filter.addAction(STOP_ACTION);
filter.addAction(NEXT_ACTION);
filter.addAction(PREVIOUS_ACTION);
filter.addAction(PREVIOUS_FORCE_ACTION);
filter.addAction(REPEAT_ACTION);
filter.addAction(SHUFFLE_ACTION);
// Attach the broadcast listener
registerReceiver(mIntentReceiver, filter);
mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);
// Initialize the wake lock
final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
mWakeLock.setReferenceCounted(false);
final Intent shutdownIntent = new Intent(this, MusicService.class);
shutdownIntent.setAction(SHUTDOWN);
mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);
scheduleDelayedShutdown();
reloadQueueAfterPermissionCheck();
notifyChange(QUEUE_CHANGED);
notifyChange(META_CHANGED);
}
Aggregations