1+ /**
2+ * The entry point of the file vault.
3+ * When the user opens the vault for the first time, it shows a screen to help user setup password.
4+ * And open the vault after the sign up.
5+ * If the user has setup password before, it displays login screen to allow user login to the vault.
6+ */
17package com .katcom .androidFileVault ;
28
39import android .content .Intent ;
612import android .content .res .AssetManager ;
713import android .os .Bundle ;
814import androidx .fragment .app .Fragment ;
15+
16+ import android .util .Log ;
917import android .view .LayoutInflater ;
1018import android .view .View ;
1119import android .view .ViewGroup ;
2028import java .io .FileDescriptor ;
2129import java .io .FileNotFoundException ;
2230import java .io .IOException ;
31+ import java .security .KeyStoreException ;
32+ import java .security .NoSuchAlgorithmException ;
33+ import java .security .UnrecoverableEntryException ;
2334
2435public class EntryFragment extends Fragment {
36+ private static final String TAG = "EntryFragment" ;
2537 private Button mVaultOpenButton ;
2638 private FileManager mVault ;
2739 @ Override
@@ -41,6 +53,11 @@ public void onClick(View v) {
4153 return view ;
4254 }
4355
56+ /**
57+ * If it is the first time user opens the vault, it setup the vault by displaying the SetPassword activity,
58+ * generating a private key for encryption and decryption, and copying sample files into the vault
59+ * Otherwise, shows the screen where user can login by entering the password.
60+ */
4461 private void openVault () {
4562 if (!hasPassword ()){
4663 // Launch activity to setup password
@@ -57,12 +74,16 @@ private void openVault() {
5774 }
5875 }
5976
77+ /**
78+ * Generate a private key in the vault for encryption and decryption of files
79+ */
6080 private void generatePrivateKey () {
61- if (!mVault .hasPrivateKey ()){
6281 mVault .generateKey ();
63- }
6482 }
6583
84+ /**
85+ * Import some sample files from assets to the vault
86+ */
6687 private void copySampleFiles () {
6788 File file = new File (this .getContext ().getFilesDir () + "/" + FileManager .sVaultDirectory );
6889 if (!file .exists ()) {
@@ -89,18 +110,23 @@ private void copySampleFiles() {
89110 mVault .importFileFromAsset (filename ,filepath ,targetPath );
90111
91112 }
92- }catch (FileNotFoundException e ){
93- e .printStackTrace ();;
94- } catch (IOException e ) {
95- e .printStackTrace ();
113+ }catch (IOException | NoSuchAlgorithmException | KeyStoreException | UnrecoverableEntryException e ){
114+ Log .e (TAG ,e .toString ());
96115 }
97116 }
98117
118+ /**
119+ * Launch the activity to allow user setup a password
120+ */
99121 private void setPassword () {
100122 Intent intent = new Intent (this .getContext (), SetPasswordActivity .class );
101123 startActivity (intent );
102124 }
103125
126+ /**
127+ * Check if the user has set a password before
128+ * @return if a password has been set
129+ */
104130 private boolean hasPassword (){
105131 SecureSharePreference secretShare = SecureSharePreference .getInstance (getContext (), Login .LOGIN_INFO_PREF_FILE );
106132 return secretShare .contains (Login .TAG_PASSWORD );
0 commit comments