Don't kill apps if they are not in restricted mode

Also respect the killAfterRestore flag for them.

Before this change, the android:killAfterRestore attribute was only
respected for apps that do Key/Value backups. This was because Full
backup apps used to always be started in restricted mode for B&R
operations and the framework needed to kill the app to reset the
restricted mode state.

Now, full backup apps may not be started in restricted mode
(after ag/30155472) so there's no need to kill them unless if they set
killAfterRestore.

For this to work, we need to keep track of whether an app is in
restricted mode. I've moved all connection/disconnection logic to the
new connection manager class so this is now fairly easy.

Note that apps will only not be in restricted mode if they are K/V or if
enable_restricted_mode_changes is enabled and they opted out. So I think
all the new behavior is guarded by the same flag.

Flag: com.android.server.backup.enable_restricted_mode_changes
Bug: 376661510
Test: atest BackupAgentConnectionManagerTest & atest CtsBackupHostTestCases
Change-Id: I1e94fb3b794961904a6c603ac34b00f3878f4e3e
11 files changed