List of usage examples for android.os PowerManager PARTIAL_WAKE_LOCK
int PARTIAL_WAKE_LOCK
To view the source code for android.os PowerManager PARTIAL_WAKE_LOCK.
Click Source Link
From source file:Main.java
public static PowerManager.WakeLock acquireLock(Context context) { if (wakeLock == null || !wakeLock.isHeld()) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TT"); wakeLock.setReferenceCounted(true); wakeLock.acquire();/* www .j a va 2 s. com*/ } return wakeLock; }
From source file:Main.java
/** * Hold wake lock.//from ww w . j av a 2s . co m * * @param context * the context */ public static void holdWakeLock(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); wakeLock.acquire(); }
From source file:Main.java
public static void acquireTemporaryWakelocks(Context context, long timeout) { if (wakeLock == null) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "PushSMS"); }// w w w . ja va2s.co m wakeLock.acquire(timeout); if (wifiLock == null) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock("PushSMS"); } wifiLock.acquire(); new Handler().postDelayed(new Runnable() { @Override public void run() { wifiLock.release(); } }, timeout); }
From source file:org.traccar.client.WakefulBroadcastReceiver.java
public static void startWakefulForegroundService(Context context, Intent intent) { synchronized (mActiveWakeLocks) { int id = mNextId; mNextId++;/*from w w w.j av a 2 s.co m*/ if (mNextId <= 0) { mNextId = 1; } intent.putExtra(EXTRA_WAKE_LOCK_ID, id); ContextCompat.startForegroundService(context, intent); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WakefulBroadcastReceiver.class.getSimpleName()); wl.setReferenceCounted(false); wl.acquire(60 * 1000); mActiveWakeLocks.put(id, wl); } }
From source file:ca.mcgill.hs.uploader.UploadThread.java
/** * Executes the upload in a separate thread *///from w ww .ja va 2s .c o m @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); int finalStatus = Constants.STATUS_UNKNOWN_ERROR; boolean countRetry = false; int retryAfter = 0; AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; String filename = null; http_request_loop: while (true) { try { final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); filename = mInfo.mFileName; final File file = new File(filename); if (!file.exists()) { Log.e(Constants.TAG, "file" + filename + " is to be uploaded, but cannot be found."); finalStatus = Constants.STATUS_FILE_ERROR; break http_request_loop; } client = AndroidHttpClient.newInstance(Constants.DEFAULT_USER_AGENT, mContext); Log.v(Constants.TAG, "initiating upload for " + mInfo.mUri); final HttpPost request = new HttpPost(Constants.UPLOAD_URL); request.addHeader("MAC", NetworkHelper.getMacAddress(mContext)); final MultipartEntity mpEntity = new MultipartEntity(); mpEntity.addPart("uploadedfile", new FileBody(file, "binary/octet-stream")); request.setEntity(mpEntity); HttpResponse response; try { response = client.execute(request); final HttpEntity resEntity = response.getEntity(); String responseMsg = null; if (resEntity != null) { responseMsg = EntityUtils.toString(resEntity); Log.i(Constants.TAG, "Server Response: " + responseMsg); } if (resEntity != null) { resEntity.consumeContent(); } if (!responseMsg.contains("SUCCESS 0x64asv65")) { Log.i(Constants.TAG, "Server Response: " + responseMsg); } } catch (final IllegalArgumentException e) { finalStatus = Constants.STATUS_BAD_REQUEST; request.abort(); break http_request_loop; } catch (final IOException e) { if (!NetworkHelper.isNetworkAvailable(mContext)) { finalStatus = Constants.STATUS_RUNNING_PAUSED; } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { finalStatus = Constants.STATUS_RUNNING_PAUSED; countRetry = true; } else { Log.d(Constants.TAG, "IOException trying to excute request for " + mInfo.mUri + " : " + e); finalStatus = Constants.STATUS_HTTP_DATA_ERROR; } request.abort(); break http_request_loop; } final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 503 && mInfo.mNumFailed < Constants.MAX_RETRIES) { Log.v(Constants.TAG, "got HTTP response code 503"); finalStatus = Constants.STATUS_RUNNING_PAUSED; countRetry = true; retryAfter = Constants.MIN_RETRY_AFTER; retryAfter += NetworkHelper.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1); retryAfter *= 1000; request.abort(); break http_request_loop; } else { finalStatus = Constants.STATUS_SUCCESS; } break; } catch (final RuntimeException e) { finalStatus = Constants.STATUS_UNKNOWN_ERROR; } finally { mInfo.mHasActiveThread = false; if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { client.close(); client = null; } if (finalStatus == Constants.STATUS_SUCCESS) { // TODO: Move the file. } } } }
From source file:me.postar.postarv2.LocalService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Functions.getParcels(parcels, this); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Postar"); if (Functions.isConnectedToInternet(LocalService.this)) { Ion.with(this).load("GET", "https://e-racuni.postacg.me/PracenjePosiljaka/").asString().withResponse() .setCallback(new FutureCallback<Response<String>>() { @Override/*from www . ja v a 2s.c o m*/ public void onCompleted(Exception e, Response<String> result) { Document html = Jsoup.parse(result.getResult()); Element viewState = html.getElementById("__VIEWSTATE"); Element eventValidation = html.getElementById("__EVENTVALIDATION"); Element btnPronadji = html.getElementById("btnPronadji"); for (final PostParcel parcel : parcels) { if (parcel.isAlarmOn()) { Ion.with(LocalService.this) .load("POST", "https://e-racuni.postacg.me/PracenjePosiljaka/") .setBodyParameter("__VIEWSTATE", viewState.val()) .setBodyParameter("__EVENTVALIDATION", eventValidation.val()) .setBodyParameter("btnPronadji", btnPronadji.val()) .setBodyParameter("txtPrijemniBroj", parcel.getParcelNo()).asString() .withResponse().setCallback(new FutureCallback<Response<String>>() { @Override public void onCompleted(Exception e, final Response<String> result) { Document html = Jsoup.parse(result.getResult()); Element table = html.getElementById("dgInfo"); if (table != null) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( LocalService.this) .setSmallIcon(R.drawable.ic_mail_outline) .setLargeIcon(BitmapFactory.decodeResource( getResources(), R.drawable.ic_mail_outline)) .setAutoCancel(true); mBuilder.setContentTitle(getString(R.string.message_title)); mBuilder.setContentText( getString(R.string.message_content)); Intent activityIntent = new Intent(LocalService.this, StatusActivity.class); activityIntent.putExtra("parcel", parcel); PendingIntent resultPendingIntent = PendingIntent .getActivity(LocalService.this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); stopSelf(); wl.release(); } } }); } } } }); } return START_NOT_STICKY; }
From source file:com.google.android.apps.muzei.TaskQueueService.java
@Override protected void onHandleIntent(Intent intent) { if (intent.getAction() == null) { return;//from w w w. j a v a 2 s. co m } String action = intent.getAction(); if (ACTION_DOWNLOAD_CURRENT_ARTWORK.equals(action)) { // This is normally not started by a WakefulBroadcastReceiver so request a // new wakelock. PowerManager pwm = (PowerManager) getSystemService(POWER_SERVICE); PowerManager.WakeLock lock = pwm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); lock.acquire(DOWNLOAD_ARTWORK_WAKELOCK_TIMEOUT_MILLIS); try { // Handle internal download artwork request ArtworkCache.getInstance(this).maybeDownloadCurrentArtworkSync(); } finally { if (lock.isHeld()) { lock.release(); } } WakefulBroadcastReceiver.completeWakefulIntent(intent); } }
From source file:com.commonsware.android.antidoze.ScheduledService.java
@Override public void onCreate() { super.onCreate(); PowerManager mgr = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getSimpleName()); wakeLock.acquire();//from ww w .ja va2 s.c o m if (BuildConfig.IS_FOREGROUND) { foregroundify(); } log = new File(getExternalFilesDir(null), "antidoze-log.txt"); log.getParentFile().mkdirs(); sched.scheduleAtFixedRate(this, 0, 15, TimeUnit.SECONDS); }
From source file:com.cpd.receivers.LibraryRenewAlarmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, AppTags.UFRGS_MOBILE); //Acquire the lock wl.acquire();/*from w w w . j a va2s .c o m*/ prefs = context.getSharedPreferences(AppTags.LIBRARY_LOGIN_PREF, Context.MODE_PRIVATE); editor = prefs.edit(); int value = prefs.getInt(AppTags.ALARM_COUNTER, 0); value = value + 1; editor.putInt(AppTags.ALARM_COUNTER, value); editor.commit(); LibraryLoader loader = new LibraryLoader(context); loader.renewBooks(null, true); if (value == DAILY_RETRIES) { launchNotification(context, context.getString(R.string.we_tried_to_renew_your_items_notification_title), context.getString(R.string.verify_return_date_notification_message)); editor.putInt(AppTags.ALARM_COUNTER, 0); editor.commit(); } wl.release(); }
From source file:org.apache.cordova.plugin.powermanagement.PowerManagement.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult result = null;/*w w w . jav a 2 s. c o m*/ if (action.equals("acquireWakeLock")) { result = this.acquireWakeLock(PowerManager.PARTIAL_WAKE_LOCK); } else if (action.equals("releaseWakeLock")) { result = this.releaseWakeLock(); } callbackContext.sendPluginResult(result); return true; }