Loading src/com/android/settings/search/DeviceIndexFeatureProvider.java +8 −0 Original line number Diff line number Diff line Loading @@ -24,8 +24,10 @@ import android.content.Context; import android.net.Uri; import android.os.Build; import android.provider.Settings; import android.util.Log; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.slices.SettingsSliceProvider; import java.util.List; Loading @@ -48,6 +50,12 @@ public interface DeviceIndexFeatureProvider { default void updateIndex(Context context, boolean force) { if (!isIndexingEnabled()) { Log.w(TAG, "Skipping: device index is not enabled"); return; } if (!Utils.isDeviceProvisioned(context)) { Log.w(TAG, "Skipping: device is not provisioned"); return; } Loading tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java +16 −3 Original line number Diff line number Diff line Loading @@ -15,7 +15,6 @@ package com.android.settings.search; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; Loading @@ -24,6 +23,7 @@ import static org.mockito.Mockito.when; import android.app.Activity; import android.app.job.JobScheduler; import android.provider.Settings; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.SettingsRobolectricTestRunner; Loading @@ -47,7 +47,7 @@ public class DeviceIndexFeatureProviderTest { } @Test public void verifyDisabled() { public void updateIndex_disabled_shouldDoNothing() { when(mProvider.isIndexingEnabled()).thenReturn(false); mProvider.updateIndex(mActivity, false); Loading @@ -55,7 +55,20 @@ public class DeviceIndexFeatureProviderTest { } @Test public void verifyIndexing() { public void updateIndex_enabled_unprovisioned_shouldDoNothing() { when(mProvider.isIndexingEnabled()).thenReturn(true); Settings.Global.putInt(mActivity.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0); mProvider.updateIndex(mActivity, false); verify(mProvider, never()).index(any(), any(), any(), any(), any()); } @Test public void updateIndex_enabled_provisioned_shouldIndex() { Settings.Global.putInt(mActivity.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); JobScheduler jobScheduler = mock(JobScheduler.class); when(mProvider.isIndexingEnabled()).thenReturn(true); when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler); Loading Loading
src/com/android/settings/search/DeviceIndexFeatureProvider.java +8 −0 Original line number Diff line number Diff line Loading @@ -24,8 +24,10 @@ import android.content.Context; import android.net.Uri; import android.os.Build; import android.provider.Settings; import android.util.Log; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.slices.SettingsSliceProvider; import java.util.List; Loading @@ -48,6 +50,12 @@ public interface DeviceIndexFeatureProvider { default void updateIndex(Context context, boolean force) { if (!isIndexingEnabled()) { Log.w(TAG, "Skipping: device index is not enabled"); return; } if (!Utils.isDeviceProvisioned(context)) { Log.w(TAG, "Skipping: device is not provisioned"); return; } Loading
tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java +16 −3 Original line number Diff line number Diff line Loading @@ -15,7 +15,6 @@ package com.android.settings.search; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; Loading @@ -24,6 +23,7 @@ import static org.mockito.Mockito.when; import android.app.Activity; import android.app.job.JobScheduler; import android.provider.Settings; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.SettingsRobolectricTestRunner; Loading @@ -47,7 +47,7 @@ public class DeviceIndexFeatureProviderTest { } @Test public void verifyDisabled() { public void updateIndex_disabled_shouldDoNothing() { when(mProvider.isIndexingEnabled()).thenReturn(false); mProvider.updateIndex(mActivity, false); Loading @@ -55,7 +55,20 @@ public class DeviceIndexFeatureProviderTest { } @Test public void verifyIndexing() { public void updateIndex_enabled_unprovisioned_shouldDoNothing() { when(mProvider.isIndexingEnabled()).thenReturn(true); Settings.Global.putInt(mActivity.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0); mProvider.updateIndex(mActivity, false); verify(mProvider, never()).index(any(), any(), any(), any(), any()); } @Test public void updateIndex_enabled_provisioned_shouldIndex() { Settings.Global.putInt(mActivity.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); JobScheduler jobScheduler = mock(JobScheduler.class); when(mProvider.isIndexingEnabled()).thenReturn(true); when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler); Loading