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

Commit bea8b3bb authored by Rhed Jao's avatar Rhed Jao
Browse files

Add Support of disabling or enabling component for the backup agent

Allow backup agent component to be disabled or enabled by the
package manager api. The system is unable to bind the backup
agent, when it's disabled.

Bug: 112662591
Test: atest CtsBackupTestCases
Change-Id: I987274ac36a80cbc74df18944b11de14d0814fc7
parent efd77e94
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -11970,6 +11970,31 @@ public class ActivityManagerService extends IActivityManager.Stub
            Slog.w(TAG, "Unable to bind backup agent for " + packageName);
            return false;
        }
        if (app.backupAgentName != null) {
            final ComponentName backupAgentName = new ComponentName(
                    app.packageName, app.backupAgentName);
            int enableState = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
            try {
                enableState = pm.getComponentEnabledSetting(backupAgentName, instantiatedUserId);
            } catch (RemoteException e) {
                // can't happen; package manager is process-local
            }
            switch (enableState) {
                case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
                case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
                case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
                    Slog.w(TAG, "Unable to bind backup agent for " + backupAgentName
                            + ", the backup agent component is disabled.");
                    return false;
                case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
                case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
                default:
                    // Since there's no way to declare a backup agent disabled in the manifest,
                    // assume the case COMPONENT_ENABLED_STATE_DEFAULT to be enabled.
                    break;
            }
        }
        int oldBackupUid;
        int newBackupUid;
+6 −0
Original line number Diff line number Diff line
@@ -196,6 +196,12 @@ public class AndroidPackageUtils {
            }
        }

        if (pkg.getBackupAgentName() != null) {
            if (Objects.equals(className, pkg.getBackupAgentName())) {
                return true;
            }
        }

        return false;
    }