List of usage examples for android.net ConnectivityManager CONNECTIVITY_ACTION
String CONNECTIVITY_ACTION
To view the source code for android.net ConnectivityManager CONNECTIVITY_ACTION.
Click Source Link
From source file:eu.faircode.netguard.ActivitySettings.java
@Override protected void onResume() { super.onResume(); checkPermissions(null);//from w w w.j av a 2 s.co m // Listen for preference changes SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); // Listen for interactive state changes IntentFilter ifInteractive = new IntentFilter(); ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(interactiveStateReceiver, ifInteractive); // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); }
From source file:de.schildbach.wallet.marscoin.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);/*from w ww .ja v a2 s. c om*/ final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("marscoin", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:de.schildbach.wallet.elysium.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);/*from www . jav a 2 s.co m*/ final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("Elysium", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:net.kidlogger.kidlogger.KLService.java
public void setupLogging() { // Set up GPS / Network logging if (Settings.loggingGps(this)) { startGpsUpdates();/*from w w w . j a v a 2s.co m*/ gpsOn = true; } // Set up WiFi logging if (Settings.loggingWifi(this)) { wifiReceiver = new WifiReceiver(this); registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); wifiOn = true; } // Set up SMS logging if (Settings.loggingSms(this)) { smsObserver = new SmsObserver(this, handlering); IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED); registerReceiver(smsObserver.inSms, smsFilter); smsOn = true; } // Set up Calls logging if (Settings.loggingCalls(this)) { IntentFilter callsFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); callsReceiver = new CallsReceiver(this); registerReceiver(callsReceiver, callsFilter); callOn = true; } // Set up Idle logging IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); idleFilter.addAction(Intent.ACTION_USER_PRESENT); idleReceiver = new IdleReceiver(this); registerReceiver(idleReceiver, idleFilter); idleOn = true; /*if(Settings.loggingIdle(this)){ IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); idleFilter.addAction(Intent.ACTION_USER_PRESENT); idleReceiver = new IdleReceiver(this); registerReceiver(idleReceiver, idleFilter); idleOn = true; }*/ // Set up URL logging if (Settings.loggingUrl(this)) { urlObserver = new HistoryObserver(this, handlering); urlOn = true; } // Set up USB logging if (Settings.loggingUsb(this)) { IntentFilter usbFilter = new IntentFilter(Intent.ACTION_UMS_CONNECTED); usbFilter.addAction(Intent.ACTION_UMS_DISCONNECTED); usbReceiver = new UsbReceiver(this); registerReceiver(usbReceiver, usbFilter); usbOn = true; } // Set up Tasks logging if (logTask) { // Check if a new Application was started taskScan = new Runnable() { public void run() { new Thread(new Runnable() { public void run() { doScanTask(); } }).start(); if (userPresent) { handleTask.postDelayed(this, SCAN_TASK_TIME); scanningTask = true; } else { scanningTask = false; } } }; handleTask.postDelayed(taskScan, SCAN_TASK_TIME); taskOn = true; } // Set up Clipboard logging if (logClip) { // Scan clipboard content, only first 30 characters clipboardScan = new Runnable() { public void run() { new Thread(new Runnable() { public void run() { doScanClipboard(); } }).start(); if (userPresent) { handleClipb.postDelayed(this, SCAN_CLIP_TIME); scanningClip = true; } else { scanningClip = false; } } }; handleClipb.postDelayed(clipboardScan, SCAN_CLIP_TIME); clipOn = true; } // Set up Power logging if (Settings.loggingPower(this)) { IntentFilter powerFilter = new IntentFilter(Intent.ACTION_SHUTDOWN); powerReceiver = new ShutdownReceiver(this); registerReceiver(powerReceiver, powerFilter); powerOn = true; } // Set up Memory Card logging if (Settings.loggingMedia(this)) { IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED); mediaFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL); mediaFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); mediaFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); mediaFilter.addAction(Intent.ACTION_MEDIA_SHARED); mediaFilter.addDataScheme("file"); mediaReceiver = new MediaReceiver(this); registerReceiver(mediaReceiver, mediaFilter); mediaOn = true; } // Set up GSM logging if (Settings.loggingGsm(this)) { gsmObserver = new GsmObserver(this); telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telManager.listen(gsmObserver, PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_CELL_LOCATION); gsmOn = true; } // Set up Airplane mode receiver if (Settings.loggingAir(this)) { IntentFilter airFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); airReceiver = new AirplaneReceiver(this); registerReceiver(airReceiver, airFilter); airOn = true; } // Set up Photos logging if (Settings.loggingPhotos(this)) { photoObserver = new PhotoObserver(this, this, handlering); photoOn = true; } // Set up SliceMultimediaFile if (Settings.uploadPhotos(this) || Settings.uploadRecords(this)) { mediaSlicer = new SliceMultimediaFile(this); } // Set up ConnectivityReceiver mConReceiver = new ConnectivityReceiver(this); registerReceiver(mConReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); // Ser up CallIntentReceiver //outCallReceiver = new CallIntentReceiver(); //registerReceiver(outCallReceiver, new IntentFilter(KLService.OUTGOING_CALL)); }
From source file:devcoin.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);// w w w. ja v a2 s . c o m final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } log.info("using " + blockStore.getClass().getName()); try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); maybeRotateKeys(); }
From source file:com.bushstar.htmlcoin_android_wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); config = application.getConfiguration(); final Wallet wallet = application.getWallet(); bestChainHeightEver = config.getBestChainHeightEver(); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);//from ww w . j a v a 2 s . c o m final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } log.info("using " + blockStore.getClass().getName()); validHashStoreFile = new File(getDir("validhashes", Context.MODE_PRIVATE), Constants.VALID_HASHES_FILENAME); try { validHashStore = new ValidHashStore(validHashStoreFile); } catch (IOException x) { validHashStoreFile.delete(); final String msg = "validhashstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore, validHashStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); maybeRotateKeys(); }
From source file:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java
@Override public void onStart() { super.onStart(); if (mGoogleApiClient != null) mGoogleApiClient.connect();//from w ww.j a va2 s .c o m // Registering the broadcast receivers //registerReceiver(bReceiver, new IntentFilter(Constants.RECEIVED_RESOURCES_UPDATE)); registerReceiver(mConnReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); }
From source file:biz.wiz.android.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); config = application.getConfiguration(); final Wallet wallet = application.getWallet(); peerConnectivityListener = new PeerConnectivityListener(); broadcastPeerState(0);// w ww . j a v a 2 s.co m blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.Files.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final InputStream checkpointsInputStream = getAssets() .open(Constants.Files.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); // implicitly start PeerGroup application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:org.hopestarter.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); config = application.getConfiguration(); final Wallet wallet = application.getWallet(); peerConnectivityListener = new PeerConnectivityListener(); broadcastPeerState(0);//from ww w. j a v a 2 s.c o m blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.Files.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.reset(); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final long start = System.currentTimeMillis(); final InputStream checkpointsInputStream = getAssets() .open(Constants.Files.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); log.info("checkpoints loaded from '{}', took {}ms", Constants.Files.CHECKPOINTS_FILENAME, System.currentTimeMillis() - start); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); // implicitly start PeerGroup application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:mintcoin.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); config = application.getConfiguration(); final Wallet wallet = application.getWallet(); peerConnectivityListener = new PeerConnectivityListener(); broadcastPeerState(0);//w w w. jav a 2 s .co m blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.Files.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final long start = System.currentTimeMillis(); final InputStream checkpointsInputStream = getAssets() .open(Constants.Files.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); log.info("checkpoints loaded from '{}', took {}ms", Constants.Files.CHECKPOINTS_FILENAME, System.currentTimeMillis() - start); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); // implicitly start PeerGroup application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }