/** * doDbUpgrade is triggered by someone calling the static method "processPackageReplacedBroadcast" * * @param cps - a String array containing all the ContentProvider authorities to upgrade * @return */ protected boolean doDbUpgrade(final Intent intent) { boolean success = false; try { // First set the global lock on the Base ContentProvider LogUtils.i(LogUtils.TAG, "Package has been replaced, perform database upgrades..."); // PIMContentProviderBase.setMaintenanceLock(cpLock, true); // Get the list of content authorities from the Intent extras Bundle extras = intent.getExtras(); String[] cps = extras.getStringArray(CP_LIST); if (cps == null) { // Nothing to upgrade? return success; } // Write out our current task information to a preference file writeActionState(DB_UPGRADE_ACTION, cps); // Lock all providers, then upgrade, then unlock lockProviders(cps); success = upgradeProviders(cps); unlockProviders(cps); } catch (Exception e) { LogUtils.e(LogUtils.TAG, "Database upgrade exception: %s", e.getMessage()); } finally { // Unlock the Base Content Provider // PIMContentProviderBase.setMaintenanceLock(cpLock, false); } LogUtils.i(LogUtils.TAG, "Package has been replaced, perform database upgrades...done"); return success; }
/** * readActionState - read in state from preference file * * @return current action from the preference file */ protected int readActionState() { int currentAction = UNKNOWN_ACTION; try { SharedPreferences prefs = getApplicationContext().getSharedPreferences(CPMAINT_STATE_PREFERENCE, MODE_PRIVATE); if (prefs != null) { currentAction = prefs.getInt(CURRENT_TASK, UNKNOWN_ACTION); } } catch (Exception e) { LogUtils.e(LogUtils.TAG, "Unable to get CP Maint action: %s", e.getMessage()); } return currentAction; }
private ConversationMessage getMessageFromCursor(MessageCursor cursor) { // ignore cursors that are still loading results if (cursor == null || !cursor.isLoaded()) { LogUtils.i(LOG_TAG, "CONV RENDER: existing cursor is null, rendering from scratch"); return null; } if (mActivity == null || mActivity.isFinishing()) { // Activity is finishing, just bail. return null; } if (!cursor.moveToFirst()) { LogUtils.e(LOG_TAG, "unable to open message cursor"); return null; } return cursor.getMessage(); }
/** * writeActionState - write out some state to a preference file * * @param action - integer * @return N/A */ protected void writeActionState(int action, String[] cps) { try { SharedPreferences prefs = getApplicationContext().getSharedPreferences(CPMAINT_STATE_PREFERENCE, MODE_PRIVATE); SharedPreferences.Editor editPrefs = prefs.edit(); editPrefs.putInt(CURRENT_TASK, action); if (cps != null) { // Save the list of ContentProvider authority strings to the shared pref Set<String> mySet = new HashSet<String>(Arrays.asList(cps)); editPrefs.putStringSet(CP_LIST, mySet); } editPrefs.commit(); } catch (Exception e) { LogUtils.e(LogUtils.TAG, "Unable to save CP Maint action: %s", e.getMessage()); } }
/** * getActionState - write out some state to a preference file * * @return current action from the preference file */ protected String[] getCPListFromSharedPrefs() { try { SharedPreferences prefs = getApplicationContext().getSharedPreferences(CPMAINT_STATE_PREFERENCE, MODE_PRIVATE); if (prefs != null) { Set<String> cps = prefs.getStringSet(CP_LIST, null); if (cps != null) { // Convert the set to an array of String objects return cps.toArray(new String[cps.size()]); } } } catch (Exception e) { LogUtils.e( LogUtils.TAG, "Cannot get ContentProvider list from preferences: %s", e.getMessage()); } return null; }