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

Commit b7c2ea64 authored by Todd Kennedy's avatar Todd Kennedy Committed by android-build-merger
Browse files

Merge "Enable local search for instant apps" into pi-dev

am: 35a6c583

Change-Id: I6c459808616cb8aa400f5c98d329696afefa905a
parents d7901bd0 35a6c583
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -451,6 +451,9 @@ public abstract class PackageManagerInternal {
    /** Whether the binder caller can access instant apps. */
    public abstract boolean canAccessInstantApps(int callingUid, int userId);

    /** Whether the binder caller can access the given component. */
    public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId);

    /**
     * Returns {@code true} if a given package has instant application meta-data.
     * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc)
+9 −0
Original line number Diff line number Diff line
@@ -23857,6 +23857,15 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
            return PackageManagerService.this.canViewInstantApps(callingUid, userId);
        }
        @Override
        public boolean canAccessComponent(int callingUid, ComponentName component, int userId) {
            synchronized (mPackages) {
                final PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
                return !PackageManagerService.this.filterAppAccessLPr(
                        ps, callingUid, component, TYPE_UNKNOWN, userId);
            }
        }
        @Override
        public boolean hasInstantApplicationMetadata(String packageName, int userId) {
            synchronized (mPackages) {
+74 −8
Original line number Diff line number Diff line
@@ -26,14 +26,18 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo;
import android.os.Binder;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import com.android.server.LocalServices;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -119,7 +123,15 @@ public class Searchables {
        SearchableInfo result;
        synchronized (this) {
            result = mSearchablesMap.get(activity);
            if (result != null) return result;
            if (result != null) {
                final PackageManagerInternal pm =
                        LocalServices.getService(PackageManagerInternal.class);
                if (pm.canAccessComponent(Binder.getCallingUid(), result.getSearchActivity(),
                        UserHandle.getCallingUserId())) {
                    return result;
                }
                return null;
            }
        }

        // Step 2.  See if the current activity references a searchable.
@@ -170,8 +182,16 @@ public class Searchables {
                result = mSearchablesMap.get(referredActivity);
                if (result != null) {
                    mSearchablesMap.put(activity, result);
                }
            }
            if (result != null) {
                final PackageManagerInternal pm =
                        LocalServices.getService(PackageManagerInternal.class);
                if (pm.canAccessComponent(Binder.getCallingUid(), result.getSearchActivity(),
                        UserHandle.getCallingUserId())) {
                    return result;
                }
                return null;
            }
        }

@@ -410,7 +430,7 @@ public class Searchables {
            activities =
                    mPm.queryIntentActivities(intent,
                    intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                    flags, mUserId).getList();
                    flags | PackageManager.MATCH_INSTANT, mUserId).getList();
        } catch (RemoteException re) {
            // Local call
        }
@@ -421,37 +441,83 @@ public class Searchables {
     * Returns the list of searchable activities.
     */
    public synchronized ArrayList<SearchableInfo> getSearchablesList() {
        ArrayList<SearchableInfo> result = new ArrayList<SearchableInfo>(mSearchablesList);
        return result;
        return createFilterdSearchableInfoList(mSearchablesList);
    }

    /**
     * Returns a list of the searchable activities that can be included in global search.
     */
    public synchronized ArrayList<SearchableInfo> getSearchablesInGlobalSearchList() {
        return new ArrayList<SearchableInfo>(mSearchablesInGlobalSearchList);
        return createFilterdSearchableInfoList(mSearchablesInGlobalSearchList);
    }

    /**
     * Returns a list of activities that handle the global search intent.
     */
    public synchronized ArrayList<ResolveInfo> getGlobalSearchActivities() {
        return new ArrayList<ResolveInfo>(mGlobalSearchActivities);
        return createFilterdResolveInfoList(mGlobalSearchActivities);
    }

    private ArrayList<SearchableInfo> createFilterdSearchableInfoList(List<SearchableInfo> list) {
        if (list == null) {
            return null;
        }
        final ArrayList<SearchableInfo> resultList = new ArrayList<>(list.size());
        final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
        final int callingUid = Binder.getCallingUid();
        final int callingUserId = UserHandle.getCallingUserId();
        for (SearchableInfo info : list) {
            if (pm.canAccessComponent(callingUid, info.getSearchActivity(), callingUserId)) {
                resultList.add(info);
            }
        }
        return resultList;
    }

    private ArrayList<ResolveInfo> createFilterdResolveInfoList(List<ResolveInfo> list) {
        if (list == null) {
            return null;
        }
        final ArrayList<ResolveInfo> resultList = new ArrayList<>(list.size());
        final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
        final int callingUid = Binder.getCallingUid();
        final int callingUserId = UserHandle.getCallingUserId();
        for (ResolveInfo info : list) {
            if (pm.canAccessComponent(
                    callingUid, info.activityInfo.getComponentName(), callingUserId)) {
                resultList.add(info);
            }
        }
        return resultList;
    }

    /**
     * Gets the name of the global search activity.
     */
    public synchronized ComponentName getGlobalSearchActivity() {
        final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
        final int callingUid = Binder.getCallingUid();
        final int callingUserId = UserHandle.getCallingUserId();
        if (mCurrentGlobalSearchActivity != null
                && pm.canAccessComponent(callingUid, mCurrentGlobalSearchActivity, callingUserId)) {
            return mCurrentGlobalSearchActivity;
        }
        return null;
    }

    /**
     * Gets the name of the web search activity.
     */
    public synchronized ComponentName getWebSearchActivity() {
        final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
        final int callingUid = Binder.getCallingUid();
        final int callingUserId = UserHandle.getCallingUserId();
        if (mWebSearchActivity != null
                && pm.canAccessComponent(callingUid, mWebSearchActivity, callingUserId)) {
            return mWebSearchActivity;
        }
        return null;
    }

    void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Searchable authorities:");