Merge "Adjust lookup table mechanism to support new UI of conditional card"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e828ac2..e14135c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10060,7 +10060,7 @@
     <!-- Title for prevent ringing gesture screen -->
     <string name="gesture_prevent_ringing_screen_title">Prevent ringing</string>
     <!-- Title for prevent ringing setting -->
-    <string name="gesture_prevent_ringing_title">Press Power &amp; Volume Up together</string>
+    <string name="gesture_prevent_ringing_title">Press Power &amp; Volume Up together to</string>
     <!-- Title for prevent ringing setting -->
     <string name="gesture_prevent_ringing_sound_title">Shortcut to prevent ringing</string>
     <!-- Option for prevent ringing setting -->
diff --git a/res/xml/prevent_ringing_gesture_settings.xml b/res/xml/prevent_ringing_gesture_settings.xml
index 5135664..62f0223 100644
--- a/res/xml/prevent_ringing_gesture_settings.xml
+++ b/res/xml/prevent_ringing_gesture_settings.xml
@@ -26,13 +26,8 @@
         app:animation="@raw/gesture_prevent_ringing"
         app:preview="@drawable/gesture_prevent_ringing" />
 
-    <ListPreference
-        android:key="gesture_prevent_ringing"
-        android:title="@string/gesture_prevent_ringing_title"
-        android:entries="@array/gesture_prevent_ringing_entries"
-        android:entryValues="@array/gesture_prevent_ringing_values"
-        app:controller="com.android.settings.gestures.PreventRingingPreferenceController"
-        app:keywords="@string/keywords_gesture"
-        app:allowDividerAbove="true" />
-
+    <PreferenceCategory
+        android:key="gesture_prevent_ringing_category"
+        android:title="@string/gesture_prevent_ringing_title">
+    </PreferenceCategory>
 </PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
index 18e9906..78a8614 100644
--- a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
@@ -92,18 +92,18 @@
 
     @VisibleForTesting
     void finishIfAccountMissing() {
-        AccountManager accountManager = (AccountManager) getContext().getSystemService(
-                Context.ACCOUNT_SERVICE);
-        boolean accountExists = false;
-        for (Account account : accountManager.getAccountsByType(mAccount.type)) {
-            if (account.equals(mAccount)) {
-                accountExists = true;
-                break;
+        final Context context = getContext();
+        final UserManager um = context.getSystemService(UserManager.class);
+        final AccountManager accountManager = (AccountManager) context.getSystemService(
+                AccountManager.class);
+        for (UserHandle userHandle : um.getUserProfiles()) {
+            for (Account account : accountManager.getAccountsAsUser(userHandle.getIdentifier())) {
+                if (account.equals(mAccount)) {
+                    return;
+                }
             }
         }
-        if (!accountExists) {
-            finish();
-        }
+        finish();
     }
 
     @Override
@@ -177,4 +177,4 @@
             accountTypePreferenceLoader.updatePreferenceIntents(prefs, mAccountType, mAccount);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
index 2d95c31..65181c4 100644
--- a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
@@ -63,7 +63,7 @@
         implements PreferenceControllerMixin, LifecycleObserver, OnPause, OnDestroy {
     @VisibleForTesting
     static final boolean USE_FAKE_DATA = false;
-    private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10;
+    private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 20;
     private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
     private static final int STATS_TYPE = BatteryStats.STATS_SINCE_CHARGED;
 
diff --git a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
index 069085b..2e9b5a5 100644
--- a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
+++ b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
@@ -20,8 +20,6 @@
 import android.content.Context;
 import android.provider.Settings;
 
-import androidx.annotation.NonNull;
-
 import com.android.internal.hardware.AmbientDisplayConfiguration;
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
@@ -31,6 +29,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import androidx.annotation.NonNull;
+
 public class GesturesSettingPreferenceController extends BasePreferenceController {
     private final AssistGestureFeatureProvider mFeatureProvider;
     private List<AbstractPreferenceController> mGestureControllers;
@@ -76,7 +76,7 @@
                 .setConfig(ambientDisplayConfiguration));
         controllers.add(new DoubleTapScreenPreferenceController(context, FAKE_PREF_KEY)
                 .setConfig(ambientDisplayConfiguration));
-        controllers.add(new PreventRingingPreferenceController(context, FAKE_PREF_KEY));
+        controllers.add(new PreventRingingParentPreferenceController(context, FAKE_PREF_KEY));
         return controllers;
     }
 
diff --git a/src/com/android/settings/gestures/PreventRingingGesturePreferenceController.java b/src/com/android/settings/gestures/PreventRingingGesturePreferenceController.java
new file mode 100644
index 0000000..cb9bf4f
--- /dev/null
+++ b/src/com/android/settings/gestures/PreventRingingGesturePreferenceController.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.gestures;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.provider.Settings;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.widget.RadioButtonPreference;
+import com.android.settings.widget.VideoPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnCreate;
+import com.android.settingslib.core.lifecycle.events.OnPause;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceScreen;
+
+public class PreventRingingGesturePreferenceController extends AbstractPreferenceController
+        implements RadioButtonPreference.OnClickListener, LifecycleObserver, OnSaveInstanceState,
+        OnResume, OnPause, OnCreate, PreferenceControllerMixin {
+
+    @VisibleForTesting static final String KEY_VIBRATE = "prevent_ringing_option_vibrate";
+    @VisibleForTesting static final String KEY_NONE = "prevent_ringing_option_none";
+    @VisibleForTesting static final String KEY_MUTE = "prevent_ringing_option_mute";
+
+    private final String KEY_VIDEO_PAUSED = "key_video_paused";
+    private final String PREF_KEY_VIDEO = "gesture_prevent_ringing_video";
+    private final String KEY = "gesture_prevent_ringing_category";
+    private final Context mContext;
+
+    private VideoPreference mVideoPreference;
+    private boolean mVideoPaused;
+
+    private PreferenceCategory mPreferenceCategory;
+    @VisibleForTesting RadioButtonPreference mVibratePref;
+    @VisibleForTesting RadioButtonPreference mNonePref;
+    @VisibleForTesting RadioButtonPreference mMutePref;
+
+    private SettingObserver mSettingObserver;
+
+    public PreventRingingGesturePreferenceController(Context context, Lifecycle lifecycle) {
+        super(context);
+        mContext = context;
+
+        if (lifecycle != null) {
+            lifecycle.addObserver(this);
+        }
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        if (isAvailable()) {
+            mPreferenceCategory = (PreferenceCategory) screen.findPreference(getPreferenceKey());
+            mVibratePref = makeRadioPreference(KEY_VIBRATE, R.string.prevent_ringing_option_vibrate);
+            mMutePref = makeRadioPreference(KEY_MUTE, R.string.prevent_ringing_option_mute);
+            mNonePref = makeRadioPreference(KEY_NONE, R.string.prevent_ringing_option_none);
+
+            if (mPreferenceCategory != null) {
+                mSettingObserver = new SettingObserver(mPreferenceCategory);
+            }
+
+            mVideoPreference = (VideoPreference) screen.findPreference(getVideoPrefKey());
+        }
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_volumeHushGestureEnabled);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY;
+    }
+
+    public String getVideoPrefKey() {
+        return PREF_KEY_VIDEO;
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        outState.putBoolean(KEY_VIDEO_PAUSED, mVideoPaused);
+    }
+
+    @Override
+    public void onRadioButtonClicked(RadioButtonPreference preference) {
+        int preventRingingSetting = keyToSetting(preference.getKey());
+        if (preventRingingSetting != Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE)) {
+            Settings.Secure.putInt(mContext.getContentResolver(),
+                    Settings.Secure.VOLUME_HUSH_GESTURE, preventRingingSetting);
+        }
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        int preventRingingSetting = Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE);
+
+        final boolean isVibrate = preventRingingSetting == Settings.Secure.VOLUME_HUSH_VIBRATE;
+        final boolean isMute = preventRingingSetting == Settings.Secure.VOLUME_HUSH_MUTE;
+        final boolean isOff = preventRingingSetting == Settings.Secure.VOLUME_HUSH_OFF
+                || (!isVibrate && !isMute);
+        if (mVibratePref != null && mVibratePref.isChecked() != isVibrate) {
+            mVibratePref.setChecked(isVibrate);
+        }
+        if (mMutePref != null && mMutePref.isChecked() != isMute) {
+            mMutePref.setChecked(isMute);
+        }
+        if (mNonePref != null && mNonePref.isChecked() != isOff) {
+            mNonePref.setChecked(isOff);
+        }
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        if (savedInstanceState != null) {
+            mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
+        }
+    }
+
+    @Override
+    public void onResume() {
+        if (mSettingObserver != null) {
+            mSettingObserver.register(mContext.getContentResolver());
+            mSettingObserver.onChange(false, null);
+        }
+
+        if (mVideoPreference != null) {
+            mVideoPreference.onViewVisible(mVideoPaused);
+        }
+    }
+
+    @Override
+    public void onPause() {
+        if (mSettingObserver != null) {
+            mSettingObserver.unregister(mContext.getContentResolver());
+        }
+
+        if (mVideoPreference != null) {
+            mVideoPaused = mVideoPreference.isVideoPaused();
+            mVideoPreference.onViewInvisible();
+        }
+    }
+
+    private int keyToSetting(String key) {
+        switch (key) {
+            case KEY_NONE:
+                return Settings.Secure.VOLUME_HUSH_OFF;
+            case KEY_MUTE:
+                return Settings.Secure.VOLUME_HUSH_MUTE;
+            case KEY_VIBRATE:
+            default:
+                return Settings.Secure.VOLUME_HUSH_VIBRATE;
+        }
+    }
+
+    private RadioButtonPreference makeRadioPreference(String key, int titleId) {
+        RadioButtonPreference pref = new RadioButtonPreference(mPreferenceCategory.getContext());
+        pref.setKey(key);
+        pref.setTitle(titleId);
+        pref.setOnClickListener(this);
+        mPreferenceCategory.addPreference(pref);
+        return pref;
+    }
+
+    private class SettingObserver extends ContentObserver {
+        private final Uri VOLUME_HUSH_GESTURE = Settings.Secure.getUriFor(
+                Settings.Secure.VOLUME_HUSH_GESTURE);
+
+        private final Preference mPreference;
+
+        public SettingObserver(Preference preference) {
+            super(new Handler());
+            mPreference = preference;
+        }
+
+        public void register(ContentResolver cr) {
+            cr.registerContentObserver(VOLUME_HUSH_GESTURE, false, this);
+        }
+
+        public void unregister(ContentResolver cr) {
+            cr.unregisterContentObserver(this);
+        }
+
+        @Override
+        public void onChange(boolean selfChange, Uri uri) {
+            super.onChange(selfChange, uri);
+            if (uri == null || VOLUME_HUSH_GESTURE.equals(uri)) {
+                updateState(mPreference);
+            }
+        }
+    }
+}
diff --git a/src/com/android/settings/gestures/PreventRingingGestureSettings.java b/src/com/android/settings/gestures/PreventRingingGestureSettings.java
index 84b4e16..3e8ae85 100644
--- a/src/com/android/settings/gestures/PreventRingingGestureSettings.java
+++ b/src/com/android/settings/gestures/PreventRingingGestureSettings.java
@@ -23,8 +23,11 @@
 import com.android.settings.R;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.search.SearchIndexable;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -40,6 +43,18 @@
     }
 
     @Override
+    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+        return buildPreferenceControllers(context, getSettingsLifecycle());
+    }
+
+    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
+            Lifecycle lifecycle) {
+        List<AbstractPreferenceController> controllers = new ArrayList<>();
+        controllers.add(new PreventRingingGesturePreferenceController(context, lifecycle));
+        return controllers;
+    }
+
+    @Override
     public int getMetricsCategory() {
         return MetricsProto.MetricsEvent.SETTINGS_PREVENT_RINGING;
     }
@@ -68,6 +83,12 @@
                     sir.xmlResId = R.xml.prevent_ringing_gesture_settings;
                     return Arrays.asList(sir);
                 }
+
+                @Override
+                public List<AbstractPreferenceController> createPreferenceControllers(
+                        Context context) {
+                    return buildPreferenceControllers(context, null);
+                }
             };
 
 }
diff --git a/src/com/android/settings/gestures/PreventRingingPreferenceController.java b/src/com/android/settings/gestures/PreventRingingPreferenceController.java
deleted file mode 100644
index 570c1c6..0000000
--- a/src/com/android/settings/gestures/PreventRingingPreferenceController.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.gestures;
-
-import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE;
-import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
-import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.provider.Settings;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.widget.VideoPreference;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnCreate;
-import com.android.settingslib.core.lifecycle.events.OnPause;
-import com.android.settingslib.core.lifecycle.events.OnResume;
-import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
-
-public class PreventRingingPreferenceController extends PreventRingingParentPreferenceController
-        implements Preference.OnPreferenceChangeListener,
-        LifecycleObserver, OnResume, OnPause, OnCreate, OnSaveInstanceState {
-
-    private static final String PREF_KEY_VIDEO = "gesture_prevent_ringing_video";
-    @VisibleForTesting
-    static final String KEY_VIDEO_PAUSED = "key_video_paused";
-
-    private VideoPreference mVideoPreference;
-    @VisibleForTesting
-    boolean mVideoPaused;
-
-    public PreventRingingPreferenceController(Context context, String key) {
-        super(context, key);
-    }
-
-    @Override
-    public int getAvailabilityStatus() {
-        final int status = super.getAvailabilityStatus();
-        if (status == AVAILABLE_UNSEARCHABLE) {
-            return AVAILABLE;
-        }
-        return status;
-    }
-
-    @Override
-    public void displayPreference(PreferenceScreen screen) {
-        super.displayPreference(screen);
-        if (isAvailable()) {
-            mVideoPreference = (VideoPreference) screen.findPreference(getVideoPrefKey());
-        }
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
-        if (preference != null) {
-            if (preference instanceof ListPreference) {
-                ListPreference pref = (ListPreference) preference;
-                int value = Settings.Secure.getInt(
-                        mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE);
-                switch (value) {
-                    case VOLUME_HUSH_VIBRATE:
-                        pref.setValue(String.valueOf(value));
-                        break;
-                    case VOLUME_HUSH_MUTE:
-                        pref.setValue(String.valueOf(value));
-                        break;
-                    default:
-                        pref.setValue(String.valueOf(VOLUME_HUSH_OFF));
-                }
-            }
-        }
-    }
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        if (savedInstanceState != null) {
-            mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
-        }
-    }
-
-    @Override
-    public void onSaveInstanceState(Bundle outState) {
-        outState.putBoolean(KEY_VIDEO_PAUSED, mVideoPaused);
-    }
-
-    @Override
-    public void onPause() {
-        if (mVideoPreference != null) {
-            mVideoPaused = mVideoPreference.isVideoPaused();
-            mVideoPreference.onViewInvisible();
-        }
-    }
-
-    @Override
-    public void onResume() {
-        if (mVideoPreference != null) {
-            mVideoPreference.onViewVisible(mVideoPaused);
-        }
-    }
-
-    protected String getVideoPrefKey() {
-        return PREF_KEY_VIDEO;
-    }
-
-    @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
-        int value = Integer.parseInt((String) newValue);
-        Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, value);
-        preference.setSummary(getSummary());
-        return true;
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index a4d1567..2648916 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -35,8 +35,10 @@
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.content.pm.UserInfo;
 import android.os.Bundle;
 import android.os.UserHandle;
+import android.os.UserManager;
 
 import androidx.fragment.app.FragmentActivity;
 import androidx.preference.Preference;
@@ -44,9 +46,12 @@
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.dashboard.DashboardFeatureProviderImpl;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowAccountManager;
+import com.android.settings.testutils.shadow.ShadowUserManager;
 import com.android.settingslib.drawer.CategoryKey;
 import com.android.settingslib.drawer.Tile;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -54,10 +59,11 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.Shadows;
 import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowAccountManager;
+import org.robolectric.shadow.api.Shadow;
 import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = {ShadowAccountManager.class, ShadowUserManager.class})
 public class AccountDetailDashboardFragmentTest {
 
     private static final String METADATA_CATEGORY = "com.android.settings.category";
@@ -86,6 +92,11 @@
         when(mFragment.getContext()).thenReturn(mContext);
     }
 
+    @After
+    public void tearDown() {
+        ShadowAccountManager.reset();
+    }
+
     @Test
     public void testCategory_isAccountDetail() {
         assertThat(new AccountDetailDashboardFragment().getCategoryKey())
@@ -152,17 +163,45 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class})
     public void onResume_accountMissing_shouldFinish() {
+        ShadowUserManager userManager = Shadow.extract(
+                mContext.getSystemService(UserManager.class));
+        ShadowAccountManager acctMgr = Shadow.extract(
+                mContext.getSystemService(AccountManager.class));
+
+        userManager.addProfile(new UserInfo(1, null, 0));
+        acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test"));
+
         mFragment.finishIfAccountMissing();
         verify(mFragment).finish();
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class})
-    public void onResume_accountPresent_shouldNotFinish() {
-        AccountManager mgr = mContext.getSystemService(AccountManager.class);
-        Shadows.shadowOf(mgr).addAccount(mFragment.mAccount);
+    public void onResume_accountPresentOneProfile_shouldNotFinish() {
+        ShadowUserManager userManager = Shadow.extract(
+                mContext.getSystemService(UserManager.class));
+        ShadowAccountManager acctMgr = Shadow.extract(
+                mContext.getSystemService(AccountManager.class));
+
+        userManager.addProfile(new UserInfo(1, null, 0));
+        acctMgr.addAccountForUser(1, mFragment.mAccount);
+
+        mFragment.finishIfAccountMissing();
+        verify(mFragment, never()).finish();
+    }
+
+    @Test
+    public void onResume_accountPresentTwoProfiles_shouldNotFinish() {
+        ShadowUserManager userManager = Shadow.extract(
+                mContext.getSystemService(UserManager.class));
+        ShadowAccountManager acctMgr = Shadow.extract(
+                mContext.getSystemService(AccountManager.class));
+
+        userManager.addProfile(new UserInfo(1, null, 0));
+        userManager.addProfile(new UserInfo(2, null, 0));
+        acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test"));
+        acctMgr.addAccountForUser(2, mFragment.mAccount);
+
         mFragment.finishIfAccountMissing();
         verify(mFragment, never()).finish();
     }
diff --git a/tests/robotests/src/com/android/settings/accounts/ChooseAccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/ChooseAccountPreferenceControllerTest.java
index 22c2cdb..241765e 100644
--- a/tests/robotests/src/com/android/settings/accounts/ChooseAccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/ChooseAccountPreferenceControllerTest.java
@@ -76,7 +76,7 @@
     @After
     public void tearDown() {
         ShadowContentResolver.reset();
-        ShadowAccountManager.resetAuthenticator();
+        ShadowAccountManager.reset();
         ShadowRestrictedLockUtilsInternal.clearDisabledTypes();
     }
 
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingGesturePreferenceControllerTest.java
new file mode 100644
index 0000000..6d77d77
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingGesturePreferenceControllerTest.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.preference.PreferenceCategory;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.widget.RadioButtonPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class PreventRingingGesturePreferenceControllerTest {
+
+    private Context mContext;
+    private Resources mResources;
+    private PreventRingingGesturePreferenceController mController;
+
+    @Before
+    public void setUp() {
+        mContext = spy(RuntimeEnvironment.application);
+        mResources = mock(Resources.class);
+        when(mContext.getResources()).thenReturn(mResources);
+        when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
+                .thenReturn(true);
+        mController = new PreventRingingGesturePreferenceController(mContext, null);
+        mController.mVibratePref = new RadioButtonPreference(mContext);
+        mController.mNonePref = new RadioButtonPreference(mContext);
+        mController.mMutePref = new RadioButtonPreference(mContext);
+    }
+
+    @Test
+    public void testIsAvailable_configIsTrue_shouldReturnTrue() {
+        when(mResources.getBoolean(
+                com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(true);
+
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void testIsAvailable_configIsFalse_shouldReturnFalse() {
+        when(mResources.getBoolean(
+                com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(false);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void testUpdateState_mute() {
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
+                Settings.Secure.VOLUME_HUSH_MUTE);
+        mController.updateState(null);
+        assertThat(mController.mVibratePref.isChecked()).isFalse();
+        assertThat(mController.mNonePref.isChecked()).isFalse();
+        assertThat(mController.mMutePref.isChecked()).isTrue();
+    }
+
+    @Test
+    public void testUpdateState_vibrate() {
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
+                Settings.Secure.VOLUME_HUSH_VIBRATE);
+        mController.updateState(null);
+        assertThat(mController.mVibratePref.isChecked()).isTrue();
+        assertThat(mController.mNonePref.isChecked()).isFalse();
+        assertThat(mController.mMutePref.isChecked()).isFalse();
+    }
+
+    @Test
+    public void testUpdateState_other() {
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
+                7);
+        mController.updateState(null);
+        assertThat(mController.mVibratePref.isChecked()).isFalse();
+        assertThat(mController.mNonePref.isChecked()).isTrue();
+        assertThat(mController.mMutePref.isChecked()).isFalse();
+    }
+
+    @Test
+    public void testRadioButtonClicked_mute() {
+        RadioButtonPreference rbPref = new RadioButtonPreference(mContext);
+        rbPref.setKey(PreventRingingGesturePreferenceController.KEY_MUTE);
+
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
+                Settings.Secure.VOLUME_HUSH_OFF);
+        mController.onRadioButtonClicked(rbPref);
+
+        assertThat(Settings.Secure.VOLUME_HUSH_MUTE).isEqualTo(
+                Settings.Secure.getInt(mContext.getContentResolver(),
+                        Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_OFF));
+    }
+
+    @Test
+    public void testRadioButtonClicked_vibrate() {
+        RadioButtonPreference rbPref = new RadioButtonPreference(mContext);
+        rbPref.setKey(PreventRingingGesturePreferenceController.KEY_VIBRATE);
+
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
+                Settings.Secure.VOLUME_HUSH_OFF);
+        mController.onRadioButtonClicked(rbPref);
+
+        assertThat(Settings.Secure.VOLUME_HUSH_VIBRATE).isEqualTo(
+                Settings.Secure.getInt(mContext.getContentResolver(),
+                        Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_OFF));
+    }
+
+    @Test
+    public void testRadioButtonClicked_off() {
+        RadioButtonPreference rbPref = new RadioButtonPreference(mContext);
+        rbPref.setKey(PreventRingingGesturePreferenceController.KEY_NONE);
+
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
+                Settings.Secure.VOLUME_HUSH_MUTE);
+
+        mController.onRadioButtonClicked(rbPref);
+
+        assertThat(Settings.Secure.VOLUME_HUSH_OFF).isEqualTo(
+                Settings.Secure.getInt(mContext.getContentResolver(),
+                        Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE));
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
deleted file mode 100644
index 65c3b5d..0000000
--- a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.gestures;
-
-import static android.provider.Settings.Secure.VOLUME_HUSH_GESTURE;
-import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE;
-import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static junit.framework.Assert.assertEquals;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-public class PreventRingingPreferenceControllerTest {
-
-    private static final String KEY_PICK_UP = "gesture_prevent_ringing";
-
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
-    private PreventRingingPreferenceController mController;
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mController = new PreventRingingPreferenceController(mContext, KEY_PICK_UP);
-    }
-
-    @Test
-    public void testIsAvailable_configIsTrue_shouldReturnTrue() {
-        when(mContext.getResources().getBoolean(
-                com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(true);
-
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void testIsAvailable_configIsFalse_shouldReturnFalse() {
-        when(mContext.getResources().getBoolean(
-                com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(false);
-
-        assertThat(mController.isAvailable()).isFalse();
-    }
-
-    @Test
-    public void testUpdateState_mute() {
-        ListPreference pref = mock(ListPreference.class);
-        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
-                Settings.Secure.VOLUME_HUSH_MUTE);
-        mController.updateState(pref);
-        verify(pref).setValue(String.valueOf(Settings.Secure.VOLUME_HUSH_MUTE));
-    }
-
-    @Test
-    public void testUpdateState_vibrate() {
-        ListPreference pref = mock(ListPreference.class);
-        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
-                Settings.Secure.VOLUME_HUSH_VIBRATE);
-        mController.updateState(pref);
-        verify(pref).setValue(String.valueOf(Settings.Secure.VOLUME_HUSH_VIBRATE));
-    }
-
-    @Test
-    public void testUpdateState_other() {
-        ListPreference pref = mock(ListPreference.class);
-        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
-                7);
-        mController.updateState(pref);
-        verify(pref).setValue(String.valueOf(Settings.Secure.VOLUME_HUSH_OFF));
-    }
-
-    @Test
-    public void testUpdateState_parentPage() {
-        Preference pref = mock(Preference.class);
-        // verify no exception
-        mController.updateState(pref);
-    }
-
-    @Test
-    public void testOnPreferenceChange() {
-        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
-                7);
-
-        mController.onPreferenceChange(mock(Preference.class), String.valueOf(VOLUME_HUSH_MUTE));
-
-        assertEquals(VOLUME_HUSH_MUTE, Settings.Secure.getInt(mContext.getContentResolver(),
-                VOLUME_HUSH_GESTURE, VOLUME_HUSH_OFF));
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java
index 03aabb5..4401926 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java
@@ -16,19 +16,24 @@
 
 package com.android.settings.testutils.shadow;
 
+import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.AuthenticatorDescription;
+import android.annotation.NonNull;
 
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Implements(AccountManager.class)
 public class ShadowAccountManager{
 
     private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>();
+    private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>();
 
     @Implementation
     public AuthenticatorDescription[] getAuthenticatorTypesAsUser(int userId) {
@@ -39,7 +44,24 @@
         sAuthenticators.put(authenticator.type, authenticator);
     }
 
-    public static void resetAuthenticator() {
+    public static void reset() {
         sAuthenticators.clear();
+        sAccountsByUserId.clear();
+    }
+
+    @Implementation @NonNull
+    public Account[] getAccountsAsUser(int userId) {
+        if (sAccountsByUserId.containsKey(userId)) {
+            return sAccountsByUserId.get(userId).toArray(new Account[0]);
+        } else {
+            return new Account[0];
+        }
+    }
+
+    public static void addAccountForUser(int userId, Account account) {
+        if (!sAccountsByUserId.containsKey(userId)) {
+            sAccountsByUserId.put(userId, new ArrayList<>());
+        }
+        sAccountsByUserId.get(userId).add(account);
     }
 }