Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67952e94 authored by Antony Sargent's avatar Antony Sargent
Browse files

Add "Instant apps" filter to app listing

Bug: 35098444
Test: new test added in ApplicationsStateTest.java ; run it by doing the
following commands:
 make SettingsLibTests -j40
 adb install -r $OUT/data/app/SettingsLibTests/SettingsLibTests.apk
 adb shell am instrument -w com.android.settingslib

In Settings->Apps&Notifications->Apps, the list of filters before this CL is:

 All | Enabled | Disabled

With this CL, the filter list becomes:

 All apps | Installed apps | Disabled apps | Instant apps

Change-Id: Ia2ec099f758901839a2aa84fe155ae032990092f
parent dcdaaec8
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -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;
    }

}
+47 −5
Original line number Diff line number Diff line
@@ -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 && !AppUtils.isInstant(entry.info);
        }
    };

    public static final AppFilter FILTER_INSTANT = new AppFilter() {
        @Override
        public void init() {
        }

        @Override
        public boolean filterApp(AppEntry entry) {
            return !entry.info.enabled;
            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);
+29 −0
Original line number Diff line number Diff line
@@ -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();
    }
}