From f8c6db4677db6450d02d9e094ded3d0a0e986987 Mon Sep 17 00:00:00 2001 From: Nancy Chen Date: Mon, 14 Dec 2015 19:05:40 -0800 Subject: Fix DialerSettingsActivity so it does not crash pre-M. UserManager.isSystemUser() is not available pre-M, so we need to copy over the logic. Bug: 25776171 Change-Id: I8e7c8e7215a8b55009283ecb137cc54443e61ab8 --- .../android/dialer/compat/UserManagerCompat.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/com/android/dialer/compat/UserManagerCompat.java (limited to 'src/com/android/dialer/compat') diff --git a/src/com/android/dialer/compat/UserManagerCompat.java b/src/com/android/dialer/compat/UserManagerCompat.java new file mode 100644 index 000000000..a1fdcc68e --- /dev/null +++ b/src/com/android/dialer/compat/UserManagerCompat.java @@ -0,0 +1,37 @@ +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; + } +} -- cgit v1.2.3