Example usage for android.os PowerManager PARTIAL_WAKE_LOCK

List of usage examples for android.os PowerManager PARTIAL_WAKE_LOCK

Introduction

In this page you can find the example usage for android.os PowerManager PARTIAL_WAKE_LOCK.

Prototype

int PARTIAL_WAKE_LOCK

To view the source code for android.os PowerManager PARTIAL_WAKE_LOCK.

Click Source Link

Document

Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off.

Usage

From source file:com.achep.acdisplay.services.activemode.ActiveModeService.java

private void pingConsumingSensorsInternal() {
    // Find maximum remaining time.
    int remainingTime = -1;
    for (ActiveModeSensor ams : mSensors) {
        if (ams.isAttached() && ams instanceof ActiveModeSensor.Consuming) {
            ActiveModeSensor.Consuming sensor = (ActiveModeSensor.Consuming) ams;
            remainingTime = Math.max(remainingTime, sensor.getRemainingTime());
        }/*w w w.j a v  a  2 s  . c om*/
    }

    long now = SystemClock.elapsedRealtime();
    int delta = (int) (now - mConsumingPingTimestamp);

    remainingTime -= delta;
    if (remainingTime < 0) {
        return; // Too late
    }

    // Acquire wake lock to be sure that sensors will be fine.
    releaseWakeLock();
    PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);
    mWakeLock.acquire(remainingTime);

    // Ping sensors
    for (ActiveModeSensor ams : mSensors) {
        if (ams.isAttached() && ams instanceof ActiveModeSensor.Consuming) {
            ActiveModeSensor.Consuming sensor = (ActiveModeSensor.Consuming) ams;

            int sensorRemainingTime = sensor.getRemainingTime() - delta;
            if (sensorRemainingTime > 0) {
                sensor.ping(sensorRemainingTime);
            }
        }
    }
}

From source file:eu.chainfire.opendelta.UpdateService.java

@SuppressWarnings("deprecation")
@Override//from  w w w  .  j a  va  2s.c  o m
public void onCreate() {
    super.onCreate();

    config = Config.getInstance(this);

    wakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(
            config.getKeepScreenOn() ? PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                    : PowerManager.PARTIAL_WAKE_LOCK,
            "OpenDelta WakeLock");
    wifiLock = ((WifiManager) getSystemService(WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL,
            "OpenDelta WifiLock");

    handlerThread = new HandlerThread("OpenDelta Service Thread");
    handlerThread.start();
    handler = new Handler(handlerThread.getLooper());

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    scheduler = new Scheduler(this, this);

    networkState = new NetworkState();
    networkState.start(this, this,
            prefs.getInt(PREF_AUTO_UPDATE_NETWORKS_NAME, PREF_AUTO_UPDATE_NETWORKS_DEFAULT));

    batteryState = new BatteryState();
    batteryState.start(this, this, 50, true);

    screenState = new ScreenState();
    screenState.start(this, this);

    prefs.registerOnSharedPreferenceChangeListener(this);

    autoState();
}

From source file:com.iamplus.musicplayer.MusicService.java

@Override
public void onCreate() {
    Log.i(TAG, "debug: Creating service");

    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    //      mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
    //            .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock");

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    mWakeLock.setReferenceCounted(false);

    //mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    // create the Audio Focus Helper, if the Audio Focus feature is available (SDK 8 or above)
    if (android.os.Build.VERSION.SDK_INT >= 8)
        mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this);
    else/*w w  w.  ja  v a2  s .  co m*/
        mAudioFocus = AudioFocus.Focused; // no focus feature, so we always "have" audio focus

    //mDummyAlbumArt = BitmapFactory.decodeResource(getResources(), R.drawable.albumart_mp_unknown);

    mMediaButtonReceiverComponent = new ComponentName(this, MusicIntentReceiver.class);

    e_play_mode emode = MusicRetriever.getPlayModePref(this, e_play_mode.e_play_mode_normal);
    MusicRetriever.getInstance().setPlayMode(emode);
}

From source file:com.wordpress.httpstheredefiningproductions.phonefinder.recorder.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    //initialize the thing that will keep the service running
    mgr = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    //turn on the wakelock
    PowerManager.WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
    wakeLock.acquire();//from   www. j  a va  2s .  com
    //start the notification
    startForeground(FOREGROUND_ID, buildForegroundNotification("Phone Finder"));
    try {
        //start the listening
        Message msg = new Message();
        msg.what = MSG_RECOGNIZER_START_LISTENING;
        mServerMessenger.send(msg);
    } catch (RemoteException e) {

    }
    //keep running the service:
    return START_STICKY;
}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

public void startNmeaRelay() throws IOException {
    if (relaying) {
        Log.d(TAG, "Already relaying: do nothing");
        return;/*from  w ww  .  j  a  va 2 s  .  c o m*/
    }

    context.reset();

    pLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    pLock.acquire();
    updateState(State.STARTING);

    nmeaWorker = new NmeaRelayWorker();
    nmeaWorker.start();

    Log.d(TAG, "Requesting location updates through GPS");
    locationManager.addNmeaListener(this);
    locationManager.addGpsStatusListener(this);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 0, this);

    Log.i(TAG, "NMEA relay started");
    relaying = true;
    fireNmeaRelayContextChanged();
}

From source file:com.rks.musicx.services.MusicXService.java

private void initMediaData() {
    try {//from  ww  w  .  j a  v  a  2  s  .c  om
        MediaPlayerSingleton.getInstance().getMediaPlayer();
        MediaPlayerSingleton.getInstance().getMediaPlayer().setOnPreparedListener(this);
        MediaPlayerSingleton.getInstance().getMediaPlayer().setOnCompletionListener(this);
        MediaPlayerSingleton.getInstance().getMediaPlayer().setOnErrorListener(this);
        MediaPlayerSingleton.getInstance().getMediaPlayer().setAudioStreamType(AudioManager.STREAM_MUSIC);
        MediaPlayerSingleton.getInstance().getMediaPlayer().setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);
        Log.d(TAG, "MediaInit");
    } catch (Exception e) {
        Log.d(TAG, "initMedia_error", e);
    }
}

From source file:org.protocoderrunner.base.BaseActivity.java

public void setWakeLock(boolean b) {

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    if (wl == null) {
        wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        if (b) {//from w w w . j av a2s. c o m
            wl.acquire();
        }
    } else {
        if (!b) {
            wl.release();
        }
    }

}

From source file:github.daneren2005.dsub.service.DownloadService.java

@Override
public void onCreate() {
    super.onCreate();

    final SharedPreferences prefs = Util.getPreferences(this);
    new Thread(new Runnable() {
        public void run() {
            Looper.prepare();//w ww  .jav  a  2 s .  c  om

            mediaPlayer = new MediaPlayer();
            mediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK);

            audioSessionId = -1;
            Integer id = prefs.getInt(Constants.CACHE_AUDIO_SESSION_ID, -1);
            if (id != -1) {
                try {
                    audioSessionId = id;
                    mediaPlayer.setAudioSessionId(audioSessionId);
                } catch (Throwable e) {
                    audioSessionId = -1;
                }
            }

            if (audioSessionId == -1) {
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                try {
                    audioSessionId = mediaPlayer.getAudioSessionId();
                    prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).commit();
                } catch (Throwable t) {
                    // Froyo or lower
                }
            }

            mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
                    handleError(new Exception("MediaPlayer error: " + what + " (" + more + ")"));
                    return false;
                }
            });

            try {
                Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
                i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
                i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
                sendBroadcast(i);
            } catch (Throwable e) {
                // Froyo or lower
            }

            effectsController = new AudioEffectsController(DownloadService.this, audioSessionId);
            if (prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) {
                getEqualizerController();
            }

            mediaPlayerLooper = Looper.myLooper();
            mediaPlayerHandler = new Handler(mediaPlayerLooper);

            if (runListenersOnInit) {
                onSongsChanged();
                onSongProgress();
                onStateUpdate();
            }

            Looper.loop();
        }
    }, "DownloadService").start();

    Util.registerMediaButtonEventReceiver(this);

    if (mRemoteControl == null) {
        // Use the remote control APIs (if available) to set the playback state
        mRemoteControl = RemoteControlClientHelper.createInstance();
        ComponentName mediaButtonReceiverComponent = new ComponentName(getPackageName(),
                MediaButtonIntentReceiver.class.getName());
        mRemoteControl.register(this, mediaButtonReceiverComponent);
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    wakeLock.setReferenceCounted(false);

    try {
        timerDuration = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "5"));
    } catch (Throwable e) {
        timerDuration = 5;
    }
    sleepTimer = null;

    keepScreenOn = prefs.getBoolean(Constants.PREFERENCES_KEY_KEEP_SCREEN_ON, false);

    mediaRouter = new MediaRouteManager(this);

    instance = this;
    shufflePlayBuffer = new ShufflePlayBuffer(this);
    artistRadioBuffer = new ArtistRadioBuffer(this);
    lifecycleSupport.onCreate();
}

From source file:org.csp.everyaware.offline.Map.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("Map", "******************************onCreate()******************************");
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.map_container);

    mToBeHideBtn = (Button) findViewById(R.id.startStopBtn);
    mToBeHideBtn.setVisibility(View.GONE);

    mPowerMan = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = mPowerMan.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CPUalwaysOn");

    Utils.setStep(Constants.TRACK_MAP, getApplicationContext());

    mDbManager = DbManager.getInstance(getApplicationContext());
    mDbManager.openDb();/*from  w ww.  java 2 s .  co  m*/

    //it will contain  displayed latlng points
    mLatLngPoints = new ArrayList<ExtendedLatLng>();

    //istantiate custom implementation of LocationSource interface
    mLocationSource = new MyLocationSource();

    //google map initialization
    setUpMapIfNeeded(savedInstanceState);

    //obtaining references to buttons and defining listeners
    getButtonRefs();

    mHandler = new Handler();

    mKmlParser = new KmlParser();

    //starting store'n'forward service and saving reference to it
    Intent serviceIntent = new Intent(getApplicationContext(), StoreAndForwardService.class);
    Utils.storeForwServIntent = serviceIntent;
    startService(serviceIntent);

    //set appropriate colors in all seven black carbon levels under black carbon text box
    setBcLevelColors();
}

From source file:info.guardianproject.otr.app.im.service.RemoteImService.java

@Override
public void onCreate() {
    debug("ImService started");
    final String prev = Debug.getTrail(this, SERVICE_CREATE_TRAIL_KEY);
    if (prev != null)
        Debug.recordTrail(this, PREV_SERVICE_CREATE_TRAIL_TAG, prev);
    Debug.recordTrail(this, SERVICE_CREATE_TRAIL_KEY, new Date());
    final String prevConnections = Debug.getTrail(this, CONNECTIONS_TRAIL_TAG);
    if (prevConnections != null)
        Debug.recordTrail(this, PREV_CONNECTIONS_TRAIL_TAG, prevConnections);
    Debug.recordTrail(this, CONNECTIONS_TRAIL_TAG, "0");

    mConnections = new Hashtable<String, ImConnectionAdapter>();
    mHandler = new Handler();

    Debug.onServiceStart();/*from   ww  w.j ava2 s.  co  m*/

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IM_WAKELOCK");

    // Clear all account statii to logged-out, since we just got started and we don't want
    // leftovers from any previous crash.
    clearConnectionStatii();

    mStatusBarNotifier = new StatusBarNotifier(this);
    mServiceHandler = new ServiceHandler();

    //mSettingsMonitor = new SettingsMonitor();

    /*
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
    registerReceiver(mSettingsMonitor, intentFilter);
    */

    //  setBackgroundData(ImApp.getApplication().isNetworkAvailableAndConnected());

    mPluginHelper = ImPluginHelper.getInstance(this);
    mPluginHelper.loadAvailablePlugins();

    // Have the heartbeat start autoLogin, unless onStart turns this off
    mNeedCheckAutoLogin = true;

    HeartbeatService.startBeating(getApplicationContext());
}