Browse Source

Added no password mode when starting a new account.

Signed-off-by: Sofian Benissa <sofian.benissa@mubs.edu.lb>
Sofian Benissa 1 year ago
parent
commit
187b6119b5

+ 1 - 1
.idea/deploymentTargetDropDown.xml

@@ -12,6 +12,6 @@
         </deviceKey>
       </Target>
     </targetSelectedWithDropDown>
-    <timeTargetWasSelectedWithDropDown value="2022-04-01T19:37:31.675075Z" />
+    <timeTargetWasSelectedWithDropDown value="2022-05-07T19:50:45.785915Z" />
   </component>
 </project>

+ 2 - 1
.idea/misc.xml

@@ -16,8 +16,9 @@
         <entry key="app/src/main/res/layout/activity_message_list.xml" value="0.23175675675675675" />
         <entry key="app/src/main/res/layout/activity_notepad.xml" value="0.23175675675675675" />
         <entry key="app/src/main/res/layout/activity_setup_in_process.xml" value="0.23175675675675675" />
+        <entry key="app/src/main/res/layout/activity_verify_identity.xml" value="0.23175675675675675" />
         <entry key="app/src/main/res/layout/fragment_password_entry.xml" value="0.23175675675675675" />
-        <entry key="app/src/main/res/layout/fragment_setup_password2.xml" value="0.23175675675675675" />
+        <entry key="app/src/main/res/layout/fragment_setup_password2.xml" value="0.22" />
         <entry key="app/src/main/res/layout/fragment_setup_settings.xml" value="0.23175675675675675" />
         <entry key="app/src/main/res/layout/fragment_setup_username.xml" value="0.23175675675675675" />
         <entry key="app/src/main/res/layout/item_audio_message_received.xml" value="0.23175675675675675" />

+ 93 - 81
app/src/main/java/com/dx/anonymousmessenger/ui/view/app/PasswordEntryFragment.java

@@ -83,62 +83,105 @@ public class PasswordEntryFragment extends Fragment {
         //clean app bar
         ((MaterialToolbar)requireActivity().findViewById(R.id.toolbar)).getMenu().clear();
         ((MaterialToolbar)requireActivity().findViewById(R.id.toolbar)).setNavigationIcon(R.drawable.ic_stat_name);
+        //try the easy password here and login if it works
+        login(true);
         btn_next.setOnClickListener(v -> {
+            login(false);
+        });
+
+        txtPassword.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                //see if we can detect screen obstructed here
+            }
+
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+                if(s.length()>6){
+                    try{
+                        btn_next.setEnabled(true);
+                    }catch (Exception ignored) {}
+                }
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {}
+        });
+
+        //todo warn user against using a non free keyboard with internet access.
+//        InputMethodManager im = (InputMethodManager)app.getSystemService(Context.INPUT_METHOD_SERVICE);
+//        String list = im.getEnabledInputMethodList().toString();
+//        Log.d("ANONYMOUSMESSENGER","!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+//        Log.d("ANONYMOUSMESSENGER",list);
+
+//        for (int i=0;i<list.length();i++){
+//            Log.d("ANONYMOUSMESSENGER",list[i]);
+//        }
+
+        return rootView;
+    }
+
+    public void login(boolean easy){
+        if(!easy){
             btn_next.setEnabled(false);
             txtPassword.setEnabled(false);
             btn_next.setVisibility(View.GONE);
             progressBar.setVisibility(View.VISIBLE);
-            new Thread(() -> {
-                try {
-                    SQLiteDatabase database = isPasswordCorrect(Objects.requireNonNull(txtPassword.getText()).toString().getBytes(StandardCharsets.UTF_8));
-                    if (getActivity() != null) {
-                        requireActivity().runOnUiThread(() -> ((AppActivity) getActivity()).goToTorActivity());
-                    }
-                    String pass = txtPassword.getText().toString();
+        }
+        new Thread(() -> {
+            try {
+                SQLiteDatabase database = isPasswordCorrect(easy?"easy_password".getBytes(StandardCharsets.UTF_8):Objects.requireNonNull(txtPassword.getText()).toString().getBytes(StandardCharsets.UTF_8));
+                if (getActivity() != null) {
+                    requireActivity().runOnUiThread(() -> ((AppActivity) getActivity()).goToTorActivity());
+                }
+                String pass = easy?"easy_password":txtPassword.getText().toString();
+                if (!easy) {
                     txtPassword = null;
-                    btn_next = null;
-                    progressBar = null;
-                    rootView = null;
-                    Cursor cr = database.rawQuery("SELECT * FROM account LIMIT 1;", null);
-                    if (cr != null && cr.moveToFirst()) {
-                        DxAccount account = new DxAccount(cr.getString(0));
-                        try {
-                            database.execSQL("ALTER TABLE account ADD COLUMN profile_image_path TEXT default ''");
-                        }catch (Exception ignored){
-                            try{
-                                account.setProfileImagePath(cr.getString(2));
-                            }catch (Exception ignored2){}
-                        }
+                }
+                btn_next = null;
+                progressBar = null;
+                rootView = null;
+                Cursor cr = database.rawQuery("SELECT * FROM account LIMIT 1;", null);
+                if (cr != null && cr.moveToFirst()) {
+                    DxAccount account = new DxAccount(cr.getString(0));
+                    try {
+                        database.execSQL("ALTER TABLE account ADD COLUMN profile_image_path TEXT default ''");
+                    }catch (Exception ignored){
+                        try{
+                            account.setProfileImagePath(cr.getString(2));
+                        }catch (Exception ignored2){}
+                    }
 
-                        cr.close();
-                        account.setPassword(pass.getBytes(StandardCharsets.UTF_8));
-                        app.setAccount(account,false);
-                        if (!app.isServerReady()) {
+                    cr.close();
+                    account.setPassword(easy?"easy_password".getBytes(StandardCharsets.UTF_8):pass.getBytes(StandardCharsets.UTF_8));
+                    app.setAccount(account,false);
+                    if (!app.isServerReady()) {
 //                            if (app.getTorThread() != null) {
 //                                app.getTorThread().interrupt();
 //                                app.setTorThread(null);
 //                            }
-                            app.startTor();
-                        }
-                    } else {
+                        app.startTor();
+                    }
+                } else {
 //                        Objects.requireNonNull(getActivity()).runOnUiThread(() -> {
 //                            txtPassword.setEnabled(true);
 //                            btn_next.setVisibility(View.VISIBLE);
 //                            progressBar.setVisibility(View.GONE);
 //                            txtPassword.setError("An unexpected error happened");
 //                        });
-                        Intent intent = new Intent(getActivity(), AppActivity.class);
-                        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
-                        startActivity(intent);
-                        getActivity().finish();
-                    }
-                    if (cr!=null && !cr.isClosed()) {
-                        cr.close();
-                    }
-                } catch (SQLiteException e) {
-                    e.printStackTrace();
-                    if (getActivity() != null) {
-                        requireActivity().runOnUiThread(() -> {
+                    Intent intent = new Intent(getActivity(), AppActivity.class);
+                    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+                    startActivity(intent);
+                    getActivity().finish();
+                }
+                if (cr!=null && !cr.isClosed()) {
+                    cr.close();
+                }
+            } catch (SQLiteException e) {
+                e.printStackTrace();
+                if (getActivity() != null) {
+                    requireActivity().runOnUiThread(() -> {
+                        if(!easy){
                             try{
                                 txtPassword.setText("");
                                 txtPassword.setEnabled(true);
@@ -149,58 +192,27 @@ public class PasswordEntryFragment extends Fragment {
                                 btn_next.setVisibility(View.VISIBLE);
                                 progressBar.setVisibility(View.GONE);
                             }catch (Exception ignored) {}
-                        });
-                    }
-                } catch (Exception e) {
-                    if (getActivity() != null) {
+                        }
+                    });
+                }
+            } catch (Exception e) {
+                if (getActivity() != null) {
 //                        Objects.requireNonNull(getActivity()).runOnUiThread(() -> {
 //                            txtPassword.setEnabled(true);
 //                            btn_next.setVisibility(View.VISIBLE);
 //                            progressBar.setVisibility(View.GONE);
 //                            txtPassword.setError("An unexpected error happened");
 //                        });
-                        Intent intent = new Intent(getActivity(), AppActivity.class);
-                        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
-                        startActivity(intent);
-                        try{
-                            requireActivity().finish();
-                        }catch (Exception ignored) {}
-                    }
-                    e.printStackTrace();
-                }
-            }).start();
-        });
-
-        txtPassword.addTextChangedListener(new TextWatcher() {
-            @Override
-            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-                //see if we can detect screen obstructed here
-            }
-
-            @Override
-            public void onTextChanged(CharSequence s, int start, int before, int count) {
-                if(s.length()>6){
+                    Intent intent = new Intent(getActivity(), AppActivity.class);
+                    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+                    startActivity(intent);
                     try{
-                        btn_next.setEnabled(true);
+                        requireActivity().finish();
                     }catch (Exception ignored) {}
                 }
+                e.printStackTrace();
             }
-
-            @Override
-            public void afterTextChanged(Editable s) {}
-        });
-
-        //todo warn user against using a non free keyboard with internet access.
-//        InputMethodManager im = (InputMethodManager)app.getSystemService(Context.INPUT_METHOD_SERVICE);
-//        String list = im.getEnabledInputMethodList().toString();
-//        Log.d("ANONYMOUSMESSENGER","!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-//        Log.d("ANONYMOUSMESSENGER",list);
-
-//        for (int i=0;i<list.length();i++){
-//            Log.d("ANONYMOUSMESSENGER",list[i]);
-//        }
-
-        return rootView;
+        }).start();
     }
 
     public SQLiteDatabase isPasswordCorrect(byte[] password) throws SQLiteException{

+ 19 - 5
app/src/main/java/com/dx/anonymousmessenger/ui/view/setup/SetupPasswordFragment.java

@@ -1,5 +1,10 @@
 package com.dx.anonymousmessenger.ui.view.setup;
 
+import static android.content.Context.INPUT_METHOD_SERVICE;
+import static android.view.View.INVISIBLE;
+import static android.view.View.VISIBLE;
+import static com.dx.anonymousmessenger.crypto.PasswordStrengthEstimator.QUITE_WEAK;
+
 import android.os.Bundle;
 import android.os.IBinder;
 import android.text.Editable;
@@ -25,11 +30,6 @@ import java.nio.charset.StandardCharsets;
 import java.util.HashSet;
 import java.util.Objects;
 
-import static android.content.Context.INPUT_METHOD_SERVICE;
-import static android.view.View.INVISIBLE;
-import static android.view.View.VISIBLE;
-import static com.dx.anonymousmessenger.crypto.PasswordStrengthEstimator.QUITE_WEAK;
-
 /**
  * A simple {@link Fragment} subclass.
  * Use the {@link SetupPasswordFragment#newInstance} factory method to
@@ -43,6 +43,7 @@ public class SetupPasswordFragment extends Fragment {
     private TextInputEditText passwordConfirmation;
     private StrengthMeter strengthMeter;
     private Button nextButton;
+    private Button easyButton;
     private ProgressBar progressBar;
 
     public SetupPasswordFragment() {
@@ -74,6 +75,7 @@ public class SetupPasswordFragment extends Fragment {
                 v.findViewById(R.id.password_confirm_wrapper);
         passwordConfirmation = v.findViewById(R.id.password_confirm);
         nextButton = v.findViewById(R.id.next);
+        easyButton = v.findViewById(R.id.btn_easy_password);
         progressBar = v.findViewById(R.id.progress);
         FloatingActionButton help = v.findViewById(R.id.fab_password_help);
 
@@ -165,6 +167,18 @@ public class SetupPasswordFragment extends Fragment {
 //            }
         });
 
+        easyButton.setOnClickListener(v1 ->{
+            IBinder token = passwordEntry.getWindowToken();
+            Object o = requireContext().getSystemService(INPUT_METHOD_SERVICE);
+            ((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
+            passwordEntry.setEnabled(false);
+            passwordConfirmation.setEnabled(false);
+            nextButton.setVisibility(INVISIBLE);
+            progressBar.setVisibility(VISIBLE);
+            //set easy password here
+            ((CreateUserActivity) requireActivity()).createAccount("easy_password".getBytes(StandardCharsets.UTF_8));
+        });
+
         return v;
     }
 

+ 18 - 1
app/src/main/res/layout/activity_verify_identity.xml

@@ -37,10 +37,27 @@
             android:layout_height="wrap_content"
             android:layout_margin="15dp"
             android:gravity="center|start"
-            android:padding="15dp"
+            android:padding="10dp"
             android:text=""
+            android:textAlignment="center"
             android:textAppearance="?android:attr/textAppearanceLarge"
             android:typeface="monospace" />
 
+        <TextView
+            android:id="@+id/txt_identity_info"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="15dp"
+            android:elegantTextHeight="false"
+            android:gravity="center|start"
+            android:padding="10dp"
+            android:text="dfhgdfsghfdghdf"
+            android:textAlignment="center"
+            android:textAllCaps="false"
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:textSize="16sp"
+            android:textStyle="italic"
+            android:typeface="monospace" />
+
     </LinearLayout>
 </ScrollView>

+ 16 - 1
app/src/main/res/layout/fragment_setup_password2.xml

@@ -94,6 +94,20 @@
             app:layout_constraintTop_toBottomOf="@+id/fab_password_help"
             tools:enabled="true" />
 
+        <Button
+            android:id="@+id/btn_easy_password"
+            style="@style/DXButton"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:enabled="true"
+            android:text="@string/continue_without_password"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintRight_toRightOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/next"
+            app:layout_constraintVertical_bias="0.752"
+            tools:enabled="true" />
+
         <ProgressBar
             android:id="@+id/progress"
             style="?android:attr/progressBarStyle"
@@ -114,7 +128,8 @@
             android:src="@drawable/ic_baseline_help_24"
             app:fabSize="normal"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/password_confirm_wrapper" />
+            app:layout_constraintTop_toBottomOf="@+id/password_confirm_wrapper"
+            tools:ignore="ContentDescription,SpeakableTextPresentCheck" />
 
     </androidx.constraintlayout.widget.ConstraintLayout>
 

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -372,4 +372,5 @@
     <string name="nickname_help_explain">Click to get info about nickname use</string>
     <string name="no_recent_messages">No Recent Messages!</string>
     <string name="unpinned_messages_get_deleted">Did you know unpinned messages get deleted every 24 hours?</string>
+    <string name="continue_without_password">Don\'t Use a Password</string>
 </resources>