mock out rest of connect activity, start writing regen ident code

This commit is contained in:
Dan Ballard 2017-09-03 16:02:40 -07:00
parent 03e0ea6bb4
commit 767fccef40
2 changed files with 93 additions and 30 deletions

View File

@ -7,6 +7,7 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
@ -25,30 +26,26 @@ public class ConnectActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
// Load identity and connect to addr. Enable appropriate buttons
// If no identity, generate.
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(im.ricochet.androidod.R.layout.activity_connect); setContentView(im.ricochet.androidod.R.layout.activity_connect);
TextView progressText = (TextView)findViewById(im.ricochet.androidod.R.id.progressTextView); TextView progressText = (TextView)findViewById(im.ricochet.androidod.R.id.progressTextView);
progressText.setText("Loading private key..."); //progressText.setText("Loading private key...");
Log.i(TAG, "Loading private key...");
SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE); SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE);
String privateKey = prefs.getString(PRIVATE_KEY_KEY, ""); String privateKey = prefs.getString(PRIVATE_KEY_KEY, "");
Log.i(TAG, "Loaded! '" + privateKey + "'");
if (privateKey.equals("")) { if (privateKey.equals("")) {
Log.i(TAG, "Failed to load private key from preferences, generating new"); // Kick of identity generateion
progressText.setText("Generating private key..."); regenIdentity();
try { } else {
privateKey = GoRicochetMobile.generatePrivateKey(); Button regenButton = (Button)findViewById(R.id.regenIdentButton);
} catch (Exception e) { regenButton.setEnabled(true);
Log.e(TAG, e.toString());
} }
Log.i(TAG, "Generated!: '" + privateKey + "'");
SharedPreferences.Editor prefsEditor = prefs.edit(); /*Log.i(TAG, "Ready!");
prefsEditor.putString(PRIVATE_KEY_KEY, privateKey);
prefsEditor.commit();
}
Log.i(TAG, "Ready!");
progressText.setText("Ready!"); progressText.setText("Ready!");
ProgressBar progressBar = (ProgressBar)findViewById(im.ricochet.androidod.R.id.progressBar); ProgressBar progressBar = (ProgressBar)findViewById(im.ricochet.androidod.R.id.progressBar);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
@ -60,7 +57,33 @@ public class ConnectActivity extends AppCompatActivity {
Log.i(TAG, "Starting Echo Bot"); Log.i(TAG, "Starting Echo Bot");
//GoRicochetMobile.echoBot(privateKey); //GoRicochetMobile.echoBot(privateKey);
new EchoBot(privateKey).execute(); new EchoBot(privateKey).execute();
*/
}
private void regenIdentity() {
Button regenButton = (Button)findViewById(R.id.regenIdentButton);
regenButton.setEnabled(false);
TextView progressText = (TextView)findViewById(im.ricochet.androidod.R.id.progressTextView);
progressText.setText("Generating new identity...");
ProgressBar spinner = (ProgressBar)findViewById(R.id.progressBar);
spinner.setVisibility(View.VISIBLE);
String privateKey;
try {
privateKey = GoRicochetMobile.generatePrivateKey();
SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = prefs.edit();
prefsEditor.putString(PRIVATE_KEY_KEY, privateKey);
prefsEditor.commit();
progressText.setText("");
} catch (Exception e) {
Log.e(TAG, e.toString());
progressText.setText("ERROR: unable to generate new identity: " + e.toString());
}
spinner.setVisibility(View.INVISIBLE);
regenButton.setEnabled(true);
} }
private class EchoBot extends AsyncTask<Void, Void, Void> { private class EchoBot extends AsyncTask<Void, Void, Void> {

View File

@ -11,12 +11,10 @@
style="@style/Widget.AppCompat.ProgressBar" style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/connect"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginTop="8dp"
android:layout_marginTop="32dp" app:layout_constraintTop_toBottomOf="@+id/addressText" />
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/connect" />
<EditText <EditText
android:id="@+id/addressText" android:id="@+id/addressText"
@ -37,11 +35,11 @@
android:id="@+id/textView" android:id="@+id/textView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Onion Address:"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:layout_marginLeft="0dp" android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/addressText" /> android:layout_marginTop="8dp"
android:text="Connect to Onion address:"
app:layout_constraintLeft_toLeftOf="@+id/addressText"
app:layout_constraintTop_toTopOf="parent" />
<Button <Button
android:id="@+id/connect" android:id="@+id/connect"
@ -50,6 +48,7 @@
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:enabled="false"
android:text="Connect" android:text="Connect"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
@ -59,12 +58,9 @@
android:id="@+id/progressTextView" android:id="@+id/progressTextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" tools:layout_editor_absoluteX="195dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/connect" />
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBar" />
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView2"
@ -72,10 +68,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_marginTop="32dp"
android:text="Required step: Orbot/Settings/Torrc Custom Config:" android:text="Required step: Orbot/Settings/Torrc Custom Config:"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.511"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@+id/progressTextView" /> app:layout_constraintTop_toBottomOf="@+id/progressTextView" />
<TextView <TextView
@ -99,4 +96,47 @@
app:layout_constraintTop_toBottomOf="@+id/textView3" app:layout_constraintTop_toBottomOf="@+id/textView3"
android:layout_marginLeft="0dp" android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/textView3" /> app:layout_constraintLeft_toLeftOf="@+id/textView3" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DisableNetwork 0"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/textView4"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Identity:"
app:layout_constraintTop_toBottomOf="@+id/textView5"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/regenIdentButton" />
<TextView
android:id="@+id/identityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ricochet:"
app:layout_constraintLeft_toRightOf="@+id/textView6"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="@+id/textView6"
android:layout_marginTop="0dp" />
<Button
android:id="@+id/regenIdentButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:enabled="false"
android:text="Regenerate Identity"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>