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);
}
use of android.os.PowerManager in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
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();
}
use of android.os.PowerManager in project android_frameworks_base by ResurrectionRemix.
the class WakeUpCall method screenOn.
private void screenOn(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
@SuppressWarnings("deprecation") WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOG_TAG);
wl.acquire(500);
}
Aggregations