Fix installed app search query.

Now it shows system apps when user query match name.

Change-Id: Ic4d622d2d4872554172e34aa9be250b36a3c3da3
Fix: 34257148
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-01-20 14:12:44 -08:00
parent e44be9f729
commit ba83109807
2 changed files with 75 additions and 1 deletions

View File

@@ -17,6 +17,8 @@
package com.android.settings.search2;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.os.UserManager;
@@ -38,8 +40,11 @@ import java.util.Arrays;
import java.util.List;
import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
import static android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -94,6 +99,55 @@ public class InstalledAppResultLoaderTest {
assertThat(mLoader.loadInBackground().size()).isEqualTo(2);
}
@Test
public void query_matchingQuery_shouldReturnSystemAppUpdates() {
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
.thenReturn(Arrays.asList(
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_UPDATED_SYSTEM_APP,
0 /* targetSdkVersion */)));
final String query = "app";
mLoader = new InstalledAppResultLoader(mContext, mPackageManagerWrapper, query);
assertThat(mLoader.loadInBackground().size()).isEqualTo(1);
}
@Test
public void query_matchingQuery_shouldReturnSystemAppIfLaunchable() {
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
.thenReturn(Arrays.asList(
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_SYSTEM,
0 /* targetSdkVersion */)));
final List<ResolveInfo> list = mock(List.class);
when(list.size()).thenReturn(1);
when(mPackageManagerWrapper.queryIntentActivitiesAsUser(
any(Intent.class), anyInt(), anyInt()))
.thenReturn(list);
final String query = "app";
mLoader = new InstalledAppResultLoader(mContext, mPackageManagerWrapper, query);
assertThat(mLoader.loadInBackground().size()).isEqualTo(1);
}
@Test
public void query_matchingQuery_shouldNOtReturnSystemAppIfNotLaunchable() {
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
.thenReturn(Arrays.asList(
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_SYSTEM,
0 /* targetSdkVersion */)));
when(mPackageManagerWrapper.queryIntentActivitiesAsUser(
any(Intent.class), anyInt(), anyInt()))
.thenReturn(null);
final String query = "app";
mLoader = new InstalledAppResultLoader(mContext, mPackageManagerWrapper, query);
assertThat(mLoader.loadInBackground()).isEmpty();
}
@Test
public void query_matchingQuery_shouldRankBasedOnSimilarity() {
final String query = "app";