summaryrefslogtreecommitdiff
path: root/src/com/android/dialer
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dialer')
-rw-r--r--src/com/android/dialer/compat/UserManagerCompat.java37
-rw-r--r--src/com/android/dialer/settings/DialerSettingsActivity.java9
2 files changed, 42 insertions, 4 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;
+ }
+}
diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java
index d7b8e117d..13d196595 100644
--- a/src/com/android/dialer/settings/DialerSettingsActivity.java
+++ b/src/com/android/dialer/settings/DialerSettingsActivity.java
@@ -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;
@@ -71,8 +73,8 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity {
TelephonyManager telephonyManager =
(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- // "Call Settings" (full settings) is shown if the current user is primary user and there
- // is only one SIM. Before N, "Calling accounts" setting is shown if the current user is
+ // "Call Settings" (full settings) is shown if the current user is primary user and there
+ // is only one SIM. Before N, "Calling accounts" setting is shown if the current user is
// primary user and there are multiple SIMs. In N+, "Calling accounts" is shown whenever
// "Call Settings" is not shown.
boolean isPrimaryUser = isPrimaryUser();
@@ -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));
}
}