Fixed crash, now performing upgrade in background thread

pull/14/head
Tim Su 16 years ago
parent 934ff46fbb
commit 581cdacbfd

@ -20,6 +20,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.text.InputType;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -283,4 +284,23 @@ public class AndroidUtilities {
public static int getSdkVersion() {
return Integer.parseInt(android.os.Build.VERSION.SDK);
}
/**
* Copy databases to a given folder. Useful for debugging
* @param folder
*/
public static void copyDatabases(Context context, String folder) {
File folderFile = new File(folder);
if(!folderFile.exists())
folderFile.mkdir();
for(String db : context.databaseList()) {
File dbFile = context.getDatabasePath(db);
try {
copyFile(dbFile, new File(folderFile.getAbsolutePath() +
File.separator + db));
} catch (Exception e) {
Log.e("ERROR", "ERROR COPYING DB " + db, e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
}

@ -132,7 +132,11 @@ public class FilterAdapter extends BaseExpandableListAdapter {
convertView = newView(convertView, parent);
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
viewHolder.item = (FilterListItem)getChild(groupPosition, childPosition);
Object item = getChild(groupPosition, childPosition);
if(!(item instanceof FilterListItem))
return convertView;
viewHolder.item = (FilterListItem) item;
populateView(viewHolder, true, false);
return convertView;

@ -113,92 +113,108 @@ public class Astrid2To3UpgradeHelper {
/**
* Perform the upgrade from Astrid 2 to Astrid 3
*/
public void upgrade2To3() {
public void upgrade2To3(final UpgradeService upgradeService, final int from) {
final Context context = ContextManager.getContext();
// if there's already a database table, clear it out (!!!)
// if from < 1 (we don't know what version, and database exists, leave it alone)
if(from < 1 && Arrays.asList(context.databaseList()).contains(database.getName()))
return;
// else, if there's already a database table, clear it out (!!!)
if(Arrays.asList(context.databaseList()).contains(database.getName()))
context.deleteDatabase(database.getName());
// pop up a progress dialog
ProgressDialog dialog = null;
final ProgressDialog dialog;
if(context instanceof Activity)
dialog = dialogUtilities.progressDialog(context, context.getString(R.string.DLG_wait));
// initiate a backup
String backupFile = legacyBackup();
database.openForWriting();
try {
// --- upgrade tasks table
HashMap<String, Property<?>> propertyMap =
new HashMap<String, Property<?>>();
propertyMap.put("_id", Task.ID); //$NON-NLS-1$
propertyMap.put(LegacyTaskModel.NAME, Task.TITLE);
propertyMap.put(LegacyTaskModel.NOTES, Task.NOTES);
// (don't update progress percentage, we don't use this anymore)
propertyMap.put(LegacyTaskModel.IMPORTANCE, Task.IMPORTANCE);
propertyMap.put(LegacyTaskModel.ESTIMATED_SECONDS, Task.ESTIMATED_SECONDS);
propertyMap.put(LegacyTaskModel.ELAPSED_SECONDS, Task.ELAPSED_SECONDS);
propertyMap.put(LegacyTaskModel.TIMER_START, Task.TIMER_START);
propertyMap.put(LegacyTaskModel.DEFINITE_DUE_DATE, Task.DUE_DATE);
propertyMap.put(LegacyTaskModel.HIDDEN_UNTIL, Task.HIDE_UNTIL);
propertyMap.put(LegacyTaskModel.POSTPONE_COUNT, Task.POSTPONE_COUNT);
propertyMap.put(LegacyTaskModel.NOTIFICATIONS, Task.REMINDER_PERIOD);
propertyMap.put(LegacyTaskModel.NOTIFICATION_FLAGS, Task.REMINDER_FLAGS);
propertyMap.put(LegacyTaskModel.LAST_NOTIFIED, Task.REMINDER_LAST);
propertyMap.put(LegacyTaskModel.REPEAT, Task.RECURRENCE);
propertyMap.put(LegacyTaskModel.CREATION_DATE, Task.CREATION_DATE);
propertyMap.put(LegacyTaskModel.COMPLETION_DATE, Task.COMPLETION_DATE);
propertyMap.put(LegacyTaskModel.CALENDAR_URI, Task.CALENDAR_URI);
propertyMap.put(LegacyTaskModel.FLAGS, Task.FLAGS);
upgradeTable(context, tasksTable,
propertyMap, new Task(), taskDao);
// --- upgrade tags tables
migrateTagsToMetadata();
// --- upgrade alerts
AlarmDatabase alarmsDatabase = new AlarmDatabase();
alarmsDatabase.openForWriting();
propertyMap.clear();
propertyMap.put("_id", Alarm.ID); //$NON-NLS-1$
propertyMap.put(LegacyAlertModel.TASK, Alarm.TASK);
propertyMap.put(LegacyAlertModel.DATE, Alarm.TIME);
upgradeTable(context, alertsTable, propertyMap, new Alarm(),
alarmsDatabase.getDao());
alarmsDatabase.close();
// --- upgrade RTM sync mappings
migrateSyncMappingToMetadata();
// --- clean up database
metadataService.cleanup();
// --- upgrade properties
SharedPreferences prefs = Preferences.getPrefs(context);
Editor editor = prefs.edit();
int random = Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours, -1);
if(random != -1) {
// convert days => hours
editor.putString(context.getString(R.string.p_rmd_default_random_hours),
Integer.toString(random * 24));
else
dialog = null;
new Thread(new Runnable() {
@Override
public void run() {
// initiate a backup
String backupFile = legacyBackup();
database.openForWriting();
try {
// --- upgrade tasks table
HashMap<String, Property<?>> propertyMap =
new HashMap<String, Property<?>>();
propertyMap.put("_id", Task.ID); //$NON-NLS-1$
propertyMap.put(LegacyTaskModel.NAME, Task.TITLE);
propertyMap.put(LegacyTaskModel.NOTES, Task.NOTES);
// (don't update progress percentage, we don't use this anymore)
propertyMap.put(LegacyTaskModel.IMPORTANCE, Task.IMPORTANCE);
propertyMap.put(LegacyTaskModel.ESTIMATED_SECONDS, Task.ESTIMATED_SECONDS);
propertyMap.put(LegacyTaskModel.ELAPSED_SECONDS, Task.ELAPSED_SECONDS);
propertyMap.put(LegacyTaskModel.TIMER_START, Task.TIMER_START);
propertyMap.put(LegacyTaskModel.DEFINITE_DUE_DATE, Task.DUE_DATE);
propertyMap.put(LegacyTaskModel.HIDDEN_UNTIL, Task.HIDE_UNTIL);
propertyMap.put(LegacyTaskModel.POSTPONE_COUNT, Task.POSTPONE_COUNT);
propertyMap.put(LegacyTaskModel.NOTIFICATIONS, Task.REMINDER_PERIOD);
propertyMap.put(LegacyTaskModel.NOTIFICATION_FLAGS, Task.REMINDER_FLAGS);
propertyMap.put(LegacyTaskModel.LAST_NOTIFIED, Task.REMINDER_LAST);
propertyMap.put(LegacyTaskModel.REPEAT, Task.RECURRENCE);
propertyMap.put(LegacyTaskModel.CREATION_DATE, Task.CREATION_DATE);
propertyMap.put(LegacyTaskModel.COMPLETION_DATE, Task.COMPLETION_DATE);
propertyMap.put(LegacyTaskModel.CALENDAR_URI, Task.CALENDAR_URI);
propertyMap.put(LegacyTaskModel.FLAGS, Task.FLAGS);
upgradeTable(context, tasksTable,
propertyMap, new Task(), taskDao);
// --- upgrade tags tables
migrateTagsToMetadata();
// --- upgrade alerts
AlarmDatabase alarmsDatabase = new AlarmDatabase();
alarmsDatabase.openForWriting();
propertyMap.clear();
propertyMap.put("_id", Alarm.ID); //$NON-NLS-1$
propertyMap.put(LegacyAlertModel.TASK, Alarm.TASK);
propertyMap.put(LegacyAlertModel.DATE, Alarm.TIME);
upgradeTable(context, alertsTable, propertyMap, new Alarm(),
alarmsDatabase.getDao());
alarmsDatabase.close();
// --- upgrade RTM sync mappings
migrateSyncMappingToMetadata();
// --- clean up database
metadataService.cleanup();
// --- upgrade properties
SharedPreferences prefs = Preferences.getPrefs(context);
Editor editor = prefs.edit();
int random = Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours, -1);
if(random != -1) {
// convert days => hours
editor.putString(context.getString(R.string.p_rmd_default_random_hours),
Integer.toString(random * 24));
}
} catch (Exception e) {
exceptionService.reportError("backup-error", e); //$NON-NLS-1$
if(backupFile != null) {
// try to restore the latest XML
TasksXmlImporter.importTasks(context, backupFile, null);
}
} finally {
database.close();
if(context instanceof Activity) {
((Activity)context).runOnUiThread(new Runnable() {
public void run() {
if(dialog != null)
dialog.dismiss();
upgradeService.showChangeLog(from);
}
});
}
}
}
} catch (Exception e) {
if(dialog != null)
dialog.dismiss();
}).start();
exceptionService.reportError("backup-error", e); //$NON-NLS-1$
if(backupFile != null) {
// try to restore the latest XML
TasksXmlImporter.importTasks(context, backupFile, null);
}
} finally {
if(dialog != null)
dialog.dismiss();
database.close();
}
}
// --- database upgrade helpers

@ -8,10 +8,11 @@ import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
@ -75,16 +76,20 @@ public class StartupService {
int latestSetVersion = Preferences.getCurrentVersion();
int version = 0;
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(Constants.PACKAGE, 0);
PackageInfo pi = pm.getPackageInfo(Constants.PACKAGE, PackageManager.GET_META_DATA);
version = pi.versionCode;
} catch (Exception e) {
exceptionService.reportError("astrid-startup-package-read", e); //$NON-NLS-1$
}
Log.i("astrid", "Astrid Startup. " + latestSetVersion + //$NON-NLS-1$ //$NON-NLS-2$
" => " + version); //$NON-NLS-1$
// invoke upgrade service
boolean justUpgraded = latestSetVersion != version;
if(justUpgraded) {
if(justUpgraded && version > 0) {
upgradeService.performUpgrade(latestSetVersion);
Preferences.setCurrentVersion(version);
}

@ -19,17 +19,15 @@ public final class UpgradeService {
* @param to
*/
public void performUpgrade(int from) {
if(from < 1)
return;
if(from == 135)
AddOnService.recordOem();
if(from < 136)
new Astrid2To3UpgradeHelper().upgrade2To3();
// display changelog
showChangeLog(from);
if(from < 136) {
new Astrid2To3UpgradeHelper().upgrade2To3(this, from);
} else {
// display changelog
showChangeLog(from);
}
}
/**
@ -42,30 +40,11 @@ public final class UpgradeService {
*/
@SuppressWarnings("nls")
public void showChangeLog(int from) {
if(!(ContextManager.getContext() instanceof Activity))
if(!(ContextManager.getContext() instanceof Activity) || from == 0)
return;
StringBuilder changeLog = new StringBuilder();
if(from <= 130)
newVersionString(changeLog, "2.14.0 (5/24/10)", new String[] {
"Pick a calendar to 'Add to Calendar' (in Settings menu)",
"RTM: archived lists are ignored",
"Fixed user-reported crashes!"});
if(from > 130 && from <= 131)
newVersionString(changeLog, "2.14.1 (5/29/10)", new String[] {
"Fixed crash while using PureCalendar widget",
});
if(from > 130 && from <= 132)
newVersionString(changeLog, "2.14.2 (5/29/10)", new String[] {
"Fixed crashes occuring with certain languages (Spanish, Polish)",
"Fixed backup service deleting too many old days backups",
});
if(from > 130 && from <= 133)
newVersionString(changeLog, "2.14.3 (6/11/10)", new String[] {
"Fixed crashes occuring with certain languages (Swedish, Turkish)",
"Fixed other crashes that users have reported",
});
if(from <= 135)
newVersionString(changeLog, "3.0.0 (8/3/10)", new String[] {
"Astrid is brand new inside and out! In addition to a new " +

@ -88,7 +88,7 @@ public class Astrid2To3UpgradeTests extends DatabaseTestCase {
// --- helper methods
public void upgrade2To3() {
new Astrid2To3UpgradeHelper().upgrade2To3();
new Astrid2To3UpgradeHelper().upgrade2To3(125);
}
public static void assertDatesEqual(Date old, long newDate) {

Loading…
Cancel
Save