List of usage examples for android.os PowerManager newWakeLock
public WakeLock newWakeLock(int levelAndFlags, String tag)
From source file:org.kegbot.app.service.CheckinService.java
@Override public void onCreate() { super.onCreate(); mPrefsHelper = new PreferenceHelper(this); final PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "kbcheckin"); mDeviceId = DeviceId.getDeviceId(this); try {//from w w w . j av a2 s. c om final PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); mKegbotVersion = pinfo.versionCode; } catch (NameNotFoundException e) { Log.w(TAG, "Could not look up own package info."); } resetCheckinStateIfNeeded(); registerAlarm(); }
From source file:org.gateshipone.odyssey.artworkdatabase.BulkDownloadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.getAction().equals(ACTION_START_BULKDOWNLOAD)) { Log.v(TAG, "Starting bulk download in service with thread id: " + Thread.currentThread().getId()); // reset counter mRemainingArtists = 0;/* w w w .j av a2 s. c o m*/ mRemainingAlbums = 0; mSumImageDownloads = 0; String artistProvider = getString(R.string.pref_artwork_provider_artist_default); String albumProvider = getString(R.string.pref_artwork_provider_album_default); mWifiOnly = true; // read setting from extras Bundle extras = intent.getExtras(); if (extras != null) { artistProvider = extras.getString(BUNDLE_KEY_ARTIST_PROVIDER, getString(R.string.pref_artwork_provider_artist_default)); albumProvider = extras.getString(BUNDLE_KEY_ALBUM_PROVIDER, getString(R.string.pref_artwork_provider_album_default)); mWifiOnly = intent.getBooleanExtra(BUNDLE_KEY_WIFI_ONLY, true); } if (artistProvider.equals(getString(R.string.pref_artwork_provider_none_key)) && albumProvider.equals(getString(R.string.pref_artwork_provider_none_key))) { return START_NOT_STICKY; } if (!isDownloadAllowed(this)) { return START_NOT_STICKY; } PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Odyssey_BulkDownloader"); // FIXME do some timeout checking. e.g. 5 minutes no new image then cancel the process mWakelock.acquire(); ArtworkManager artworkManager = ArtworkManager.getInstance(getApplicationContext()); artworkManager.initialize(artistProvider, albumProvider, mWifiOnly); artworkManager.bulkLoadImages(this, getApplicationContext()); } return START_STICKY; }
From source file:com.google.android.marvin.mytalkback.FullScreenReadController.java
@SuppressWarnings("deprecation") public FullScreenReadController(TalkBackService service) { mService = service;/* www . j av a 2 s. co m*/ mSpeechController = service.getSpeechController(); mCursorController = service.getCursorController(); mFeedbackController = MappedFeedbackController.getInstance(); final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); setReadingState(AutomaticReadingState.STOPPED); }
From source file:org.csploit.android.core.System.java
public static void init(Context context) throws Exception { mContext = context;/*from w w w . j a v a 2 s . c o m*/ try { Logger.debug("initializing System..."); mStoragePath = getSettings().getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString()); mSessionName = "csploit-session-" + java.lang.System.currentTimeMillis(); mKnownIssues = new KnownIssues(); mPlugins = new ArrayList<>(); mOpenPorts = new SparseIntArray(3); mServices = new HashMap<>(); mPorts = new HashMap<>(); // if we are here, network initialization didn't throw any error, lock wifi WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifiLock == null) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock"); if (!mWifiLock.isHeld()) mWifiLock.acquire(); // wake lock if enabled if (getSettings().getBoolean("PREF_WAKE_LOCK", true)) { PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (mWakeLock == null) mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock"); if (!mWakeLock.isHeld()) mWakeLock.acquire(); } // set ports try { HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080")); HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081")); HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082")); MSF_RPC_PORT = Integer.parseInt(getSettings().getString("MSF_RPC_PORT", "55553")); } catch (NumberFormatException e) { HTTP_PROXY_PORT = 8080; HTTP_SERVER_PORT = 8081; HTTPS_REDIR_PORT = 8082; MSF_RPC_PORT = 55553; } uncaughtReloadNetworkMapping(); ThreadHelper.getSharedExecutor().execute(new Runnable() { @Override public void run() { preloadServices(); preloadVendors(); } }); } catch (Exception e) { if (!(e instanceof NoRouteToHostException)) errorLogging(e); throw e; } }
From source file:fr.bmartel.android.tictactoe.gcm.MyGcmListenerService.java
/** * Called when message is received.//from w w w.j a v a 2s . c o m * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); if (from.startsWith("/topics/" + GameSingleton.DEVICE_ID)) { Log.d(TAG, "Message: " + message); try { JSONObject object = new JSONObject(message); ArrayList<String> eventItem = new ArrayList<>(); eventItem.add(object.toString()); broadcastUpdateStringList(BroadcastFilters.EVENT_MESSAGE, eventItem); if (!GameSingleton.activityForeground) { if (object.has(RequestConstants.DEVICE_MESSAGE_TOPIC) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) { GameMessageTopic topic = GameMessageTopic .getTopic(object.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC)); ChallengeMessage challengeMessage = new ChallengeMessage(topic, object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID), object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)); Log.i(TAG, "challenged by " + challengeMessage.getChallengerName() + " : " + challengeMessage.getChallengerId()); Intent intent2 = new Intent(this, DeviceListActivity.class); intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Fight!") .setContentText("challenged by " + challengeMessage.getChallengerName()) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(new Random().nextInt(9999), notificationBuilder.build()); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if (isScreenOn == false) { PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock"); wl.acquire(10000); PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock"); wl_cpu.acquire(10000); } GameSingleton.pendingChallengeMessage = challengeMessage; GameSingleton.pendingChallenge = true; } } } catch (JSONException e) { e.printStackTrace(); } } }
From source file:net.patchingzone.ru4real.nuevo.TorchActivityPlugin.java
private void startWakeLock() { if (wakeLock == null) { Log.d(TAG, "wakeLock is null, getting a new WakeLock"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); Log.d(TAG, "PowerManager acquired"); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG); Log.d(TAG, "WakeLock set"); }//from www.j a v a2s. co m wakeLock.acquire(); Log.d(TAG, "WakeLock acquired"); }
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()); }/*from ww w . ja v a 2 s. c o m*/ } 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:com.nbplus.vbroadlauncher.service.BroadcastChatHeadService.java
public void acquireCpuWakeLock() { Log.e(TAG, "Acquiring cpu wake lock"); if (mCpuWakeLock != null) { return;/*w w w . j a v a 2 s .c om*/ } PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mCpuWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "I'm your father"); mCpuWakeLock.acquire(); }
From source file:com.elixsr.portforwarder.forwarding.ForwardingService.java
@Override public void onCreate() { super.onCreate(); /*/* w ww .j a v a2s .co m*/ Sourced from: https://developer.android.com/intl/ja/training/scheduling/wakelock.html */ PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, PORT_FORWARD_SERVICE_WAKE_LOCK_TAG); wakeLock.acquire(); tracker = ((FwdApplication) this.getApplication()).getDefaultTracker(); }
From source file:com.android.screenspeak.eventprocessor.ProcessorVolumeStream.java
@SuppressWarnings("deprecation") public ProcessorVolumeStream(FeedbackController feedbackController, CursorController cursorController, DimScreenController dimScreenController, ScreenSpeakService service) { if (feedbackController == null) throw new IllegalStateException("CachedFeedbackController is null"); if (cursorController == null) throw new IllegalStateException("CursorController is null"); if (dimScreenController == null) throw new IllegalStateException("DimScreenController is null"); mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE); mCursorController = cursorController; mFeedbackController = feedbackController; final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, WL_TAG); mPrefs = PreferenceManager.getDefaultSharedPreferences(service); mService = service;//from ww w .jav a 2 s . co m mDimScreenController = dimScreenController; mPatternDetector = new VolumeButtonPatternDetector(); mPatternDetector.setOnPatternMatchListener(this); }