Build Intents at index time
In order to index Intents into Icing, they need to be built at Index time rather than at Search time. Test: make RunSettingsRoboTests Bug: 36443380 Change-Id: Ia731b5038380bb658232e2e175f52a81d86d7e02
This commit is contained in:
@@ -14,14 +14,17 @@
|
||||
package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import android.util.ArrayMap;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.search2.DatabaseIndexingUtils;
|
||||
import com.android.settings.search2.InlineSwitchPayload;
|
||||
import com.android.settings.search2.ResultPayload;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -71,7 +74,11 @@ public class AutoBrightnessPreferenceController extends PreferenceController imp
|
||||
valueMap.put(SCREEN_BRIGHTNESS_MODE_AUTOMATIC, true);
|
||||
valueMap.put(SCREEN_BRIGHTNESS_MODE_MANUAL, false);
|
||||
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
getClass().getName(), KEY_AUTO_BRIGHTNESS,
|
||||
mContext.getString(R.string.display_settings));
|
||||
|
||||
return new InlineSwitchPayload(SCREEN_BRIGHTNESS_MODE,
|
||||
ResultPayload.SettingsSource.SYSTEM, valueMap);
|
||||
ResultPayload.SettingsSource.SYSTEM, valueMap, intent);
|
||||
}
|
||||
}
|
||||
|
@@ -17,21 +17,15 @@
|
||||
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.BadParcelableException;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -46,9 +40,6 @@ import java.util.Set;
|
||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_CLASS_NAME;
|
||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ICON;
|
||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ID;
|
||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_INTENT_ACTION;
|
||||
import static com.android.settings.search2.DatabaseResultLoader
|
||||
.COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS;
|
||||
import static com.android.settings.search2.DatabaseResultLoader
|
||||
.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
|
||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_KEY;
|
||||
@@ -132,7 +123,6 @@ class CursorToSearchResultConverter {
|
||||
mKeys.add(docId);
|
||||
|
||||
final String pkgName = cursor.getString(COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
|
||||
final String action = cursor.getString(COLUMN_INDEX_INTENT_ACTION);
|
||||
final String title = cursor.getString(COLUMN_INDEX_TITLE);
|
||||
final String summaryOn = cursor.getString(COLUMN_INDEX_SUMMARY_ON);
|
||||
final String className = cursor.getString(COLUMN_INDEX_CLASS_NAME);
|
||||
@@ -140,16 +130,7 @@ class CursorToSearchResultConverter {
|
||||
final String iconResStr = cursor.getString(COLUMN_INDEX_ICON);
|
||||
final int payloadType = cursor.getInt(COLUMN_INDEX_PAYLOAD_TYPE);
|
||||
final byte[] marshalledPayload = cursor.getBlob(COLUMN_INDEX_PAYLOAD);
|
||||
final ResultPayload payload;
|
||||
|
||||
if (marshalledPayload != null) {
|
||||
payload = getUnmarshalledPayload(marshalledPayload, payloadType);
|
||||
} else if (payloadType == ResultPayload.PayloadType.INTENT) {
|
||||
payload = getIntentPayload(cursor, action, key, className, pkgName);
|
||||
} else {
|
||||
Log.w(TAG, "Error creating payload - bad marshalling data or mismatched types");
|
||||
return null;
|
||||
}
|
||||
final ResultPayload payload = getUnmarshalledPayload(marshalledPayload, payloadType);
|
||||
|
||||
final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor);
|
||||
final int rank = getRank(title, breadcrumbs, baseRank, key);
|
||||
@@ -196,34 +177,12 @@ class CursorToSearchResultConverter {
|
||||
return icon;
|
||||
}
|
||||
|
||||
private IntentPayload getIntentPayload(Cursor cursor, String action, String key,
|
||||
String className, String pkgName ) {
|
||||
IntentPayload payload;
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
final String screenTitle = cursor.getString(COLUMN_INDEX_SCREEN_TITLE);
|
||||
// Action is null, we will launch it as a sub-setting
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||
final Intent intent = Utils.onBuildStartFragmentIntent(mContext,
|
||||
className, args, null, 0, screenTitle, false,
|
||||
MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
|
||||
payload = new IntentPayload(intent);
|
||||
} else {
|
||||
final Intent intent = new Intent(action);
|
||||
final String targetClass = cursor.getString(COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS);
|
||||
if (!TextUtils.isEmpty(pkgName) && !TextUtils.isEmpty(targetClass)) {
|
||||
final ComponentName component = new ComponentName(pkgName, targetClass);
|
||||
intent.setComponent(component);
|
||||
}
|
||||
intent.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||
payload = new IntentPayload(intent);
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
private ResultPayload getUnmarshalledPayload(byte[] unmarshalledPayload, int payloadType) {
|
||||
try {
|
||||
switch (payloadType) {
|
||||
case ResultPayload.PayloadType.INTENT:
|
||||
return ResultPayloadUtils.unmarshall(unmarshalledPayload,
|
||||
ResultPayload.CREATOR);
|
||||
case ResultPayload.PayloadType.INLINE_SWITCH:
|
||||
return ResultPayloadUtils.unmarshall(unmarshalledPayload,
|
||||
InlineSwitchPayload.CREATOR);
|
||||
@@ -269,5 +228,4 @@ class CursorToSearchResultConverter {
|
||||
}
|
||||
return baseRank;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@@ -39,6 +40,7 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.search.IndexDatabaseHelper;
|
||||
import com.android.settings.search.Indexable;
|
||||
@@ -927,7 +929,7 @@ public class DatabaseIndexingManager {
|
||||
.setNormalizedSummaryOff(normalizedSummaryOff)
|
||||
.setSpaceDelimitedKeywords(spaceDelimitedKeywords);
|
||||
|
||||
updateOneRow(database, builder.build());
|
||||
updateOneRow(database, builder.build(mContext));
|
||||
}
|
||||
|
||||
private void updateOneRow(SQLiteDatabase database, DatabaseRow row) {
|
||||
@@ -1212,7 +1214,45 @@ public class DatabaseIndexingManager {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatabaseRow build() {
|
||||
/**
|
||||
* Adds intent to inline payloads, or creates an Intent Payload as a fallback if the
|
||||
* payload is null.
|
||||
*/
|
||||
private void setIntent(Context context) {
|
||||
if (mPayload != null) {
|
||||
return;
|
||||
}
|
||||
final Intent intent = buildIntent(context);
|
||||
mPayload = new ResultPayload(intent);
|
||||
mPayloadType = ResultPayload.PayloadType.INTENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Intent payload to builder.
|
||||
*/
|
||||
private Intent buildIntent(Context context) {
|
||||
final Intent intent;
|
||||
|
||||
if (TextUtils.isEmpty(mIntentAction)) {
|
||||
// Action is null, we will launch it as a sub-setting
|
||||
intent = DatabaseIndexingUtils.buildSubsettingIntent(context, mClassName, mKey,
|
||||
mScreenTitle);
|
||||
} else {
|
||||
intent = new Intent(mIntentAction);
|
||||
final String targetClass = mIntentTargetClass;
|
||||
if (!TextUtils.isEmpty(mIntentTargetPackage)
|
||||
&& !TextUtils.isEmpty(targetClass)) {
|
||||
final ComponentName component = new ComponentName(mIntentTargetPackage,
|
||||
targetClass);
|
||||
intent.setComponent(component);
|
||||
}
|
||||
intent.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mKey);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
public DatabaseRow build(Context context) {
|
||||
setIntent(context);
|
||||
return new DatabaseRow(this);
|
||||
}
|
||||
}
|
||||
|
@@ -19,15 +19,20 @@ package com.android.settings.search2;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
@@ -57,6 +62,18 @@ public class DatabaseIndexingUtils {
|
||||
private static final Pattern REMOVE_DIACRITICALS_PATTERN
|
||||
= Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
|
||||
|
||||
/**
|
||||
* Builds intent into a subsetting.
|
||||
*/
|
||||
public static Intent buildSubsettingIntent(Context context, String className, String key,
|
||||
String screenTitle) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||
return Utils.onBuildStartFragmentIntent(context,
|
||||
className, args, null, 0, screenTitle, false,
|
||||
MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className which wil provide the map between from {@link Uri}s to
|
||||
* {@link PreferenceController}
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* Abstract Payload for inline settings results.
|
||||
*/
|
||||
@@ -35,7 +37,9 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
*/
|
||||
@SettingsSource public int settingSource;
|
||||
|
||||
public InlinePayload(String uri, @PayloadType int type, @SettingsSource int source) {
|
||||
public InlinePayload(String uri, @PayloadType int type, @SettingsSource int source,
|
||||
Intent intent) {
|
||||
super(intent);
|
||||
settingsUri = uri;
|
||||
inlineType = type;
|
||||
settingSource = source;
|
||||
|
@@ -18,6 +18,7 @@
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.Settings;
|
||||
@@ -38,14 +39,15 @@ public class InlineSwitchPayload extends InlinePayload {
|
||||
public final Map<Integer, Boolean> valueMap;
|
||||
|
||||
public InlineSwitchPayload(String newUri, @SettingsSource int settingsSource,
|
||||
Map<Integer, Boolean> map) {
|
||||
super(newUri, PayloadType.INLINE_SWITCH, settingsSource);
|
||||
Map<Integer, Boolean> map, Intent intent) {
|
||||
super(newUri, PayloadType.INLINE_SWITCH, settingsSource, intent);
|
||||
valueMap = map;
|
||||
}
|
||||
|
||||
private InlineSwitchPayload(Parcel in) {
|
||||
super(in.readString() /* Uri */ , in.readInt() /* Payload Type */,
|
||||
in.readInt() /* Settings Source */);
|
||||
in.readInt() /* Settings Source */,
|
||||
(Intent) in.readParcelable(Intent.class.getClassLoader()) /* Intent */);
|
||||
valueMap = in.readHashMap(Integer.class.getClassLoader());
|
||||
}
|
||||
|
||||
@@ -64,6 +66,7 @@ public class InlineSwitchPayload extends InlinePayload {
|
||||
dest.writeString(settingsUri);
|
||||
dest.writeInt(inlineType);
|
||||
dest.writeInt(settingSource);
|
||||
dest.writeParcelable(mIntent, flags);
|
||||
dest.writeMap(valueMap);
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,6 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.applications.ManageApplications;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.utils.AsyncLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -98,7 +97,7 @@ public class InstalledAppResultLoader extends AsyncLoader<List<? extends SearchR
|
||||
.addTitle(info.loadLabel(pm))
|
||||
.addRank(getRank(wordDiff))
|
||||
.addBreadcrumbs(getBreadCrumb())
|
||||
.addPayload(new IntentPayload(intent));
|
||||
.addPayload(new ResultPayload(intent));
|
||||
results.add(builder.build());
|
||||
}
|
||||
}
|
||||
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.search2;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
|
||||
/**
|
||||
* Encapsulates the standard intent based results as seen in first party apps and Settings results.
|
||||
*/
|
||||
public class IntentPayload extends ResultPayload {
|
||||
public final Intent intent;
|
||||
|
||||
private IntentPayload(Parcel in) {
|
||||
intent = in.readParcelable(IntentPayload.class.getClassLoader());
|
||||
}
|
||||
|
||||
public IntentPayload(Intent newIntent) {
|
||||
intent = newIntent;
|
||||
}
|
||||
|
||||
@ResultPayload.PayloadType public int getType() {
|
||||
return PayloadType.INTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(intent, flags);
|
||||
}
|
||||
|
||||
public static final Creator<IntentPayload> CREATOR = new Creator<IntentPayload>() {
|
||||
@Override
|
||||
public IntentPayload createFromParcel(Parcel in) {
|
||||
return new IntentPayload(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentPayload[] newArray(int size) {
|
||||
return new IntentPayload[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@@ -40,7 +40,7 @@ public class IntentSearchViewHolder extends SearchViewHolder {
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
fragment.onSearchResultClicked();
|
||||
final Intent intent = ((IntentPayload) result.payload).intent;
|
||||
final Intent intent = result.payload.getIntent();
|
||||
final ComponentName cn = intent.getComponent();
|
||||
final Pair<Integer, Object> rank = Pair.create(
|
||||
MetricsEvent.FIELD_SETTINGS_SERACH_RESULT_RANK, getAdapterPosition());
|
||||
|
@@ -17,6 +17,8 @@
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -26,14 +28,15 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* A interface for search results types. Examples include Inline results, third party apps
|
||||
* or any future possibilities.
|
||||
*/
|
||||
public abstract class ResultPayload implements Parcelable {
|
||||
public class ResultPayload implements Parcelable {
|
||||
protected final Intent mIntent;
|
||||
|
||||
@IntDef({PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH,
|
||||
PayloadType.INTENT, PayloadType.SAVED_QUERY})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface PayloadType {
|
||||
/**
|
||||
* Resulting page will be started using an intent
|
||||
* Resulting page will be started using an mIntent
|
||||
*/
|
||||
int INTENT = 0;
|
||||
|
||||
@@ -64,6 +67,42 @@ public abstract class ResultPayload implements Parcelable {
|
||||
}
|
||||
|
||||
|
||||
private ResultPayload(Parcel in) {
|
||||
mIntent = in.readParcelable(ResultPayload.class.getClassLoader());
|
||||
}
|
||||
|
||||
public ResultPayload(Intent intent) {
|
||||
mIntent = intent;
|
||||
}
|
||||
|
||||
@ResultPayload.PayloadType
|
||||
public abstract int getType();
|
||||
public int getType() {
|
||||
return PayloadType.INTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(mIntent, flags);
|
||||
}
|
||||
|
||||
public static final Creator<ResultPayload> CREATOR = new Creator<ResultPayload>() {
|
||||
@Override
|
||||
public ResultPayload createFromParcel(Parcel in) {
|
||||
return new ResultPayload(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultPayload[] newArray(int size) {
|
||||
return new ResultPayload[size];
|
||||
}
|
||||
};
|
||||
|
||||
public Intent getIntent() {
|
||||
return mIntent;
|
||||
}
|
||||
}
|
||||
|
@@ -27,11 +27,13 @@ public class SavedQueryPayload extends ResultPayload {
|
||||
public final String query;
|
||||
|
||||
public SavedQueryPayload(String query) {
|
||||
super(null /* Intent */);
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
SavedQueryPayload(Parcel in) {
|
||||
super(null /* Intent */);
|
||||
query = in.readString();
|
||||
}
|
||||
|
||||
|
@@ -25,14 +25,8 @@ import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.display.AutoBrightnessPreferenceController;
|
||||
import com.android.settings.gestures.DoubleTapPowerPreferenceController;
|
||||
import com.android.settings.gestures.DoubleTapScreenPreferenceController;
|
||||
import com.android.settings.gestures.DoubleTwistPreferenceController;
|
||||
import com.android.settings.gestures.PickupGesturePreferenceController;
|
||||
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
|
||||
import com.android.settings.search2.DatabaseIndexingUtils;
|
||||
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.ResultPayload;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -103,13 +97,13 @@ public class DatabaseIndexingUtilsTest {
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
return new IntentPayload(null);
|
||||
return new ResultPayload(null);
|
||||
}
|
||||
};
|
||||
ArrayMap<String,PreferenceController> map = new ArrayMap<>();
|
||||
map.put(key, prefController);
|
||||
|
||||
ResultPayload payload = DatabaseIndexingUtils.getPayloadFromUriMap(map, key);
|
||||
assertThat(payload).isInstanceOf(IntentPayload.class);
|
||||
assertThat(payload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
}
|
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.util.ArrayMap;
|
||||
import android.content.Context;
|
||||
@@ -43,7 +44,7 @@ public class InlineSwitchPayloadTest {
|
||||
final int source = ResultPayload.SettingsSource.SECURE;
|
||||
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, null);
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, null, null);
|
||||
try {
|
||||
payload.getSwitchValue(context);
|
||||
fail("Should have thrown exception for null map");
|
||||
@@ -59,7 +60,7 @@ public class InlineSwitchPayloadTest {
|
||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, null);
|
||||
try {
|
||||
payload.getSwitchValue(context);
|
||||
fail("Should have thrown exception for bad map");
|
||||
@@ -76,13 +77,19 @@ public class InlineSwitchPayloadTest {
|
||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||
map.put(1, true);
|
||||
map.put(0, false);
|
||||
final String intentKey = "key";
|
||||
final String intentVal = "value";
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(intentKey, intentVal);
|
||||
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, intent);
|
||||
final Intent retainedIntent = payload.getIntent();
|
||||
assertThat(payload.settingsUri).isEqualTo(uri);
|
||||
assertThat(payload.inlineType).isEqualTo(type);
|
||||
assertThat(payload.settingSource).isEqualTo(source);
|
||||
assertThat(payload.valueMap.get(1)).isTrue();
|
||||
assertThat(payload.valueMap.get(0)).isFalse();
|
||||
assertThat(retainedIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,20 +100,27 @@ public class InlineSwitchPayloadTest {
|
||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||
map.put(1, true);
|
||||
map.put(0, false);
|
||||
final String intentKey = "key";
|
||||
final String intentVal = "value";
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(intentKey, intentVal);
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.writeString(uri);
|
||||
parcel.writeInt(type);
|
||||
parcel.writeInt(source);
|
||||
parcel.writeParcelable(intent, 0);
|
||||
parcel.writeMap(map);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
InlineSwitchPayload payload = InlineSwitchPayload.CREATOR.createFromParcel(parcel);
|
||||
final Intent builtIntent = payload.getIntent();
|
||||
assertThat(payload.settingsUri).isEqualTo(uri);
|
||||
assertThat(payload.inlineType).isEqualTo(type);
|
||||
assertThat(payload.settingSource).isEqualTo(source);
|
||||
assertThat(payload.valueMap.get(1)).isTrue();
|
||||
assertThat(payload.valueMap.get(0)).isFalse();
|
||||
assertThat(builtIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -117,7 +117,7 @@ public class InlineSwitchViewHolderTest {
|
||||
builder.addTitle(TITLE)
|
||||
.addSummary(SUMMARY)
|
||||
.addRank(1)
|
||||
.addPayload(new InlineSwitchPayload("", 0, null))
|
||||
.addPayload(new InlineSwitchPayload("", 0, null, null))
|
||||
.addBreadcrumbs(new ArrayList<>())
|
||||
.addIcon(mIcon)
|
||||
.addPayload(mPayload);
|
||||
|
@@ -18,12 +18,12 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.ResultPayload;
|
||||
import com.android.settings.search2.SearchResult;
|
||||
import com.android.settings.search2.SearchResult.Builder;
|
||||
@@ -57,7 +57,7 @@ public class SearchResultBuilderTest {
|
||||
mSummary = "summary";
|
||||
mBreadcrumbs = new ArrayList<>();
|
||||
mRank = 3;
|
||||
mResultPayload = new IntentPayload(null);
|
||||
mResultPayload = new ResultPayload(new Intent());
|
||||
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
mIcon = context.getDrawable(R.drawable.ic_search_history);
|
||||
|
@@ -31,9 +31,8 @@ import com.android.settings.search2.AppSearchResult;
|
||||
import com.android.settings.search2.DatabaseResultLoader;
|
||||
import com.android.settings.search2.InlineSwitchViewHolder;
|
||||
import com.android.settings.search2.InstalledAppResultLoader;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.IntentSearchViewHolder;
|
||||
import com.android.settings.search2.ResultPayload;
|
||||
import com.android.settings.search2.IntentSearchViewHolder;
|
||||
import com.android.settings.search2.SearchFeatureProvider;
|
||||
import com.android.settings.search2.SearchFragment;
|
||||
import com.android.settings.search2.SearchResult;
|
||||
@@ -154,7 +153,7 @@ public class SearchResultsAdapterTest {
|
||||
|
||||
private List<SearchResult> getDummyDbResults() {
|
||||
List<SearchResult> results = new ArrayList<>();
|
||||
IntentPayload payload = new IntentPayload(new Intent());
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
builder.addPayload(payload);
|
||||
|
||||
@@ -175,7 +174,7 @@ public class SearchResultsAdapterTest {
|
||||
|
||||
private List<AppSearchResult> getDummyAppResults() {
|
||||
List<AppSearchResult> results = new ArrayList<>();
|
||||
IntentPayload payload = new IntentPayload(new Intent());
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
AppSearchResult.Builder builder = new AppSearchResult.Builder();
|
||||
builder.addPayload(payload);
|
||||
|
||||
@@ -198,7 +197,7 @@ public class SearchResultsAdapterTest {
|
||||
ArrayList<SearchResult> sampleResults = new ArrayList<>();
|
||||
ArrayList<String> breadcrumbs = new ArrayList<>();
|
||||
final Drawable icon = mContext.getDrawable(R.drawable.ic_search_history);
|
||||
final ResultPayload payload = new IntentPayload(null);
|
||||
final ResultPayload payload = new ResultPayload(null);
|
||||
final SearchResult.Builder builder = new Builder();
|
||||
builder.addTitle("title")
|
||||
.addSummary("summary")
|
||||
|
@@ -20,7 +20,9 @@ package com.android.settings.search2;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
@@ -58,6 +60,7 @@ public class CursorToSearchResultConverterTest {
|
||||
private static final String TARGET_PACKAGE = "a.b.c";
|
||||
private static final String TARGET_CLASS = "a.b.c.class";
|
||||
private static final String QUERY = "query";
|
||||
private static final String KEY = "key";
|
||||
private static final Intent INTENT = new Intent("com.android.settings");
|
||||
private static final int ICON = R.drawable.ic_search_history;
|
||||
private static final int BASE_RANK = 1;
|
||||
@@ -78,20 +81,20 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testParseNullResults_ReturnsNull() {
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, null, BASE_RANK);
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, null, BASE_RANK);
|
||||
assertThat(results).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_NotNull() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||
assertThat(results).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesRank() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
assertThat(results.get(i).rank).isEqualTo(BASE_RANK);
|
||||
@@ -100,7 +103,7 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesTitle() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
assertThat(results.get(i).title).isEqualTo(TITLES[i]);
|
||||
@@ -109,7 +112,7 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesSummary() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
assertThat(results.get(i).summary).isEqualTo(SUMMARY);
|
||||
@@ -118,19 +121,38 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesIcon() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
Drawable resultDrawable = results.get(i).icon;
|
||||
assertThat(resultDrawable).isNotNull();
|
||||
assertThat(resultDrawable.toString()).isEqualTo(mDrawable.toString());
|
||||
}
|
||||
final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
|
||||
final String BLANK = "";
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
"Longer than 20 characters", // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
DisplaySettings.class.getName(),
|
||||
BLANK, // screen title
|
||||
ICON, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
BLANK, // Key
|
||||
PayloadType.INTENT, // Payload Type
|
||||
payload // Payload
|
||||
});
|
||||
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, cursor, BASE_RANK);
|
||||
|
||||
Drawable resultDrawable = results.get(0).icon;
|
||||
assertThat(resultDrawable).isNotNull();
|
||||
assertThat(resultDrawable.toString()).isEqualTo(mDrawable.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_NoIcon() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(false /* hasIcon */), BASE_RANK);
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(false /* hasIcon */, "" /* className */,
|
||||
"" /* key */), BASE_RANK);
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
Drawable resultDrawable = results.get(i).icon;
|
||||
assertThat(resultDrawable).isNull();
|
||||
@@ -139,7 +161,7 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesPayloadType() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||
ResultPayload payload;
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
@@ -150,7 +172,8 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testLongTitle_PenalizedInRank() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
|
||||
final String BLANK = "";
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
@@ -164,75 +187,26 @@ public class CursorToSearchResultConverterTest {
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
BLANK, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
PayloadType.INTENT, // Payload Type
|
||||
payload // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
assertThat(results.get(0).rank).isEqualTo(BASE_RANK + 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesIntentForSubSettings() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
SwipeToNotificationSettings.class.getName(),
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
BLANK, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
IntentPayload payload = (IntentPayload) results.get(0).payload;
|
||||
Intent intent = payload.intent;
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesIntentPayload() {
|
||||
List<SearchResult> results = mConverter.convertCursor(
|
||||
public void testParseCursor_MatchesResultPayload() {
|
||||
final List<SearchResult> results = mConverter.convertCursor(
|
||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||
IntentPayload payload;
|
||||
ResultPayload payload;
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
payload = (IntentPayload) results.get(i).payload;
|
||||
Intent intent = payload.intent;
|
||||
payload = results.get(i).payload;
|
||||
Intent intent = payload.getIntent();
|
||||
assertThat(intent.getAction()).isEqualTo(INTENT.getAction());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesIntentPayloadForExternalApps() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
null, // class
|
||||
TITLES[0], // Title
|
||||
null, // icon
|
||||
Intent.ACTION_VIEW, // action
|
||||
TARGET_PACKAGE, // target package
|
||||
TARGET_CLASS, // target class
|
||||
QUERY, // Key
|
||||
PayloadType.INTENT, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
IntentPayload payload = (IntentPayload) results.get(0).payload;
|
||||
Intent intent = payload.intent;
|
||||
|
||||
assertThat(intent.getComponent().getPackageName()).isEqualTo(TARGET_PACKAGE);
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(TARGET_CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesInlineSwitchPayload() {
|
||||
@@ -244,7 +218,11 @@ public class CursorToSearchResultConverterTest {
|
||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||
map.put(1, true);
|
||||
map.put(0, false);
|
||||
final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
|
||||
final String intentKey = "key";
|
||||
final String intentVal = "value";
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(intentKey, intentVal);
|
||||
final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, intent);
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
@@ -261,14 +239,16 @@ public class CursorToSearchResultConverterTest {
|
||||
type, // Payload Type
|
||||
ResultPayloadUtils.marshall(payload) // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
InlineSwitchPayload newPayload = (InlineSwitchPayload) results.get(0).payload;
|
||||
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
final InlineSwitchPayload newPayload = (InlineSwitchPayload) results.get(0).payload;
|
||||
final Intent rebuiltIntent = newPayload.getIntent();
|
||||
assertThat(newPayload.settingsUri).isEqualTo(uri);
|
||||
assertThat(newPayload.inlineType).isEqualTo(type);
|
||||
assertThat(newPayload.settingSource).isEqualTo(source);
|
||||
assertThat(newPayload.valueMap.get(1)).isTrue();
|
||||
assertThat(newPayload.valueMap.get(0)).isFalse();
|
||||
assertThat(rebuiltIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||
}
|
||||
|
||||
// The following tests are temporary, and should be removed when we replace the Search
|
||||
@@ -276,77 +256,28 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testWifiKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "main_toggle_wifi";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBluetoothKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "main_toggle_bluetooth";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAirplaneKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "toggle_airplane";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
@@ -354,156 +285,60 @@ public class CursorToSearchResultConverterTest {
|
||||
|
||||
@Test
|
||||
public void testHotspotKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "tether_settings";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatterySaverKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "battery_saver";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNFCKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "toggle_nfc";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataSaverKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "restrict_background";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataUsageKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "data_usage_enable";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoamingKey_PrioritizedResult() {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final String key = "button_roaming_key";
|
||||
|
||||
cursor.addRow(new Object[]{
|
||||
ID, // Doc ID
|
||||
TITLES[0], // Title
|
||||
SUMMARY, // Summary on
|
||||
SUMMARY, // summary off
|
||||
WifiSettings.class.getName(), // ClassName
|
||||
BLANK, // screen title
|
||||
null, // icon
|
||||
BLANK, // action
|
||||
null, // target package
|
||||
BLANK, // target class
|
||||
key, // Key
|
||||
0, // Payload Type
|
||||
null // Payload
|
||||
});
|
||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||
BASE_RANK);
|
||||
|
||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||
}
|
||||
@@ -511,28 +346,33 @@ public class CursorToSearchResultConverterTest {
|
||||
// End of temporary tests
|
||||
|
||||
private MatrixCursor getDummyCursor() {
|
||||
return getDummyCursor(true /* hasIcon */);
|
||||
return getDummyCursor(true /* hasIcon */, KEY, "" /* className */);
|
||||
}
|
||||
|
||||
private MatrixCursor getDummyCursor(boolean hasIcon) {
|
||||
private MatrixCursor getDummyCursor(String key, String className) {
|
||||
return getDummyCursor(false, key, className);
|
||||
}
|
||||
|
||||
private MatrixCursor getDummyCursor(boolean hasIcon, String key, String className) {
|
||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||
final String BLANK = "";
|
||||
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
|
||||
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
ArrayList<String> item = new ArrayList<>(DatabaseResultLoader.SELECT_COLUMNS.length);
|
||||
ArrayList<Object> item = new ArrayList<>(DatabaseResultLoader.SELECT_COLUMNS.length);
|
||||
item.add(ID + i); // Doc ID
|
||||
item.add(TITLES[i]); // Title
|
||||
item.add(SUMMARY); // Summary on
|
||||
item.add(BLANK); // summary off
|
||||
item.add(BLANK); // classname
|
||||
item.add(className); // classname
|
||||
item.add(BLANK); // screen title
|
||||
item.add(hasIcon ? Integer.toString(ICON) : null); // Icon
|
||||
item.add(INTENT.getAction()); // Intent action
|
||||
item.add(BLANK); // target package
|
||||
item.add(BLANK); // target class
|
||||
item.add(BLANK); // Key
|
||||
item.add(TARGET_PACKAGE); // target package
|
||||
item.add(TARGET_CLASS); // target class
|
||||
item.add(key); // Key
|
||||
item.add(Integer.toString(0)); // Payload Type
|
||||
item.add(null); // Payload
|
||||
item.add(payload); // Payload
|
||||
|
||||
cursor.addRow(item);
|
||||
}
|
||||
|
@@ -225,7 +225,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -319,7 +322,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload - should be updated to real payloads as controllers are added
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -401,7 +407,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload - should be updated to real payloads as controllers are added
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -455,7 +464,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload - should be updated to real payloads as controllers are added
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -509,7 +521,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload - should be updated to real payloads as controllers are added
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
// Tests for the flow: IndexOneResource -> IndexFromProvider -> IndexFromResource ->
|
||||
@@ -578,7 +593,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload - should be updated to real payloads as controllers are added
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -643,7 +661,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload - should be updated to real payloads as controllers are added
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -880,7 +901,10 @@ public class DatabaseIndexingManagerTest {
|
||||
// Payload Type - default is 0
|
||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||
// Payload
|
||||
assertThat(cursor.getBlob(20)).isNull();
|
||||
byte[] payload = cursor.getBlob(20);
|
||||
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||
ResultPayload.CREATOR);
|
||||
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -59,6 +59,7 @@ public class DatabaseResultLoaderTest {
|
||||
private SiteMapManager mSiteMapManager;
|
||||
private Context mContext;
|
||||
private DatabaseResultLoader loader;
|
||||
private ResultPayload mResultPayload;
|
||||
|
||||
private final String titleOne = "titleOne";
|
||||
private final String titleTwo = "titleTwo";
|
||||
@@ -74,6 +75,7 @@ public class DatabaseResultLoaderTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mResultPayload = new ResultPayload(new Intent());
|
||||
FakeFeatureFactory.setupForTest(mMockContext);
|
||||
FakeFeatureFactory factory =
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
|
||||
@@ -215,12 +217,11 @@ public class DatabaseResultLoaderTest {
|
||||
public void testDeDupe_noDuplicates_originalListReturn() {
|
||||
// Three elements with unique titles and summaries
|
||||
List<SearchResult> results = new ArrayList();
|
||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
||||
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
builder.addTitle(titleOne)
|
||||
.addSummary(summaryOne)
|
||||
.addPayload(intentPayload);
|
||||
.addPayload(mResultPayload);
|
||||
SearchResult resultOne = builder.build();
|
||||
results.add(resultOne);
|
||||
|
||||
@@ -245,13 +246,12 @@ public class DatabaseResultLoaderTest {
|
||||
@Test
|
||||
public void testDeDupe_oneDuplicate_duplicateRemoved() {
|
||||
List<SearchResult> results = new ArrayList();
|
||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
||||
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
builder.addTitle(titleOne)
|
||||
.addSummary(summaryOne)
|
||||
.addRank(0)
|
||||
.addPayload(intentPayload);
|
||||
.addPayload(mResultPayload);
|
||||
SearchResult resultOne = builder.build();
|
||||
results.add(resultOne);
|
||||
|
||||
@@ -278,9 +278,7 @@ public class DatabaseResultLoaderTest {
|
||||
@Test
|
||||
public void testDeDupe_firstDupeInline_secondDuplicateRemoved() {
|
||||
List<SearchResult> results = new ArrayList();
|
||||
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0,
|
||||
null);
|
||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
||||
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0, null, null);
|
||||
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
// Inline result
|
||||
@@ -295,7 +293,7 @@ public class DatabaseResultLoaderTest {
|
||||
builder.addTitle(titleOne)
|
||||
.addSummary(summaryOne)
|
||||
.addRank(1)
|
||||
.addPayload(intentPayload);
|
||||
.addPayload(mResultPayload);
|
||||
SearchResult resultTwo = builder.build();
|
||||
results.add(resultTwo);
|
||||
|
||||
@@ -329,23 +327,20 @@ public class DatabaseResultLoaderTest {
|
||||
* (1) Intent One
|
||||
*/
|
||||
List<SearchResult> results = new ArrayList();
|
||||
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0,
|
||||
null);
|
||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
||||
|
||||
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0, null, null);
|
||||
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
// Intent One
|
||||
builder.addTitle(titleOne)
|
||||
.addSummary(summaryOne)
|
||||
.addPayload(intentPayload);
|
||||
.addPayload(mResultPayload);
|
||||
SearchResult resultOne = builder.build();
|
||||
results.add(resultOne);
|
||||
|
||||
// Intent Two
|
||||
builder.addTitle(titleTwo)
|
||||
.addSummary(summaryTwo)
|
||||
.addPayload(intentPayload);
|
||||
.addPayload(mResultPayload);
|
||||
SearchResult resultTwo = builder.build();
|
||||
results.add(resultTwo);
|
||||
|
||||
@@ -365,7 +360,7 @@ public class DatabaseResultLoaderTest {
|
||||
// Intent Four
|
||||
builder.addTitle(titleFour)
|
||||
.addSummary(summaryOne)
|
||||
.addPayload(intentPayload);
|
||||
.addPayload(mResultPayload);
|
||||
SearchResult resultFive = builder.build();
|
||||
results.add(resultFive);
|
||||
|
||||
@@ -395,6 +390,7 @@ public class DatabaseResultLoaderTest {
|
||||
private void insertSpecialCase(String specialCase) {
|
||||
String normalized = DatabaseIndexingUtils.normalizeHyphen(specialCase);
|
||||
normalized = DatabaseIndexingUtils.normalizeString(normalized);
|
||||
final ResultPayload payload = new ResultPayload(new Intent());
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, normalized.hashCode());
|
||||
@@ -419,12 +415,14 @@ public class DatabaseResultLoaderTest {
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, ResultPayloadUtils.marshall(payload));
|
||||
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
}
|
||||
|
||||
private void setUpDb() {
|
||||
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(new Intent()));
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
||||
@@ -448,7 +446,7 @@ public class DatabaseResultLoaderTest {
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
|
||||
@@ -475,7 +473,7 @@ public class DatabaseResultLoaderTest {
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
|
||||
values = new ContentValues();
|
||||
@@ -501,7 +499,7 @@ public class DatabaseResultLoaderTest {
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
* Copyright (C) 2017 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.
|
||||
@@ -10,32 +10,37 @@
|
||||
* 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 static for the specific language governing permissions and
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow;
|
||||
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow.Builder;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.ResultPayload;
|
||||
import com.android.settings.search2.ResultPayloadUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.Result;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DatabaseRowTest {
|
||||
private Builder builder;
|
||||
private Builder mBuilder;
|
||||
|
||||
private static final String LOCALE = "locale";
|
||||
private static final String UPDATED_TITLE = "updated title";
|
||||
@@ -46,7 +51,7 @@ public class DatabaseRowTest {
|
||||
private static final String NORMALIZED_SUMMARY_OFF = "normalized summary off";
|
||||
private static final String ENTRIES = "entries";
|
||||
private static final String CLASS_NAME = "class name";
|
||||
private static final String SCREEN_TITLE = "sceen title";
|
||||
private static final String SCREEN_TITLE = "screen title";
|
||||
private static final int ICON_RES_ID = 0xff;
|
||||
private static final int RANK = 1;
|
||||
private static final String SPACE_DELIMITED_KEYWORDS = "keywords";
|
||||
@@ -56,28 +61,23 @@ public class DatabaseRowTest {
|
||||
private static final boolean ENABLED = true;
|
||||
private static final String KEY = "key";
|
||||
private static final int USER_ID = 1;
|
||||
private static IntentPayload intentPayload;
|
||||
|
||||
private final String EXTRA_KEY = "key";
|
||||
private final String EXTRA_VALUE = "value";
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
||||
intentPayload = new IntentPayload(intent);
|
||||
|
||||
builder = new DatabaseRow.Builder();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mBuilder = createBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullRowBuild_NonNull() {
|
||||
public void testFullRowBuild_nonNull() {
|
||||
DatabaseRow row = generateRow();
|
||||
assertThat(row).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimativesBuild_NoDataLoss() {
|
||||
public void testPrimitivesBuild_noDataLoss() {
|
||||
DatabaseRow row = generateRow();
|
||||
|
||||
assertThat(row.locale).isEqualTo(LOCALE);
|
||||
@@ -100,30 +100,61 @@ public class DatabaseRowTest {
|
||||
assertThat(row.userId).isEqualTo(USER_ID);
|
||||
assertThat(row.key).isEqualTo(KEY);
|
||||
assertThat(row.payloadType).isEqualTo(ResultPayload.PayloadType.INTENT);
|
||||
assertThat(row.payload).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayload_PayloadTypeAdded() {
|
||||
DatabaseRow row = generateRow();
|
||||
byte[] marshalledPayload = row.payload;
|
||||
IntentPayload payload = ResultPayloadUtils.unmarshall(marshalledPayload,
|
||||
IntentPayload.CREATOR);
|
||||
|
||||
Intent intent = payload.intent;
|
||||
assertThat(intent.getExtra(EXTRA_KEY)).isEqualTo(EXTRA_VALUE);
|
||||
public void testGenericIntent_addedToPayload() {
|
||||
final DatabaseRow row = generateRow();
|
||||
final ResultPayload payload = ResultPayloadUtils.unmarshall(row.payload,
|
||||
ResultPayload.CREATOR);
|
||||
final ComponentName name = payload.getIntent().getComponent();
|
||||
assertThat(name.getClassName()).isEqualTo(INTENT_TARGET_CLASS);
|
||||
assertThat(name.getPackageName()).isEqualTo(INTENT_TARGET_PACKAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestNullPayload_NoCrash() {
|
||||
Builder builder = new Builder();
|
||||
builder.setPayload(null);
|
||||
DatabaseRow row = builder.build();
|
||||
public void testRowWithInlinePayload_genericPayloadNotAdded() {
|
||||
final String URI = "test uri";
|
||||
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0,
|
||||
new HashMap<Integer, Boolean>(), null);
|
||||
mBuilder.setPayload(payload);
|
||||
final DatabaseRow row = generateRow();
|
||||
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
||||
.unmarshall(row.payload, InlineSwitchPayload.CREATOR);
|
||||
|
||||
assertThat(row.payload).isNull();
|
||||
assertThat(row.payloadType).isEqualTo(ResultPayload.PayloadType.INLINE_SWITCH);
|
||||
assertThat(unmarshalledPayload.settingsUri).isEqualTo(URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRowWithInlinePayload_intentAddedToInlinePayload() {
|
||||
final String URI = "test uri";
|
||||
final ComponentName component = new ComponentName(INTENT_TARGET_PACKAGE,
|
||||
INTENT_TARGET_CLASS);
|
||||
final Intent intent = new Intent();
|
||||
intent.setComponent(component);
|
||||
|
||||
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0,
|
||||
new HashMap<Integer, Boolean>(), intent);
|
||||
mBuilder.setPayload(payload);
|
||||
final DatabaseRow row = generateRow();
|
||||
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
||||
.unmarshall(row.payload, InlineSwitchPayload.CREATOR);
|
||||
final ComponentName name = unmarshalledPayload.getIntent().getComponent();
|
||||
|
||||
assertThat(name.getClassName()).isEqualTo(INTENT_TARGET_CLASS);
|
||||
assertThat(name.getPackageName()).isEqualTo(INTENT_TARGET_PACKAGE);
|
||||
}
|
||||
|
||||
|
||||
private DatabaseRow generateRow() {
|
||||
builder.setLocale(LOCALE)
|
||||
return mBuilder.build(mContext);
|
||||
}
|
||||
|
||||
private DatabaseRow.Builder createBuilder() {
|
||||
mBuilder = new DatabaseRow.Builder();
|
||||
mBuilder.setLocale(LOCALE)
|
||||
.setUpdatedTitle(UPDATED_TITLE)
|
||||
.setNormalizedTitle(NORMALIZED_TITLE)
|
||||
.setUpdatedSummaryOn(UPDATED_SUMMARY_ON)
|
||||
@@ -141,10 +172,7 @@ public class DatabaseRowTest {
|
||||
.setIntentTargetClass(INTENT_TARGET_CLASS)
|
||||
.setEnabled(ENABLED)
|
||||
.setKey(KEY)
|
||||
.setUserId(USER_ID)
|
||||
.setPayload(intentPayload);
|
||||
|
||||
return(builder.build());
|
||||
.setUserId(USER_ID);
|
||||
return mBuilder;
|
||||
}
|
||||
}
|
||||
;
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
* Copyright (C) 2017 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.
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -29,10 +29,6 @@ import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.IntentSearchViewHolder;
|
||||
import com.android.settings.search2.SearchFragment;
|
||||
import com.android.settings.search2.SearchResult;
|
||||
import com.android.settings.search2.SearchResult.Builder;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
@@ -105,7 +101,7 @@ public class IntentSearchViewHolderTest {
|
||||
verify(mFragment).startActivity(any(Intent.class));
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_RESULT),
|
||||
eq(((IntentPayload)result.payload).intent.getComponent().flattenToString()),
|
||||
eq(((ResultPayload)result.payload).getIntent().getComponent().flattenToString()),
|
||||
any(Pair.class));
|
||||
}
|
||||
|
||||
@@ -113,7 +109,7 @@ public class IntentSearchViewHolderTest {
|
||||
public void testBindViewElements_emptySummary_hideSummaryView() {
|
||||
final SearchResult result = new Builder().addTitle(TITLE)
|
||||
.addRank(1)
|
||||
.addPayload(new IntentPayload(null))
|
||||
.addPayload(new ResultPayload(null))
|
||||
.addIcon(mIcon)
|
||||
.build();
|
||||
|
||||
@@ -129,7 +125,7 @@ public class IntentSearchViewHolderTest {
|
||||
breadcrumbs.add("c");
|
||||
final SearchResult result = new Builder().addTitle(TITLE)
|
||||
.addRank(1)
|
||||
.addPayload(new IntentPayload(null))
|
||||
.addPayload(new ResultPayload(null))
|
||||
.addBreadcrumbs(breadcrumbs)
|
||||
.addIcon(mIcon)
|
||||
.build();
|
||||
@@ -144,7 +140,7 @@ public class IntentSearchViewHolderTest {
|
||||
builder.addTitle(TITLE)
|
||||
.addSummary(SUMMARY)
|
||||
.addRank(1)
|
||||
.addPayload(new IntentPayload(
|
||||
.addPayload(new ResultPayload(
|
||||
new Intent().setComponent(new ComponentName("pkg", "class"))))
|
||||
.addBreadcrumbs(new ArrayList<>())
|
||||
.addIcon(mIcon);
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
* Copyright (C) 2017 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.
|
||||
@@ -15,13 +15,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -31,8 +30,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class IntentPayloadTest {
|
||||
private IntentPayload mPayload;
|
||||
public class ResultPayloadTest {
|
||||
private ResultPayload mPayload;
|
||||
|
||||
private final String EXTRA_KEY = "key";
|
||||
private final String EXTRA_VALUE = "value";
|
||||
@@ -43,14 +42,14 @@ public class IntentPayloadTest {
|
||||
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
mPayload = new IntentPayload(intent);
|
||||
mPayload = new ResultPayload(intent);
|
||||
mPayload.writeToParcel(parcel, 0);
|
||||
// Reset parcel for reading
|
||||
parcel.setDataPosition(0);
|
||||
IntentPayload newPayload = IntentPayload.CREATOR.createFromParcel(parcel);
|
||||
ResultPayload newPayload = ResultPayload.CREATOR.createFromParcel(parcel);
|
||||
|
||||
String originalIntentExtra = mPayload.intent.getStringExtra(EXTRA_KEY);
|
||||
String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
|
||||
String originalIntentExtra = mPayload.getIntent().getStringExtra(EXTRA_KEY);
|
||||
String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
|
||||
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
* Copyright (C) 2017 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.
|
||||
@@ -15,28 +15,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.BadParcelableException;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.ResultPayloadUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.StreamCorruptedException;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ResultPayloadUtilsTest {
|
||||
private IntentPayload payload;
|
||||
private ResultPayload payload;
|
||||
|
||||
private final String EXTRA_KEY = "key";
|
||||
private final String EXTRA_VALUE = "value";
|
||||
@@ -45,14 +40,14 @@ public class ResultPayloadUtilsTest {
|
||||
public void setUp() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
||||
payload = new IntentPayload(intent);
|
||||
payload = new ResultPayload(intent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshallBadData_ExceptionThrown() {
|
||||
byte[] badData = "I'm going to fail :)".getBytes();
|
||||
try {
|
||||
ResultPayloadUtils.unmarshall(badData, IntentPayload.CREATOR);
|
||||
ResultPayloadUtils.unmarshall(badData, ResultPayload.CREATOR);
|
||||
fail("unmarshall should throw exception");
|
||||
} catch ( RuntimeException e) {
|
||||
assertThat(e).isNotNull();
|
||||
@@ -60,7 +55,7 @@ public class ResultPayloadUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarshallIntentPayload_NonEmptyArray() {
|
||||
public void testMarshallResultPayload_NonEmptyArray() {
|
||||
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
|
||||
assertThat(marshalledPayload).isNotNull();
|
||||
assertThat(marshalledPayload).isNotEmpty();
|
||||
@@ -69,11 +64,11 @@ public class ResultPayloadUtilsTest {
|
||||
@Test
|
||||
public void testUnmarshall_PreservedData() {
|
||||
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
|
||||
IntentPayload newPayload = ResultPayloadUtils.unmarshall(marshalledPayload,
|
||||
IntentPayload.CREATOR);
|
||||
ResultPayload newPayload = ResultPayloadUtils.unmarshall(marshalledPayload,
|
||||
ResultPayload.CREATOR);
|
||||
|
||||
String originalIntentExtra = payload.intent.getStringExtra(EXTRA_KEY);
|
||||
String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
|
||||
String originalIntentExtra = payload.getIntent().getStringExtra(EXTRA_KEY);
|
||||
String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
|
||||
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
|
||||
}
|
||||
|
Reference in New Issue
Block a user