Loading src/com/android/settings/aware/AwareFeatureProvider.java +5 −0 Original line number Diff line number Diff line Loading @@ -18,10 +18,15 @@ package com.android.settings.aware; import android.content.Context; import androidx.fragment.app.Fragment; public interface AwareFeatureProvider { /** Returns true if the aware sensor is supported. */ boolean isSupported(Context context); /** Returns true if the aware feature is enabled. */ boolean isEnabled(Context context); /** Show information dialog. */ void showRestrictionDialog(Fragment parent); } src/com/android/settings/aware/AwareFeatureProviderImpl.java +6 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.settings.aware; import android.content.Context; import androidx.fragment.app.Fragment; public class AwareFeatureProviderImpl implements AwareFeatureProvider { @Override public boolean isSupported(Context context) { Loading @@ -28,4 +30,8 @@ public class AwareFeatureProviderImpl implements AwareFeatureProvider { public boolean isEnabled(Context context) { return false; } @Override public void showRestrictionDialog(Fragment parent) { } } src/com/android/settings/system/SystemDashboardFragment.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ import android.content.Context; import android.os.Bundle; import android.provider.SearchIndexableResource; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settingslib.search.SearchIndexable; Loading @@ -40,6 +42,8 @@ public class SystemDashboardFragment extends DashboardFragment { private static final String KEY_RESET = "reset_dashboard"; public static final String EXTRA_SHOW_AWARE_DISABLED = "show_aware_dialog_disabled"; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Loading @@ -49,6 +53,17 @@ public class SystemDashboardFragment extends DashboardFragment { if (getVisiblePreferenceCount(screen) == screen.getInitialExpandedChildrenCount() + 1) { screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE); } showRestrictionDialog(); } @VisibleForTesting public void showRestrictionDialog() { final Bundle args = getArguments(); if (args != null && args.getBoolean(EXTRA_SHOW_AWARE_DISABLED, false)) { FeatureFactory.getFactory(getContext()).getAwareFeatureProvider() .showRestrictionDialog(this); } } @Override Loading tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java +40 −3 Original line number Diff line number Diff line Loading @@ -18,8 +18,17 @@ package com.android.settings.system; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.os.Bundle; import com.android.settings.aware.AwareFeatureProvider; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.ShadowUserManager; Loading @@ -38,11 +47,17 @@ import java.util.List; @Config(shadows = {SettingsShadowResources.class, ShadowUserManager.class}) public class SystemDashboardFragmentTest { private Context mContext; private SystemDashboardFragment mFragment; @Before public void setup() { SettingsShadowResources.overrideResource( com.android.internal.R.bool.config_supportSystemNavigationKeys, true); ShadowUserManager.getShadow().setIsAdminUser(true); mContext = RuntimeEnvironment.application; mFragment = spy(new SystemDashboardFragment()); when(mFragment.getContext()).thenReturn(mContext); } @After Loading @@ -52,13 +67,35 @@ public class SystemDashboardFragmentTest { @Test public void testNonIndexableKeys_existInXmlLayout() { final Context context = RuntimeEnvironment.application; final List<String> niks = SystemDashboardFragment.SEARCH_INDEX_DATA_PROVIDER .getNonIndexableKeys(context); .getNonIndexableKeys(mContext); final int xmlId = (new SystemDashboardFragment()).getPreferenceScreenResId(); final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId); assertThat(keys).containsAllIn(niks); } @Test public void showRestrictionDialog_hasValidExtra_shouldShowDialog() { final AwareFeatureProvider mProvider = FakeFeatureFactory.setupForTest().mAwareFeatureProvider; final Bundle bundle = new Bundle(); bundle.putBoolean(SystemDashboardFragment.EXTRA_SHOW_AWARE_DISABLED, true); when(mFragment.getArguments()).thenReturn(bundle); mFragment.showRestrictionDialog(); verify(mProvider).showRestrictionDialog(any()); } @Test public void showRestrictionDialog_hasInvalidExtra_shouldNotShowDialog() { final AwareFeatureProvider mProvider = FakeFeatureFactory.setupForTest().mAwareFeatureProvider; mFragment.showRestrictionDialog(); verify(mProvider, never()).showRestrictionDialog(any()); } } Loading
src/com/android/settings/aware/AwareFeatureProvider.java +5 −0 Original line number Diff line number Diff line Loading @@ -18,10 +18,15 @@ package com.android.settings.aware; import android.content.Context; import androidx.fragment.app.Fragment; public interface AwareFeatureProvider { /** Returns true if the aware sensor is supported. */ boolean isSupported(Context context); /** Returns true if the aware feature is enabled. */ boolean isEnabled(Context context); /** Show information dialog. */ void showRestrictionDialog(Fragment parent); }
src/com/android/settings/aware/AwareFeatureProviderImpl.java +6 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.settings.aware; import android.content.Context; import androidx.fragment.app.Fragment; public class AwareFeatureProviderImpl implements AwareFeatureProvider { @Override public boolean isSupported(Context context) { Loading @@ -28,4 +30,8 @@ public class AwareFeatureProviderImpl implements AwareFeatureProvider { public boolean isEnabled(Context context) { return false; } @Override public void showRestrictionDialog(Fragment parent) { } }
src/com/android/settings/system/SystemDashboardFragment.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ import android.content.Context; import android.os.Bundle; import android.provider.SearchIndexableResource; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settingslib.search.SearchIndexable; Loading @@ -40,6 +42,8 @@ public class SystemDashboardFragment extends DashboardFragment { private static final String KEY_RESET = "reset_dashboard"; public static final String EXTRA_SHOW_AWARE_DISABLED = "show_aware_dialog_disabled"; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Loading @@ -49,6 +53,17 @@ public class SystemDashboardFragment extends DashboardFragment { if (getVisiblePreferenceCount(screen) == screen.getInitialExpandedChildrenCount() + 1) { screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE); } showRestrictionDialog(); } @VisibleForTesting public void showRestrictionDialog() { final Bundle args = getArguments(); if (args != null && args.getBoolean(EXTRA_SHOW_AWARE_DISABLED, false)) { FeatureFactory.getFactory(getContext()).getAwareFeatureProvider() .showRestrictionDialog(this); } } @Override Loading
tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java +40 −3 Original line number Diff line number Diff line Loading @@ -18,8 +18,17 @@ package com.android.settings.system; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.os.Bundle; import com.android.settings.aware.AwareFeatureProvider; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.ShadowUserManager; Loading @@ -38,11 +47,17 @@ import java.util.List; @Config(shadows = {SettingsShadowResources.class, ShadowUserManager.class}) public class SystemDashboardFragmentTest { private Context mContext; private SystemDashboardFragment mFragment; @Before public void setup() { SettingsShadowResources.overrideResource( com.android.internal.R.bool.config_supportSystemNavigationKeys, true); ShadowUserManager.getShadow().setIsAdminUser(true); mContext = RuntimeEnvironment.application; mFragment = spy(new SystemDashboardFragment()); when(mFragment.getContext()).thenReturn(mContext); } @After Loading @@ -52,13 +67,35 @@ public class SystemDashboardFragmentTest { @Test public void testNonIndexableKeys_existInXmlLayout() { final Context context = RuntimeEnvironment.application; final List<String> niks = SystemDashboardFragment.SEARCH_INDEX_DATA_PROVIDER .getNonIndexableKeys(context); .getNonIndexableKeys(mContext); final int xmlId = (new SystemDashboardFragment()).getPreferenceScreenResId(); final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId); assertThat(keys).containsAllIn(niks); } @Test public void showRestrictionDialog_hasValidExtra_shouldShowDialog() { final AwareFeatureProvider mProvider = FakeFeatureFactory.setupForTest().mAwareFeatureProvider; final Bundle bundle = new Bundle(); bundle.putBoolean(SystemDashboardFragment.EXTRA_SHOW_AWARE_DISABLED, true); when(mFragment.getArguments()).thenReturn(bundle); mFragment.showRestrictionDialog(); verify(mProvider).showRestrictionDialog(any()); } @Test public void showRestrictionDialog_hasInvalidExtra_shouldNotShowDialog() { final AwareFeatureProvider mProvider = FakeFeatureFactory.setupForTest().mAwareFeatureProvider; mFragment.showRestrictionDialog(); verify(mProvider, never()).showRestrictionDialog(any()); } }