Merge "Add "Instant apps" filter to app listing"
This commit is contained in:
committed by
Android (Google) Code Review
commit
8b0813c3e4
@@ -19,9 +19,11 @@ package com.android.settingslib.applications;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.usb.IUsbManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -68,4 +70,29 @@ public class AppUtils {
|
||||
return prefActList.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean indicating whether the given package should be considered an instant app
|
||||
*/
|
||||
public static boolean isInstant(ApplicationInfo info) {
|
||||
if (info.isInstantApp()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// For debugging/testing, we support setting the following property to a comma-separated
|
||||
// list of search terms (typically, but not necessarily, full package names) to match
|
||||
// against the package names of the app.
|
||||
String propVal = SystemProperties.get("settingsdebug.instant.packages");
|
||||
if (propVal != null && !propVal.isEmpty() && info.packageName != null) {
|
||||
String[] searchTerms = propVal.split(",");
|
||||
if (searchTerms != null) {
|
||||
for (String term : searchTerms) {
|
||||
if (info.packageName.contains(term)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ public class ApplicationsState {
|
||||
|
||||
boolean mResumed;
|
||||
boolean mHaveDisabledApps;
|
||||
boolean mHaveInstantApps;
|
||||
|
||||
// Information about all applications. Synchronize on mEntriesMap
|
||||
// to protect access to these.
|
||||
@@ -212,6 +213,7 @@ public class ApplicationsState {
|
||||
}
|
||||
|
||||
mHaveDisabledApps = false;
|
||||
mHaveInstantApps = false;
|
||||
for (int i=0; i<mApplications.size(); i++) {
|
||||
final ApplicationInfo info = mApplications.get(i);
|
||||
// Need to trim out any applications that are disabled by
|
||||
@@ -224,6 +226,10 @@ public class ApplicationsState {
|
||||
}
|
||||
mHaveDisabledApps = true;
|
||||
}
|
||||
if (!mHaveInstantApps && AppUtils.isInstant(info)) {
|
||||
mHaveInstantApps = true;
|
||||
}
|
||||
|
||||
int userId = UserHandle.getUserId(info.uid);
|
||||
final AppEntry entry = mEntriesMap.get(userId).get(info.packageName);
|
||||
if (entry != null) {
|
||||
@@ -250,6 +256,9 @@ public class ApplicationsState {
|
||||
public boolean haveDisabledApps() {
|
||||
return mHaveDisabledApps;
|
||||
}
|
||||
public boolean haveInstantApps() {
|
||||
return mHaveInstantApps;
|
||||
}
|
||||
|
||||
void doPauseIfNeededLocked() {
|
||||
if (!mResumed) {
|
||||
@@ -379,6 +388,9 @@ public class ApplicationsState {
|
||||
}
|
||||
mHaveDisabledApps = true;
|
||||
}
|
||||
if (AppUtils.isInstant(info)) {
|
||||
mHaveInstantApps = true;
|
||||
}
|
||||
mApplications.add(info);
|
||||
if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_LOAD_ENTRIES)) {
|
||||
mBackgroundHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ENTRIES);
|
||||
@@ -408,13 +420,22 @@ public class ApplicationsState {
|
||||
mApplications.remove(idx);
|
||||
if (!info.enabled) {
|
||||
mHaveDisabledApps = false;
|
||||
for (int i=0; i<mApplications.size(); i++) {
|
||||
if (!mApplications.get(i).enabled) {
|
||||
for (ApplicationInfo otherInfo : mApplications) {
|
||||
if (!otherInfo.enabled) {
|
||||
mHaveDisabledApps = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (AppUtils.isInstant(info)) {
|
||||
mHaveInstantApps = false;
|
||||
for (ApplicationInfo otherInfo : mApplications) {
|
||||
if (AppUtils.isInstant(otherInfo)) {
|
||||
mHaveInstantApps = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!mMainHandler.hasMessages(MainHandler.MSG_PACKAGE_LIST_CHANGED)) {
|
||||
mMainHandler.sendEmptyMessage(MainHandler.MSG_PACKAGE_LIST_CHANGED);
|
||||
}
|
||||
@@ -1290,6 +1311,7 @@ public class ApplicationsState {
|
||||
public static final AppFilter FILTER_PERSONAL = new AppFilter() {
|
||||
private int mCurrentUser;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
mCurrentUser = ActivityManager.getCurrentUser();
|
||||
}
|
||||
@@ -1301,8 +1323,9 @@ public class ApplicationsState {
|
||||
};
|
||||
|
||||
public static final AppFilter FILTER_WITHOUT_DISABLED_UNTIL_USED = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
// do nothings
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1315,6 +1338,7 @@ public class ApplicationsState {
|
||||
public static final AppFilter FILTER_WORK = new AppFilter() {
|
||||
private int mCurrentUser;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
mCurrentUser = ActivityManager.getCurrentUser();
|
||||
}
|
||||
@@ -1329,6 +1353,7 @@ public class ApplicationsState {
|
||||
* Displays a combined list with "downloaded" and "visible in launcher" apps only.
|
||||
*/
|
||||
public static final AppFilter FILTER_DOWNLOADED_AND_LAUNCHER = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -1348,6 +1373,7 @@ public class ApplicationsState {
|
||||
};
|
||||
|
||||
public static final AppFilter FILTER_THIRD_PARTY = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -1363,26 +1389,40 @@ public class ApplicationsState {
|
||||
};
|
||||
|
||||
public static final AppFilter FILTER_DISABLED = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterApp(AppEntry entry) {
|
||||
return !entry.info.enabled;
|
||||
return !entry.info.enabled && !AppUtils.isInstant(entry.info);
|
||||
}
|
||||
};
|
||||
|
||||
public static final AppFilter FILTER_INSTANT = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterApp(AppEntry entry) {
|
||||
return AppUtils.isInstant(entry.info);
|
||||
}
|
||||
};
|
||||
|
||||
public static final AppFilter FILTER_ALL_ENABLED = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterApp(AppEntry entry) {
|
||||
return entry.info.enabled;
|
||||
return entry.info.enabled && !AppUtils.isInstant(entry.info);
|
||||
}
|
||||
};
|
||||
|
||||
public static final AppFilter FILTER_EVERYTHING = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -1393,6 +1433,7 @@ public class ApplicationsState {
|
||||
};
|
||||
|
||||
public static final AppFilter FILTER_WITH_DOMAIN_URLS = new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -1405,6 +1446,7 @@ public class ApplicationsState {
|
||||
public static final AppFilter FILTER_NOT_HIDE = new AppFilter() {
|
||||
private String[] mHidePackageNames;
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
mHidePackageNames = context.getResources()
|
||||
.getStringArray(R.array.config_hideWhenDisabled_packageNames);
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.settingslib.applications;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
|
||||
@@ -107,4 +108,32 @@ public class ApplicationsStateTest {
|
||||
|
||||
assertThat(ApplicationsState.FILTER_OTHER_APPS.filterApp(mEntry)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstantFilterAcceptsInstantApp() {
|
||||
when(mEntry.info.isInstantApp()).thenReturn(true);
|
||||
assertThat(ApplicationsState.FILTER_INSTANT.filterApp(mEntry)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstantFilterRejectsNonInstantApp() {
|
||||
when(mEntry.info.isInstantApp()).thenReturn(false);
|
||||
assertThat(ApplicationsState.FILTER_INSTANT.filterApp(mEntry)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnabledFilterRejectsInstantApp() {
|
||||
mEntry.info.enabled = true;
|
||||
assertThat(ApplicationsState.FILTER_ALL_ENABLED.filterApp(mEntry)).isTrue();
|
||||
when(mEntry.info.isInstantApp()).thenReturn(true);
|
||||
assertThat(ApplicationsState.FILTER_ALL_ENABLED.filterApp(mEntry)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisabledFilterRejectsInstantApp() {
|
||||
mEntry.info.enabled = false;
|
||||
assertThat(ApplicationsState.FILTER_DISABLED.filterApp(mEntry)).isTrue();
|
||||
when(mEntry.info.isInstantApp()).thenReturn(true);
|
||||
assertThat(ApplicationsState.FILTER_DISABLED.filterApp(mEntry)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user