Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c524743 authored by Satoshi Niwa's avatar Satoshi Niwa
Browse files

Fix BackupManagerConstants observation for non-system users

On devices with Headless System User Mode (HSUM) enabled, BackupManagerConstants was not being notified of settings changes for non-system users.
This was because it was initialized with the system user's ContentResolver, causing it to observe settings changes only for the system user.

This change addresses the issue by creating a user-specific Context within UserBackupManagerService for the relevant user ID.
The ContentResolver from this user-specific context is then used to instantiate BackupManagerConstants, ensuring that it correctly observes settings changes for the intended user.

Bug: 413811693
Bug: 415890568
Test: atest android.cts.backup.SuccessNotificationHostSideTest
Flag: EXEMPT bug fix
Change-Id: Ic5c5427e1746032446aaab27d41420f21458e3ca
parent 712bd48c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -561,7 +561,10 @@ public class UserBackupManagerService {
        mJournalDir.mkdirs(); // creates mBaseStateDir along the way
        mJournal = null; // will be created on first use

        mConstants = new BackupManagerConstants(mBackupHandler, mContext.getContentResolver());
        // We need a context for the user in question to observe setting changes for that user.
        Context userContext = mContext.createContextAsUser(UserHandle.of(mUserId), /* flags */ 0);

        mConstants = new BackupManagerConstants(mBackupHandler, userContext.getContentResolver());
        // We are observing changes to the constants throughout the lifecycle of BMS. This is
        // because we reference the constants in multiple areas of BMS, which otherwise would
        // require frequent starting and stopping.