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

Commit c3e509ca authored by Bernardo Rufino's avatar Bernardo Rufino
Browse files

Clear calling uid in isAppEligibleForBackup() and variant

This method is called by bmgr backupnow. Bmgr pid is not system uid.
When executing the method it fails with permission denied because it
can't bind to the transport. Before binding on-demand we haven't seen
this error because we didn't try to bind in the method, it was always
bound.

Bug: 72215413
Test: adb shell bmgr backupnow -all
Change-Id: I82ad712e893abfec4727d568ab48a49945645eb4
parent 5e1f8546
Loading
Loading
Loading
Loading
+32 −22
Original line number Diff line number Diff line
@@ -3464,6 +3464,8 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.BACKUP, "isAppEligibleForBackup");

        long oldToken = Binder.clearCallingIdentity();
        try {
            String callerLogString = "BMS.isAppEligibleForBackup";
            TransportClient transportClient =
                    mTransportManager.getCurrentTransportClient(callerLogString);
@@ -3474,6 +3476,9 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
                mTransportManager.disposeOfTransportClient(transportClient, callerLogString);
            }
            return eligible;
        } finally {
            Binder.restoreCallingIdentity(oldToken);
        }
    }

    @Override
@@ -3481,6 +3486,8 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.BACKUP, "filterAppsEligibleForBackup");

        long oldToken = Binder.clearCallingIdentity();
        try {
            String callerLogString = "BMS.filterAppsEligibleForBackup";
            TransportClient transportClient =
                    mTransportManager.getCurrentTransportClient(callerLogString);
@@ -3496,6 +3503,9 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
                mTransportManager.disposeOfTransportClient(transportClient, callerLogString);
            }
            return eligibleApps.toArray(new String[eligibleApps.size()]);
        } finally {
            Binder.restoreCallingIdentity(oldToken);
        }
    }

    @Override