aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/search/LocalSearchProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/tv/search/LocalSearchProvider.java')
-rw-r--r--src/com/android/tv/search/LocalSearchProvider.java224
1 files changed, 147 insertions, 77 deletions
diff --git a/src/com/android/tv/search/LocalSearchProvider.java b/src/com/android/tv/search/LocalSearchProvider.java
index ef9336d7..97e7f229 100644
--- a/src/com/android/tv/search/LocalSearchProvider.java
+++ b/src/com/android/tv/search/LocalSearchProvider.java
@@ -24,19 +24,19 @@ import android.database.MatrixCursor;
import android.net.Uri;
import android.os.SystemClock;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;
-
-import com.android.tv.TvApplication;
+import com.android.tv.TvSingletons;
+import com.android.tv.common.CommonConstants;
import com.android.tv.common.SoftPreconditions;
-import com.android.tv.common.TvCommonUtils;
+import com.android.tv.common.util.CommonUtils;
+import com.android.tv.common.util.PermissionUtils;
import com.android.tv.perf.EventNames;
import com.android.tv.perf.PerformanceMonitor;
import com.android.tv.perf.TimerEvent;
-import com.android.tv.util.PermissionUtils;
import com.android.tv.util.TvUriMatcher;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -46,32 +46,34 @@ public class LocalSearchProvider extends ContentProvider {
private static final boolean DEBUG = false;
/** The authority for LocalSearchProvider. */
- public static final String AUTHORITY = "com.android.tv.search";
+ public static final String AUTHORITY = CommonConstants.BASE_PACKAGE + ".search";
public static final int PROGRESS_PERCENTAGE_HIDE = -1;
// TODO: Remove this once added to the SearchManager.
private static final String SUGGEST_COLUMN_PROGRESS_BAR_PERCENTAGE = "progress_bar_percentage";
- private static final String[] SEARCHABLE_COLUMNS = new String[] {
- SearchManager.SUGGEST_COLUMN_TEXT_1,
- SearchManager.SUGGEST_COLUMN_TEXT_2,
- SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE,
- SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
- SearchManager.SUGGEST_COLUMN_INTENT_DATA,
- SearchManager.SUGGEST_COLUMN_CONTENT_TYPE,
- SearchManager.SUGGEST_COLUMN_IS_LIVE,
- SearchManager.SUGGEST_COLUMN_VIDEO_WIDTH,
- SearchManager.SUGGEST_COLUMN_VIDEO_HEIGHT,
- SearchManager.SUGGEST_COLUMN_DURATION,
- SUGGEST_COLUMN_PROGRESS_BAR_PERCENTAGE
- };
+ private static final String[] SEARCHABLE_COLUMNS =
+ new String[] {
+ SearchManager.SUGGEST_COLUMN_TEXT_1,
+ SearchManager.SUGGEST_COLUMN_TEXT_2,
+ SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE,
+ SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
+ SearchManager.SUGGEST_COLUMN_INTENT_DATA,
+ SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA,
+ SearchManager.SUGGEST_COLUMN_CONTENT_TYPE,
+ SearchManager.SUGGEST_COLUMN_IS_LIVE,
+ SearchManager.SUGGEST_COLUMN_VIDEO_WIDTH,
+ SearchManager.SUGGEST_COLUMN_VIDEO_HEIGHT,
+ SearchManager.SUGGEST_COLUMN_DURATION,
+ SUGGEST_COLUMN_PROGRESS_BAR_PERCENTAGE
+ };
private static final String EXPECTED_PATH_PREFIX = "/" + SearchManager.SUGGEST_URI_PATH_QUERY;
static final String SUGGEST_PARAMETER_ACTION = "action";
// The launcher passes 10 as a 'limit' parameter by default.
- @VisibleForTesting
- static final int DEFAULT_SEARCH_LIMIT = 10;
+ @VisibleForTesting static final int DEFAULT_SEARCH_LIMIT = 10;
+
@VisibleForTesting
static final int DEFAULT_SEARCH_ACTION = SearchInterface.ACTION_TYPE_AMBIGUOUS;
@@ -85,26 +87,41 @@ public class LocalSearchProvider extends ContentProvider {
@Override
public boolean onCreate() {
- mPerformanceMonitor = TvApplication.getSingletons(getContext()).getPerformanceMonitor();
+ mPerformanceMonitor = TvSingletons.getSingletons(getContext()).getPerformanceMonitor();
return true;
}
@VisibleForTesting
void setSearchInterface(SearchInterface searchInterface) {
- SoftPreconditions.checkState(TvCommonUtils.isRunningInTest());
+ SoftPreconditions.checkState(CommonUtils.isRunningInTest());
mSearchInterface = searchInterface;
}
@Override
- public Cursor query(@NonNull Uri uri, String[] projection, String selection,
- String[] selectionArgs, String sortOrder) {
+ public Cursor query(
+ @NonNull Uri uri,
+ String[] projection,
+ String selection,
+ String[] selectionArgs,
+ String sortOrder) {
if (TvUriMatcher.match(uri) != TvUriMatcher.MATCH_ON_DEVICE_SEARCH) {
throw new IllegalArgumentException("Unknown URI: " + uri);
}
TimerEvent queryTimer = mPerformanceMonitor.startTimer();
if (DEBUG) {
- Log.d(TAG, "query(" + uri + ", " + Arrays.toString(projection) + ", " + selection + ", "
- + Arrays.toString(selectionArgs) + ", " + sortOrder + ")");
+ Log.d(
+ TAG,
+ "query("
+ + uri
+ + ", "
+ + Arrays.toString(projection)
+ + ", "
+ + selection
+ + ", "
+ + Arrays.toString(selectionArgs)
+ + ", "
+ + sortOrder
+ + ")");
}
long time = SystemClock.elapsedRealtime();
SearchInterface search = mSearchInterface;
@@ -118,8 +135,8 @@ public class LocalSearchProvider extends ContentProvider {
}
}
String query = uri.getLastPathSegment();
- int limit = getQueryParamater(uri, SearchManager.SUGGEST_PARAMETER_LIMIT,
- DEFAULT_SEARCH_LIMIT);
+ int limit =
+ getQueryParamater(uri, SearchManager.SUGGEST_PARAMETER_LIMIT, DEFAULT_SEARCH_LIMIT);
if (limit <= 0) {
limit = DEFAULT_SEARCH_LIMIT;
}
@@ -134,8 +151,13 @@ public class LocalSearchProvider extends ContentProvider {
}
Cursor c = createSuggestionsCursor(results);
if (DEBUG) {
- Log.d(TAG, "Elapsed time(count=" + c.getCount() + "): "
- + (SystemClock.elapsedRealtime() - time) + "(msec)");
+ Log.d(
+ TAG,
+ "Elapsed time(count="
+ + c.getCount()
+ + "): "
+ + (SystemClock.elapsedRealtime() - time)
+ + "(msec)");
}
mPerformanceMonitor.stopTimer(queryTimer, EventNames.ON_DEVICE_SEARCH);
return c;
@@ -157,17 +179,18 @@ public class LocalSearchProvider extends ContentProvider {
int index = 0;
for (SearchResult result : results) {
row.clear();
- row.add(result.title);
- row.add(result.description);
- row.add(result.imageUri);
- row.add(result.intentAction);
- row.add(result.intentData);
- row.add(result.contentType);
- row.add(result.isLive ? LIVE_CONTENTS : NO_LIVE_CONTENTS);
- row.add(result.videoWidth == 0 ? null : String.valueOf(result.videoWidth));
- row.add(result.videoHeight == 0 ? null : String.valueOf(result.videoHeight));
- row.add(result.duration == 0 ? null : String.valueOf(result.duration));
- row.add(String.valueOf(result.progressPercentage));
+ row.add(result.getTitle());
+ row.add(result.getDescription());
+ row.add(result.getImageUri());
+ row.add(result.getIntentAction());
+ row.add(result.getIntentData());
+ row.add(result.getIntentExtraData());
+ row.add(result.getContentType());
+ row.add(result.getIsLive() ? LIVE_CONTENTS : NO_LIVE_CONTENTS);
+ row.add(result.getVideoWidth() == 0 ? null : String.valueOf(result.getVideoWidth()));
+ row.add(result.getVideoHeight() == 0 ? null : String.valueOf(result.getVideoHeight()));
+ row.add(result.getDuration() == 0 ? null : String.valueOf(result.getDuration()));
+ row.add(String.valueOf(result.getProgressPercentage()));
cursor.addRow(row);
if (DEBUG) Log.d(TAG, "Result[" + (++index) + "]: " + result);
}
@@ -199,40 +222,87 @@ public class LocalSearchProvider extends ContentProvider {
throw new UnsupportedOperationException();
}
- /**
- * A placeholder to a search result.
- */
- public static class SearchResult {
- public long channelId;
- public String channelNumber;
- public String title;
- public String description;
- public String imageUri;
- public String intentAction;
- public String intentData;
- public String contentType;
- public boolean isLive;
- public int videoWidth;
- public int videoHeight;
- public long duration;
- public int progressPercentage;
-
- @Override
- public String toString() {
- return "SearchResult{channelId=" + channelId +
- ", channelNumber=" + channelNumber +
- ", title=" + title +
- ", description=" + description +
- ", imageUri=" + imageUri +
- ", intentAction=" + intentAction +
- ", intentData=" + intentData +
- ", contentType=" + contentType +
- ", isLive=" + isLive +
- ", videoWidth=" + videoWidth +
- ", videoHeight=" + videoHeight +
- ", duration=" + duration +
- ", progressPercentage=" + progressPercentage +
- "}";
+ /** A placeholder to a search result. */
+ // TODO(b/72052568): Get autovalue to work in aosp master
+ public abstract static class SearchResult {
+ public static Builder builder() {
+ // primitive fields cannot be nullable. Set to default;
+ return new AutoValue_LocalSearchProvider_SearchResult.Builder()
+ .setChannelId(0)
+ .setIsLive(false)
+ .setVideoWidth(0)
+ .setVideoHeight(0)
+ .setDuration(0)
+ .setProgressPercentage(0);
+ }
+
+ // TODO(b/72052568): Get autovalue to work in aosp master
+ abstract static class Builder {
+ abstract Builder setChannelId(long value);
+
+ abstract Builder setChannelNumber(String value);
+
+ abstract Builder setTitle(String value);
+
+ abstract Builder setDescription(String value);
+
+ abstract Builder setImageUri(String value);
+
+ abstract Builder setIntentAction(String value);
+
+ abstract Builder setIntentData(String value);
+
+ abstract Builder setIntentExtraData(String value);
+
+ abstract Builder setContentType(String value);
+
+ abstract Builder setIsLive(boolean value);
+
+ abstract Builder setVideoWidth(int value);
+
+ abstract Builder setVideoHeight(int value);
+
+ abstract Builder setDuration(long value);
+
+ abstract Builder setProgressPercentage(int value);
+
+ abstract SearchResult build();
}
+
+ abstract long getChannelId();
+
+ @Nullable
+ abstract String getChannelNumber();
+
+ @Nullable
+ abstract String getTitle();
+
+ @Nullable
+ abstract String getDescription();
+
+ @Nullable
+ abstract String getImageUri();
+
+ @Nullable
+ abstract String getIntentAction();
+
+ @Nullable
+ abstract String getIntentData();
+
+ @Nullable
+ abstract String getIntentExtraData();
+
+ @Nullable
+ abstract String getContentType();
+
+ abstract boolean getIsLive();
+
+ abstract int getVideoWidth();
+
+ abstract int getVideoHeight();
+
+ abstract long getDuration();
+
+ abstract int getProgressPercentage();
}
-} \ No newline at end of file
+}