Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1fe45125 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Do not perform device index before device provision." into pi-dev

parents ef088843 4b04ba59
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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;
        }

+16 −3
Original line number Diff line number Diff line
@@ -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);