Added getSearchUri() to InstalledAppProvider

This allows for searching installed app names for ones which match
a string.  It searches based on the "label" as declared in the
manifest in the <application> tag as "android:label".
This commit is contained in:
Peter Serwylo 2014-05-08 06:46:50 +09:30 committed by Hans-Christoph Steiner
parent 60f5a1441c
commit 5e02404d6a

View File

@ -64,10 +64,14 @@ public class InstalledAppProvider extends FDroidProvider {
private static final String PROVIDER_NAME = "InstalledAppProvider"; private static final String PROVIDER_NAME = "InstalledAppProvider";
private static final String PATH_SEARCH = "search";
private static final int CODE_SEARCH = CODE_SINGLE + 1;
private static final UriMatcher matcher = new UriMatcher(-1); private static final UriMatcher matcher = new UriMatcher(-1);
static { static {
matcher.addURI(getAuthority(), null, CODE_LIST); matcher.addURI(getAuthority(), null, CODE_LIST);
matcher.addURI(getAuthority(), PATH_SEARCH + "/*", CODE_SEARCH);
matcher.addURI(getAuthority(), "*", CODE_SINGLE); matcher.addURI(getAuthority(), "*", CODE_SINGLE);
} }
@ -79,6 +83,13 @@ public class InstalledAppProvider extends FDroidProvider {
return Uri.withAppendedPath(getContentUri(), appId); return Uri.withAppendedPath(getContentUri(), appId);
} }
public static Uri getSearchUri(String keywords) {
return getContentUri().buildUpon()
.appendPath(PATH_SEARCH)
.appendPath(keywords)
.build();
}
public static String getApplicationLabel(Context context, String packageName) { public static String getApplicationLabel(Context context, String packageName) {
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo; ApplicationInfo appInfo;
@ -116,6 +127,10 @@ public class InstalledAppProvider extends FDroidProvider {
return new QuerySelection("appId = ?", new String[] { appId } ); return new QuerySelection("appId = ?", new String[] { appId } );
} }
private QuerySelection querySearch(String keywords) {
return new QuerySelection("applicationLabel LIKE ?", new String[] { "%" + keywords + "%" } );
}
@Override @Override
public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) { public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) {
if (sortOrder == null) { if (sortOrder == null) {
@ -131,6 +146,10 @@ public class InstalledAppProvider extends FDroidProvider {
selection = selection.add(queryApp(uri.getLastPathSegment())); selection = selection.add(queryApp(uri.getLastPathSegment()));
break; break;
case CODE_SEARCH:
selection = selection.add(querySearch(uri.getLastPathSegment()));
break;
default: default:
String message = "Invalid URI for installed app content provider: " + uri; String message = "Invalid URI for installed app content provider: " + uri;
Log.e("FDroid", message); Log.e("FDroid", message);