自动备份还原出错 - 这是一个问题吗?

时间:2016-01-08 01:38:43

标签: android android-6.0-marshmallow android-backup-service

我最近将我的项目升级到API 23,当我在API 22设备上测试时,我看到了这个错误。数据似乎恢复正常,但我仍然担心这个错误。

V/BackupManagerService: beginRestoreSession: pkg=com.nsouthdomain.nsouthapp transport=null
V/RestoreSession: restorePackage pkg=com.nsouthdomain.nsouthapp obs=android.app.backup.IRestoreObserver$Stub$Proxy@2fa157c8
D/BackupManagerService: MSG_RUN_RESTORE observer=android.app.backup.IRestoreObserver$Stub$Proxy@2fa157c8
I/GmsBackupTransport: Http Response Code : 200
I/GmsBackupTransport: Current restore package : PackageInfo{18bcdafa @pm@}
D/BackupManagerService: initiateOneRestore packageName=@pm@
V/BackupServiceBinder: doRestore() invoked
I/GmsBackupTransport: Current restore package : PackageInfo{2a7d98ab com.nsouthdomain.nsouthapp}
I/BackupManagerService: Next restore package: RestoreDescription{com.nsouthdomain.nsouthapp : KEY_VALUE}
V/BackupManagerService: Package com.nsouthdomain.nsouthapp restore version [68] is compatible with installed version [68]
D/ActivityManager: startProcessLocked calleePkgName: com.nsouthdomain.nsouthapp, hostingType: backup
D/BackupManagerService: awaiting agent for ApplicationInfo{218199ea com.nsouthdomain.nsouthapp}
D/BackupManagerService: agentConnected pkg=com.nsouthdomain.nsouthapp agent=android.os.BinderProxy@3892b56a
I/BackupManagerService: got agent android.app.IBackupAgent$Stub$Proxy@3b9ba5b
D/BackupManagerService: initiateOneRestore packageName=com.nsouthdomain.nsouthapp
E/BackupManagerService: SElinux restorecon failed for /cache/com.nsouthdomain.nsouthapp.stage
com.nsouthdomain.nsouthapp V/BackupServiceBinder: doRestore() invoked
V/BackupManagerService: No more packages; finishing restore
I/BackupRestoreController: restoreFinished for 0
I/BackupManagerService: Restore complete.
E/RestoreSession: Error in finishRestore
                java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.backup.d.r.a(android.content.Context)' on a null object reference
                at android.os.Parcel.readException(Parcel.java:1552)
                at android.os.Parcel.readException(Parcel.java:1499)
                at com.android.internal.backup.IBackupTransport$Stub$Proxy.finishRestore(IBackupTransport.java:819)
                at com.android.server.backup.BackupManagerService$ActiveRestoreSession$EndRestoreRunnable.run(BackupManagerService.java:9810)
                at android.os.Handler.handleCallback(Handler.java:739)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:145)
                at android.os.HandlerThread.run(HandlerThread.java:61)
V/BackupManagerService: Clearing restore session and halting timeout
W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1752 com.android.server.backup.BackupManagerService.warnEdmAdminOperationCompleted:10074 com.android.server.backup.BackupManagerService.clearRestoreSession:9485 com.android.server.backup.BackupManagerService$ActiveRestoreSession$EndRestoreRunnable.run:9822 android.os.Handler.handleCallback:739 

来自我的主餐:

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:backupAgent="MyBackupAgent"
        android:fullBackupContent="@xml/mybackupscheme"
        android:debuggable="true"
...

mybackupscheme.xml

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
</full-backup-content>

我的备用助手类

public class MyBackupAgent extends BackupAgentHelper {

    @Override
    public void onCreate(){
        Log.d("GradeTracker.MyBakAgent", "onCreate called");

        FileBackupHelper myDb = new FileBackupHelper(this, "../databases/" + DBAdapter.DATABASE_NAME);
        addHelper(DBAdapter.DATABASE_NAME, myDb); 
    }

    @Override
    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
         ParcelFileDescriptor newState) throws IOException {
        Log.d("GradeTracker.MyBacAgent", "onBackup called");
            synchronized (DBAdapter.dbBackupLockObject) {
                    super.onBackup(oldState, data, newState);
            }
    }

    @Override
    public void onRestore(BackupDataInput data, int appVersionCode,
                    ParcelFileDescriptor newState) throws IOException {
            Log.d("GradeTracker.MyBakAgent", "onRestore called with version " + String.valueOf(appVersionCode));
            synchronized (DBAdapter.dbBackupLockObject) {
                   try {
                       super.onRestore(data, appVersionCode, newState);
                   } catch (Exception ex){
                       ex.printStackTrace();
                   }
            }
    }
}

1 个答案:

答案 0 :(得分:0)

你不应该使用这两种机制。使用BackupAgent使用较旧的(pre-M)备份或使用新的M机制。

如果您想并排使用它们,请阅读:http://developer.android.com/training/backup/autosyncapi.html#previous-androids