Skip to content

Commit f6cf7ca

Browse files
committed
[KeyGo Backup] Fixed import issue
This addresses an issue that occurred when attempting to import a backup by clicking on a .keygo file. Previously, the application would occasionally throw a "Permission denied" error.
1 parent 2643123 commit f6cf7ca

File tree

12 files changed

+111
-40
lines changed

12 files changed

+111
-40
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
android:supportsRtl="false"
2323
android:theme="@style/AppTheme"
2424
tools:targetApi="34">
25+
<activity
26+
android:name=".ui.sync.ImportActivity"
27+
android:exported="true"
28+
android:theme="@style/AppTheme.NoActionBar">
29+
<intent-filter>
30+
<action android:name="android.intent.action.VIEW" />
31+
32+
<category android:name="android.intent.category.DEFAULT" />
33+
34+
<data android:mimeType="application/octet-stream" />
35+
<data android:pathPattern=".*\\.keygo" />
36+
<data android:scheme="content" />
37+
</intent-filter>
38+
</activity>
2539
<activity
2640
android:name=".ui.MainActivity"
2741
android:exported="false"
@@ -40,15 +54,6 @@
4054

4155
<category android:name="android.intent.category.LAUNCHER" />
4256
</intent-filter>
43-
<intent-filter>
44-
<action android:name="android.intent.action.VIEW" />
45-
46-
<category android:name="android.intent.category.DEFAULT" />
47-
48-
<data android:mimeType="application/octet-stream" />
49-
<data android:pathPattern=".*\\.keygo" />
50-
<data android:scheme="content" />
51-
</intent-filter>
5257
</activity>
5358

5459
<service

app/src/main/java/de/davis/passwordmanager/PasswordManagerApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class PasswordManagerApplication extends Application {
2525
@Override
2626
public void onCreate() {
2727
super.onCreate();
28+
SecureElementDatabase.createAndGet(this);
2829

2930
DynamicColors.applyToActivitiesIfAvailable(this);
3031

app/src/main/java/de/davis/passwordmanager/security/element/SecureElementManager.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,23 @@ public class SecureElementManager {
1212
private static SecureElementManager instance;
1313

1414
private final DashboardAdapter adapter;
15-
private final TriggerDataChanged triggerDataChanged;
15+
private TriggerDataChanged triggerDataChanged;
1616

17-
private SecureElementManager(TriggerDataChanged triggerDataChanged) {
18-
this.triggerDataChanged = triggerDataChanged;
17+
private SecureElementManager() {
1918
adapter = new DashboardAdapter();
2019
}
2120

22-
public static SecureElementManager createNew(TriggerDataChanged triggerDataChanged){
23-
instance = new SecureElementManager(triggerDataChanged);
24-
return instance;
25-
}
26-
2721
public static SecureElementManager getInstance(){
2822
if(instance == null)
29-
throw new NullPointerException("call createNew first");
23+
instance = new SecureElementManager();
3024

3125
return instance;
3226
}
3327

28+
public void setTriggerDataChanged(TriggerDataChanged triggerDataChanged) {
29+
this.triggerDataChanged = triggerDataChanged;
30+
}
31+
3432
public DashboardAdapter getAdapter() {
3533
return adapter;
3634
}

app/src/main/java/de/davis/passwordmanager/ui/BaseMainActivity.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.davis.passwordmanager.ui;
22

3-
import android.net.Uri;
43
import android.os.Bundle;
54
import android.view.View;
65

@@ -13,8 +12,6 @@
1312
import com.google.android.material.navigation.NavigationBarView;
1413

1514
import de.davis.passwordmanager.R;
16-
import de.davis.passwordmanager.sync.DataTransfer;
17-
import de.davis.passwordmanager.sync.keygo.KeyGoTransfer;
1815
import de.davis.passwordmanager.ui.views.AddBottomSheet;
1916

2017
public class BaseMainActivity extends AppCompatActivity {
@@ -24,12 +21,6 @@ protected void onCreate(Bundle savedInstanceState) {
2421
super.onCreate(savedInstanceState);
2522
setContentView(R.layout.activity_main);
2623

27-
Uri data = getIntent().getData();
28-
if(data != null){
29-
KeyGoTransfer transfer = new KeyGoTransfer(this);
30-
transfer.start(DataTransfer.TYPE_IMPORT, data);
31-
}
32-
3324
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
3425
if(navHostFragment == null)
3526
return;

app/src/main/java/de/davis/passwordmanager/ui/dashboard/DashboardFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
8181
arm.registerCreate();
8282
arm.registerEdit(null);
8383

84-
SecureElementManager manager = SecureElementManager.createNew(sem -> {
84+
SecureElementManager manager = SecureElementManager.getInstance();
85+
manager.setTriggerDataChanged(sem -> {
8586
boolean hasElements = sem.hasElements();
8687
binding.listPane.progress.setVisibility(View.GONE);
8788

app/src/main/java/de/davis/passwordmanager/ui/login/ChangePasswordFragment.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.davis.passwordmanager.ui.login;
22

3+
import android.app.Activity;
34
import android.content.Intent;
45
import android.os.Bundle;
56
import android.view.LayoutInflater;
@@ -100,7 +101,13 @@ public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
100101

101102
//if(requireActivity().getIntent().getExtras() == null)
102103
((PasswordManagerApplication)requireActivity().getApplication()).setShouldAuthenticate(false);
103-
startActivity(new Intent(requireContext(), MainActivity.class).setData(requireActivity().getIntent().getData()));
104+
105+
boolean intentAuthOnly = requireActivity().getIntent().getBooleanExtra(getString(R.string.preference_authenticate_only), false);
106+
if(intentAuthOnly){
107+
requireActivity().setResult(Activity.RESULT_OK);
108+
}else
109+
startActivity(new Intent(requireContext(), MainActivity.class));
110+
requireActivity().finish();
104111
((PasswordManagerApplication)requireActivity().getApplication()).setShouldAuthenticate(true);
105112
}
106113

app/src/main/java/de/davis/passwordmanager/ui/login/EnterPasswordFragment.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import android.content.Intent;
1010
import android.os.Bundle;
1111
import android.service.autofill.FillRequest;
12-
import android.util.Log;
1312
import android.view.LayoutInflater;
1413
import android.view.View;
1514
import android.view.ViewGroup;
@@ -70,8 +69,7 @@ public Intent onSuccess() {
7069
return i;
7170
}
7271

73-
startActivity(new Intent(getContext(), MainActivity.class)
74-
.setData(requireActivity().getIntent().getData()));
72+
startActivity(new Intent(getContext(), MainActivity.class));
7573
return null;
7674
}
7775
};

app/src/main/java/de/davis/passwordmanager/ui/login/LoginActivity.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5-
import android.net.Uri;
65
import android.os.Bundle;
76

87
import androidx.annotation.NonNull;
98
import androidx.appcompat.app.AppCompatActivity;
109

1110
import de.davis.passwordmanager.R;
12-
import de.davis.passwordmanager.database.SecureElementDatabase;
1311
import de.davis.passwordmanager.security.MasterPassword;
1412

1513
public class LoginActivity extends AppCompatActivity {
@@ -22,12 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
2220
if(savedInstanceState != null)
2321
return;
2422

25-
SecureElementDatabase.createAndGet(this);
2623

27-
if(getIntent().getBooleanExtra(getString(R.string.preference_authenticate_only), false)){
28-
getSupportFragmentManager().beginTransaction().replace(R.id.container, new EnterPasswordFragment()).commit();
29-
return;
30-
}
3124

3225
boolean masterPasswordAvailable = MasterPassword.getOne().blockingGet() != null;
3326
if(getIntent().getBooleanExtra(getString(R.string.preference_master_password), false)){
@@ -46,7 +39,7 @@ public static Intent getIntentForAuthentication(@NonNull Context context){
4639

4740
public static Intent getIntentForAuthentication(@NonNull Context context, Intent destActivity){
4841
Intent intent = new Intent(context, LoginActivity.class);
49-
intent.putExtra(context.getString(R.string.preference_authenticate_only), MasterPassword.getOne().blockingGet() != null);
42+
intent.putExtra(context.getString(R.string.preference_authenticate_only), true);
5043

5144
if(destActivity != null)
5245
intent.putExtra(context.getString(R.string.authentication_destination), destActivity);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package de.davis.passwordmanager.ui.sync;
2+
3+
import android.content.Intent;
4+
import android.net.Uri;
5+
import android.os.Bundle;
6+
7+
import androidx.activity.result.ActivityResultLauncher;
8+
import androidx.activity.result.contract.ActivityResultContracts;
9+
import androidx.appcompat.app.AppCompatActivity;
10+
11+
import de.davis.passwordmanager.backup.DataBackup;
12+
import de.davis.passwordmanager.backup.keygo.KeyGoBackup;
13+
import de.davis.passwordmanager.databinding.ActivityImportBinding;
14+
import de.davis.passwordmanager.ui.MainActivity;
15+
import de.davis.passwordmanager.ui.login.LoginActivity;
16+
17+
public class ImportActivity extends AppCompatActivity {
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
ActivityImportBinding binding = ActivityImportBinding.inflate(getLayoutInflater());
23+
setContentView(binding.getRoot());
24+
25+
ActivityResultLauncher<Intent> auth = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
26+
if(result.getResultCode() != RESULT_OK)
27+
return;
28+
29+
Intent intent = getIntent();
30+
if(intent == null || intent.getAction() == null)
31+
return;
32+
33+
if (!intent.getAction().equals(Intent.ACTION_VIEW))
34+
return;
35+
36+
Uri fileUri = intent.getData();
37+
if(fileUri == null)
38+
return;
39+
40+
KeyGoBackup backup = new KeyGoBackup(this);
41+
backup.execute(DataBackup.TYPE_IMPORT, fileUri, r -> {
42+
startActivity(new Intent(this, MainActivity.class));
43+
});
44+
});
45+
46+
auth.launch(LoginActivity.getIntentForAuthentication(this));
47+
binding.button.setOnClickListener(v -> auth.launch(LoginActivity.getIntentForAuthentication(this)));
48+
}
49+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:gravity="center"
8+
android:orientation="vertical"
9+
tools:context=".ui.sync.ImportActivity">
10+
11+
<de.davis.passwordmanager.ui.views.InformationView
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
app:information="@string/authenticate_to_import"
15+
app:multiline="true"
16+
app:title="@string/import_str">
17+
18+
<Button
19+
android:id="@+id/button"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:layout_marginTop="8dp"
23+
android:text="@string/authenticate" />
24+
</de.davis.passwordmanager.ui.views.InformationView>
25+
26+
</LinearLayout>

0 commit comments

Comments
 (0)