aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2010-05-23 05:38:57 +0000
committerKenny Root <kenny@the-b.org>2010-05-23 05:38:57 +0000
commit41ba899cb71c83955bcaa9fc25f70d2b1fe01ed5 (patch)
treed6b10f820556de118d2473237dad9c73c250302c
parentf5d392e3a334d230fb782a1faff37bda8153750f (diff)
downloadconnectbot-41ba899cb71c83955bcaa9fc25f70d2b1fe01ed5.tar.gz
connectbot-41ba899cb71c83955bcaa9fc25f70d2b1fe01ed5.tar.bz2
connectbot-41ba899cb71c83955bcaa9fc25f70d2b1fe01ed5.zip
Add backup feature for API 8
git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@502 df292f66-193f-0410-a5fc-6d59da041ff2
-rw-r--r--AndroidManifest.xml5
-rw-r--r--default.properties2
-rw-r--r--src/org/connectbot/service/BackupAgent.java73
-rw-r--r--src/org/connectbot/service/BackupWrapper.java71
-rw-r--r--src/org/connectbot/util/HostDatabase.java4
-rw-r--r--src/org/connectbot/util/OnDbWrittenListener.java26
-rw-r--r--src/org/connectbot/util/PreferenceConstants.java5
7 files changed, 180 insertions, 6 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 053907d..13444ee 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -7,7 +7,8 @@
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
- android:description="@string/app_desc">
+ android:description="@string/app_desc"
+ android:backupAgent=".service.BackupAgent">
<activity android:name=".HostListActivity" >
<intent-filter>
@@ -50,7 +51,7 @@
</application>
- <uses-sdk android:targetSdkVersion="6" android:minSdkVersion="3" />
+ <uses-sdk android:targetSdkVersion="8" android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
diff --git a/default.properties b/default.properties
index c11575b..8cebe7d 100644
--- a/default.properties
+++ b/default.properties
@@ -11,4 +11,4 @@
split.density=false
# Project target.
-target=android-6
+target=android-8
diff --git a/src/org/connectbot/service/BackupAgent.java b/src/org/connectbot/service/BackupAgent.java
new file mode 100644
index 0000000..1e3bd81
--- /dev/null
+++ b/src/org/connectbot/service/BackupAgent.java
@@ -0,0 +1,73 @@
+/*
+ * ConnectBot: simple, powerful, open-source SSH client for Android
+ * Copyright 2010 Kenny Root, Jeffrey Sharkey
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.connectbot.service;
+
+import java.io.IOException;
+
+import org.connectbot.util.HostDatabase;
+import org.connectbot.util.PreferenceConstants;
+import org.connectbot.util.PubkeyDatabase;
+
+import android.app.backup.BackupAgentHelper;
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+import android.app.backup.FileBackupHelper;
+import android.app.backup.SharedPreferencesBackupHelper;
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+/**
+ * @author kroot
+ *
+ */
+public class BackupAgent extends BackupAgentHelper {
+ @Override
+ public void onCreate() {
+ Log.d("ConnectBot.BackupAgent", "onCreate called");
+
+ SharedPreferencesBackupHelper prefs = new SharedPreferencesBackupHelper(this, getPackageName() + "_preferences");
+ addHelper(PreferenceConstants.BACKUP_PREF_KEY, prefs);
+
+ FileBackupHelper hosts = new FileBackupHelper(this, "../databases/" + HostDatabase.DB_NAME);
+ addHelper(HostDatabase.DB_NAME, hosts);
+
+ FileBackupHelper pubkeys = new FileBackupHelper(this, "../databases/" + PubkeyDatabase.DB_NAME);
+ addHelper(PubkeyDatabase.DB_NAME, pubkeys);
+
+ }
+
+ @Override
+ public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
+ ParcelFileDescriptor newState) throws IOException {
+ synchronized (HostDatabase.dbLock) {
+ super.onBackup(oldState, data, newState);
+ }
+ }
+
+ @Override
+ public void onRestore(BackupDataInput data, int appVersionCode,
+ ParcelFileDescriptor newState) throws IOException {
+ Log.d("ConnectBot.BackupAgent", "onRestore called");
+
+ synchronized (HostDatabase.dbLock) {
+ Log.d("ConnectBot.BackupAgent", "onRestore in-lock");
+
+ super.onRestore(data, appVersionCode, newState);
+ }
+ }
+}
diff --git a/src/org/connectbot/service/BackupWrapper.java b/src/org/connectbot/service/BackupWrapper.java
new file mode 100644
index 0000000..bfc7535
--- /dev/null
+++ b/src/org/connectbot/service/BackupWrapper.java
@@ -0,0 +1,71 @@
+/*
+ * ConnectBot: simple, powerful, open-source SSH client for Android
+ * Copyright 2010 Kenny Root, Jeffrey Sharkey
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.connectbot.service;
+
+import org.connectbot.util.PreferenceConstants;
+
+import android.app.backup.BackupManager;
+import android.content.Context;
+
+/**
+ * @author kroot
+ *
+ */
+public abstract class BackupWrapper {
+ public static BackupWrapper getInstance() {
+ if (PreferenceConstants.PRE_FROYO)
+ return PreFroyo.Holder.sInstance;
+ else
+ return FroyoAndBeyond.Holder.sInstance;
+ }
+
+ public abstract void onDataChanged(Context context);
+
+ private static class PreFroyo extends BackupWrapper {
+ private static class Holder {
+ private static final PreFroyo sInstance = new PreFroyo();
+ }
+
+ @Override
+ public void onDataChanged(Context context) {
+ // do nothing for now
+ }
+ }
+
+ private static class FroyoAndBeyond extends BackupWrapper {
+ private static class Holder {
+ private static final FroyoAndBeyond sInstance = new FroyoAndBeyond();
+ }
+
+ private static BackupManager mBackupManager;
+
+ @Override
+ public void onDataChanged(Context context) {
+ checkBackupManager(context);
+ if (mBackupManager != null) {
+ mBackupManager.dataChanged();
+ }
+ }
+
+ private void checkBackupManager(Context context) {
+ if (mBackupManager == null) {
+ mBackupManager = new BackupManager(context);
+ }
+ }
+ }
+}
diff --git a/src/org/connectbot/util/HostDatabase.java b/src/org/connectbot/util/HostDatabase.java
index bd567ce..b0dce6d 100644
--- a/src/org/connectbot/util/HostDatabase.java
+++ b/src/org/connectbot/util/HostDatabase.java
@@ -134,14 +134,12 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
addIndexName(TABLE_COLOR_DEFAULTS + FIELD_COLOR_SCHEME + "index");
}
- private Object dbLock;
+ public static final Object[] dbLock = new Object[0];
public HostDatabase(Context context) {
super(context, DB_NAME, null, DB_VERSION);
getWritableDatabase().close();
-
- dbLock = new Object();
}
@Override
diff --git a/src/org/connectbot/util/OnDbWrittenListener.java b/src/org/connectbot/util/OnDbWrittenListener.java
new file mode 100644
index 0000000..ef33797
--- /dev/null
+++ b/src/org/connectbot/util/OnDbWrittenListener.java
@@ -0,0 +1,26 @@
+/*
+ * ConnectBot: simple, powerful, open-source SSH client for Android
+ * Copyright 2010 Kenny Root, Jeffrey Sharkey
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.connectbot.util;
+
+/**
+ * @author kroot
+ *
+ */
+public interface OnDbWrittenListener {
+ public void onDbWritten();
+}
diff --git a/src/org/connectbot/util/PreferenceConstants.java b/src/org/connectbot/util/PreferenceConstants.java
index ee1b95a..37e1871 100644
--- a/src/org/connectbot/util/PreferenceConstants.java
+++ b/src/org/connectbot/util/PreferenceConstants.java
@@ -25,6 +25,8 @@ import android.os.Build;
*/
public class PreferenceConstants {
public static final boolean PRE_ECLAIR = (Integer.parseInt(Build.VERSION.SDK) <= 4);
+ public static final boolean PRE_FROYO = PRE_ECLAIR ? true :
+ (Build.VERSION.SDK_INT <= 7);
public static final String MEMKEYS = "memkeys";
public static final String UPDATE = "update";
@@ -77,4 +79,7 @@ public class PreferenceConstants {
public static final float DEFAULT_BELL_VOLUME = 0.25f;
public static final String CONNECTION_PERSIST = "connPersist";
+
+ /* Backup identifiers */
+ public static final String BACKUP_PREF_KEY = "prefs";
}