mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-12 05:58:07 -05:00
Fix debug backup/restore methods
This commit is contained in:
parent
a8b8ed6f14
commit
b42afcd32c
@ -177,7 +177,7 @@
|
|||||||
android:windowSoftInputMode="stateHidden">
|
android:windowSoftInputMode="stateHidden">
|
||||||
|
|
||||||
<!-- VIEW with mimeType application/pgp-encrypted -->
|
<!-- VIEW with mimeType application/pgp-encrypted -->
|
||||||
<intent-filter android:label="@string/intent_import_key">
|
<intent-filter android:label="@string/intent_send_decrypt">
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
@ -316,42 +316,37 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void copy(File in, File out) throws IOException {
|
private static void copy(File in, File out) throws IOException {
|
||||||
FileInputStream ss = new FileInputStream(in);
|
FileInputStream is = new FileInputStream(in);
|
||||||
FileOutputStream ds = new FileOutputStream(out);
|
FileOutputStream os = new FileOutputStream(out);
|
||||||
byte[] buf = new byte[512];
|
byte[] buf = new byte[512];
|
||||||
while (ss.available() > 0) {
|
while (is.available() > 0) {
|
||||||
int count = ss.read(buf, 0, 512);
|
int count = is.read(buf, 0, 512);
|
||||||
ds.write(buf, 0, count);
|
os.write(buf, 0, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debugRead(Context context) throws IOException {
|
public static void debugBackup(Context context, boolean restore) throws IOException {
|
||||||
if (!Constants.DEBUG) {
|
if (!Constants.DEBUG) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File in = context.getDatabasePath("debug.db");
|
|
||||||
File out = context.getDatabasePath("openkeychain.db");
|
File in;
|
||||||
|
File out;
|
||||||
|
if (restore) {
|
||||||
|
in = context.getDatabasePath("debug_backup.db");
|
||||||
|
out = context.getDatabasePath("openkeychain.db");
|
||||||
|
} else {
|
||||||
|
in = context.getDatabasePath("openkeychain.db");
|
||||||
|
out = context.getDatabasePath("debug_backup.db");
|
||||||
|
out.createNewFile();
|
||||||
|
}
|
||||||
if (!in.canRead()) {
|
if (!in.canRead()) {
|
||||||
throw new IOException("Cannot read " + in.getName());
|
throw new IOException("Cannot read " + in.getName());
|
||||||
}
|
}
|
||||||
if (!out.canRead()) {
|
if (!out.canWrite()) {
|
||||||
throw new IOException("Cannot write " + out.getName());
|
throw new IOException("Cannot write " + out.getName());
|
||||||
}
|
}
|
||||||
copy(in, out);
|
copy(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debugWrite(Context context) throws IOException {
|
|
||||||
if (!Constants.DEBUG) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File in = context.getDatabasePath("openkeychain.db");
|
|
||||||
File out = context.getDatabasePath("debug.db");
|
|
||||||
if (!in.canRead()) {
|
|
||||||
throw new IOException("Cannot read " + in.getName());
|
|
||||||
}
|
|
||||||
if (!out.canRead()) {
|
|
||||||
throw new IOException("Cannot write " + out.getName());
|
|
||||||
}
|
|
||||||
copy(in, out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -94,22 +94,22 @@ public class KeyListActivity extends DrawerActivity {
|
|||||||
|
|
||||||
case R.id.menu_key_list_debug_read:
|
case R.id.menu_key_list_debug_read:
|
||||||
try {
|
try {
|
||||||
KeychainDatabase.debugRead(this);
|
KeychainDatabase.debugBackup(this, true);
|
||||||
Notify.showNotify(this, "Restored Notify.Style backup", Notify.Style.INFO);
|
Notify.showNotify(this, "Restored debug_backup.db", Notify.Style.INFO);
|
||||||
getContentResolver().notifyChange(KeychainContract.KeyRings.CONTENT_URI, null);
|
getContentResolver().notifyChange(KeychainContract.KeyRings.CONTENT_URI, null);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "IO Error", e);
|
Log.e(Constants.TAG, "IO Error", e);
|
||||||
Notify.showNotify(this, "IO Notify.Style: " + e.getMessage(), Notify.Style.ERROR);
|
Notify.showNotify(this, "IO Error " + e.getMessage(), Notify.Style.ERROR);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_key_list_debug_write:
|
case R.id.menu_key_list_debug_write:
|
||||||
try {
|
try {
|
||||||
KeychainDatabase.debugWrite(this);
|
KeychainDatabase.debugBackup(this, false);
|
||||||
Notify.showNotify(this, "Backup Notify.Style", Notify.Style.INFO);
|
Notify.showNotify(this, "Backup to debug_backup.db completed", Notify.Style.INFO);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
Log.e(Constants.TAG, "IO Error", e);
|
Log.e(Constants.TAG, "IO Error", e);
|
||||||
Notify.showNotify(this, "IO Notify.Style: " + e.getMessage(), Notify.Style.ERROR);
|
Notify.showNotify(this, "IO Error: " + e.getMessage(), Notify.Style.ERROR);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -133,7 +133,6 @@
|
|||||||
android:id="@+id/view_key_action_upload"
|
android:id="@+id/view_key_action_upload"
|
||||||
android:paddingLeft="8dp"
|
android:paddingLeft="8dp"
|
||||||
android:paddingRight="8dp"
|
android:paddingRight="8dp"
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user