Verified Commit 64c38046 authored by Sarath's avatar Sarath
Browse files

Dojo settings not identified during the startup

parent 9e5b8b16
......@@ -46,6 +46,7 @@
<activity android:name="com.samourai.sentinel.MainActivity2"
android:label="@string/app_name"
android:theme="@style/AppTheme.Launcher"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan"
>
......
......@@ -5,9 +5,11 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.invertedx.torservice.TorProxyManager;
import com.samourai.sentinel.network.dojo.DojoUtil;
import com.samourai.sentinel.tor.TorManager;
import com.samourai.sentinel.util.AppUtil;
import com.samourai.sentinel.util.ConnectivityStatus;
......@@ -15,6 +17,9 @@ import com.samourai.sentinel.util.PrefsUtil;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.TestNet3Params;
import org.json.JSONException;
import java.io.IOException;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
......@@ -34,39 +39,27 @@ public class MainActivity extends Activity {
setContentView(R.layout.activity_main);
loaderTxView = findViewById(R.id.loader_text);
if(PrefsUtil.getInstance(MainActivity.this).getValue(PrefsUtil.TESTNET, false)) {
if (PrefsUtil.getInstance(MainActivity.this).getValue(PrefsUtil.TESTNET, false)) {
SamouraiSentinel.getInstance().setCurrentNetworkParams(TestNet3Params.get());
}
if(AppUtil.getInstance(MainActivity.this).isSideLoaded() && !(PrefsUtil.getInstance(MainActivity.this).getValue(PrefsUtil.XPUB, "").length() > 0 || SamouraiSentinel.getInstance(MainActivity.this).payloadExists())) {
if (AppUtil.getInstance(MainActivity.this).isSideLoaded() && !(PrefsUtil.getInstance(MainActivity.this).getValue(PrefsUtil.XPUB, "").length() > 0 || SamouraiSentinel.getInstance(MainActivity.this).payloadExists())) {
doSelectNet();
}
else {
if (ConnectivityStatus.hasConnectivity(getApplicationContext()) && PrefsUtil.getInstance(getApplicationContext()).getValue(PrefsUtil.ENABLE_TOR, false)) {
loaderTxView.setText(getText(R.string.initializing_tor));
Disposable disposable = TorManager.getInstance(getApplicationContext())
.getTorStatus()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(connection_states -> {
if (connection_states == TorProxyManager.ConnectionStatus.CONNECTED) {
doMain();
compositeDisposables.dispose();
}
});
compositeDisposables.add(disposable);
}else {
doMain();
}
} else {
doMain();
}
}
private void doMain() {
Intent intent;
intent = new Intent(MainActivity.this, MainActivity2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
this.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
startActivity(intent);
finish();
}
@Override
......@@ -75,7 +68,7 @@ public class MainActivity extends Activity {
compositeDisposables.dispose();
}
private void doSelectNet() {
private void doSelectNet() {
AlertDialog.Builder dlg = new AlertDialog.Builder(this)
.setTitle(R.string.app_name)
......@@ -101,10 +94,16 @@ public class MainActivity extends Activity {
}
});
if(!isFinishing()) {
if (!isFinishing()) {
dlg.show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i("onActivityResult", "DONE");
}
}
......@@ -9,14 +9,19 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
//import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.invertedx.torservice.TorProxyManager;
import com.samourai.sentinel.api.APIFactory;
import com.samourai.sentinel.network.dojo.DojoUtil;
import com.samourai.sentinel.service.BackgroundManager;
import com.samourai.sentinel.service.WebSocketService;
import com.samourai.sentinel.tor.TorManager;
import com.samourai.sentinel.util.AppUtil;
import com.samourai.sentinel.util.ConnectivityStatus;
import com.samourai.sentinel.util.ExchangeRateFactory;
......@@ -31,6 +36,11 @@ import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
public class MainActivity2 extends Activity {
private ProgressDialog progress = null;
......@@ -41,19 +51,21 @@ public class MainActivity2 extends Activity {
private Timer timer = null;
private Handler handler = null;
private TextView loaderTxView;
private CompositeDisposable disposables = new CompositeDisposable();
protected BackgroundManager.Listener bgListener = new BackgroundManager.Listener() {
protected BackgroundManager.Listener bgListener = new BackgroundManager.Listener() {
public void onBecameForeground() {
public void onBecameForeground() {
Intent intent = new Intent("com.samourai.sentinel.BalanceFragment.REFRESH\"");
Intent intent = new Intent("com.samourai.sentinel.BalanceFragment.REFRESH");
LocalBroadcastManager.getInstance(MainActivity2.this.getApplicationContext()).sendBroadcast(intent);
}
public void onBecameBackground() {
public void onBecameBackground() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(AppUtil.getInstance(MainActivity2.this.getApplicationContext()).isServiceRunning(WebSocketService.class)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (AppUtil.getInstance(MainActivity2.this.getApplicationContext()).isServiceRunning(WebSocketService.class)) {
stopService(new Intent(MainActivity2.this.getApplicationContext(), WebSocketService.class));
}
}
......@@ -66,16 +78,17 @@ public class MainActivity2 extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loaderTxView = findViewById(R.id.loader_text);
mTitle = getTitle();
boolean isVerified = false;
Bundle extras = getIntent().getExtras();
if(extras != null && extras.containsKey("verified")) {
if (extras != null && extras.containsKey("verified")) {
isVerified = extras.getBoolean("verified");
}
if(!ConnectivityStatus.hasConnectivity(MainActivity2.this)) {
if (!ConnectivityStatus.hasConnectivity(MainActivity2.this)) {
new AlertDialog.Builder(MainActivity2.this)
.setTitle(R.string.app_name)
......@@ -87,17 +100,16 @@ public class MainActivity2 extends Activity {
}
}).show();
}
else {
} else {
if(PrefsUtil.getInstance(MainActivity2.this).getValue("popup_" + getResources().getString(R.string.version_name), false) == true) {
if (PrefsUtil.getInstance(MainActivity2.this).getValue("popup_" + getResources().getString(R.string.version_name), false) == true) {
if(PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.XPUB, "").length() > 0 || SamouraiSentinel.getInstance(MainActivity2.this).payloadExists()) {
if (PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.XPUB, "").length() > 0 || SamouraiSentinel.getInstance(MainActivity2.this).payloadExists()) {
if(isVerified || PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.PIN_HASH, "").length() == 0) {
if (isVerified || PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.PIN_HASH, "").length() == 0) {
if(PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.XPUB, "").length() > 0) {
if (PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.XPUB, "").length() > 0) {
String xpub = PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.XPUB, "");
SamouraiSentinel.getInstance(MainActivity2.this).getXPUBs().put(xpub, "My account");
......@@ -113,72 +125,60 @@ public class MainActivity2 extends Activity {
AppUtil.getInstance(MainActivity2.this).restartApp();
}
else {
} else {
try {
JSONObject obj = SamouraiSentinel.getInstance(MainActivity2.this).deserialize(null);
SamouraiSentinel.getInstance(MainActivity2.this).parseJSON(obj);
if(SamouraiSentinel.getInstance(MainActivity2.this).getXPUBs().keySet().size() < 1 &&
if (SamouraiSentinel.getInstance(MainActivity2.this).getXPUBs().keySet().size() < 1 &&
SamouraiSentinel.getInstance(MainActivity2.this).getBIP49().keySet().size() < 1 &&
SamouraiSentinel.getInstance(MainActivity2.this).getBIP84().keySet().size() < 1 &&
SamouraiSentinel.getInstance(MainActivity2.this).getLegacy().keySet().size() < 1) {
SamouraiSentinel.getInstance(MainActivity2.this).getLegacy().keySet().size() < 1) {
SamouraiSentinel.getInstance(MainActivity2.this).restoreFromPrefs();
}
if(SamouraiSentinel.getInstance(MainActivity2.this).getXPUBs().keySet().size() < 1 &&
if (SamouraiSentinel.getInstance(MainActivity2.this).getXPUBs().keySet().size() < 1 &&
SamouraiSentinel.getInstance(MainActivity2.this).getBIP49().keySet().size() < 1 &&
SamouraiSentinel.getInstance(MainActivity2.this).getBIP84().keySet().size() < 1 &&
SamouraiSentinel.getInstance(MainActivity2.this).getLegacy().keySet().size() < 1) {
SamouraiSentinel.getInstance(MainActivity2.this).getLegacy().keySet().size() < 1) {
Intent intent = new Intent(MainActivity2.this, InitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else {
} else {
doTimer();
Intent intent = new Intent(MainActivity2.this, BalanceActivity.class);
startActivity(intent);
gotoBalanceActivity();
}
}
catch(IOException ioe) {
} catch (IOException ioe) {
Toast.makeText(MainActivity2.this, R.string.wallet_restored_ko, Toast.LENGTH_SHORT).show();
}
catch(JSONException je) {
} catch (JSONException je) {
Toast.makeText(MainActivity2.this, R.string.wallet_restored_ko, Toast.LENGTH_SHORT).show();
}
}
}
else {
} else {
Intent i = new Intent(MainActivity2.this, PinEntryActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(i);
}
}
else {
} else {
SamouraiSentinel.getInstance(MainActivity2.this).restoreFromPrefs();
if(SamouraiSentinel.getInstance(MainActivity2.this).getXPUBs().keySet().size() < 1 && SamouraiSentinel.getInstance(MainActivity2.this).getLegacy().keySet().size() < 1) {
if (SamouraiSentinel.getInstance(MainActivity2.this).getXPUBs().keySet().size() < 1 && SamouraiSentinel.getInstance(MainActivity2.this).getLegacy().keySet().size() < 1) {
Intent intent = new Intent(MainActivity2.this, InitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else {
} else {
doTimer();
Intent intent = new Intent(MainActivity2.this, BalanceActivity.class);
startActivity(intent);
gotoBalanceActivity();
}
}
}
else {
} else {
Intent intent = new Intent(MainActivity2.this, OneTimePopup.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
......@@ -191,6 +191,66 @@ public class MainActivity2 extends Activity {
}
void gotoBalanceActivity() {
try {
JSONObject obj = SamouraiSentinel.getInstance(MainActivity2.this).deserialize(null);
SamouraiSentinel.getInstance(MainActivity2.this).parseJSON(obj);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
boolean checkPoint = DojoUtil.getInstance(getApplicationContext()).isDojoEnabled() ||
(ConnectivityStatus.hasConnectivity(getApplicationContext()) && PrefsUtil.getInstance(getApplicationContext()).getValue(PrefsUtil.ENABLE_TOR, false));
if (checkPoint) {
loaderTxView.setText(getText(R.string.initializing_tor));
Disposable disposable = TorManager.getInstance(getApplicationContext())
.getTorStatus()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.filter(status -> status == (TorProxyManager.ConnectionStatus.CONNECTED))
.take(1)
.subscribe(connection_states -> {
if (connection_states == TorProxyManager.ConnectionStatus.CONNECTED) {
if (DojoUtil.getInstance(getApplicationContext()).isDojoEnabled()) {
connectDOJO();
} else {
Intent intent = new Intent(MainActivity2.this, BalanceActivity.class);
startActivity(intent);
finish();
}
}
});
disposables.add(disposable);
} else {
}
}
private void connectDOJO() {
loaderTxView.setText(R.string.connecting_to_dojo);
Disposable disposable = DojoUtil.getInstance(getApplicationContext()).setDojoParams(DojoUtil.getInstance(getApplicationContext()).getDojoParams())
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(aBoolean -> {
loaderTxView.setText("Successfully connected to Dojo Node");
new Handler().postDelayed(() -> {
Toast.makeText(getApplicationContext(), "Successfully connected to Dojo", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity2.this, BalanceActivity.class);
startActivity(intent);
this.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}, 800);
}, error -> {
loaderTxView.setText("Error Connecting node : ".concat(error.getMessage()));
});
disposables.add(disposable);
}
@Override
protected void onResume() {
super.onResume();
......@@ -215,12 +275,12 @@ public class MainActivity2 extends Activity {
AppUtil.getInstance(MainActivity2.this).deleteQR();
if(AppUtil.getInstance(MainActivity2.this.getApplicationContext()).isServiceRunning(WebSocketService.class)) {
if (AppUtil.getInstance(MainActivity2.this.getApplicationContext()).isServiceRunning(WebSocketService.class)) {
stopService(new Intent(MainActivity2.this.getApplicationContext(), WebSocketService.class));
}
BackgroundManager.get(this).removeListener(bgListener);
disposables.dispose();
super.onDestroy();
}
......@@ -231,7 +291,7 @@ public class MainActivity2 extends Activity {
private void doTimer() {
if(timer == null) {
if (timer == null) {
timer = new Timer();
handler = new Handler();
......
......@@ -215,7 +215,9 @@ public class SamouraiSentinel {
if(obj != null && obj.has("receives")) {
ReceiveLookAtUtil.getInstance().fromJSON(obj.getJSONArray("receives"));
}
if(obj != null && obj.has("dojo")) {
Log.i("CALLED",obj.toString());
if(obj.has("dojo")) {
Log.i("CALLED","dojo".concat(obj.toString()));
DojoUtil.getInstance(context).fromJSON(new JSONObject(obj.getString("dojo")));
}
......
......@@ -142,6 +142,8 @@ public class DojoUtil {
}
public boolean isDojoEnabled() {
Log.i("CALLED", ":CcccccLL");
return getDojoParams() != null;
}
......@@ -179,7 +181,7 @@ public class DojoUtil {
}
public void fromJSON(JSONObject obj) {
Log.i("CALLED", ":CLL");
if (isValidPairingPayload(obj.toString())) {
dojoParams = obj.toString();
......
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="120">
<alpha
android:fromAlpha="0"
android:toAlpha="1"></alpha>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="120">
<alpha
android:fromAlpha="1"
android:toAlpha="0" />
</set>
\ No newline at end of file
......@@ -179,5 +179,6 @@
<string name="tor_initializing">Tor initializing</string>
<string name="enable">Enable</string>
<string name="disabled">Disabled</string>
<string name="connecting_to_dojo">Connecting to dojo</string>
</resources>
......@@ -14,6 +14,7 @@
<style name="AppTheme.Launcher" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowAnimationStyle">@null</item>
<item name="android:statusBarColor">
@color/window
</item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment