Search in sources :

Example 66 with PowerManager

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;
    }
}
Also used : PowerManager(android.os.PowerManager) IStatusBarService(com.android.internal.statusbar.IStatusBarService) AudioManager(android.media.AudioManager) ToneGenerator(android.media.ToneGenerator) SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) UserHandle(android.os.UserHandle) Intent(android.content.Intent) Vibrator(android.os.Vibrator) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException)

Example 67 with PowerManager

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);
}
Also used : PowerManager(android.os.PowerManager)

Example 68 with PowerManager

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);
}
Also used : PowerManager(android.os.PowerManager) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 69 with PowerManager

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();
}
Also used : TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) BroadcastInterceptingContext(com.android.server.BroadcastInterceptingContext) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Capture(org.easymock.Capture) NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) PowerManager(android.os.PowerManager) NetworkStatsService(com.android.server.net.NetworkStatsService) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager)

Example 70 with PowerManager

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);
}
Also used : PowerManager(android.os.PowerManager) WakeLock(android.os.PowerManager.WakeLock)

Aggregations

PowerManager (android.os.PowerManager)289 IntentFilter (android.content.IntentFilter)50 Intent (android.content.Intent)44 Handler (android.os.Handler)33 RemoteException (android.os.RemoteException)31 PendingIntent (android.app.PendingIntent)29 HandlerThread (android.os.HandlerThread)26 Context (android.content.Context)24 IPowerManager (android.os.IPowerManager)21 View (android.view.View)19 Resources (android.content.res.Resources)15 AlarmManager (android.app.AlarmManager)11 SharedPreferences (android.content.SharedPreferences)11 TextView (android.widget.TextView)11 NotificationCompat (android.support.v4.app.NotificationCompat)10 ComponentName (android.content.ComponentName)9 KeyguardManager (android.app.KeyguardManager)8 Vibrator (android.os.Vibrator)8 MotionEvent (android.view.MotionEvent)8 ContentResolver (android.content.ContentResolver)7