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

Commit 19aae756 authored by Danning Chen's avatar Danning Chen Committed by Android (Google) Code Review
Browse files

Merge "Add getShareTargets() to ShortcutServiceInternal and get caller's user...

Merge "Add getShareTargets() to ShortcutServiceInternal and get caller's user ID from AppPredictionSessionId"
parents 3ef9003e 91f90e0f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.UserIdInt;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.LocusId;
import android.content.pm.LauncherApps.ShortcutQuery;
@@ -92,4 +93,11 @@ public abstract class ShortcutServiceInternal {
    public abstract void uncacheShortcuts(int launcherUserId,
            @NonNull String callingPackage, @NonNull String packageName,
            @NonNull List<String> shortcutIds, int userId);

    /**
     * Retrieves all of the direct share targets that match the given IntentFilter for the specified
     * user.
     */
    public abstract List<ShortcutManager.ShareShortcutInfo> getShareTargets(
            @NonNull String callingPackage, @NonNull IntentFilter intentFilter, int userId);
}
+7 −0
Original line number Diff line number Diff line
@@ -2773,6 +2773,13 @@ public class ShortcutService extends IShortcutService.Stub {
                    userId, /* doCache= */ false);
        }

        @Override
        public List<ShortcutManager.ShareShortcutInfo> getShareTargets(
                @NonNull String callingPackage, @NonNull IntentFilter intentFilter, int userId) {
            return ShortcutService.this.getShareTargets(
                    callingPackage, intentFilter, userId).getList();
        }

        private void updateCachedShortcutsInternal(int launcherUserId,
                @NonNull String callingPackage, @NonNull String packageName,
                @NonNull List<String> shortcutIds, int userId, boolean doCache) {
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ public class PeopleService extends SystemService {
        @Override
        public void onCreatePredictionSession(AppPredictionContext context,
                AppPredictionSessionId sessionId) {
            mSessions.put(sessionId, new SessionInfo(context, mDataManager));
            mSessions.put(sessionId, new SessionInfo(context, mDataManager, sessionId.getUserId()));
        }

        @Override
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.people;

import android.annotation.UserIdInt;
import android.app.prediction.AppPredictionContext;
import android.app.prediction.AppTarget;
import android.app.prediction.IPredictionCallback;
@@ -38,9 +39,10 @@ class SessionInfo {
    private final RemoteCallbackList<IPredictionCallback> mCallbacks =
            new RemoteCallbackList<>();

    SessionInfo(AppPredictionContext predictionContext, DataManager dataManager) {
    SessionInfo(AppPredictionContext predictionContext, DataManager dataManager,
            @UserIdInt int callingUserId) {
        mAppTargetPredictor = AppTargetPredictor.create(predictionContext,
                this::updatePredictions, dataManager);
                this::updatePredictions, dataManager, callingUserId);
    }

    void addCallback(IPredictionCallback callback) {
+9 −17
Original line number Diff line number Diff line
@@ -34,13 +34,11 @@ import android.content.IntentFilter;
import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.content.pm.ShortcutManager.ShareShortcutInfo;
import android.content.pm.ShortcutServiceInternal;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Binder;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Process;
@@ -83,7 +81,6 @@ import java.util.function.Function;
 */
public class DataManager {

    private static final String PLATFORM_PACKAGE_NAME = "android";
    private static final int MY_UID = Process.myUid();
    private static final int MY_PID = Process.myPid();
    private static final long QUERY_EVENTS_MAX_AGE_MS = DateUtils.DAY_IN_MILLIS;
@@ -106,7 +103,6 @@ public class DataManager {

    private ShortcutServiceInternal mShortcutServiceInternal;
    private PackageManagerInternal mPackageManagerInternal;
    private ShortcutManager mShortcutManager;
    private UserManager mUserManager;

    public DataManager(Context context) {
@@ -125,7 +121,6 @@ public class DataManager {
    public void initialize() {
        mShortcutServiceInternal = LocalServices.getService(ShortcutServiceInternal.class);
        mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
        mShortcutManager = mContext.getSystemService(ShortcutManager.class);
        mUserManager = mContext.getSystemService(UserManager.class);

        mShortcutServiceInternal.addListener(new ShortcutServiceListener());
@@ -171,8 +166,7 @@ public class DataManager {
        mNotificationListeners.put(userId, notificationListener);
        try {
            notificationListener.registerAsSystemService(mContext,
                    new ComponentName(PLATFORM_PACKAGE_NAME, getClass().getCanonicalName()),
                    userId);
                    new ComponentName(mContext, getClass()), userId);
        } catch (RemoteException e) {
            // Should never occur for local calls.
        }
@@ -242,8 +236,8 @@ public class DataManager {
     * Iterates through all the {@link PackageData}s owned by the unlocked users who are in the
     * same profile group as the calling user.
     */
    public void forAllPackages(Consumer<PackageData> consumer) {
        List<UserInfo> users = mUserManager.getEnabledProfiles(mInjector.getCallingUserId());
    void forPackagesInProfile(@UserIdInt int callingUserId, Consumer<PackageData> consumer) {
        List<UserInfo> users = mUserManager.getEnabledProfiles(callingUserId);
        for (UserInfo userInfo : users) {
            UserData userData = getUnlockedUserData(userInfo.id);
            if (userData != null) {
@@ -275,8 +269,10 @@ public class DataManager {
     * Gets the {@link ShareShortcutInfo}s from all packages owned by the calling user that match
     * the specified {@link IntentFilter}.
     */
    public List<ShareShortcutInfo> getShareShortcuts(@NonNull IntentFilter intentFilter) {
        return mShortcutManager.getShareTargets(intentFilter);
    public List<ShareShortcutInfo> getShareShortcuts(@NonNull IntentFilter intentFilter,
            @UserIdInt int callingUserId) {
        return mShortcutServiceInternal.getShareTargets(
                mContext.getPackageName(), intentFilter, callingUserId);
    }

    /** Reports the {@link AppTargetEvent} from App Prediction Manager. */
@@ -361,7 +357,7 @@ public class DataManager {
        @ShortcutQuery.QueryFlags int queryFlags = ShortcutQuery.FLAG_MATCH_DYNAMIC
                | ShortcutQuery.FLAG_MATCH_PINNED | ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER;
        return mShortcutServiceInternal.getShortcuts(
                mInjector.getCallingUserId(), /*callingPackage=*/ PLATFORM_PACKAGE_NAME,
                UserHandle.USER_SYSTEM, mContext.getPackageName(),
                /*changedSince=*/ 0, packageName, shortcutIds, /*locusIds=*/ null,
                /*componentName=*/ null, queryFlags, userId, MY_PID, MY_UID);
    }
@@ -775,7 +771,7 @@ public class DataManager {

        @Override
        public void onReceive(Context context, Intent intent) {
            forAllPackages(PackageData::saveToDisk);
            forAllUnlockedUsers(userData -> userData.forAllPackages(PackageData::saveToDisk));
        }
    }

@@ -809,9 +805,5 @@ public class DataManager {
                Function<String, PackageData> packageDataGetter) {
            return new UsageStatsQueryHelper(userId, packageDataGetter);
        }

        int getCallingUserId() {
            return Binder.getCallingUserHandle().getIdentifier();
        }
    }
}
Loading