backup_data: SKIP_PADDING FAILED at line X

北战南征 提交于 2019-12-08 09:23:59

问题


I am using the Google Backup API for SharedPreferences as described here:

http://developer.android.com/guide/topics/data/backup.html#RequestingRestore

When using bmgr, as described here: http://developer.android.com/tools/help/bmgr.html

I do get the log messages for onRestore an onBackup methods, but in onRestore I get this line:

06-06 11:24:16.546: D/backup_data(24615): SKIP_PADDING FAILED at line 332

The only reference for it is here: https://github.com/comex/frash/blob/master/utils/utils/BackupData.cpp

And no input is read.

My Helper class:

public class NoteBackupAgent extends BackupAgentHelper {

    public static final Object[] DATA_LOCK = new Object[0];
    private static final String PREFS_BACKUP_KEY = Const.ENTRY_PREFS;

    @Override
    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState) throws IOException {

        Log.d(toString(), "########### onBackup() " + oldState.getStatSize());

        synchronized (DATA_LOCK) {
            super.onBackup(oldState, data, newState);
        }
    }

    @Override
    public void onCreate() {
        SharedPreferencesBackupHelper preferencesHelper = new SharedPreferencesBackupHelper(this,
                getPackageName() + "_preferences");
        Toast.makeText(getApplicationContext(), "onCreate", Toast.LENGTH_LONG).show();
        addHelper(PREFS_BACKUP_KEY, preferencesHelper);

    }

    @Override
    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
            throws IOException {

        synchronized (DATA_LOCK) {
            //super.onRestore(data, appVersionCode, newState);

            // There should be only one entity, but the safest
            // way to consume it is using a while loop
            StringBuilder total = new StringBuilder();

            while (data.readNextHeader()) {
                String key = data.getKey();
                int dataSize = data.getDataSize();

                // If the key is ours (for saving top score). Note this key was used when
                // we wrote the backup entity header
                if (PREFS_BACKUP_KEY.equals(key)) {
                    // Create an input stream for the BackupDataInput
                    byte[] dataBuf = new byte[dataSize];
                    data.readEntityData(dataBuf, 0, dataSize);
                    ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
                    DataInputStream in = new DataInputStream(baStream);

                    BufferedReader r = new BufferedReader(new InputStreamReader(in));

                    String line;
                    while ((line = r.readLine()) != null) {
                        total.append(line);
                    }
                    Log.d(toString(), "########## data " + total);
                } else {
                    data.skipEntityData();
                }
            }

            Log.d(toString(), "########## onRestore()" + total.toString());
        }
    }

}

回答1:


In our case the solution was preventing enforcing Base64 encodings on the values stored in our shared preferences. As you mentoined @Demonick, https://github.com/comex/frash/blob/master/utils/utils/BackupData.cpp is the cause of the error, BackupDataReader::skip_padding() is using Base32 encoding for paddings.

Conclusion is: Prevent using Base64.encodeToString(input, Base64.NO_PADDING) for writing shared preferences.



来源:https://stackoverflow.com/questions/24078449/backup-data-skip-padding-failed-at-line-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!