Search in sources :

Example 1 with AndroidWhirlpoolWalletService

use of com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService in project samourai-wallet-android by Samourai-Wallet.

the class TorService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (Objects.requireNonNull(intent.getAction()).equals(TorService.STOP_SERVICE)) {
        if (DojoUtil.getInstance(getApplicationContext()).getDojoParams() != null && !intent.hasExtra("KILL_TOR")) {
            Toast.makeText(getApplicationContext(), "You cannot stop Tor service when dojo is connected", Toast.LENGTH_SHORT).show();
            return START_STICKY;
        }
        Disposable disposable = TorManager.getInstance(getApplicationContext()).stopTor().subscribe(stat -> {
            compositeDisposable.dispose();
            stopSelf();
        }, error -> {
        // 
        });
        compositeDisposable.add(disposable);
        AndroidWhirlpoolWalletService whirlpoolWalletService = AndroidWhirlpoolWalletService.getInstance();
        if (whirlpoolWalletService.getWhirlpoolWallet().isPresent()) {
            // restart WhirlpoolWallet with new Tor config
            whirlpoolWalletService.restart(this).subscribeOn(Schedulers.io()).subscribe();
        }
    } else if (intent.getAction().equals(TorService.RENEW_IDENTITY)) {
        renewIdentity();
        return START_STICKY;
    } else if (Objects.requireNonNull(intent.getAction()).equals(TorService.START_SERVICE)) {
        if (!TorManager.getInstance(getApplicationContext()).isProcessRunning) {
            startTor();
        }
    }
    return START_STICKY;
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) AndroidWhirlpoolWalletService(com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService)

Example 2 with AndroidWhirlpoolWalletService

use of com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService in project samourai-wallet-android by Samourai-Wallet.

the class TorService method startTor.

private void startTor() {
    title = "Tor: Waiting";
    updateNotification("Connecting....");
    if (torDisposable != null) {
        compositeDisposable.delete(torDisposable);
        Log.i(TAG, "startTOR: ".concat(String.valueOf(torDisposable.isDisposed())));
    }
    torDisposable = TorManager.getInstance(getApplicationContext()).startTor().debounce(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(proxy -> {
        title = "Tor: Running";
        updateNotification("Running....");
    }, Throwable::printStackTrace);
    compositeDisposable.add(torDisposable);
    Disposable statusDisposable = TorManager.getInstance(this).torStatus.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(state -> {
        if (state == TorManager.CONNECTION_STATES.CONNECTED) {
            AndroidWhirlpoolWalletService whirlpoolWalletService = AndroidWhirlpoolWalletService.getInstance();
            if (whirlpoolWalletService.getWhirlpoolWallet().isPresent()) {
                // restart WhirlpoolWallet with new Tor config once Tor is connected
                whirlpoolWalletService.restart(this).subscribeOn(Schedulers.io()).subscribe();
            }
        }
    });
    logger();
    compositeDisposable.add(statusDisposable);
}
Also used : Context(android.content.Context) BuildConfig(com.samourai.wallet.BuildConfig) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) DojoUtil(com.samourai.wallet.network.dojo.DojoUtil) Toast(android.widget.Toast) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) WebUtil(com.samourai.wallet.util.WebUtil) TOR_CHANNEL_ID(com.samourai.wallet.SamouraiApplication.TOR_CHANNEL_ID) NotificationManager(android.app.NotificationManager) Service(android.app.Service) AndroidWhirlpoolWalletService(com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService) ContextCompat(android.support.v4.content.ContextCompat) R(com.samourai.wallet.R) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) GROUP_ALERT_SUMMARY(android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) AndroidWhirlpoolWalletService(com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService)

Aggregations

AndroidWhirlpoolWalletService (com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Service (android.app.Service)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IBinder (android.os.IBinder)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 GROUP_ALERT_SUMMARY (android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY)1 ContextCompat (android.support.v4.content.ContextCompat)1 Log (android.util.Log)1 Toast (android.widget.Toast)1 BuildConfig (com.samourai.wallet.BuildConfig)1 R (com.samourai.wallet.R)1 TOR_CHANNEL_ID (com.samourai.wallet.SamouraiApplication.TOR_CHANNEL_ID)1 DojoUtil (com.samourai.wallet.network.dojo.DojoUtil)1 WebUtil (com.samourai.wallet.util.WebUtil)1