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

Commit 8b0813c3 authored by Antony Sargent's avatar Antony Sargent Committed by Android (Google) Code Review
Browse files

Merge "Add "Instant apps" filter to app listing"

parents 8ef92bce 67952e94
Loading
Loading
Loading
Loading
+27 −0
Original line number Original line Diff line number Diff line
@@ -19,9 +19,11 @@ package com.android.settingslib.applications;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.IUsbManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;


@@ -68,4 +70,29 @@ public class AppUtils {
        return prefActList.size() > 0;
        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 Original line Diff line number Diff line
@@ -98,6 +98,7 @@ public class ApplicationsState {


    boolean mResumed;
    boolean mResumed;
    boolean mHaveDisabledApps;
    boolean mHaveDisabledApps;
    boolean mHaveInstantApps;


    // Information about all applications.  Synchronize on mEntriesMap
    // Information about all applications.  Synchronize on mEntriesMap
    // to protect access to these.
    // to protect access to these.
@@ -212,6 +213,7 @@ public class ApplicationsState {
        }
        }


        mHaveDisabledApps = false;
        mHaveDisabledApps = false;
        mHaveInstantApps = false;
        for (int i=0; i<mApplications.size(); i++) {
        for (int i=0; i<mApplications.size(); i++) {
            final ApplicationInfo info = mApplications.get(i);
            final ApplicationInfo info = mApplications.get(i);
            // Need to trim out any applications that are disabled by
            // Need to trim out any applications that are disabled by
@@ -224,6 +226,10 @@ public class ApplicationsState {
                }
                }
                mHaveDisabledApps = true;
                mHaveDisabledApps = true;
            }
            }
            if (!mHaveInstantApps && AppUtils.isInstant(info)) {
                mHaveInstantApps = true;
            }

            int userId = UserHandle.getUserId(info.uid);
            int userId = UserHandle.getUserId(info.uid);
            final AppEntry entry = mEntriesMap.get(userId).get(info.packageName);
            final AppEntry entry = mEntriesMap.get(userId).get(info.packageName);
            if (entry != null) {
            if (entry != null) {
@@ -250,6 +256,9 @@ public class ApplicationsState {
    public boolean haveDisabledApps() {
    public boolean haveDisabledApps() {
        return mHaveDisabledApps;
        return mHaveDisabledApps;
    }
    }
    public boolean haveInstantApps() {
        return mHaveInstantApps;
    }


    void doPauseIfNeededLocked() {
    void doPauseIfNeededLocked() {
        if (!mResumed) {
        if (!mResumed) {
@@ -379,6 +388,9 @@ public class ApplicationsState {
                    }
                    }
                    mHaveDisabledApps = true;
                    mHaveDisabledApps = true;
                }
                }
                if (AppUtils.isInstant(info)) {
                    mHaveInstantApps = true;
                }
                mApplications.add(info);
                mApplications.add(info);
                if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_LOAD_ENTRIES)) {
                if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_LOAD_ENTRIES)) {
                    mBackgroundHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ENTRIES);
                    mBackgroundHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ENTRIES);
@@ -408,13 +420,22 @@ public class ApplicationsState {
                mApplications.remove(idx);
                mApplications.remove(idx);
                if (!info.enabled) {
                if (!info.enabled) {
                    mHaveDisabledApps = false;
                    mHaveDisabledApps = false;
                    for (int i=0; i<mApplications.size(); i++) {
                    for (ApplicationInfo otherInfo : mApplications) {
                        if (!mApplications.get(i).enabled) {
                        if (!otherInfo.enabled) {
                            mHaveDisabledApps = true;
                            mHaveDisabledApps = true;
                            break;
                            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)) {
                if (!mMainHandler.hasMessages(MainHandler.MSG_PACKAGE_LIST_CHANGED)) {
                    mMainHandler.sendEmptyMessage(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() {
    public static final AppFilter FILTER_PERSONAL = new AppFilter() {
        private int mCurrentUser;
        private int mCurrentUser;


        @Override
        public void init() {
        public void init() {
            mCurrentUser = ActivityManager.getCurrentUser();
            mCurrentUser = ActivityManager.getCurrentUser();
        }
        }
@@ -1301,8 +1323,9 @@ public class ApplicationsState {
    };
    };


    public static final AppFilter FILTER_WITHOUT_DISABLED_UNTIL_USED = new AppFilter() {
    public static final AppFilter FILTER_WITHOUT_DISABLED_UNTIL_USED = new AppFilter() {
        @Override
        public void init() {
        public void init() {
            // do nothings
            // do nothing
        }
        }


        @Override
        @Override
@@ -1315,6 +1338,7 @@ public class ApplicationsState {
    public static final AppFilter FILTER_WORK = new AppFilter() {
    public static final AppFilter FILTER_WORK = new AppFilter() {
        private int mCurrentUser;
        private int mCurrentUser;


        @Override
        public void init() {
        public void init() {
            mCurrentUser = ActivityManager.getCurrentUser();
            mCurrentUser = ActivityManager.getCurrentUser();
        }
        }
@@ -1329,6 +1353,7 @@ public class ApplicationsState {
     * Displays a combined list with "downloaded" and "visible in launcher" apps only.
     * Displays a combined list with "downloaded" and "visible in launcher" apps only.
     */
     */
    public static final AppFilter FILTER_DOWNLOADED_AND_LAUNCHER = new AppFilter() {
    public static final AppFilter FILTER_DOWNLOADED_AND_LAUNCHER = new AppFilter() {
        @Override
        public void init() {
        public void init() {
        }
        }


@@ -1348,6 +1373,7 @@ public class ApplicationsState {
    };
    };


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


@@ -1363,26 +1389,40 @@ public class ApplicationsState {
    };
    };


    public static final AppFilter FILTER_DISABLED = new AppFilter() {
    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() {
        public void init() {
        }
        }


        @Override
        @Override
        public boolean filterApp(AppEntry entry) {
        public boolean filterApp(AppEntry entry) {
            return !entry.info.enabled;
            return AppUtils.isInstant(entry.info);
        }
        }
    };
    };


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


        @Override
        @Override
        public boolean filterApp(AppEntry entry) {
        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() {
    public static final AppFilter FILTER_EVERYTHING = new AppFilter() {
        @Override
        public void init() {
        public void init() {
        }
        }


@@ -1393,6 +1433,7 @@ public class ApplicationsState {
    };
    };


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


@@ -1405,6 +1446,7 @@ public class ApplicationsState {
    public static final AppFilter FILTER_NOT_HIDE = new AppFilter() {
    public static final AppFilter FILTER_NOT_HIDE = new AppFilter() {
        private String[] mHidePackageNames;
        private String[] mHidePackageNames;


        @Override
        public void init(Context context) {
        public void init(Context context) {
            mHidePackageNames = context.getResources()
            mHidePackageNames = context.getResources()
                .getStringArray(R.array.config_hideWhenDisabled_packageNames);
                .getStringArray(R.array.config_hideWhenDisabled_packageNames);
+29 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settingslib.applications;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertThat;


import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;


import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;


@@ -107,4 +108,32 @@ public class ApplicationsStateTest {


        assertThat(ApplicationsState.FILTER_OTHER_APPS.filterApp(mEntry)).isTrue();
        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();
    }
}
}