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

Commit 01ed6212 authored by preranap's avatar preranap Committed by Prerana Patil
Browse files

Modify DevicePolicyManagerService to extend IDevicePolicyManager.aidl

Problem: ArcDevicePolicyManagerService extends BaseIDevicePolicyManager which is an abstract class that defines the required interface for IDevicePolicyManager.aidl.
Whenever a method is added to IDevicePolicyManager.aidl, an empty override method should be added in BaseIDevicePolicyManager to avoid build breakage in downstream branches. But since upstream developers are mostly unaware of this class, that doesn’t happen leading to build failures in ARC.

Solution: DevicePolicyManagerService extends IDevicePolicyManager.aidl instead of BaseIDevicePolicyManager and we remove BaseIDevicePolicyManager altogether
Design Doc: http://doc/1rGmymvoKZCn3H2Gbic5cnlgyZJo8ZtlgDzX5o0sG4zE

Bug: 187842408
Test: atest CtsDevicePolicyTestCases
Test: tast run DUT enterprise.ARCProvisioning.vm
Change-Id: I80ab8fd1be197e0dfa146836d4b65bc13db24740
parent 845df38b
Loading
Loading
Loading
Loading
+15 −19
Original line number Original line Diff line number Diff line
@@ -221,6 +221,7 @@ import android.app.admin.DevicePolicyStringResource;
import android.app.admin.DeviceStateCache;
import android.app.admin.DeviceStateCache;
import android.app.admin.FactoryResetProtectionPolicy;
import android.app.admin.FactoryResetProtectionPolicy;
import android.app.admin.FullyManagedDeviceProvisioningParams;
import android.app.admin.FullyManagedDeviceProvisioningParams;
import android.app.admin.IDevicePolicyManager;
import android.app.admin.ManagedProfileProvisioningParams;
import android.app.admin.ManagedProfileProvisioningParams;
import android.app.admin.ManagedSubscriptionsPolicy;
import android.app.admin.ManagedSubscriptionsPolicy;
import android.app.admin.NetworkEvent;
import android.app.admin.NetworkEvent;
@@ -442,7 +443,7 @@ import java.util.stream.Collectors;
/**
/**
 * Implementation of the device policy APIs.
 * Implementation of the device policy APIs.
 */
 */
public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    protected static final String LOG_TAG = "DevicePolicyManager";
    protected static final String LOG_TAG = "DevicePolicyManager";
@@ -920,25 +921,26 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private final ArrayList<Object> mPendingUserCreatedCallbackTokens = new ArrayList<>();
    private final ArrayList<Object> mPendingUserCreatedCallbackTokens = new ArrayList<>();
    public static final class Lifecycle extends SystemService {
    public static final class Lifecycle extends SystemService {
        private BaseIDevicePolicyManager mService;
        private DevicePolicyManagerService mService;
        public Lifecycle(Context context) {
        public Lifecycle(Context context) {
            super(context);
            super(context);
            String dpmsClassName = context.getResources()
            String dpmsClassName = context.getResources()
                    .getString(R.string.config_deviceSpecificDevicePolicyManagerService);
                    .getString(R.string.config_deviceSpecificDevicePolicyManagerService);
            if (TextUtils.isEmpty(dpmsClassName)) {
            if (TextUtils.isEmpty(dpmsClassName)) {
                dpmsClassName = DevicePolicyManagerService.class.getName();
                mService = new DevicePolicyManagerService(context);
            }
            } else {
                try {
                try {
                    Class<?> serviceClass = Class.forName(dpmsClassName);
                    Class<?> serviceClass = Class.forName(dpmsClassName);
                    Constructor<?> constructor = serviceClass.getConstructor(Context.class);
                    Constructor<?> constructor = serviceClass.getConstructor(Context.class);
                mService = (BaseIDevicePolicyManager) constructor.newInstance(context);
                    mService = (DevicePolicyManagerService) constructor.newInstance(context);
                } catch (Exception e) {
                } catch (Exception e) {
                    throw new IllegalStateException(
                    throw new IllegalStateException(
                        "Failed to instantiate DevicePolicyManagerService with class name: "
                        "Failed to instantiate DevicePolicyManagerService with class name: "
                        + dpmsClassName, e);
                        + dpmsClassName, e);
                }
                }
            }
            }
        }
        /** Sets the {@link DevicePolicySafetyChecker}. */
        /** Sets the {@link DevicePolicySafetyChecker}. */
        public void setDevicePolicySafetyChecker(DevicePolicySafetyChecker safetyChecker) {
        public void setDevicePolicySafetyChecker(DevicePolicySafetyChecker safetyChecker) {
@@ -1348,7 +1350,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        }
    }
    }
    @Override
    public void setDevicePolicySafetyChecker(DevicePolicySafetyChecker safetyChecker) {
    public void setDevicePolicySafetyChecker(DevicePolicySafetyChecker safetyChecker) {
        CallerIdentity callerIdentity = getCallerIdentity();
        CallerIdentity callerIdentity = getCallerIdentity();
        Preconditions.checkCallAuthorization(mIsAutomotive || isAdb(callerIdentity), "can only set "
        Preconditions.checkCallAuthorization(mIsAutomotive || isAdb(callerIdentity), "can only set "
@@ -3090,7 +3091,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    }
    @VisibleForTesting
    @VisibleForTesting
    @Override
    void systemReady(int phase) {
    void systemReady(int phase) {
        if (!mHasFeature) {
        if (!mHasFeature) {
            return;
            return;
@@ -3289,7 +3289,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        }
    }
    }
    @Override
    void handleStartUser(int userId) {
    void handleStartUser(int userId) {
        synchronized (getLockObject()) {
        synchronized (getLockObject()) {
            pushScreenCapturePolicy(userId);
            pushScreenCapturePolicy(userId);
@@ -3337,7 +3336,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                        targetUserId, protectedPackages));
                        targetUserId, protectedPackages));
    }
    }
    @Override
    void handleUnlockUser(int userId) {
    void handleUnlockUser(int userId) {
        startOwnerService(userId, "unlock-user");
        startOwnerService(userId, "unlock-user");
        if (isCoexistenceFlagEnabled()) {
        if (isCoexistenceFlagEnabled()) {
@@ -3345,12 +3343,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        }
    }
    }
    @Override
    void handleOnUserUnlocked(int userId) {
    void handleOnUserUnlocked(int userId) {
        showNewUserDisclaimerIfNecessary(userId);
        showNewUserDisclaimerIfNecessary(userId);
    }
    }
    @Override
    void handleStopUser(int userId) {
    void handleStopUser(int userId) {
        updateNetworkPreferenceForUser(userId, List.of(PreferentialNetworkServiceConfig.DEFAULT));
        updateNetworkPreferenceForUser(userId, List.of(PreferentialNetworkServiceConfig.DEFAULT));
        mDeviceAdminServiceController.stopServicesForUser(userId, /* actionForLog= */ "stop-user");
        mDeviceAdminServiceController.stopServicesForUser(userId, /* actionForLog= */ "stop-user");