Home | History | Annotate | Download | only in naughty
      1 /*
      2  * Copyright (C) 2010 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.quicksearchbox.tests.naughty;
     18 
     19 import android.app.SearchManager;
     20 import android.content.Intent;
     21 import android.database.Cursor;
     22 import android.database.MatrixCursor;
     23 import android.net.Uri;
     24 import android.util.Log;
     25 
     26 import java.util.List;
     27 
     28 public class HangingSuggestionProvider extends NaughtySuggestionProvider {
     29 
     30     private static final String TAG = HangingSuggestionProvider.class.getSimpleName();
     31 
     32     private static final String[] COLUMNS = {
     33         "_id",
     34         SearchManager.SUGGEST_COLUMN_TEXT_1,
     35         SearchManager.SUGGEST_COLUMN_ICON_1,
     36         SearchManager.SUGGEST_COLUMN_TEXT_2,
     37         SearchManager.SUGGEST_COLUMN_ICON_2,
     38         SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
     39         SearchManager.SUGGEST_COLUMN_INTENT_DATA,
     40     };
     41 
     42     @Override
     43     public Cursor query(Uri uri, String[] projectionIn, String selection,
     44             String[] selectionArgs, String sortOrder) {
     45         Log.d(TAG, "query(" + uri + ")");
     46 
     47         List<String> path = uri.getPathSegments();
     48         String query = null;
     49         if (path.size() > 0) {
     50             query = path.get(path.size()-1);
     51         }
     52 
     53         if ("hang".equals(query)) {
     54             beNaughty();
     55             return null;
     56         } else {
     57             MatrixCursor cursor = new MatrixCursor(COLUMNS);
     58             if ("icon".equals(query)) {
     59 
     60                 for (int i = 0; i < 100; i++) {
     61                     cursor.addRow(new Object[]{
     62                         i,
     63                         "Naughty suggestion " + i,
     64                         "content://com.android.quicksearchbox.tests.naughty.hanging/naughty/icon/" + i,
     65                         "Hanging icon 1",
     66                         null,
     67                         Intent.ACTION_VIEW,
     68                         "content://com.android.quicksearchbox.tests.naughty.hanging/naughty/" + i
     69                     });
     70                 }
     71             } else if ("icon2".equals(query)) {
     72 
     73                 for (int i = 0; i < 100; i++) {
     74                     cursor.addRow(new Object[]{
     75                         i,
     76                         "Naughty suggestion " + i,
     77                         R.drawable.hang,
     78                         "Hanging icon 2",
     79                         "content://com.android.quicksearchbox.tests.naughty.hanging/icon2/" + i,
     80                         Intent.ACTION_VIEW,
     81                         "content://com.android.quicksearchbox.naughty.crashing/" + i
     82                     });
     83                 }
     84             } else {
     85                 cursor.addRow(new Object[]{
     86                     0,
     87                     "Enter 'hang' or 'icon'",
     88                     R.drawable.hang,
     89                     "To make me hang",
     90                     null,
     91                     Intent.ACTION_VIEW,
     92                     "content://com.android.quicksearchbox.tests.naughty.hanging/naughty/0"
     93                 });
     94             }
     95             return cursor;
     96         }
     97     }
     98 
     99     @Override
    100     protected void beNaughty() {
    101         try {
    102             Object o = new Object();
    103             synchronized(o) {
    104                 o.wait();
    105             }
    106         } catch (InterruptedException e) {
    107         }
    108     }
    109 
    110 }
    111