1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.globalsearch; 18 19 import java.util.ArrayList; 20 21 import android.app.SearchManager; 22 import android.content.ComponentName; 23 import android.content.ContentProvider; 24 import android.content.ContentValues; 25 import android.database.Cursor; 26 import android.net.Uri; 27 28 /** 29 * A write only content provider made availalbe to SearchDialog to report click when a user searches 30 * in global search, pivots into an app, and clicks on a result. 31 */ 32 public class StatsProvider extends ContentProvider { 33 private ShortcutRepository mShortcutRepo; 34 35 @Override onCreate()36 public boolean onCreate() { 37 mShortcutRepo = ShortcutRepositoryImplLog.create(getContext()); 38 return true; 39 } 40 41 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)42 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { 43 throw new UnsupportedOperationException(); 44 } 45 46 @Override getType(Uri uri)47 public String getType(Uri uri) { 48 return null; 49 } 50 51 @Override insert(Uri uri, ContentValues values)52 public Uri insert(Uri uri, ContentValues values) { 53 ComponentName name = ComponentName.unflattenFromString(values.getAsString( 54 SearchManager.SEARCH_CLICK_REPORT_COLUMN_COMPONENT)); 55 String query = values.getAsString(SearchManager.SEARCH_CLICK_REPORT_COLUMN_QUERY); 56 57 // Don't shortcut if this is not a promoted source. 58 boolean promotedSource = false; 59 ArrayList<ComponentName> sourceRanking = mShortcutRepo.getSourceRanking(); 60 for (int i = 0; i < SuggestionSession.NUM_PROMOTED_SOURCES && i < sourceRanking.size(); 61 i++) { 62 if (name.equals(sourceRanking.get(i))) { 63 promotedSource = true; 64 } 65 } 66 if (!promotedSource) return null; 67 68 final SuggestionData suggestionData = new SuggestionData.Builder(name) 69 .format(values.getAsString(SearchManager.SUGGEST_COLUMN_FORMAT)) 70 .title(values.getAsString(SearchManager.SUGGEST_COLUMN_TEXT_1)) 71 .description(values.getAsString(SearchManager.SUGGEST_COLUMN_TEXT_2)) 72 .icon1(values.getAsString(SearchManager.SUGGEST_COLUMN_ICON_1)) 73 .icon2(values.getAsString(SearchManager.SUGGEST_COLUMN_ICON_2)) 74 .intentQuery(values.getAsString(SearchManager.SUGGEST_COLUMN_QUERY)) 75 .intentAction(values.getAsString(SearchManager.SUGGEST_COLUMN_INTENT_ACTION)) 76 .intentData(values.getAsString(SearchManager.SUGGEST_COLUMN_INTENT_DATA)) 77 .intentExtraData(values.getAsString(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA)) 78 .intentComponentName( 79 values.getAsString(SearchManager.SUGGEST_COLUMN_INTENT_COMPONENT_NAME)) 80 .shortcutId(values.getAsString(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID)) 81 // note: deliberately omitting background color since it is only for global search 82 // "more results" entries 83 .build(); 84 85 mShortcutRepo.reportStats(new SessionStats(query, suggestionData)); 86 return null; 87 } 88 89 @Override delete(Uri uri, String selection, String[] selectionArgs)90 public int delete(Uri uri, String selection, String[] selectionArgs) { 91 throw new UnsupportedOperationException(); 92 } 93 94 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)95 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 96 throw new UnsupportedOperationException(); 97 } 98 } 99