diff options
author | Nancy Chen <nancychen@google.com> | 2015-12-14 19:05:40 -0800 |
---|---|---|
committer | Nancy Chen <nancychen@google.com> | 2015-12-17 13:21:10 -0800 |
commit | f8c6db4677db6450d02d9e094ded3d0a0e986987 (patch) | |
tree | 00a1a86061d841d918548218247621907416237a /src/com/android/dialer/compat | |
parent | 524d87169becc3137963d1c7ebba3493d0fa5e1d (diff) |
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
Diffstat (limited to 'src/com/android/dialer/compat')
-rw-r--r-- | src/com/android/dialer/compat/UserManagerCompat.java | 37 |
1 files changed, 37 insertions, 0 deletions
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; + } +} |