From 4b04ba590327e796ec077c9896460d827f10e18c Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Wed, 16 May 2018 13:26:24 -0700 Subject: [PATCH] Do not perform device index before device provision. Bug: 79841744 Test: robotests Change-Id: I74243b6f31364220156e91fe63b56138a0240714 --- .../search/DeviceIndexFeatureProvider.java | 8 ++++++++ .../DeviceIndexFeatureProviderTest.java | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/search/DeviceIndexFeatureProvider.java b/src/com/android/settings/search/DeviceIndexFeatureProvider.java index 8e64d795b2c..bf75ee81c3e 100644 --- a/src/com/android/settings/search/DeviceIndexFeatureProvider.java +++ b/src/com/android/settings/search/DeviceIndexFeatureProvider.java @@ -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; @@ -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; } diff --git a/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java b/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java index 26c2830a01c..d4c15802b99 100644 --- a/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java +++ b/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java @@ -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; @@ -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; @@ -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); @@ -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);