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:at.tugraz.ist.akm.webservice.server.SimpleWebServer.java

public SimpleWebServer(Context context, WebserverProtocolConfig serverConfig, IHttpAccessCallback callback)
        throws Exception {
    mHttpAuthCallback = callback;//from   w  w w  .  j  av  a 2 s .co  m
    mContext = context;
    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    WifiIpAddress wifiAddressReader = new WifiIpAddress(context);

    mSocketAddress = InetAddress.getByName(wifiAddressReader.readLocalIpAddress());
    wifiAddressReader.close();
    wifiAddressReader = null;

    setNewServerConfiguration(serverConfig);

    mLog.debug("building server for [" + mServerConfig.protocolName + "://" + mSocketAddress + ":"
            + mServerConfig.port + "]");
    readRequestHandlers();
    readRequestInterceptors();
}

From source file:it.baywaylabs.jumpersumo.robot.Daemon.java

/**
 * Method auto invoked pre execute the task.
 *///from  w w w .  j  ava  2  s  .  c  om
@Override
protected void onPreExecute() {
    super.onPreExecute();
    // take CPU lock to prevent CPU from going off if the user
    // presses the power button during download
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.acquire();
    folder = new File(Constants.DIR_ROBOT_DAEMON);
    if (!folder.exists()) {
        folder.mkdir();
    }
}

From source file:net.micode.soundrecorder.RecorderService.java

@Override
public void onCreate() {
    super.onCreate();
    mRecorder = null;/*from  w w w  . j  av a 2s. c om*/
    mLowStorageNotification = null;
    mRemainingTimeCalculator = new RemainingTimeCalculator();
    mNeedUpdateRemainingTime = false;
    mNotifiManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SoundRecorder");
    mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    mAudioSampleRate = Integer
            .parseInt(settings.getString("p_audio_samplerate", Constants.DEFAULT_AUDIO_SAMPLE_RATE));

}

From source file:eu.chainfire.geolog.service.BackgroundService.java

@SuppressLint("NewApi")
@Override/*  ww  w.j  a  v a 2s.  co m*/
public void onCreate() {
    super.onCreate();
    Debug.log("Service created");

    if (thread == null) {
        Debug.log("Launching thread");
        thread = new ServiceThread();
        thread.setContext(getApplicationContext());
        thread.start();
    }

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeoLog Wakelock");

    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setClass(this, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent = PendingIntent.getActivity(this, 0, i, 0);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = (new Notification.Builder(this)).setSmallIcon(R.drawable.ic_stat_service)
            .setContentIntent(notificationIntent).setWhen(System.currentTimeMillis()).setAutoCancel(false)
            .setOngoing(true).setContentTitle(getString(R.string.service_title))
            .setContentText(getString(R.string.service_waiting));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        notificationBuilder.setShowWhen(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        /* quick turn off, maybe ? if added, make sure to add a button to preferences to disable these buttons
        notificationBuilder.
           setPriority(Notification.PRIORITY_MAX).
           addAction(0, "A", notificationIntent).
           addAction(0, "B", notificationIntent).
           addAction(0, "C", notificationIntent);
        */
    }

    updateNotification();
}

From source file:com.ichi2.async.Connection.java

public Connection() {
    sIsCancelled = false;/*from   ww  w . java  2 s  .  co m*/
    sIsCancellable = false;
    Context context = AnkiDroidApp.getInstance().getApplicationContext();
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Connection");
}

From source file:com.groundupworks.wings.core.WingsService.java

/**
 * Acquires a wake lock./*from   w w w  . j  a  v  a  2 s  .  c  o m*/
 *
 * @param context the {@link Context}.
 */
private synchronized static void acquireWakeLock(Context context) {
    // Setup wake lock.
    if (sWakeLock == null) {
        PowerManager powerManager = (PowerManager) context.getApplicationContext()
                .getSystemService(Context.POWER_SERVICE);
        sWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME);
        sWakeLock.setReferenceCounted(true);
    }

    // Acquire lock.
    sWakeLock.acquire();

    sLogger.log(WingsService.class, "acquireWakeLock", "sWakeLock=" + sWakeLock);
}

From source file:com.snt.bt.recon.services.BcScanService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    //leave cpu on
    wl = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "wlTag2");
    wl.acquire();// w w w .  jav a 2 s.  c  om

    HandlerThread handlerThread = new HandlerThread("ht");
    handlerThread.start();
    Looper looper = handlerThread.getLooper();
    handler = new Handler(looper);

    //show notification
    showNotification();

    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_START_SCAN.equals(action)) {
            //final String param1 = intent.getStringExtra(EXTRA_LAT);
            sessionId = UUID.fromString(intent.getStringExtra(EXTRA_SID));
            handleActionStartScan();

        }
    }
    return START_STICKY;
}

From source file:com.zegoggles.smssync.service.ServiceBase.java

protected int wakeLockType() {
    return PowerManager.PARTIAL_WAKE_LOCK;
}

From source file:com.zuluindia.watchpresenter.MonitorVolumeKeyPress.java

public void onCreate() {
    super.onCreate();
    settings = getSharedPreferences(Constants.SETTINGS_NAME, MODE_PRIVATE);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    Log.d(LOGCAT, "Service Started!");
    objPlayer = MediaPlayer.create(this, com.zuluindia.watchpresenter.R.raw.silence);
    objPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    objPlayer.setLooping(true);/* w  w  w .ja  v a 2  s . c  om*/
    timer = new Timer();
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    midVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 2;
    resetVolume();
}

From source file:org.amahi.anywhere.service.AudioService.java

private void setUpAudioPlayer() {
    audioPlayer = new MediaPlayer();

    audioPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    audioPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);

    audioPlayer.setOnPreparedListener(this);
    audioPlayer.setOnCompletionListener(this);
    audioPlayer.setOnErrorListener(this);
}