android.os.PowerManager Java Examples
The following examples show how to use
android.os.PowerManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlarmBroadcastReceiver.java From flickr-uploader with GNU General Public License v2.0 | 7 votes |
@Override public void onReceive(Context context, Intent intent) { PowerManager.WakeLock wl = null; try { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); wl.acquire(); if (Utils.canAutoUploadBool()) { UploadService.checkNewFiles(); } else { initAlarm(); } } catch (Throwable e) { LOG.error(ToolString.stack2string(e)); } finally { if (wl != null) { wl.release(); } } }
Example #2
Source File: NetworkTimeUpdateService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public NetworkTimeUpdateService(Context context) { mContext = context; mTime = NtpTrustedTime.getInstance(context); mAlarmManager = mContext.getSystemService(AlarmManager.class); mCM = mContext.getSystemService(ConnectivityManager.class); Intent pollIntent = new Intent(ACTION_POLL, null); mPendingPollIntent = PendingIntent.getBroadcast(mContext, POLL_REQUEST, pollIntent, 0); mPollingIntervalMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpPollingInterval); mPollingIntervalShorterMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpPollingIntervalShorter); mTryAgainTimesMax = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpRetry); mTimeErrorThresholdMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpThreshold); mWakeLock = context.getSystemService(PowerManager.class).newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, TAG); }
Example #3
Source File: FadeMediaPlayer.java From Rey-MusicPlayer with Apache License 2.0 | 6 votes |
public FadeMediaPlayer(MusicService musicService) { mMusicService = musicService; mMediaPlayer1 = new MediaPlayer(); mMediaPlayer2 = new MediaPlayer(); mHandler = new Handler(); mMediaPlayer1.setWakeMode(mMusicService, PowerManager.PARTIAL_WAKE_LOCK); mMediaPlayer1.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer2.setWakeMode(mMusicService, PowerManager.PARTIAL_WAKE_LOCK); mMediaPlayer2.setAudioStreamType(AudioManager.STREAM_MUSIC); try { startSong(); } catch (IOException e) { e.printStackTrace(); } }
Example #4
Source File: GCMBaseIntentService.java From divide with Apache License 2.0 | 6 votes |
/** * Called from the broadcast receiver. * <p> * Will process the received intent, call handleMessage(), registered(), * etc. in background threads, with a wake lock, while keeping the service * alive. */ static void runIntentInService(Context context, Intent intent, String className) { synchronized (LOCK) { if (sWakeLock == null) { // This is called from BroadcastReceiver, there is no init. PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); } } Log.v(TAG, "Acquiring wakelock"); sWakeLock.acquire(); intent.setClassName(context, className); context.startService(intent); }
Example #5
Source File: BaseWatchFace.java From NightWatch with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); display.getSize(displaySize); wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clock"); specW = View.MeasureSpec.makeMeasureSpec(displaySize.x, View.MeasureSpec.EXACTLY); specH = View.MeasureSpec.makeMeasureSpec(displaySize.y, View.MeasureSpec.EXACTLY); sharedPrefs = PreferenceManager .getDefaultSharedPreferences(this); sharedPrefs.registerOnSharedPreferenceChangeListener(this); }
Example #6
Source File: BaseWatchFace.java From xDrip with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); //mActivity = this;//TODO Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); display.getSize(displaySize); wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clock"); specW = View.MeasureSpec.makeMeasureSpec(displaySize.x, View.MeasureSpec.EXACTLY); specH = View.MeasureSpec.makeMeasureSpec(displaySize.y, View.MeasureSpec.EXACTLY); sharedPrefs = PreferenceManager .getDefaultSharedPreferences(this); sharedPrefs.registerOnSharedPreferenceChangeListener(this); smallFontsizeArray = getResources().getStringArray(R.array.toggle_fontsize); externalStatusString = getResources().getString(R.string.init_external_status); }
Example #7
Source File: AnyMotionDetector.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public AnyMotionDetector(PowerManager pm, Handler handler, SensorManager sm, DeviceIdleCallback callback, float thresholdAngle) { if (DEBUG) Slog.d(TAG, "AnyMotionDetector instantiated."); synchronized (mLock) { mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mWakeLock.setReferenceCounted(false); mHandler = handler; mSensorManager = sm; mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMeasurementInProgress = false; mMeasurementTimeoutIsActive = false; mWakelockTimeoutIsActive = false; mSensorRestartIsActive = false; mState = STATE_INACTIVE; mCallback = callback; mThresholdAngle = thresholdAngle; mRunningStats = new RunningSignalStats(); mNumSufficientSamples = (int) Math.ceil( ((double)ORIENTATION_MEASUREMENT_DURATION_MILLIS / SAMPLING_INTERVAL_MILLIS)); if (DEBUG) Slog.d(TAG, "mNumSufficientSamples = " + mNumSufficientSamples); } }
Example #8
Source File: WakeLockUtil.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
/** * @param tag will be prefixed with "signal:" if it does not already start with it. */ public static WakeLock acquire(@NonNull Context context, int lockType, long timeout, @NonNull String tag) { tag = prefixTag(tag); try { PowerManager powerManager = ServiceUtil.getPowerManager(context); WakeLock wakeLock = powerManager.newWakeLock(lockType, tag); wakeLock.acquire(timeout); Log.d(TAG, "Acquired wakelock with tag: " + tag); return wakeLock; } catch (Exception e) { Log.w(TAG, "Failed to acquire wakelock with tag: " + tag, e); return null; } }
Example #9
Source File: ApplicationMigrationService.java From Silence with GNU General Public License v3.0 | 6 votes |
@Override public void run() { notification = initializeBackgroundNotification(); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration"); try { wakeLock.acquire(); setState(new ImportState(ImportState.STATE_MIGRATING_BEGIN, null)); SmsMigrator.migrateDatabase(ApplicationMigrationService.this, masterSecret, ApplicationMigrationService.this); setState(new ImportState(ImportState.STATE_MIGRATING_COMPLETE, null)); setDatabaseImported(ApplicationMigrationService.this); stopForeground(true); notifyImportComplete(); stopSelf(); } finally { wakeLock.release(); } }
Example #10
Source File: WakefulBroadcastReceiver.java From android-recipes-app with Apache License 2.0 | 6 votes |
/** * Do a {@link android.content.Context#startService(android.content.Intent) * Context.startService}, but holding a wake lock while the service starts. * This will modify the Intent to hold an extra identifying the wake lock; * when the service receives it in {@link android.app.Service#onStartCommand * Service.onStartCommand}, it should pass back the Intent it receives there to * {@link #completeWakefulIntent(android.content.Intent)} in order to release * the wake lock. * * @param context The Context in which it operate. * @param intent The Intent with which to start the service, as per * {@link android.content.Context#startService(android.content.Intent) * Context.startService}. */ public static ComponentName startWakefulService(Context context, Intent intent) { synchronized (mActiveWakeLocks) { int id = mNextId; mNextId++; if (mNextId <= 0) { mNextId = 1; } intent.putExtra(EXTRA_WAKE_LOCK_ID, id); ComponentName comp = context.startService(intent); if (comp == null) { return null; } PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wake:" + comp.flattenToShortString()); wl.setReferenceCounted(false); wl.acquire(60*1000); mActiveWakeLocks.put(id, wl); return comp; } }
Example #11
Source File: RTSPActivity.java From cordova-rtmp-rtsp-stream with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); if (pm != null) { mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); mWakeLock.acquire(10); } Intent intent = getIntent(); _username = intent.getStringExtra("username"); _password = intent.getStringExtra("password"); _url = intent.getStringExtra("url"); Toast.makeText(this, "U: " + _username + " P: " + _password + " U: " + _url, Toast.LENGTH_SHORT).show(); _UIListener(); }
Example #12
Source File: DataLoggerService.java From DataLogger with MIT License | 6 votes |
public void onCreate() { // Fires when a service is first initialized super.onCreate(); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mMasterAddress = ""; mNotification = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.notification_content_title)) .setTicker(getResources().getString(R.string.notification_ticker)) .setContentText(getResources().getString(R.string.notification_waiting_content_text)) .setSmallIcon(R.drawable.ic_not_128) .setContentIntent(PendingIntent.getActivity(this, 1, new Intent(this, DisplayActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)) .setOngoing(true).build(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // Device does not support Bluetooth updateBluetoothState(Constants.BLUETOOTH_STATE_NOT_SUPPORTED); } else { registerReceiver(mBluetoothStateReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); } }
Example #13
Source File: MediaPlaybackService.java From coursera-android with MIT License | 6 votes |
public void setNextDataSource(String path) { mCurrentMediaPlayer.setNextMediaPlayer(null); if (mNextMediaPlayer != null) { mNextMediaPlayer.release(); mNextMediaPlayer = null; } if (path == null) { return; } mNextMediaPlayer = new CompatMediaPlayer(); mNextMediaPlayer.setWakeMode(MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK); mNextMediaPlayer.setAudioSessionId(getAudioSessionId()); if (setDataSourceImpl(mNextMediaPlayer, path)) { mCurrentMediaPlayer.setNextMediaPlayer(mNextMediaPlayer); } else { // failed to open next, we'll transition the old fashioned way, // which will skip over the faulty file mNextMediaPlayer.release(); mNextMediaPlayer = null; } }
Example #14
Source File: SystemUtil.java From a with GNU General Public License v3.0 | 6 votes |
public static void ignoreBatteryOptimization(Activity activity) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return; PowerManager powerManager = (PowerManager) activity.getSystemService(POWER_SERVICE); boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(activity.getPackageName()); // 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。 if (!hasIgnored) { try { @SuppressLint("BatteryLife") Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + activity.getPackageName())); activity.startActivity(intent); } catch (Throwable ignored) { } } }
Example #15
Source File: NetworkStatsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@VisibleForTesting NetworkStatsService(Context context, INetworkManagementService networkManager, AlarmManager alarmManager, PowerManager.WakeLock wakeLock, Clock clock, TelephonyManager teleManager, NetworkStatsSettings settings, NetworkStatsObservers statsObservers, File systemDir, File baseDir) { mContext = checkNotNull(context, "missing Context"); mNetworkManager = checkNotNull(networkManager, "missing INetworkManagementService"); mAlarmManager = checkNotNull(alarmManager, "missing AlarmManager"); mClock = checkNotNull(clock, "missing Clock"); mSettings = checkNotNull(settings, "missing NetworkStatsSettings"); mTeleManager = checkNotNull(teleManager, "missing TelephonyManager"); mWakeLock = checkNotNull(wakeLock, "missing WakeLock"); mStatsObservers = checkNotNull(statsObservers, "missing NetworkStatsObservers"); mSystemDir = checkNotNull(systemDir, "missing systemDir"); mBaseDir = checkNotNull(baseDir, "missing baseDir"); mUseBpfTrafficStats = new File("/sys/fs/bpf/traffic_uid_stats_map").exists(); LocalServices.addService(NetworkStatsManagerInternal.class, new NetworkStatsManagerInternalImpl()); }
Example #16
Source File: Device.java From turbo-editor with GNU General Public License v3.0 | 6 votes |
/** * Reboots the device into the recovery.<br /><br /> * * This method first tries using the {@link PowerManager}, if that fails it fallbacks on using the reboot command from toolbox.<br /><br /> * * Note that using the {@link PowerManager} requires your app to optain the 'REBOOT' permission. If you don't want this, just parse NULL as {@link Context} * and the method will use the fallback. This however is more likely to fail, as many toolbox versions does not support the reboot command. * And since only the kernel can write to the CBC, we need a native caller to invoke this. So there is no fallback for missing toolbox support when it comes * to rebooting into the recovery. * * @param context * A {@link Context} or NULL to skip using the {@link PowerManager} */ public Boolean rebootRecovery(Context context) { if (context != null) { try { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); pm.reboot(null); /* * This will never be reached if the reboot is successful */ return false; } catch (Throwable e) {} } Result result = mShell.execute("toolbox reboot recovery"); return result != null && result.wasSuccessful(); }
Example #17
Source File: IjkMediaPlayer.java From LivePlayback with Apache License 2.0 | 6 votes |
@SuppressLint("Wakelock") @Override public void setWakeMode(Context context, int mode) { boolean washeld = false; if (mWakeLock != null) { if (mWakeLock.isHeld()) { washeld = true; mWakeLock.release(); } mWakeLock = null; } PowerManager pm = (PowerManager) context .getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, IjkMediaPlayer.class.getName()); mWakeLock.setReferenceCounted(false); if (washeld) { mWakeLock.acquire(); } }
Example #18
Source File: HostMonitorBroadcastReceiver.java From android-host-monitor with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { String action = new HostMonitorConfig(context).getBroadcastAction(); if (intent == null || action == null || !intent.getAction().equals(action)) { return; } PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getSimpleName()); wakeLock.acquire(); HostStatus hostStatus = intent.getParcelableExtra(HostMonitor.PARAM_STATUS); onHostStatusChanged(hostStatus); wakeLock.release(); }
Example #19
Source File: PushoverUploadService.java From 600SeriesAndroidUploader with MIT License | 6 votes |
public void run() { PowerManager.WakeLock wl = getWakeLock(mContext, TAG, 60000); storeRealm = Realm.getInstance(UploaderApplication.getStoreConfiguration()); dataStore = storeRealm.where(DataStore.class).findFirst(); if (UploaderApplication.isOnline() && dataStore.isPushoverEnable()) { statPushover = (StatPushover) Stats.getInstance().readRecord(StatPushover.class); statPushover.incRun(); pushoverApi = new PushoverApi(PUSHOVER_URL); if (isValid()) process(); else statPushover.incValidError(); } storeRealm.close(); releaseWakeLock(wl); stopSelf(); }
Example #20
Source File: LockManager.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public LockManager(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "BCM:Full"); partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BCM:Partial"); proximityLock = new ProximityLock(pm); WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi"); fullLock.setReferenceCounted(false); partialLock.setReferenceCounted(false); wifiLock.setReferenceCounted(false); accelerometerListener = new AccelerometerListener(context, new AccelerometerListener.OrientationListener() { @Override public void orientationChanged(int newOrientation) { orientation = newOrientation; Log.d(TAG, "Orentation Update: " + newOrientation); updateInCallLockState(); } }); wifiLockEnforced = isWifiPowerActiveModeEnabled(context); }
Example #21
Source File: TriggerLoop.java From Trigger with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); jobSet = new ConcurrentHashMap<>(); receivers = new ConcurrentHashMap<>(); jobHappens = new ConcurrentHashMap<>(); binder = new TriggerBinder(); executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE, new TriggerWorkerFactory()); mainHandler = new Handler(Looper.getMainLooper()); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); shortDeadlineHandler = new Handler(); deadlineCheck = new DeadlineCheck(); sDeviceStatus = DeviceStatus.get(this); registerReceiver(deadlineCheck, new IntentFilter(DEADLINE_BROADCAST)); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); int granted = checkCallingOrSelfPermission("android.permission.WAKE_LOCK"); if (granted == PackageManager.PERMISSION_GRANTED) { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); } else { wakeLock = null; } handlerThread = new HandlerThread("Trigger-HandlerThread"); handlerThread.start(); checker = new CheckHandler(handlerThread.getLooper()); mayRecoverJobsFromFile(); }
Example #22
Source File: PowerUtils.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
/** * Returns {@code true} if the device is in an interactive state. */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static boolean isInteractive(@NonNull PowerManager pm) { return Device.hasLollipopApi() ? pm.isInteractive() : pm.isScreenOn(); }
Example #23
Source File: Air.java From stynico with MIT License | 5 votes |
private void wakeAndUnlock2(boolean b) { if(b) { //获取电源管理器对象 pm=(PowerManager) getSystemService(Context.POWER_SERVICE); //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); //点亮屏幕 wl.acquire(); //得到键盘锁管理器对象 km= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); kl = km.newKeyguardLock("unLock"); //解锁 kl.disableKeyguard(); } else { //锁屏 kl.reenableKeyguard(); //释放wakeLock,关灯 wl.release(); } }
Example #24
Source File: DreamManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public DreamManagerService(Context context) { super(context); mContext = context; mHandler = new DreamHandler(FgThread.get().getLooper()); mController = new DreamController(context, mHandler, mControllerListener); mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mPowerManagerInternal = getLocalService(PowerManagerInternal.class); mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, TAG); mDozeConfig = new AmbientDisplayConfiguration(mContext); }
Example #25
Source File: PowerManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") private static boolean isScreenLock(final WakeLock wakeLock) { switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) { case PowerManager.FULL_WAKE_LOCK: case PowerManager.SCREEN_BRIGHT_WAKE_LOCK: case PowerManager.SCREEN_DIM_WAKE_LOCK: return true; } return false; }
Example #26
Source File: PinEntryEditText.java From stynico with MIT License | 5 votes |
@Override public IBinder onBind(Intent intent) { IBinder mIBinder = super.onBind(intent); mBinding = true; powerMan = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerMan.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "WakeLock"); keyMan = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); keyLock = keyMan.newKeyguardLock("KeyLock"); // #TODO 换掉这些deprecated方法, return mIBinder; }
Example #27
Source File: JoH.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static PowerManager.WakeLock getWakeLock(Context context, final String name, int millis) {//KS final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);//KS PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name); wl.acquire(millis); if (debug_wakelocks) Log.d(TAG, "getWakeLock: " + name + " " + wl.toString()); return wl; }
Example #28
Source File: DownloadService.java From Popeens-DSub with GNU General Public License v3.0 | 5 votes |
public static void startService(Context context, Intent intent) { PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE); //According to Google Play logs this is causing a lot of crashes, most likely it is when ignoring battery optimizations. // As a test I am removing that part and will check back at end of BETA to see if crashes stopped if (Build.VERSION.SDK_INT < 26){ // || (powerManager != null && powerManager.isIgnoringBatteryOptimizations(intent.getPackage()))) { context.startService(intent); } else { context.startForegroundService(intent); } }
Example #29
Source File: CircleWatchface.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:CircleWatchface"); wakeLock.acquire(30000); Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); display.getSize(displaySize); specW = View.MeasureSpec.makeMeasureSpec(displaySize.x, View.MeasureSpec.EXACTLY); specH = View.MeasureSpec.makeMeasureSpec(displaySize.y, View.MeasureSpec.EXACTLY); sharedPrefs = PreferenceManager .getDefaultSharedPreferences(this); sharedPrefs.registerOnSharedPreferenceChangeListener(this); //register Message Receiver LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(Intent.ACTION_SEND)); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); myLayout = inflater.inflate(R.layout.modern_layout, null); prepareLayout(); prepareDrawTime(); //ListenerService.requestData(this); //usually connection is not set up yet wakeLock.release(); }
Example #30
Source File: NFCReaderX.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static boolean HandleGoodReading(final String tagId, byte[] data1, final long CaptureDateTime, final boolean allowUpload, byte []patchUid, byte []patchInfo ) { if (Pref.getBooleanDefaultFalse("external_blukon_algorithm")) { // If oop is used, there is no need to do the checksum It will be done by the oop. // (or actually we don't know how to do it, for us 14/de sensors). // Save raw block record (we start from block 0) LibreBlock.createAndSave(tagId, CaptureDateTime, data1, 0, allowUpload, patchUid, patchInfo); LibreOOPAlgorithm.SendData(data1, CaptureDateTime, patchUid, patchInfo); } else { final boolean checksum_ok = LibreUtils.verify(data1); if (!checksum_ok) { return false; } // The 4'th byte is where the sensor status is. if(!LibreUtils.isSensorReady(data1[4])) { Log.e(TAG, "Sensor is not ready, Ignoring reading!"); return true; } final ReadingData mResult = parseData(0, tagId, data1, CaptureDateTime); new Thread() { @Override public void run() { final PowerManager.WakeLock wl = JoH.getWakeLock("processTransferObject", 60000); try { mResult.CalculateSmothedData(); LibreAlarmReceiver.processReadingDataTransferObject(new ReadingData.TransferObject(1, mResult), CaptureDateTime, tagId, allowUpload, patchUid, patchInfo ); Home.staticRefreshBGCharts(); } finally { JoH.releaseWakeLock(wl); } } }.start(); } return true; // Checksum tests have passed. }