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

Commit 44423c57 authored by Felipe Leme's avatar Felipe Leme
Browse files

Improved logging on HsumBootUserInitializer.

Changes:
 - Make DEBUG static as the class is small enough to justify the
   cost/benefit
 - Guarded all Slogf.d() calls with DEBUG
 - Changed a Slogf.d() call to Slogf.i()
 - Moved constructor logs to init()
 - Log value of relevant flags

Flag: EXEMPT logging changes
Bug: 417943524
Test: adb shell stop; adb shell setprop log.tag.HsumBootUserInitializer DEBUG;adb shell start;adb logcat HsumBootUserInitializer *:s

Change-Id: I03ddabe6e9c1a14a82a5f70fe7a64b78ab38d8b9
parent a4fc9ffb
Loading
Loading
Loading
Loading
+29 −14
Original line number Diff line number Diff line
@@ -21,11 +21,13 @@ import android.content.ContentResolver;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.multiuser.Flags;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.am.ActivityManagerService;
@@ -42,7 +44,10 @@ public final class HsumBootUserInitializer {

    private static final String TAG = HsumBootUserInitializer.class.getSimpleName();

    private static final boolean DEBUG = false;
    // NOTE: this class is small enough that it's ok to set DEBUG dynamically (it doesn't increase
    // the binary too much and they're only called during boot). But if the number of Slogf.d()
    // calls grows too much, we should change it to false.
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    private final UserManagerService mUms;
    private final ActivityManagerService mAms;
@@ -92,16 +97,13 @@ public final class HsumBootUserInitializer {
        mContentResolver = contentResolver;
        mShouldAlwaysHaveMainUser = shouldAlwaysHaveMainUser;
        mShouldCreateInitialUser = shouldCreateInitialUser;
        if (DEBUG) {
            Slogf.d(TAG, "HsumBootUserInitializer(): shouldAlwaysHaveMainUser=%b, "
                    + "shouldCreateInitialUser=%b",
                    shouldAlwaysHaveMainUser, shouldCreateInitialUser);
        }
    }

    // TODO(b/409650316): remove after flag's completely pushed
    private void preCreateInitialUserFlagInit(TimingsTraceAndSlog t) {
        if (DEBUG) {
            Slogf.d(TAG, "preCreateInitialUserFlagInit())");
        }

        if (mShouldAlwaysHaveMainUser) {
            t.traceBegin("createMainUserIfNeeded");
@@ -114,11 +116,13 @@ public final class HsumBootUserInitializer {
    private void preCreateInitialUserCreateMainUserIfNeeded() {
        final int mainUser = mUms.getMainUserId();
        if (mainUser != UserHandle.USER_NULL) {
            if (DEBUG) {
                Slogf.d(TAG, "Found existing MainUser, userId=%d", mainUser);
            }
            return;
        }

        Slogf.d(TAG, "Creating a new MainUser");
        Slogf.i(TAG, "Creating a new MainUser");
        try {
            final UserInfo newInitialUser = mUms.createUserInternalUnchecked(
                    /* name= */ null, // null will appear as "Owner" in on-demand localisation
@@ -148,9 +152,15 @@ public final class HsumBootUserInitializer {
     * creation.
     */
    public void init(TimingsTraceAndSlog t) {
        Slogf.i(TAG, "init())");
        if (DEBUG) {
            Slogf.d(TAG, "init(): shouldAlwaysHaveMainUser=%b, "
                    + "shouldCreateInitialUser=%b, Flags.createInitialUser=%b",
                    mShouldAlwaysHaveMainUser, mShouldCreateInitialUser, Flags.createInitialUser());
        } else {
            Slogf.i(TAG, "Initializing");
        }

        if (!android.multiuser.Flags.createInitialUser()) {
        if (!Flags.createInitialUser()) {
            preCreateInitialUserFlagInit(t);
            return;
        }
@@ -164,8 +174,10 @@ public final class HsumBootUserInitializer {
            createAdminUserIfNeeded(t);
            return;
        }
        if (DEBUG) {
            Slogf.d(TAG, "Not checking if initial user exists (should be handled externally)");
        }
    }

    private void createMainUserIfNeeded(TimingsTraceAndSlog t) {
        // Always tracing as it used to be done by the caller
@@ -173,7 +185,10 @@ public final class HsumBootUserInitializer {
        try {
            int mainUserId = mUms.getMainUserId();
            if (mainUserId != UserHandle.USER_NULL) {
                Slogf.d(TAG, "createMainUserIfNeeded(): found MainUser (userId=%d)", mainUserId);
                if (DEBUG) {
                    Slogf.d(TAG, "createMainUserIfNeeded(): found MainUser (userId=%d)",
                            mainUserId);
                }
                return;
            }
            createInitialUser(/* isMainUser= */ true);
@@ -208,7 +223,7 @@ public final class HsumBootUserInitializer {
        } else {
            logName = "admin user";
        }
        Slogf.d(TAG, "Creating %s", logName);
        Slogf.i(TAG, "Creating %s", logName);
        try {
            final UserInfo newInitialUser = mUms.createUserInternalUnchecked(
                    /* name= */ null, // null will appear as "Owner" in on-demand localisation