Java Code Examples for android.app.backup.BackupDataInput#getDataSize()

The following examples show how to use android.app.backup.BackupDataInput#getDataSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyTracksBackupAgent.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: SettingsBackupAgent.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 3
Source File: SettingsBackupAgent.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 4
Source File: SettingsBackupAgent.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: SettingsBackupAgent.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: SettingsBackupAgent.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: SettingsBackupAgent.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: SettingsBackupAgent.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
@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);
    }
}