安装后1分钟应用程序数据清除 - BackupManagerService Timeout

时间:2016-01-12 03:13:29

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

我刚刚将我的应用更新为API 23.每次我更喜欢全新安装时,我都可以使用该应用程序大约一分钟才能崩溃,而且我输入的任何数据到目前为止都会消失。以下是事实:

  • 我一直在使用相同的Google帐户在物理设备和模拟器上进行测试,包括调试版本和签名APK。 (日志中“签名不匹配”的可能原因。)
  • 尝试还原时,日志显示“签名不匹配”消息。
  • 60秒后,日志显示E/BackupManagerService: Timeout restoring application ...
  • 该应用随后被强制杀死,我看到很多关于clear dataClearDataReceiver以及AccountUtils: Clearing selected account for [package]
  • 的条目

为什么会这样?是否由于签名不匹配?为什么OS 永远清除用户的数据只是因为还原失败了?

我的清单中的备份配置:

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

备份方案(默认)

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

我的备用助手:

public class MyBackupAgent extends BackupAgentHelper {

    @Override
    public void onCreate(){
        Log.d("MyApp.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("MyApp.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("MyApp.MyBakAgent", "onRestore called with version " + String.valueOf(appVersionCode));
            synchronized (DBAdapter.dbBackupLockObject) {
                   try {
                       super.onRestore(data, appVersionCode, newState);
                   } catch (Exception ex){
                       ex.printStackTrace();
                   }
            }
    }
}

相关LogCat(已提及过滤包,可提供更多信息)

01-11 21:37:10.881 3588-3588/? D/RCPManagerService: App Installed with packageNAme = com.NSouth.NSouthApp
01-11 21:37:11.311 3588-3588/? D/BackupManagerService: Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.NSouth.NSouthApp flg=0x4000010 (has extras) }
01-11 21:37:11.311 3588-3588/? D/BackupManagerService: Now staging backup of com.NSouth.NSouthApp
01-11 21:37:11.331 3588-3588/? V/EnterpriseBillingPolicyStorage: getBillingProfileForVpnEngine - start - com.NSouth.NSouthApp
01-11 21:37:11.391 3588-3588/? D/KnoxMUMContainerPolicy: packageInstalledForExternalStorage com.NSouth.NSouthApp

. . .

01-11 21:38:10.241 3588-4061/? E/BackupManagerService: Timeout restoring application com.NSouth.NSouthApp
01-11 21:38:10.251 3588-4061/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.NSouth.NSouthApp
01-11 21:38:10.251 3588-4061/? I/ActivityManager: Force stopping com.NSouth.NSouthApp appid=10459 user=0: clear data
01-11 21:38:10.251 3588-4061/? I/ActivityManager: Killing 19562:com.NSouth.NSouthApp/u0a459 (adj 0): stop com.NSouth.NSouthApp cause clear data
01-11 21:38:10.261 3588-4061/? W/ActivityManager: Force removing ActivityRecord{3f90827e u0 com.NSouth.NSouthApp/.Activity_Course t12626}: app died, no saved state
01-11 21:38:10.261 3588-4061/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.NSouth.NSouthApp
01-11 21:38:10.261 3588-4061/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.NSouth.NSouthApp
01-11 21:38:10.291 3588-4061/? I/ActivityManager:   Force finishing activity 3 ActivityRecord{3a98b6d4 u0 com.NSouth.NSouthApp/.Activity_Main t12626}
01-11 21:38:10.291 3588-4061/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.NSouth.NSouthApp
01-11 21:38:10.311 3588-4061/? I/ActivityManager: Force stopping com.NSouth.NSouthApp appid=10459 user=0: clear data
01-11 21:38:10.311 3588-4061/? I/ActivityManager:   Force finishing activity 3 ActivityRecord{3a98b6d4 u0 com.NSouth.NSouthApp/.Activity_Main t12626 f}
01-11 21:38:10.311 3588-4061/? W/ActivityManager: Duplicate finish request for ActivityRecord{3a98b6d4 u0 com.NSouth.NSouthApp/.Activity_Main t12626 f}
01-11 21:38:10.321 3588-4061/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.NSouth.NSouthApp
01-11 21:38:10.321 3588-4061/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.NSouth.NSouthApp
01-11 21:38:10.461 3588-4343/? I/WindowState: WIN DEATH: Window{1847ccd8 u0 d0 com.NSouth.NSouthApp/com.NSouth.NSouthApp.Activity_Main}
01-11 21:38:10.531 3588-3784/? E/WindowState: getStack: Window{2ed8de84 u0 d0 com.NSouth.NSouthApp/com.NSouth.NSouthApp.Activity_AddCourse} couldn't find taskId=12626 Callers=com.android.server.wm.WindowState.getDisplayContent:1246 com.android.server.wm.WindowState.isDefaultDisplay:1936 com.android.server.wm.WindowState.getMultiWindowStyleLw:2520 com.android.internal.policy.impl.multiwindow.MultiPhoneWindowManager.shouldEnableLayoutInsetsBySoftInput:1601 
01-11 21:38:10.531 3588-3784/? E/WindowState: getStack: Window{2ed8de84 u0 d0 com.NSouth.NSouthApp/com.NSouth.NSouthApp.Activity_AddCourse} couldn't find taskId=12626 Callers=com.android.server.wm.WindowState.getDisplayContent:1246 com.android.server.wm.WindowState.isDefaultDisplay:1936 com.android.server.wm.WindowState.getMultiWindowStyleLw:2520 com.android.internal.policy.impl.multiwindow.MultiPhoneWindowManager.shouldEnableLayoutInsetsBySoftInput:1601 
01-11 21:38:10.711 20089-20089/? I/ClearDataReceiver: [#DCM#] Intent Data: package:com.NSouth.NSouthApp
01-11 21:38:10.781 20089-20089/? I/ClearDataReceiver: [#DCM#] Intent Data: package:com.NSouth.NSouthApp
01-11 21:38:10.821 3588-3784/? E/WindowState: getStack: Window{2ed8de84 u0 d0 com.NSouth.NSouthApp/com.NSouth.NSouthApp.Activity_AddCourse} couldn't find taskId=12626 Callers=com.android.server.wm.WindowState.getDisplayContent:1246 com.android.server.wm.WindowState.isDefaultDisplay:1936 com.android.server.wm.WindowState.getMultiWindowStyleLw:2520 com.android.internal.policy.impl.multiwindow.MultiPhoneWindowManager.shouldEnableLayoutInsetsBySoftInput:1601 
01-11 21:38:10.821 3588-3784/? E/WindowState: getStack: Window{2ed8de84 u0 d0 com.NSouth.NSouthApp/com.NSouth.NSouthApp.Activity_AddCourse} couldn't find taskId=12626 Callers=com.android.server.wm.WindowState.getDisplayContent:1246 com.android.server.wm.WindowState.isDefaultDisplay:1936 com.android.server.wm.WindowState.getMultiWindowStyleLw:2520 com.android.internal.policy.impl.multiwindow.MultiPhoneWindowManager.shouldEnableLayoutInsetsBySoftInput:1601 
01-11 21:38:11.211 20089-20089/? I/ClearDataReceiver: [#DCM#] Intent Data: package:com.NSouth.NSouthApp
01-11 21:38:11.251 16844-20183/? D/PackageBroadcastService: Received broadcast action=android.intent.action.PACKAGE_DATA_CLEARED and uri=com.NSouth.NSouthApp
01-11 21:38:11.261 16844-20183/? D/AccountUtils: Clearing selected account for com.NSouth.NSouthApp
01-11 21:38:11.291 16844-20183/? I/LocationSettingsChecker: Removing dialog suppression flag for package com.NSouth.NSouthApp
01-11 21:38:11.311 16844-17661/? I/Icing: doRemovePackageData com.NSouth.NSouthApp

更新

我学到了一些东西。

  • 首先,如果还原操作失败,BackupManagerService source code会清楚地显示应用数据被清除且应用已关闭。 (有关还原操作,请参阅agentErrorCleanuphandleTimeout()。)
  • 其次,MyBackupAgent中的方法都没有被调用(调试日志没有写入,也没有在断点处停止)。换句话说,看起来我没有办法解决这个问题。

所以... 如果签名不匹配,这是我们应该期待的吗?我认为这不应该在制作中发生,所以也许没关系......?

更新2:如果应用的备份版本大于刚刚安装的版本,也会发生。再说一次,不应该在制作中发生,但仍然有点难看。

1 个答案:

答案 0 :(得分:0)

问题是,如果您查看BackupManagerService代码,则还原超时为60秒。

如果还原过程超过60秒,则会失败。

未调用MyBackupAgent中的方法,因为它们是另一个进程的一部分。调试代码的方法是记录消息(Log.v)。

遇到相同的问题,尝试解压缩1MB文件,我的恢复也超时。我发现的解决方案是将解压缩的文件移到onRestore之外。

因此,请尽量保持onRestore精简。

class BackupManagerService extends IBackupManager.Stub {
    ...


    // Timeout interval for deciding that a bind or clear-data has taken too long
    static final long TIMEOUT_INTERVAL = 10 * 1000;
    // Timeout intervals for agent backup & restore operations
    static final long TIMEOUT_BACKUP_INTERVAL = 30 * 1000;
    static final long TIMEOUT_RESTORE_INTERVAL = 60 * 1000;