类android.app.backup.BackupDataInput源码实例Demo

下面列出了怎么用android.app.backup.BackupDataInput的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: mytracks   文件: MyTracksBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
    ParcelFileDescriptor newState) throws IOException {
  Log.i(TAG, "Restoring from backup");
  while (data.readNextHeader()) {
    String key = data.getKey();
    Log.d(TAG, "Restoring entity " + key);
    if (key.equals(PREFERENCES_ENTITY)) {
      restorePreferences(data);
    } else {
      Log.e(TAG, "Found unknown backup entity: " + key);
      data.skipEntityData();
    }
  }
  Log.i(TAG, "Done restoring from backup");
}
 
源代码2 项目: openboard   文件: BackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    // Let the restore operation go through
    super.onRestore(data, appVersionCode, newState);

    // Remove the preferences that we don't want restored.
    final SharedPreferences.Editor prefEditor = getSharedPreferences(
            getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit();
    for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) {
        prefEditor.remove(key);
    }
    // Flush the changes to disk.
    prefEditor.commit();
}
 
源代码3 项目: Android-Keyboard   文件: BackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    // Let the restore operation go through
    super.onRestore(data, appVersionCode, newState);

    // Remove the preferences that we don't want restored.
    final SharedPreferences.Editor prefEditor = getSharedPreferences(
            getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit();
    for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) {
        prefEditor.remove(key);
    }
    // Flush the changes to disk.
    prefEditor.commit();
}
 
源代码4 项目: mobikul-standalone-pos   文件: MyBackupAgent.java
/**
 * Adding locking around the file rewrite that happens during restore is
 * similarly straightforward.
 */
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
                      ParcelFileDescriptor newState) throws IOException {
    // Hold the lock while the FileBackupHelper restores the file from
    // the data provided here.
    synchronized (sDataLock) {
        super.onRestore(data, appVersionCode, newState);
    }
}
 
源代码5 项目: CSipSimple   文件: SipBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    Log.d(THIS_FILE, "App version code : " + appVersionCode);
    super.onRestore(data, appVersionCode, newState);


}
 
源代码6 项目: AOSP-Kayboard-7.1.2   文件: BackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    // Let the restore operation go through
    super.onRestore(data, appVersionCode, newState);

    // Remove the preferences that we don't want restored.
    final SharedPreferences.Editor prefEditor = getSharedPreferences(
            getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit();
    for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) {
        prefEditor.remove(key);
    }
    // Flush the changes to disk.
    prefEditor.commit();
}
 
源代码7 项目: mytracks   文件: MyTracksBackupAgent.java
/**
 * Restores all preferences from the backup.
 * 
 * @param data the backup data to read from
 * @throws IOException if there are any errors while reading
 */
private void restorePreferences(BackupDataInput data) throws IOException {
  int dataSize = data.getDataSize();
  byte[] dataBuffer = new byte[dataSize];
  int read = data.readEntityData(dataBuffer, 0, dataSize);
  if (read != dataSize) {
    throw new IOException("Failed to read all the preferences data");
  }

  SharedPreferences preferences = this.getSharedPreferences(
      Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
  PreferenceBackupHelper importer = createPreferenceBackupHelper();
  importer.importPreferences(dataBuffer, preferences);
}
 
源代码8 项目: Study_Android_Demo   文件: SettingsBackupAgent.java
void incorporateWifiSupplicant(BackupDataInput data) {
    restoredSupplicantData = new byte[data.getDataSize()];
    if (restoredSupplicantData.length <= 0) return;
    try {
        data.readEntityData(restoredSupplicantData, 0, data.getDataSize());
    } catch (IOException e) {
        Log.w(TAG, "Unable to read supplicant data");
        restoredSupplicantData = null;
    }
}
 
源代码9 项目: Study_Android_Demo   文件: SettingsBackupAgent.java
void incorporateWifiConfigFile(BackupDataInput data) {
    restoredWifiConfigFile = new byte[data.getDataSize()];
    if (restoredWifiConfigFile.length <= 0) return;
    try {
        data.readEntityData(restoredWifiConfigFile, 0, data.getDataSize());
    } catch (IOException e) {
        Log.w(TAG, "Unable to read config file");
        restoredWifiConfigFile = null;
    }
}
 
源代码10 项目: Study_Android_Demo   文件: SettingsBackupAgent.java
private void restoreSettings(BackupDataInput data, Uri contentUri,
        HashSet<String> movedToGlobal) {
    byte[] settings = new byte[data.getDataSize()];
    try {
        data.readEntityData(settings, 0, settings.length);
    } catch (IOException ioe) {
        Log.e(TAG, "Couldn't read entity data");
        return;
    }
    restoreSettings(settings, settings.length, contentUri, movedToGlobal);
}
 
源代码11 项目: Study_Android_Demo   文件: SettingsBackupAgent.java
private void restoreSettings(BackupDataInput data, Uri contentUri,
        HashSet<String> movedToGlobal) {
    byte[] settings = new byte[data.getDataSize()];
    try {
        data.readEntityData(settings, 0, settings.length);
    } catch (IOException ioe) {
        Log.e(TAG, "Couldn't read entity data");
        return;
    }
    restoreSettings(settings, settings.length, contentUri, movedToGlobal);
}
 
源代码12 项目: Study_Android_Demo   文件: SettingsBackupAgent.java
private void restoreLockSettings(BackupDataInput data) {
    final byte[] settings = new byte[data.getDataSize()];
    try {
        data.readEntityData(settings, 0, settings.length);
    } catch (IOException ioe) {
        Log.e(TAG, "Couldn't read entity data");
        return;
    }
    restoreLockSettings(settings, settings.length);
}
 
源代码13 项目: Popeens-DSub   文件: SettingsBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
	super.onRestore(data, appVersionCode, newState);

	SharedPreferences.Editor editor = Util.getPreferences(this).edit();
	editor.remove(Constants.PREFERENCES_KEY_CACHE_LOCATION);
	editor.remove(Constants.CACHE_AUDIO_SESSION_ID);
	editor.apply();
}
 
源代码14 项目: LB-Launcher   文件: LauncherBackupAgentHelper.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    if (!Utilities.isLmpOrAbove()) {
        // No restore for old devices.
        Log.i(TAG, "You shall not pass!!!");
        Log.d(TAG, "Restore is only supported on devices running Lollipop and above.");
        return;
    }

    // Clear dB before restore
    LauncherAppState.getLauncherProvider().createEmptyDB();

    boolean hasData;
    try {
        super.onRestore(data, appVersionCode, newState);
        // If no favorite was migrated, clear the data and start fresh.
        final Cursor c = getContentResolver().query(
                LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, null, null, null, null);
        hasData = c.moveToNext();
        c.close();
    } catch (Exception e) {
        // If the restore fails, we should do a fresh start.
        Log.e(TAG, "Restore failed", e);
        hasData = false;
    }

    if (hasData && mHelper.restoreSuccessful) {
        LauncherAppState.getLauncherProvider().clearFlagEmptyDbCreated();
        LauncherClings.synchonouslyMarkFirstRunClingDismissed(this);
    } else {
        if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB");
        LauncherAppState.getLauncherProvider().createEmptyDB();
    }
}
 
源代码15 项目: Indic-Keyboard   文件: BackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    // Let the restore operation go through
    super.onRestore(data, appVersionCode, newState);

    // Remove the preferences that we don't want restored.
    final SharedPreferences.Editor prefEditor = getSharedPreferences(
            getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit();
    for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) {
        prefEditor.remove(key);
    }
    // Flush the changes to disk.
    prefEditor.commit();
}
 
源代码16 项目: ghwatch   文件: MyBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
  Log.i(TAG, "Restore from backup started");
  super.onRestore(data, appVersionCode, newState);
  PreferencesUtils.patchAfterRestore(this);
  Log.i(TAG, "Restore from backup finished");
}
 
源代码17 项目: ministocks   文件: BackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
                      ParcelFileDescriptor newState) throws IOException {
    // Hold the lock while the FileBackupHelper restores the file
    synchronized (UserData.sFileBackupLock) {
        super.onRestore(data, appVersionCode, newState);
    }
}
 
源代码18 项目: LaunchEnr   文件: LauncherBackupAgent.java
@Override
public void onRestore(
        BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) {
    // Doesn't do incremental backup/restore
}
 
源代码19 项目: andOTP   文件: BackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
    synchronized (DatabaseHelper.DatabaseFileLock) {
        super.onRestore(data, appVersionCode, newState);
    }
}
 
源代码20 项目: science-journal   文件: SimpleBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
    throws IOException {
  super.onRestore(data, appVersionCode, newState);
}
 
源代码21 项目: delion   文件: ChromeBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    // No implementation needed for Android 6.0 Auto Backup. Used only on older versions of
    // Android Backup
}
 
源代码22 项目: octoandroid   文件: OctoBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
    synchronized (DbHelper.sLock) {
        super.onRestore(data, appVersionCode, newState);
    }
}
 
源代码23 项目: Audinaut   文件: SettingsBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
    super.onRestore(data, appVersionCode, newState);
    Util.getPreferences(this).edit().remove(Constants.PREFERENCES_KEY_CACHE_LOCATION).apply();
}
 
源代码24 项目: Study_Android_Demo   文件: SettingsBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {

    HashSet<String> movedToGlobal = new HashSet<String>();
    Settings.System.getMovedKeys(movedToGlobal);
    Settings.Secure.getMovedKeys(movedToGlobal);

    while (data.readNextHeader()) {
        final String key = data.getKey();
        final int size = data.getDataSize();
        if (KEY_SYSTEM.equals(key)) {
            restoreSettings(data, Settings.System.CONTENT_URI, movedToGlobal);
            mSettingsHelper.applyAudioSettings();
        } else if (KEY_SECURE.equals(key)) {
            restoreSettings(data, Settings.Secure.CONTENT_URI, movedToGlobal);
        } else if (KEY_GLOBAL.equals(key)) {
            restoreSettings(data, Settings.Global.CONTENT_URI, null);
        } else if (KEY_WIFI_SUPPLICANT.equals(key)) {
            initWifiRestoreIfNecessary();
            mWifiRestore.incorporateWifiSupplicant(data);
        } else if (KEY_LOCALE.equals(key)) {
            byte[] localeData = new byte[size];
            data.readEntityData(localeData, 0, size);
            mSettingsHelper.setLocaleData(localeData, size);
        } else if (KEY_WIFI_CONFIG.equals(key)) {
            initWifiRestoreIfNecessary();
            mWifiRestore.incorporateWifiConfigFile(data);
         } else {
            data.skipEntityData();
        }
    }

    // If we have wifi data to restore, post a runnable to perform the
    // bounce-and-update operation a little ways in the future.
    if (mWifiRestore != null) {
        long wifiBounceDelayMillis = Settings.Global.getLong(
                getContentResolver(),
                Settings.Global.WIFI_BOUNCE_DELAY_OVERRIDE_MS,
                WIFI_BOUNCE_DELAY_MILLIS);
        new Handler(getMainLooper()).postDelayed(mWifiRestore, wifiBounceDelayMillis);
    }
}
 
源代码25 项目: Study_Android_Demo   文件: SettingsBackupAgent.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {

    HashSet<String> movedToGlobal = new HashSet<String>();
    Settings.System.getMovedToGlobalSettings(movedToGlobal);
    Settings.Secure.getMovedToGlobalSettings(movedToGlobal);
    byte[] restoredWifiSupplicantData = null;
    byte[] restoredWifiIpConfigData = null;

    while (data.readNextHeader()) {
        final String key = data.getKey();
        final int size = data.getDataSize();
        switch (key) {
            case KEY_SYSTEM :
                restoreSettings(data, Settings.System.CONTENT_URI, movedToGlobal);
                mSettingsHelper.applyAudioSettings();
                break;

            case KEY_SECURE :
                restoreSettings(data, Settings.Secure.CONTENT_URI, movedToGlobal);
                break;

            case KEY_GLOBAL :
                restoreSettings(data, Settings.Global.CONTENT_URI, null);
                break;

            case KEY_WIFI_SUPPLICANT :
                restoredWifiSupplicantData = new byte[size];
                data.readEntityData(restoredWifiSupplicantData, 0, size);
                break;

            case KEY_LOCALE :
                byte[] localeData = new byte[size];
                data.readEntityData(localeData, 0, size);
                mSettingsHelper.setLocaleData(localeData, size);
                break;

            case KEY_WIFI_CONFIG :
                restoredWifiIpConfigData = new byte[size];
                data.readEntityData(restoredWifiIpConfigData, 0, size);
                break;

            case KEY_LOCK_SETTINGS :
                restoreLockSettings(data);
                break;

            case KEY_SOFTAP_CONFIG :
                byte[] softapData = new byte[size];
                data.readEntityData(softapData, 0, size);
                restoreSoftApConfiguration(softapData);
                break;

            case KEY_NETWORK_POLICIES:
                byte[] netPoliciesData = new byte[size];
                data.readEntityData(netPoliciesData, 0, size);
                restoreNetworkPolicies(netPoliciesData);
                break;

            case KEY_WIFI_NEW_CONFIG:
                byte[] restoredWifiNewConfigData = new byte[size];
                data.readEntityData(restoredWifiNewConfigData, 0, size);
                restoreNewWifiConfigData(restoredWifiNewConfigData);
                break;

            default :
                data.skipEntityData();

        }
    }

    // Do this at the end so that we also pull in the ipconfig data.
    if (restoredWifiSupplicantData != null) {
        restoreSupplicantWifiConfigData(
                restoredWifiSupplicantData, restoredWifiIpConfigData);
    }
}
 
源代码26 项目: Trebuchet   文件: LauncherBackupAgentHelper.java
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
        throws IOException {
    if (!Utilities.ATLEAST_LOLLIPOP) {
        // No restore for old devices.
        Log.i(TAG, "You shall not pass!!!");
        Log.d(TAG, "Restore is only supported on devices running Lollipop and above.");
        return;
    }

    // Clear dB before restore
    LauncherAppState.getLauncherProvider().createEmptyDB();

    boolean hasData;
    try {
        super.onRestore(data, appVersionCode, newState);
        // If no favorite was migrated, clear the data and start fresh.
        final Cursor c = getContentResolver().query(
                LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
        hasData = c.moveToNext();
        c.close();
    } catch (Exception e) {
        // If the restore fails, we should do a fresh start.
        Log.e(TAG, "Restore failed", e);
        hasData = false;
    }

    if (hasData && mHelper.restoreSuccessful) {
        LauncherAppState.getLauncherProvider().clearFlagEmptyDbCreated();
        LauncherClings.synchonouslyMarkFirstRunClingDismissed(this);

        // Rank was added in v4.
        if (mHelper.restoredBackupVersion <= 3) {
            LauncherAppState.getLauncherProvider().updateFolderItemsRank();
        }

        if (MigrateFromRestoreTask.ENABLED && mHelper.shouldAttemptWorkspaceMigration()) {
            MigrateFromRestoreTask.markForMigration(getApplicationContext(),
                    (int) mHelper.migrationCompatibleProfileData.desktopCols,
                    (int) mHelper.migrationCompatibleProfileData.desktopRows,
                    mHelper.widgetSizes);
        }

        LauncherAppState.getLauncherProvider().convertShortcutsToLauncherActivities();
    } else {
        if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB");
        LauncherAppState.getLauncherProvider().createEmptyDB();
    }
}
 
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) {} 
 类所在包
 同包方法