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

Commit 5c03be60 authored by Felipe Leme's avatar Felipe Leme
Browse files

Deprecate (and log usage) of DPMS.getMainUserId()

To test it, enable verbose:

$ adb shell setprop log.tag.DevicePolicyManager VERBOSE

Watch logcat:

$ adb logcat DevicePolicyManager *:s

And trigger a date change:

$ adb shell date 0531103025

It will show something like:

05-31 10:30:00.021  7355  7355 V DevicePolicyManager: getMainUserId() returning 0 at:
05-31 10:30:00.021  7355  7355 V DevicePolicyManager: java.lang.Exception
05-31 10:30:00.021  7355  7355 V DevicePolicyManager: 	at com.android.server.devicepolicy.DevicePolicyManagerService.getMainUserId(DevicePolicyManagerService.java:10166)
05-31 10:30:00.021  7355  7355 V DevicePolicyManager: 	at com.android.server.devicepolicy.DevicePolicyManagerService.-$$Nest$mgetMainUserId(Unknown Source:0)
05-31 10:30:00.021  7355  7355 V DevicePolicyManager: 	at com.android.server.devicepolicy.DevicePolicyManagerService$1.onReceive(DevicePolicyManagerService.java:1305)

Bug: 420745998
Bug: 417943524
Test: see above
Flag: EXEMPT logging changes only

Change-Id: I08013990d3d071e2bba0cf39cdec3520cfe910fc
parent 51f9e51a
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -501,6 +501,7 @@ import android.util.AtomicFile;
import android.util.DebugUtils;
import android.util.IndentingPrintWriter;
import android.util.IntArray;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
@@ -10143,12 +10144,25 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        }
    }
    /**
     * @deprecated TODO(b/420745998): the concept of main user is deprecated, callers should use
     * other signals like checking if the user is admin, current user, system user, et.c..
     */
    @Deprecated
    private @UserIdInt int getMainUserId() {
        boolean logIt = Log.isLoggable(LOG_TAG, Log.VERBOSE);
        int mainUserId = mUserManagerInternal.getMainUserId();
        if (mainUserId == UserHandle.USER_NULL) {
            Slogf.d(LOG_TAG, "getMainUserId(): no main user, returning USER_SYSTEM");
            if (logIt) {
                Slogf.w(LOG_TAG, new Exception("getMainUserId() called when it's null:"));
            } else {
                Slogf.w(LOG_TAG, "getMainUserId(): no main user, returning USER_SYSTEM");
            }
            return UserHandle.USER_SYSTEM;
        }
        if (logIt) {
            Slogf.v(LOG_TAG, new Exception(), "getMainUserId() returning %d at:", mainUserId);
        }
        return mainUserId;
    }