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;
import android.net.NetworkInfo.State; import android.net.NetworkInfo.State;
import android.text.InputType; import android.text.InputType;
import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -283,4 +284,23 @@ public class AndroidUtilities {
public static int getSdkVersion() { public static int getSdkVersion() {
return Integer.parseInt(android.os.Build.VERSION.SDK); 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); convertView = newView(convertView, parent);
ViewHolder viewHolder = (ViewHolder) convertView.getTag(); 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); populateView(viewHolder, true, false);
return convertView; return convertView;

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

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

@ -19,17 +19,15 @@ public final class UpgradeService {
* @param to * @param to
*/ */
public void performUpgrade(int from) { public void performUpgrade(int from) {
if(from < 1)
return;
if(from == 135) if(from == 135)
AddOnService.recordOem(); AddOnService.recordOem();
if(from < 136) if(from < 136) {
new Astrid2To3UpgradeHelper().upgrade2To3(); new Astrid2To3UpgradeHelper().upgrade2To3(this, from);
} else {
// display changelog // display changelog
showChangeLog(from); showChangeLog(from);
}
} }
/** /**
@ -42,30 +40,11 @@ public final class UpgradeService {
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public void showChangeLog(int from) { public void showChangeLog(int from) {
if(!(ContextManager.getContext() instanceof Activity)) if(!(ContextManager.getContext() instanceof Activity) || from == 0)
return; return;
StringBuilder changeLog = new StringBuilder(); 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) if(from <= 135)
newVersionString(changeLog, "3.0.0 (8/3/10)", new String[] { newVersionString(changeLog, "3.0.0 (8/3/10)", new String[] {
"Astrid is brand new inside and out! In addition to a new " + "Astrid is brand new inside and out! In addition to a new " +

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

Loading…
Cancel
Save