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 XobotOS by xamarin.
the class IccCard method onIccSwap.
private void onIccSwap(boolean isAdded) {
// TODO: Here we assume the device can't handle SIM hot-swap
// and has to reboot. We may want to add a property,
// e.g. REBOOT_ON_SIM_SWAP, to indicate if modem support
// hot-swap.
DialogInterface.OnClickListener listener = null;
// TODO: SimRecords is not reset while SIM ABSENT (only reset while
// Radio_off_or_not_available). Have to reset in both both
// added or removed situation.
listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
if (mDbg)
log("Reboot due to SIM swap");
PowerManager pm = (PowerManager) mPhone.getContext().getSystemService(Context.POWER_SERVICE);
pm.reboot("SIM is added.");
}
}
};
Resources r = Resources.getSystem();
String title = (isAdded) ? r.getString(R.string.sim_added_title) : r.getString(R.string.sim_removed_title);
String message = (isAdded) ? r.getString(R.string.sim_added_message) : r.getString(R.string.sim_removed_message);
String buttonTxt = r.getString(R.string.sim_restart_button);
AlertDialog dialog = new AlertDialog.Builder(mPhone.getContext()).setTitle(title).setMessage(message).setPositiveButton(buttonTxt, listener).create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
}
use of android.os.PowerManager in project android_frameworks_base by ResurrectionRemix.
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_frameworks_base by ResurrectionRemix.
the class Action method processActionWithOptions.
public static void processActionWithOptions(Context context, String action, boolean isLongpress, boolean collapseShade) {
if (action == null || action.equals(ActionConstants.ACTION_NULL)) {
return;
}
boolean isKeyguardShowing = false;
try {
isKeyguardShowing = WindowManagerGlobal.getWindowManagerService().isKeyguardLocked();
} catch (RemoteException e) {
Log.w("Action", "Error getting window manager service", e);
}
IStatusBarService barService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
if (barService == null) {
// ouch
return;
}
// process the actions
if (action.equals(ActionConstants.ACTION_HOME)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_HOME, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_BACK)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_BACK, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_SEARCH)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_SEARCH, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_MENU) || action.equals(ActionConstants.ACTION_MENU_BIG)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_MENU, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_LEFT)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_LEFT, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_RIGHT)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_RIGHT, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_UP)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_UP, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_DOWN)) {
triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_DOWN, isLongpress);
return;
} else if (action.equals(ActionConstants.ACTION_POWER)) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
pm.goToSleep(SystemClock.uptimeMillis());
return;
} else if (action.equals(ActionConstants.ACTION_IME)) {
if (isKeyguardShowing) {
return;
}
context.sendBroadcastAsUser(new Intent("android.settings.SHOW_INPUT_METHOD_PICKER"), new UserHandle(UserHandle.USER_CURRENT));
return;
} else if (action.equals(ActionConstants.ACTION_VOICE_SEARCH)) {
// launch the search activity
Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
// TODO: This only stops the factory-installed search manager.
// Need to formalize an API to handle others
SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null) {
searchManager.stopSearch();
}
startActivity(context, intent, barService, isKeyguardShowing);
} catch (ActivityNotFoundException e) {
Log.e("SlimActions:", "No activity to handle assist long press action.", e);
}
return;
} else if (action.equals(ActionConstants.ACTION_VIB)) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (am != null && ActivityManagerNative.isSystemReady()) {
if (am.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) {
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vib != null) {
vib.vibrate(50);
}
} else {
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
if (tg != null) {
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
}
}
}
return;
} else if (action.equals(ActionConstants.ACTION_SILENT)) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (am != null && ActivityManagerNative.isSystemReady()) {
if (am.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
} else {
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
if (tg != null) {
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
}
}
}
return;
} else if (action.equals(ActionConstants.ACTION_VIB_SILENT)) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (am != null && ActivityManagerNative.isSystemReady()) {
if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vib != null) {
vib.vibrate(50);
}
} else if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
} else {
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
if (tg != null) {
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
}
}
}
return;
} else if (action.equals(ActionConstants.ACTION_CAMERA)) {
// ToDo: Send for secure keyguard secure camera intent.
// We need to add support for it first.
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA, null);
startActivity(context, intent, barService, isKeyguardShowing);
return;
} else if (action.equals(ActionConstants.ACTION_MEDIA_PREVIOUS)) {
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PREVIOUS, context);
return;
} else if (action.equals(ActionConstants.ACTION_MEDIA_NEXT)) {
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_NEXT, context);
return;
} else if (action.equals(ActionConstants.ACTION_MEDIA_PLAY_PAUSE)) {
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, context);
return;
} else if (action.equals(ActionConstants.ACTION_WAKE_DEVICE)) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (!powerManager.isScreenOn()) {
powerManager.wakeUp(SystemClock.uptimeMillis());
}
return;
} else {
// we must have a custom uri
Intent intent = null;
try {
intent = Intent.parseUri(action, 0);
} catch (URISyntaxException e) {
Log.e("SlimActions:", "URISyntaxException: [" + action + "]");
return;
}
startActivity(context, intent, barService, isKeyguardShowing);
return;
}
}
use of android.os.PowerManager in project android_frameworks_base by ResurrectionRemix.
the class NotificationPlayer 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);
}
Aggregations