public void ping() { ping(null); }
public void startOrResetAccountAsync(WalletAccount account) { if (connections.containsKey(account.getCoinType())) { resetAccount(account); } else { startAsync(account); } } }
public ServerClients(List<CoinAddress> coinAddresses, ConnectivityHelper connectivityHelper) { this.connectivityHelper = connectivityHelper; setupAddresses(coinAddresses); }
if (connHelper.isConnected()) { clients = getServerClients(wallet); clients.startAsync(account); clients.resetAccount(account); clients.startOrResetAccountAsync(account); if (clients != null) clients.startAsync(account); } else { log.warn("Tried to start a service for account id {} but no account found.", clients.startAsync(account);
private ServerClients getServerClients(Wallet wallet) { ServerClients newClients = new ServerClients(Constants.DEFAULT_COINS_SERVERS, connHelper); if (application.getTxCachePath() != null) { newClients.setCacheDir(application.getTxCachePath(), Constants.TX_CACHE_SIZE); } return newClients; }
this.publishProgress(TxStatus.LOADING); BitWalletSingleKey sweepWallet = new BitWalletSingleKey(type, rawKey.key); serverClients.startAsync(sweepWallet);
private void disconnectClients() { if (clients != null) { clients.stopAllAsync(); clients = null; } }
@Override public void onAttach(final Context context) { super.onAttach(context); try { listener = (Listener) context; // TODO implement differently ConnectivityHelper connHelper = new ConnectivityHelper() { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); @Override public boolean isConnected() { NetworkInfo activeInfo = connManager.getActiveNetworkInfo(); return activeInfo != null && activeInfo.isConnected(); } }; serverClients = new ServerClients(Constants.DEFAULT_COINS_SERVERS, connHelper); } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement " + Listener.class); } }
private void check(boolean isNetworkChanged) { Wallet wallet = application.getWallet(); final boolean hasEverything = hasConnectivity && hasStorage && (wallet != null); if (hasEverything && clients == null) { // log.debug("acquiring wakelock"); // wakeLock.acquire(); log.info("Creating coins clients"); clients = getServerClients(wallet); // if (lastAccount != null) clients.startAsync(wallet.getAccount(lastAccount)); } else if (hasEverything && isNetworkChanged) { log.info("Restarting coins clients as network changed"); clients.resetConnections(); } else if (!hasEverything && clients != null) { log.info("stopping stratum clients"); disconnectClients(); // log.debug("releasing wakelock"); // wakeLock.release(); } } };
public void startAsync(WalletAccount account) { if (account == null) { log.warn("Provided wallet account is null, not doing anything"); return; } CoinType type = account.getCoinType(); BlockchainConnection connection = getConnection(type); connection.addEventListener(account); connection.startAsync(); }
protected Void doInBackground(Void... params) { startSweeping(); serverClients.stopAllAsync(); return null; }
@Override public void onReceive(final Context context, final Intent intent) { log.debug("Received a tick {}", intent); if (clients != null) { clients.ping(application.getVersionString()); } long lastStop = application.getLastStop(); if (lastStop > 0) { long secondsIdle = (SystemClock.elapsedRealtime() - lastStop) / 1000; if (secondsIdle > Constants.STOP_SERVICE_AFTER_IDLE_SECS) { log.info("Idling detected, stopping service"); stopSelf(); } } } };