List of usage examples for android.net ConnectivityManager ACTION_BACKGROUND_DATA_SETTING_CHANGED
String ACTION_BACKGROUND_DATA_SETTING_CHANGED
To view the source code for android.net ConnectivityManager ACTION_BACKGROUND_DATA_SETTING_CHANGED.
Click Source Link
From source file:saphion.services.ForegroundService.java
@SuppressWarnings("deprecation") @Override/* ww w .ja v a2 s .co m*/ public void onCreate() { mPref = ForegroundService.this.getSharedPreferences(PREF_NAME, MODE_MULTI_PROCESS); // receive ACTION_BATTERY_CHANGED. IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); filter.addAction(Intent.ACTION_POWER_CONNECTED); filter.addAction(Intent.ACTION_POWER_DISCONNECTED); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intents.MYBAT_INTENT); filter.addAction(Intents.TORCH_ON); filter.addAction(Intents.TORCH_OFF); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED); filter.addAction(Intents.SWITCHER_INTENT); filter.addAction(Intents.SWITCHER_NOTI); filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); } registerReceiver(mBroadcastReceiver, filter); readbattery(); mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (!mPref.getBoolean(PreferenceHelper.NOTIFICATION_ENABLE, true)) { mNM.cancelAll();// .notify(id, notification); } try { mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); return; } catch (NoSuchMethodException e) { // Running on an older platform. mStartForeground = mStopForeground = null; } try { mSetForeground = getClass().getMethod("setForeground", mSetForegroundSignature); } catch (NoSuchMethodException e) { throw new IllegalStateException("OS doesn't have Service.startForeground OR Service.setForeground!"); } }
From source file:com.ebridgevas.android.ebridgeapp.messaging.mqttservice.MqttService.java
@SuppressWarnings("deprecation") private void registerBroadcastReceivers() { if (networkConnectionMonitor == null) { networkConnectionMonitor = new NetworkConnectionIntentReceiver(); registerReceiver(networkConnectionMonitor, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }/*from w w w.j av a 2 s . com*/ if (Build.VERSION.SDK_INT < 14 /**Build.VERSION_CODES.ICE_CREAM_SANDWICH**/ ) { // Support the old system for background data preferences ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); backgroundDataEnabled = cm.getBackgroundDataSetting(); if (backgroundDataPreferenceMonitor == null) { backgroundDataPreferenceMonitor = new BackgroundDataPreferenceReceiver(); registerReceiver(backgroundDataPreferenceMonitor, new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)); } } }
From source file:com.android.exchange.SyncManager.java
public void run() { sStop = false;//www . ja va 2 s .co m alwaysLog("!!! SyncManager thread running"); // If we're really debugging, turn on all logging if (Eas.DEBUG) { Eas.USER_LOG = true; Eas.PARSER_LOG = true; Eas.FILE_LOG = true; } // If we need to wait for the debugger, do so if (Eas.WAIT_DEBUG) { Debug.waitForDebugger(); } // Synchronize here to prevent a shutdown from happening while we initialize our observers // and receivers synchronized (sSyncLock) { if (INSTANCE != null) { mResolver = getContentResolver(); // Set up our observers; we need them to know when to start/stop various syncs based // on the insert/delete/update of mailboxes and accounts // We also observe synced messages to trigger upsyncs at the appropriate time mAccountObserver = new AccountObserver(mHandler); mResolver.registerContentObserver(Account.CONTENT_URI, true, mAccountObserver); mMailboxObserver = new MailboxObserver(mHandler); mResolver.registerContentObserver(Mailbox.CONTENT_URI, false, mMailboxObserver); mSyncedMessageObserver = new SyncedMessageObserver(mHandler); mResolver.registerContentObserver(Message.SYNCED_CONTENT_URI, true, mSyncedMessageObserver); mMessageObserver = new MessageObserver(mHandler); mResolver.registerContentObserver(Message.CONTENT_URI, true, mMessageObserver); mSyncStatusObserver = new EasSyncStatusObserver(); mStatusChangeListener = ContentResolver .addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, mSyncStatusObserver); // Set up our observer for AccountManager mAccountsUpdatedListener = new EasAccountsUpdatedListener(); AccountManager.get(getApplication()).addOnAccountsUpdatedListener(mAccountsUpdatedListener, mHandler, true); // Set up receivers for connectivity and background data setting mConnectivityReceiver = new ConnectivityReceiver(); registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); mBackgroundDataSettingReceiver = new ConnectivityReceiver(); registerReceiver(mBackgroundDataSettingReceiver, new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)); // Save away the current background data setting; we'll keep track of it with the // receiver we just registered ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mBackgroundData = cm.getBackgroundDataSetting(); // See if any settings have changed while we weren't running... checkPIMSyncSettings(); } } try { // Loop indefinitely until we're shut down while (!sStop) { runAwake(SYNC_MANAGER_ID); waitForConnectivity(); mNextWaitReason = "Heartbeat"; long nextWait = checkMailboxes(); try { synchronized (this) { if (!mKicked) { if (nextWait < 0) { log("Negative wait? Setting to 1s"); nextWait = 1 * SECONDS; } if (nextWait > 10 * SECONDS) { log("Next awake in " + nextWait / 1000 + "s: " + mNextWaitReason); runAsleep(SYNC_MANAGER_ID, nextWait + (3 * SECONDS)); } wait(nextWait); } } } catch (InterruptedException e) { // Needs to be caught, but causes no problem log("SyncManager interrupted"); } finally { synchronized (this) { if (mKicked) { //log("Wait deferred due to kick"); mKicked = false; } } } } log("Shutdown requested"); } catch (RuntimeException e) { Log.e(TAG, "RuntimeException in SyncManager", e); throw e; } finally { shutdown(); } }
From source file:com.mwebster.exchange.SyncManager.java
public void run() { mStop = false;/*from ww w . j av a 2 s.co m*/ // If we're really debugging, turn on all logging if (Eas.DEBUG) { Eas.USER_LOG = true; Eas.PARSER_LOG = true; Eas.FILE_LOG = true; } // If we need to wait for the debugger, do so if (Eas.WAIT_DEBUG) { Debug.waitForDebugger(); } // Set up our observers; we need them to know when to start/stop various syncs based // on the insert/delete/update of mailboxes and accounts // We also observe synced messages to trigger upsyncs at the appropriate time mResolver.registerContentObserver(Mailbox.CONTENT_URI, false, mMailboxObserver); mResolver.registerContentObserver(Message.SYNCED_CONTENT_URI, true, mSyncedMessageObserver); mResolver.registerContentObserver(Message.CONTENT_URI, true, mMessageObserver); ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, mSyncStatusObserver); mAccountsUpdatedListener = new EasAccountsUpdatedListener(); // TODO Find and fix root cause of duplication try { AccountManager.get(getApplication()).addOnAccountsUpdatedListener(mAccountsUpdatedListener, mHandler, true); } catch (IllegalStateException e1) { // This exception is more of a warning; we shouldn't be in the state in which we // already have a listener. } // Set up receivers for ConnectivityManager mConnectivityReceiver = new ConnectivityReceiver(); registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); mBackgroundDataSettingReceiver = new ConnectivityReceiver(); registerReceiver(mBackgroundDataSettingReceiver, new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)); // Save away background data setting; we'll keep track of it with the receiver ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mBackgroundData = cm.getBackgroundDataSetting(); // See if any settings have changed while we weren't running... checkPIMSyncSettings(); try { while (!mStop) { runAwake(SYNC_MANAGER_ID); waitForConnectivity(); mNextWaitReason = "Heartbeat"; long nextWait = checkMailboxes(); try { synchronized (this) { if (!mKicked) { if (nextWait < 0) { log("Negative wait? Setting to 1s"); nextWait = 1 * SECONDS; } if (nextWait > 10 * SECONDS) { log("Next awake in " + nextWait / 1000 + "s: " + mNextWaitReason); runAsleep(SYNC_MANAGER_ID, nextWait + (3 * SECONDS)); } wait(nextWait); } } } catch (InterruptedException e) { // Needs to be caught, but causes no problem } finally { synchronized (this) { if (mKicked) { //log("Wait deferred due to kick"); mKicked = false; } } } } log("Shutdown requested"); } catch (RuntimeException e) { Log.e(TAG, "RuntimeException in SyncManager", e); throw e; } finally { log("Finishing SyncManager"); // Lots of cleanup here // Stop our running syncs stopServiceThreads(); // Stop receivers and content observers if (mConnectivityReceiver != null) { unregisterReceiver(mConnectivityReceiver); } if (mBackgroundDataSettingReceiver != null) { unregisterReceiver(mBackgroundDataSettingReceiver); } if (INSTANCE != null) { ContentResolver resolver = getContentResolver(); resolver.unregisterContentObserver(mAccountObserver); resolver.unregisterContentObserver(mMailboxObserver); resolver.unregisterContentObserver(mSyncedMessageObserver); resolver.unregisterContentObserver(mMessageObserver); unregisterCalendarObservers(); } // Don't leak the Intent associated with this listener if (mAccountsUpdatedListener != null) { AccountManager.get(this).removeOnAccountsUpdatedListener(mAccountsUpdatedListener); mAccountsUpdatedListener = null; } // Clear pending alarms and associated Intents clearAlarms(); // Release our wake lock, if we have one synchronized (mWakeLocks) { if (mWakeLock != null) { mWakeLock.release(); mWakeLock = null; } } log("Goodbye"); } if (!mStop) { // If this wasn't intentional, try to restart the service throw new RuntimeException("EAS SyncManager crash; please restart me..."); } }
From source file:com.android.exchange.ExchangeService.java
public void run() { sStop = false;//from w w w . j av a 2 s . c o m alwaysLog("ExchangeService thread running"); // If we're really debugging, turn on all logging if (Eas.DEBUG) { Eas.USER_LOG = true; Eas.PARSER_LOG = true; Eas.FILE_LOG = true; } TempDirectory.setTempDirectory(this); // If we need to wait for the debugger, do so if (Eas.WAIT_DEBUG) { Debug.waitForDebugger(); } // Synchronize here to prevent a shutdown from happening while we initialize our observers // and receivers synchronized (sSyncLock) { if (INSTANCE != null) { mResolver = getContentResolver(); // Set up our observers; we need them to know when to start/stop various syncs based // on the insert/delete/update of mailboxes and accounts // We also observe synced messages to trigger upsyncs at the appropriate time mAccountObserver = new AccountObserver(mHandler); mResolver.registerContentObserver(Account.NOTIFIER_URI, true, mAccountObserver); mMailboxObserver = new MailboxObserver(mHandler); mResolver.registerContentObserver(Mailbox.CONTENT_URI, false, mMailboxObserver); mSyncedMessageObserver = new SyncedMessageObserver(mHandler); mResolver.registerContentObserver(Message.SYNCED_CONTENT_URI, true, mSyncedMessageObserver); // Set up receivers for connectivity and background data setting mConnectivityReceiver = new ConnectivityReceiver(); registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); mBackgroundDataSettingReceiver = new ConnectivityReceiver(); registerReceiver(mBackgroundDataSettingReceiver, new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)); // Save away the current background data setting; we'll keep track of it with the // receiver we just registered ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mBackgroundData = cm.getBackgroundDataSetting(); // Do any required work to clean up our Mailboxes (this serves to upgrade // mailboxes that existed prior to EmailProvider database version 17) MailboxUtilities.fixupUninitializedParentKeys(this, getEasAccountSelector()); } } try { // Loop indefinitely until we're shut down while (!sStop) { runAwake(EXTRA_MAILBOX_ID); waitForConnectivity(); mNextWaitReason = null; long nextWait = checkMailboxes(); try { synchronized (this) { if (!mKicked) { if (nextWait < 0) { log("Negative wait? Setting to 1s"); nextWait = 1 * SECONDS; } if (nextWait > 10 * SECONDS) { if (mNextWaitReason != null) { log("Next awake " + nextWait / 1000 + "s: " + mNextWaitReason); } runAsleep(EXTRA_MAILBOX_ID, nextWait + (3 * SECONDS)); } wait(nextWait); } } } catch (InterruptedException e) { // Needs to be caught, but causes no problem log("ExchangeService interrupted"); } finally { synchronized (this) { if (mKicked) { //log("Wait deferred due to kick"); mKicked = false; } } } } log("Shutdown requested"); } catch (ProviderUnavailableException pue) { // Shutdown cleanly in this case // NOTE: Sync adapters will also crash with this error, but that is already handled // in the adapters themselves, i.e. they return cleanly via done(). When the Email // process starts running again, the Exchange process will be started again in due // course, assuming there is at least one existing EAS account. Log.e(TAG, "EmailProvider unavailable; shutting down"); // Ask for our service to be restarted; this should kick-start the Email process as well startService(new Intent(this, ExchangeService.class)); } catch (RuntimeException e) { // Crash; this is a completely unexpected runtime error Log.e(TAG, "RuntimeException in ExchangeService", e); throw e; } finally { shutdown(); } }