Merge "Create an #isAppInstalled() util method" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b8b3d5e1ef
@@ -286,6 +286,19 @@ public class AppUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a boolean indicating whether this app is installed or not.
|
||||||
|
*
|
||||||
|
* @param appEntry AppEntry of ApplicationsState.
|
||||||
|
* @return true if the app is in installed state.
|
||||||
|
*/
|
||||||
|
public static boolean isAppInstalled(ApplicationsState.AppEntry appEntry) {
|
||||||
|
if (appEntry == null || appEntry.info == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (appEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static void setAppEntryMounted(ApplicationsState.AppEntry appEntry, boolean mounted) {
|
private static void setAppEntryMounted(ApplicationsState.AppEntry appEntry, boolean mounted) {
|
||||||
if (appEntry.mounted != mounted) {
|
if (appEntry.mounted != mounted) {
|
||||||
synchronized (appEntry) {
|
synchronized (appEntry) {
|
||||||
|
|||||||
@@ -129,6 +129,28 @@ public class AppUtilsTest {
|
|||||||
assertThat(mAppIconCacheManager.get(APP_PACKAGE_NAME, APP_UID)).isNotNull();
|
assertThat(mAppIconCacheManager.get(APP_PACKAGE_NAME, APP_UID)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAppInstalled_noAppEntry_shouldReturnFalse() {
|
||||||
|
assertThat(AppUtils.isAppInstalled(null)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAppInstalled_hasAppEntryWithInstalledFlag_shouldReturnTrue() {
|
||||||
|
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||||
|
appEntry.info = new ApplicationInfo();
|
||||||
|
appEntry.info.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||||
|
|
||||||
|
assertThat(AppUtils.isAppInstalled(appEntry)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAppInstalled_hasAppEntryWithoutInstalledFlag_shouldReturnFalse() {
|
||||||
|
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||||
|
appEntry.info = new ApplicationInfo();
|
||||||
|
|
||||||
|
assertThat(AppUtils.isAppInstalled(appEntry)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
private ApplicationsState.AppEntry createAppEntry(ApplicationInfo appInfo, int id) {
|
private ApplicationsState.AppEntry createAppEntry(ApplicationInfo appInfo, int id) {
|
||||||
ApplicationsState.AppEntry appEntry = new ApplicationsState.AppEntry(mContext, appInfo, id);
|
ApplicationsState.AppEntry appEntry = new ApplicationsState.AppEntry(mContext, appInfo, id);
|
||||||
appEntry.label = "label";
|
appEntry.label = "label";
|
||||||
|
|||||||
Reference in New Issue
Block a user