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

Commit 55bd9465 authored by Felipe Leme's avatar Felipe Leme
Browse files

Minor improvements on DPMS classes:

- Refactored DevicePolicyData.dump() on its own method.
- Fixed broken javadoc links on BaseIDevicePolicyManager
- Changed DevicePolicyData's userHandle to userId

Test: adb shell dumpsys device_policy
Bug: 172691310

Change-Id: Ia29ffb8a07a92663f5d46b0feca1b2f3c590f7f4
parent b2d6cd27
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -44,19 +44,19 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
    /**
     * To be called by {@link DevicePolicyManagerService#Lifecycle} when a new user starts.
     *
     * @see {@link SystemService#onStartUser}
     * @see {@link SystemService#onUserStarting}
     */
    abstract void handleStartUser(int userId);
    /**
     * To be called by {@link DevicePolicyManagerService#Lifecycle} when a user is being unlocked.
     *
     * @see {@link SystemService#onUnlockUser}
     * @see {@link SystemService#onUserUnlocking}
     */
    abstract void handleUnlockUser(int userId);
    /**
     * To be called by {@link DevicePolicyManagerService#Lifecycle} when a user is being stopped.
     *
     * @see {@link SystemService#onStopUser}
     * @see {@link SystemService#onUserStopping}
     */
    abstract void handleStopUser(int userId);

+41 −6
Original line number Diff line number Diff line
@@ -16,14 +16,15 @@

package com.android.server.devicepolicy;

import android.annotation.UserIdInt;
import android.app.admin.DeviceAdminInfo;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.os.FileUtils;
import android.os.PersistableBundle;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
@@ -77,13 +78,14 @@ class DevicePolicyData {
    private static final String ATTR_DEVICE_PROVISIONING_CONFIG_APPLIED =
            "device-provisioning-config-applied";
    private static final String ATTR_DEVICE_PAIRED = "device-paired";

    private static final String TAG = DevicePolicyManagerService.LOG_TAG;
    private static final boolean VERBOSE_LOG = false; // DO NOT SUBMIT WITH TRUE

    int mFailedPasswordAttempts = 0;
    boolean mPasswordValidAtLastCheckpoint = true;

    int mUserHandle;
    final @UserIdInt int mUserId;
    int mPasswordOwner = -1;
    long mLastMaximumTimeToLock = -1;
    boolean mUserSetupComplete = false;
@@ -144,8 +146,8 @@ class DevicePolicyData {
    // apps were suspended or unsuspended.
    boolean mAppsSuspended = false;

    DevicePolicyData(int userHandle) {
        mUserHandle = userHandle;
    DevicePolicyData(@UserIdInt int userId) {
        mUserId = userId;
    }

    /**
@@ -156,7 +158,7 @@ class DevicePolicyData {
        try {
            File chooseForWrite = file.chooseForWrite();
            if (VERBOSE_LOG) {
                Slog.v(TAG, "Storing data for user " + policyData.mUserHandle + " on "
                Slog.v(TAG, "Storing data for user " + policyData.mUserId + " on "
                        + chooseForWrite);
            }
            stream = new FileOutputStream(chooseForWrite, false);
@@ -365,7 +367,7 @@ class DevicePolicyData {
        FileInputStream stream = null;
        File file = journaledFile.chooseForRead();
        if (VERBOSE_LOG) {
            Slog.v(TAG, "Loading data for user " + policy.mUserHandle + " from " + file);
            Slog.v(TAG, "Loading data for user " + policy.mUserId + " from " + file);
        }
        boolean needsRewrite = false;
        try {
@@ -556,4 +558,37 @@ class DevicePolicyData {
            }
        }
    }

    void dump(IndentingPrintWriter pw) {
        pw.println();
        pw.println("Enabled Device Admins (User " + mUserId + ", provisioningState: "
                + mUserProvisioningState + "):");
        final int n = mAdminList.size();
        for (int i = 0; i < n; i++) {
            ActiveAdmin ap = mAdminList.get(i);
            if (ap != null) {
                pw.increaseIndent();
                pw.print(ap.info.getComponent().flattenToShortString());
                pw.println(":");
                pw.increaseIndent();
                ap.dump(pw);
                pw.decreaseIndent();
                pw.decreaseIndent();
            }
        }
        if (!mRemovingAdmins.isEmpty()) {
            pw.increaseIndent();
            pw.println("Removing Device Admins (User " + mUserId + "): " + mRemovingAdmins);
            pw.decreaseIndent();
        }
        pw.println();
        pw.increaseIndent();
        pw.print("mPasswordOwner="); pw.println(mPasswordOwner);
        pw.print("mUserControlDisabledPackages=");
        pw.println(mUserControlDisabledPackages);
        pw.print("mAppsSuspended="); pw.println(mAppsSuspended);
        pw.print("mUserSetupComplete="); pw.println(mUserSetupComplete);
        pw.print("mAffiliationIds="); pw.println(mAffiliationIds);
        pw.decreaseIndent();
    }
}
+2 −32
Original line number Diff line number Diff line
@@ -940,7 +940,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            // Persist updates if the removed package was an admin or delegate.
            if (removedAdmin || removedDelegate) {
                saveSettingsLocked(policy.mUserHandle);
                saveSettingsLocked(policy.mUserId);
            }
        }
        if (removedAdmin) {
@@ -8684,37 +8684,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        int userCount = mUserData.size();
        for (int u = 0; u < userCount; u++) {
            DevicePolicyData policy = getUserData(mUserData.keyAt(u));
            pw.println();
            pw.println("Enabled Device Admins (User " + policy.mUserHandle
                    + ", provisioningState: " + policy.mUserProvisioningState + "):");
            final int n = policy.mAdminList.size();
            for (int i = 0; i < n; i++) {
                ActiveAdmin ap = policy.mAdminList.get(i);
                if (ap != null) {
                    pw.increaseIndent();
                    pw.print(ap.info.getComponent().flattenToShortString());
                    pw.println(":");
                    pw.increaseIndent();
                    ap.dump(pw);
                    pw.decreaseIndent();
                    pw.decreaseIndent();
                }
            }
            if (!policy.mRemovingAdmins.isEmpty()) {
                pw.increaseIndent();
                pw.println("Removing Device Admins (User " + policy.mUserHandle + "): "
                        + policy.mRemovingAdmins);
                pw.decreaseIndent();
            }
            pw.println();
            pw.increaseIndent();
            pw.print("mPasswordOwner="); pw.println(policy.mPasswordOwner);
            pw.print("mUserControlDisabledPackages=");
            pw.println(policy.mUserControlDisabledPackages);
            pw.print("mAppsSuspended="); pw.println(policy.mAppsSuspended);
            pw.print("mUserSetupComplete="); pw.println(policy.mUserSetupComplete);
            pw.print("mAffiliationIds="); pw.println(policy.mAffiliationIds);
            pw.decreaseIndent();
            policy.dump(pw);
        }
    }