Skip to content

Commit 8f41d82

Browse files
committed
generate key
1 parent 5fdc0eb commit 8f41d82

File tree

6 files changed

+322
-45
lines changed

6 files changed

+322
-45
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
</activity>
3232

3333
</application>
34+
<uses-feature
35+
android:name="android.hardware.camera"
36+
android:required="true" />
3437
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
3538
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
3639
</manifest>

app/src/main/java/com/katcom/androidFileVault/EntryFragment.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Intent;
44
import android.content.SharedPreferences;
55
import android.content.SharedPreferences.Editor;
6+
import android.content.res.AssetManager;
67
import android.os.Bundle;
78
import androidx.fragment.app.Fragment;
89
import android.view.LayoutInflater;
@@ -15,9 +16,14 @@
1516
import com.katcom.androidFileVault.login.LoginActivity;
1617
import com.katcom.androidFileVault.login.SetPasswordActivity;
1718

19+
import java.io.File;
20+
import java.io.FileDescriptor;
21+
import java.io.FileNotFoundException;
22+
import java.io.IOException;
23+
1824
public class EntryFragment extends Fragment {
1925
private Button mVaultOpenButton;
20-
26+
private FileManager mVault;
2127
@Override
2228
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
2329
View view = inflater.inflate(R.layout.fragment_entry,container,false);
@@ -31,18 +37,65 @@ public void onClick(View v) {
3137
}
3238
});
3339

40+
mVault = FileManager.get(getContext());
3441
return view;
3542
}
3643

3744
private void openVault() {
3845
if(!hasPassword()){
46+
// Launch activity to setup password
3947
setPassword();
48+
49+
// Generate private key for encryption before copying sample files
50+
generatePrivateKey();
51+
52+
// Put some sample files in the vault
53+
copySampleFiles();
4054
}else{
4155
Intent i= new Intent(this.getContext(), LoginActivity.class);
4256
startActivity(i);
4357
}
4458
}
4559

60+
private void generatePrivateKey() {
61+
if(!mVault.hasPrivateKey()){
62+
mVault.generateKey();
63+
}
64+
}
65+
66+
private void copySampleFiles() {
67+
File file = new File(this.getContext().getFilesDir() + "/" + FileManager.sVaultDirectory);
68+
if (!file.exists()) {
69+
file.mkdir();
70+
}
71+
72+
String source = "sample_files";
73+
String vaultPath = getActivity().getFilesDir() + "/" + FileManager.sVaultDirectory;
74+
AssetManager assets = getActivity().getAssets();
75+
try {
76+
String[] files = assets.list(source);
77+
for(String filename:files){
78+
String filepath = source + "/" + filename;
79+
String targetPath = vaultPath + "/" + filename;
80+
File outFile = new File(targetPath);
81+
if(outFile.exists()){
82+
continue;
83+
}
84+
85+
//FileDescriptor in = assets.openFd(filepath).getFileDescriptor().;
86+
87+
//vault.importFile(filename,in,targetPath);
88+
//assets.openFd(filepath).close();
89+
mVault.importFileFromAsset(filename,filepath,targetPath);
90+
91+
}
92+
}catch (FileNotFoundException e){
93+
e.printStackTrace();;
94+
} catch (IOException e) {
95+
e.printStackTrace();
96+
}
97+
}
98+
4699
private void setPassword() {
47100
Intent intent = new Intent(this.getContext(), SetPasswordActivity.class);
48101
startActivity(intent);

0 commit comments

Comments
 (0)