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

Commit 24efa3aa authored by Nancy Chen's avatar Nancy Chen Committed by Android (Google) Code Review
Browse files

Merge "Fix DialerSettingsActivity so it does not crash pre-M." into ub-contactsdialer-b-dev

parents b3e1537e f8c6db46
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
package com.android.dialer.compat;

import android.content.Context;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;

import com.android.contacts.common.compat.CompatUtils;

/**
 * Compatibility class for {@link UserManager}.
 */
public class UserManagerCompat {
    /**
     * A user id constant to indicate the "system" user of the device. Copied from
     * {@link UserHandle}.
     */
    private static final int USER_SYSTEM = 0;
    /**
     * Range of uids allocated for a user.
     */
    private static final int PER_USER_RANGE = 100000;

    /**
     * Used to check if this process is running under the system user. The system user is the
     * initial user that is implicitly created on first boot and hosts most of the system services.
     *
     * @return whether this process is running under the system user.
     */
    public static boolean isSystemUser(UserManager userManager) {
        if (CompatUtils.isMarshmallowCompatible()) {
            return userManager.isSystemUser();
        }
        // Adapted from {@link UserManager} and {@link UserHandle}.
        return (Process.myUid() / PER_USER_RANGE) == USER_SYSTEM;
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -28,9 +28,11 @@ import android.telephony.TelephonyManager;
import android.view.MenuItem;
import android.widget.Toast;

import com.android.contacts.common.compat.CompatUtils;
import com.android.contacts.common.compat.SdkVersionOverride;
import com.android.dialer.R;
import com.android.dialer.compat.SettingsCompat;
import com.android.dialer.compat.UserManagerCompat;
import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity;

import java.util.List;
@@ -158,7 +160,6 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity {
     * @return Whether the current user is the primary user.
     */
    private boolean isPrimaryUser() {
        final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
        return userManager.isSystemUser();
        return UserManagerCompat.isSystemUser((UserManager) getSystemService(Context.USER_SERVICE));
    }
}