diff options
author | Andrew Lee <anwlee@google.com> | 2014-08-14 21:40:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-14 19:49:28 +0000 |
commit | 06a9c93e91e7c49e1457989d19e1d46e96b26a4d (patch) | |
tree | 573cdf881bcbbd4ee08247623261fab2346aa1fd | |
parent | 0d3a73932a23cb07168d25ec331a9abf72817346 (diff) | |
parent | 84c3780d1bb720aca5706ecaccfc58a4638db5ed (diff) |
Merge "Disable call settings for secondary users." into lmp-dev
-rw-r--r-- | src/com/android/dialer/settings/DialerSettingsActivity.java | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index 8d41d775e..b47a4edd2 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -5,6 +5,8 @@ import com.google.common.collect.Lists; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.UserHandle; +import android.os.UserManager; import android.preference.PreferenceManager; import android.preference.PreferenceActivity.Header; import android.text.TextUtils; @@ -29,6 +31,8 @@ public class DialerSettingsActivity extends AnalyticsPreferenceActivity { protected SharedPreferences mPreferences; private HeaderAdapter mHeaderAdapter; + private static final int OWNER_HANDLE_ID = 0; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -42,15 +46,17 @@ public class DialerSettingsActivity extends AnalyticsPreferenceActivity { public void onBuildHeaders(List<Header> target) { final Header contactDisplayHeader = new Header(); contactDisplayHeader.titleRes = R.string.settings_contact_display_options_title; - contactDisplayHeader.summaryRes = R.string.settings_contact_display_options_description; contactDisplayHeader.fragment = DisplayOptionsPreferenceFragment.class.getName(); target.add(contactDisplayHeader); - final Header callSettingHeader = new Header(); - callSettingHeader.titleRes = R.string.call_settings_label; - callSettingHeader.summaryRes = R.string.call_settings_description; - callSettingHeader.intent = DialtactsActivity.getCallSettingsIntent(); - target.add(callSettingHeader); + // Only add the call settings header if the current user is the primary/owner user. + if (isPrimaryUser()) { + final Header callSettingHeader = new Header(); + callSettingHeader.titleRes = R.string.call_settings_label; + callSettingHeader.summaryRes = R.string.call_settings_description; + callSettingHeader.intent = DialtactsActivity.getCallSettingsIntent(); + target.add(callSettingHeader); + } } @Override @@ -85,6 +91,23 @@ public class DialerSettingsActivity extends AnalyticsPreferenceActivity { } /** + * Whether a user handle associated with the current user is that of the primary owner. That is, + * whether there is a user handle which has an id which matches the owner's handle. + * @return Whether the current user is the primary user. + */ + private boolean isPrimaryUser() { + UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); + List<UserHandle> userHandles = userManager.getUserProfiles(); + for (int i = 0; i < userHandles.size(); i++){ + if (userHandles.get(i).myUserId() == OWNER_HANDLE_ID) { + return true; + } + } + + return false; + } + + /** * This custom {@code ArrayAdapter} is mostly identical to the equivalent one in * {@code PreferenceActivity}, except with a local layout resource. */ @@ -130,7 +153,6 @@ public class DialerSettingsActivity extends AnalyticsPreferenceActivity { } else { holder.summary.setVisibility(View.GONE); } - return view; } } |