Add option for settings to push to a device index
The index implementation is optional and left up to the OEM. Test: Open settings, see content in index Test: robo tests Bug: 68378569 Bug: 76102600 Change-Id: Idb8bb1e0cabbbe92e7a852e2eadbdcd8c2ab7d56
This commit is contained in:
@@ -255,6 +255,8 @@
|
|||||||
android:value="com.android.settings.wifi.WifiSettings" />
|
android:value="com.android.settings.wifi.WifiSettings" />
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
|
<meta-data android:name="android.metadata.SLICE_URI"
|
||||||
|
android:value="content://android.settings.slices/wifi" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
@@ -1127,6 +1129,17 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".slice.SliceDeepLinkSpringBoard"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<data android:scheme="settings"
|
||||||
|
android:host="com.android.settings.slices" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<!-- Provide direct entry into manage apps showing running services.
|
<!-- Provide direct entry into manage apps showing running services.
|
||||||
This is for compatibility with old shortcuts. -->
|
This is for compatibility with old shortcuts. -->
|
||||||
<activity-alias android:name=".RunningServices"
|
<activity-alias android:name=".RunningServices"
|
||||||
@@ -3261,7 +3274,16 @@
|
|||||||
|
|
||||||
<provider android:name=".slices.SettingsSliceProvider"
|
<provider android:name=".slices.SettingsSliceProvider"
|
||||||
android:authorities="com.android.settings.slices;android.settings.slices"
|
android:authorities="com.android.settings.slices;android.settings.slices"
|
||||||
android:exported="true">
|
android:exported="true"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<category android:name="android.app.slice.category.SLICE" />
|
||||||
|
<data android:scheme="settings"
|
||||||
|
android:host="com.android.settings.slices" />
|
||||||
|
</intent-filter>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
|
@@ -65,6 +65,7 @@ import com.android.settings.dashboard.DashboardFeatureProvider;
|
|||||||
import com.android.settings.dashboard.DashboardSummary;
|
import com.android.settings.dashboard.DashboardSummary;
|
||||||
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settings.search.DeviceIndexFeatureProvider;
|
||||||
import com.android.settings.wfd.WifiDisplaySettings;
|
import com.android.settings.wfd.WifiDisplaySettings;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
import com.android.settingslib.core.instrumentation.Instrumentable;
|
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||||
@@ -72,6 +73,7 @@ import com.android.settingslib.core.instrumentation.SharedPreferencesLogger;
|
|||||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -489,6 +491,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
|
|
||||||
updateTilesList();
|
updateTilesList();
|
||||||
|
updateDeviceIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -609,6 +612,14 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateDeviceIndex() {
|
||||||
|
DeviceIndexFeatureProvider indexProvider = FeatureFactory.getFactory(
|
||||||
|
this).getDeviceIndexFeatureProvider();
|
||||||
|
|
||||||
|
ThreadUtils.postOnBackgroundThread(
|
||||||
|
() -> indexProvider.updateIndex(SettingsActivity.this, false /* force */));
|
||||||
|
}
|
||||||
|
|
||||||
private void doUpdateTilesList() {
|
private void doUpdateTilesList() {
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
final UserManager um = UserManager.get(this);
|
final UserManager um = UserManager.get(this);
|
||||||
|
@@ -30,6 +30,7 @@ import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
|||||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||||
import com.android.settings.gestures.AssistGestureFeatureProvider;
|
import com.android.settings.gestures.AssistGestureFeatureProvider;
|
||||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||||
|
import com.android.settings.search.DeviceIndexFeatureProvider;
|
||||||
import com.android.settings.search.SearchFeatureProvider;
|
import com.android.settings.search.SearchFeatureProvider;
|
||||||
import com.android.settings.security.SecurityFeatureProvider;
|
import com.android.settings.security.SecurityFeatureProvider;
|
||||||
import com.android.settings.slices.SlicesFeatureProvider;
|
import com.android.settings.slices.SlicesFeatureProvider;
|
||||||
@@ -106,6 +107,8 @@ public abstract class FeatureFactory {
|
|||||||
|
|
||||||
public abstract AccountFeatureProvider getAccountFeatureProvider();
|
public abstract AccountFeatureProvider getAccountFeatureProvider();
|
||||||
|
|
||||||
|
public abstract DeviceIndexFeatureProvider getDeviceIndexFeatureProvider();
|
||||||
|
|
||||||
public static final class FactoryNotFoundException extends RuntimeException {
|
public static final class FactoryNotFoundException extends RuntimeException {
|
||||||
public FactoryNotFoundException(Throwable throwable) {
|
public FactoryNotFoundException(Throwable throwable) {
|
||||||
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
|
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
|
||||||
|
@@ -41,6 +41,8 @@ import com.android.settings.gestures.AssistGestureFeatureProvider;
|
|||||||
import com.android.settings.gestures.AssistGestureFeatureProviderImpl;
|
import com.android.settings.gestures.AssistGestureFeatureProviderImpl;
|
||||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||||
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
|
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
|
||||||
|
import com.android.settings.search.DeviceIndexFeatureProvider;
|
||||||
|
import com.android.settings.search.DeviceIndexFeatureProviderImpl;
|
||||||
import com.android.settings.search.SearchFeatureProvider;
|
import com.android.settings.search.SearchFeatureProvider;
|
||||||
import com.android.settings.search.SearchFeatureProviderImpl;
|
import com.android.settings.search.SearchFeatureProviderImpl;
|
||||||
import com.android.settings.security.SecurityFeatureProvider;
|
import com.android.settings.security.SecurityFeatureProvider;
|
||||||
@@ -75,6 +77,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
|||||||
private BluetoothFeatureProvider mBluetoothFeatureProvider;
|
private BluetoothFeatureProvider mBluetoothFeatureProvider;
|
||||||
private SlicesFeatureProvider mSlicesFeatureProvider;
|
private SlicesFeatureProvider mSlicesFeatureProvider;
|
||||||
private AccountFeatureProvider mAccountFeatureProvider;
|
private AccountFeatureProvider mAccountFeatureProvider;
|
||||||
|
private DeviceIndexFeatureProviderImpl mDeviceIndexFeatureProvider;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
|
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
|
||||||
@@ -208,4 +211,12 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
|||||||
}
|
}
|
||||||
return mAccountFeatureProvider;
|
return mAccountFeatureProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceIndexFeatureProvider getDeviceIndexFeatureProvider() {
|
||||||
|
if (mDeviceIndexFeatureProvider == null) {
|
||||||
|
mDeviceIndexFeatureProvider = new DeviceIndexFeatureProviderImpl();
|
||||||
|
}
|
||||||
|
return mDeviceIndexFeatureProvider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* 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.search;
|
||||||
|
|
||||||
|
import static com.android.settings.slices.SliceDeepLinkSpringBoard.INTENT;
|
||||||
|
import static com.android.settings.slices.SliceDeepLinkSpringBoard.SETTINGS;
|
||||||
|
|
||||||
|
import android.app.slice.SliceManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.slices.SettingsSliceProvider;
|
||||||
|
|
||||||
|
public interface DeviceIndexFeatureProvider {
|
||||||
|
|
||||||
|
// TODO: Remove this and index all action and intent slices through search index.
|
||||||
|
String[] ACTIONS_TO_INDEX = new String[]{
|
||||||
|
Settings.ACTION_WIFI_SETTINGS,
|
||||||
|
};
|
||||||
|
|
||||||
|
String TAG = "DeviceIndex";
|
||||||
|
|
||||||
|
String INDEX_VERSION = "settings:index_version";
|
||||||
|
|
||||||
|
// Increment when new items are added to ensure they get pushed to the device index.
|
||||||
|
int VERSION = 1;
|
||||||
|
|
||||||
|
boolean isIndexingEnabled();
|
||||||
|
|
||||||
|
void index(Context context, CharSequence title, Uri sliceUri, Uri launchUri);
|
||||||
|
|
||||||
|
default void updateIndex(Context context, boolean force) {
|
||||||
|
if (!isIndexingEnabled()) return;
|
||||||
|
|
||||||
|
if (!force && Settings.Secure.getInt(context.getContentResolver(), INDEX_VERSION, -1)
|
||||||
|
== VERSION) {
|
||||||
|
// No need to update.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageManager pm = context.getPackageManager();
|
||||||
|
for (String action : ACTIONS_TO_INDEX) {
|
||||||
|
Intent intent = new Intent(action);
|
||||||
|
intent.setPackage(context.getPackageName());
|
||||||
|
ResolveInfo activity = pm.resolveActivity(intent, PackageManager.GET_META_DATA);
|
||||||
|
if (activity == null) {
|
||||||
|
Log.e(TAG, "Unable to resolve " + action);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String sliceUri = activity.activityInfo.metaData
|
||||||
|
.getString(SliceManager.SLICE_METADATA_KEY);
|
||||||
|
if (sliceUri != null) {
|
||||||
|
Log.d(TAG, "Intent: " + createDeepLink(intent.toUri(Intent.URI_ANDROID_APP_SCHEME)));
|
||||||
|
index(context, activity.activityInfo.loadLabel(pm),
|
||||||
|
Uri.parse(sliceUri),
|
||||||
|
Uri.parse(createDeepLink(intent.toUri(Intent.URI_ANDROID_APP_SCHEME))));
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "No slice uri found for " + activity.activityInfo.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings.Secure.putInt(context.getContentResolver(), INDEX_VERSION, VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String createDeepLink(String s) {
|
||||||
|
return new Uri.Builder().scheme(SETTINGS)
|
||||||
|
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
|
.appendQueryParameter(INTENT, s)
|
||||||
|
.build()
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.search;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
public class DeviceIndexFeatureProviderImpl implements DeviceIndexFeatureProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndexingEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void index(Context context, CharSequence title, Uri sliceUri, Uri launchUri) {
|
||||||
|
// Not enabled by default.
|
||||||
|
}
|
||||||
|
}
|
@@ -17,27 +17,26 @@
|
|||||||
package com.android.settings.slices;
|
package com.android.settings.slices;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.app.slice.SliceManager;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.provider.SettingsSlicesContract;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import androidx.slice.Slice;
|
import androidx.slice.Slice;
|
||||||
import androidx.slice.SliceProvider;
|
import androidx.slice.SliceProvider;
|
||||||
import androidx.slice.builders.SliceAction;
|
|
||||||
import androidx.slice.builders.ListBuilder;
|
import androidx.slice.builders.ListBuilder;
|
||||||
|
import androidx.slice.builders.SliceAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link SliceProvider} for Settings to enabled inline results in system apps.
|
* A {@link SliceProvider} for Settings to enabled inline results in system apps.
|
||||||
@@ -106,6 +105,17 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Uri onMapIntentToUri(Intent intent) {
|
||||||
|
try {
|
||||||
|
return getContext().getSystemService(SliceManager.class).mapIntentToUri(
|
||||||
|
SliceDeepLinkSpringBoard.parse(
|
||||||
|
intent.getData(), getContext().getPackageName()));
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Slice onBindSlice(Uri sliceUri) {
|
public Slice onBindSlice(Uri sliceUri) {
|
||||||
String path = sliceUri.getPath();
|
String path = sliceUri.getPath();
|
||||||
|
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.slices;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
public class SliceDeepLinkSpringBoard extends Activity {
|
||||||
|
|
||||||
|
private static final String TAG = "DeeplinkSpringboard";
|
||||||
|
public static final String INTENT = "intent";
|
||||||
|
public static final String SETTINGS = "settings";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Uri uri = getIntent().getData();
|
||||||
|
if (uri == null) {
|
||||||
|
Log.e(TAG, "No data found");
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Intent intent = parse(uri, getPackageName());
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
Log.e(TAG, "Error decoding uri", e);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Intent parse(Uri uri, String pkg) throws URISyntaxException {
|
||||||
|
Intent intent = Intent.parseUri(uri.getQueryParameter(INTENT),
|
||||||
|
Intent.URI_ANDROID_APP_SCHEME);
|
||||||
|
// Start with some really strict constraints and loosen them if we need to.
|
||||||
|
// Don't allow components.
|
||||||
|
intent.setComponent(null);
|
||||||
|
// Clear out the extras.
|
||||||
|
if (intent.getExtras() != null) {
|
||||||
|
intent.getExtras().clear();
|
||||||
|
}
|
||||||
|
// Make sure this points at Settings.
|
||||||
|
intent.setPackage(pkg);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.search;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
|
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.app.Activity;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
public class DeviceIndexFeatureProviderTest {
|
||||||
|
|
||||||
|
private DeviceIndexFeatureProvider mProvider;
|
||||||
|
private Activity mActivity;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
FakeFeatureFactory.setupForTest();
|
||||||
|
mActivity = Robolectric.buildActivity(Activity.class).create().visible().get();
|
||||||
|
mProvider = spy(new DeviceIndexFeatureProviderImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyDisabled() {
|
||||||
|
when(mProvider.isIndexingEnabled()).thenReturn(false);
|
||||||
|
|
||||||
|
mProvider.updateIndex(mActivity, false);
|
||||||
|
verify(mProvider, never()).index(any(), any(), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyIndexing() {
|
||||||
|
when(mProvider.isIndexingEnabled()).thenReturn(true);
|
||||||
|
|
||||||
|
mProvider.updateIndex(mActivity, false);
|
||||||
|
verify(mProvider, atLeastOnce()).index(any(), any(), any(), any());
|
||||||
|
}
|
||||||
|
}
|
@@ -33,6 +33,7 @@ import com.android.settings.localepicker.LocaleFeatureProvider;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.overlay.SupportFeatureProvider;
|
import com.android.settings.overlay.SupportFeatureProvider;
|
||||||
import com.android.settings.overlay.SurveyFeatureProvider;
|
import com.android.settings.overlay.SurveyFeatureProvider;
|
||||||
|
import com.android.settings.search.DeviceIndexFeatureProvider;
|
||||||
import com.android.settings.search.SearchFeatureProvider;
|
import com.android.settings.search.SearchFeatureProvider;
|
||||||
import com.android.settings.security.SecurityFeatureProvider;
|
import com.android.settings.security.SecurityFeatureProvider;
|
||||||
import com.android.settings.slices.SlicesFeatureProvider;
|
import com.android.settings.slices.SlicesFeatureProvider;
|
||||||
@@ -63,6 +64,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
|||||||
public final SlicesFeatureProvider slicesFeatureProvider;
|
public final SlicesFeatureProvider slicesFeatureProvider;
|
||||||
public SearchFeatureProvider searchFeatureProvider;
|
public SearchFeatureProvider searchFeatureProvider;
|
||||||
public final AccountFeatureProvider mAccountFeatureProvider;
|
public final AccountFeatureProvider mAccountFeatureProvider;
|
||||||
|
public final DeviceIndexFeatureProvider deviceIndexFeatureProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||||
@@ -101,6 +103,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
|||||||
bluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
|
bluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
|
||||||
slicesFeatureProvider = mock(SlicesFeatureProvider.class);
|
slicesFeatureProvider = mock(SlicesFeatureProvider.class);
|
||||||
mAccountFeatureProvider = mock(AccountFeatureProvider.class);
|
mAccountFeatureProvider = mock(AccountFeatureProvider.class);
|
||||||
|
deviceIndexFeatureProvider = mock(DeviceIndexFeatureProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -182,4 +185,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
|||||||
public AccountFeatureProvider getAccountFeatureProvider() {
|
public AccountFeatureProvider getAccountFeatureProvider() {
|
||||||
return mAccountFeatureProvider;
|
return mAccountFeatureProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceIndexFeatureProvider getDeviceIndexFeatureProvider() {
|
||||||
|
return deviceIndexFeatureProvider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user