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

Commit a342b794 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Implement direct share targets quota based onto app share score in...

Merge "Implement direct share targets quota based onto app share score in ChooserTarget ranking protorype." into rvc-dev am: 2133dc6e am: 9a8ffc82 am: e0f01785

Change-Id: Ic346a4cab3b5b2e5aeef367bf009cf5cbba694df
parents 2af9a906 e0f01785
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ class AppPredictionServiceResolverComparator extends AbstractResolverComparator
    private final AppPredictor mAppPredictor;
    private final AppPredictor mAppPredictor;
    private final Context mContext;
    private final Context mContext;
    private final Map<ComponentName, Integer> mTargetRanks = new HashMap<>();
    private final Map<ComponentName, Integer> mTargetRanks = new HashMap<>();
    private final Map<ComponentName, Integer> mTargetScores = new HashMap<>();
    private final UserHandle mUser;
    private final UserHandle mUser;
    private final Intent mIntent;
    private final Intent mIntent;
    private final String mReferrerPackage;
    private final String mReferrerPackage;
@@ -138,6 +139,11 @@ class AppPredictionServiceResolverComparator extends AbstractResolverComparator
        // Null value is okay if we have defaulted to the ResolverRankerService.
        // Null value is okay if we have defaulted to the ResolverRankerService.
        if (msg.what == RANKER_SERVICE_RESULT && msg.obj != null) {
        if (msg.what == RANKER_SERVICE_RESULT && msg.obj != null) {
            final List<AppTarget> sortedAppTargets = (List<AppTarget>) msg.obj;
            final List<AppTarget> sortedAppTargets = (List<AppTarget>) msg.obj;
            if (checkAppTargetRankValid(sortedAppTargets)) {
                sortedAppTargets.forEach(target -> mTargetScores.put(
                        new ComponentName(target.getPackageName(), target.getClassName()),
                        target.getRank()));
            }
            for (int i = 0; i < sortedAppTargets.size(); i++) {
            for (int i = 0; i < sortedAppTargets.size(); i++) {
                mTargetRanks.put(new ComponentName(sortedAppTargets.get(i).getPackageName(),
                mTargetRanks.put(new ComponentName(sortedAppTargets.get(i).getPackageName(),
                        sortedAppTargets.get(i).getClassName()), i);
                        sortedAppTargets.get(i).getClassName()), i);
@@ -147,11 +153,23 @@ class AppPredictionServiceResolverComparator extends AbstractResolverComparator
        }
        }
    }
    }


    private boolean checkAppTargetRankValid(List<AppTarget> sortedAppTargets) {
        for (AppTarget target : sortedAppTargets) {
            if (target.getRank() != 0) {
                return true;
            }
        }
        return false;
    }

    @Override
    @Override
    float getScore(ComponentName name) {
    float getScore(ComponentName name) {
        if (mResolverRankerService != null) {
        if (mResolverRankerService != null) {
            return mResolverRankerService.getScore(name);
            return mResolverRankerService.getScore(name);
        }
        }
        if (!mTargetScores.isEmpty()) {
            return mTargetScores.get(name);
        }
        Integer rank = mTargetRanks.get(name);
        Integer rank = mTargetRanks.get(name);
        if (rank == null) {
        if (rank == null) {
            Log.w(TAG, "Score requested for unknown component.");
            Log.w(TAG, "Score requested for unknown component.");
+48 −22
Original line number Original line Diff line number Diff line
@@ -207,9 +207,6 @@ public class ChooserListAdapter extends ResolverListAdapter {
        if (mListViewDataChanged) {
        if (mListViewDataChanged) {
            if (mAppendDirectShareEnabled) {
            if (mAppendDirectShareEnabled) {
                appendServiceTargetsWithQuota();
                appendServiceTargetsWithQuota();
                if (mPendingChooserTargetService.isEmpty()) {
                    fillAllServiceTargets();
                }
            }
            }
            super.notifyDataSetChanged();
            super.notifyDataSetChanged();
        }
        }
@@ -493,6 +490,8 @@ public class ChooserListAdapter extends ResolverListAdapter {
                    pendingChooserTargetServiceConnections) {
                    pendingChooserTargetServiceConnections) {
        ComponentName origComponentName = origTarget != null ? origTarget.getResolvedComponentName()
        ComponentName origComponentName = origTarget != null ? origTarget.getResolvedComponentName()
                : !targets.isEmpty() ? targets.get(0).getComponentName() : null;
                : !targets.isEmpty() ? targets.get(0).getComponentName() : null;
        Log.i(TAG,
                "parkTargetIntoMemory " + origComponentName + ", " + targets.size() + " targets");
        mPendingChooserTargetService = pendingChooserTargetServiceConnections.stream()
        mPendingChooserTargetService = pendingChooserTargetServiceConnections.stream()
                .map(ChooserActivity.ChooserTargetServiceConnection::getComponentName)
                .map(ChooserActivity.ChooserTargetServiceConnection::getComponentName)
                .filter(componentName -> !componentName.equals(origComponentName))
                .filter(componentName -> !componentName.equals(origComponentName))
@@ -532,20 +531,34 @@ public class ChooserListAdapter extends ResolverListAdapter {
    private void appendServiceTargetsWithQuota() {
    private void appendServiceTargetsWithQuota() {
        int maxRankedTargets = mChooserListCommunicator.getMaxRankedTargets();
        int maxRankedTargets = mChooserListCommunicator.getMaxRankedTargets();
        List<ComponentName> topComponentNames = getTopComponentNames(maxRankedTargets);
        List<ComponentName> topComponentNames = getTopComponentNames(maxRankedTargets);
        int appRank = 0;
        float totalScore = 0f;
        for (ComponentName component : topComponentNames) {
            if (!mPendingChooserTargetService.contains(component)
                    && !mParkingDirectShareTargets.containsKey(component)) {
                continue;
            }
            totalScore += super.getScore(component);
        }
        boolean shouldWaitPendingService = false;
        for (ComponentName component : topComponentNames) {
        for (ComponentName component : topComponentNames) {
            if (!mPendingChooserTargetService.contains(component)
            if (!mPendingChooserTargetService.contains(component)
                    && !mParkingDirectShareTargets.containsKey(component)) {
                    && !mParkingDirectShareTargets.containsKey(component)) {
                continue;
                continue;
            }
            }
            appRank++;
            float score = super.getScore(component);
            int quota = Math.round(maxRankedTargets * score / totalScore);
            if (mPendingChooserTargetService.contains(component) && quota >= 1) {
                shouldWaitPendingService = true;
            }
            if (!mParkingDirectShareTargets.containsKey(component)) {
                continue;
            }
            // Append targets into direct share row as per quota.
            Pair<List<ChooserTargetInfo>, Integer> parkingTargetsItem =
            Pair<List<ChooserTargetInfo>, Integer> parkingTargetsItem =
                    mParkingDirectShareTargets.get(component);
                    mParkingDirectShareTargets.get(component);
            if (parkingTargetsItem != null && parkingTargetsItem.second == 0) {
            List<ChooserTargetInfo> parkingTargets = parkingTargetsItem.first;
            List<ChooserTargetInfo> parkingTargets = parkingTargetsItem.first;
                int initTargetsQuota = appRank <= maxRankedTargets / 2 ? 2 : 1;
            int insertedNum = parkingTargetsItem.second;
                int insertedNum = 0;
            while (insertedNum < quota && !parkingTargets.isEmpty()) {
                while (insertedNum < initTargetsQuota && !parkingTargets.isEmpty()) {
                if (!checkDuplicateTarget(parkingTargets.get(0))) {
                if (!checkDuplicateTarget(parkingTargets.get(0))) {
                    mServiceTargets.add(mValidServiceTargetsNum, parkingTargets.get(0));
                    mServiceTargets.add(mValidServiceTargetsNum, parkingTargets.get(0));
                    mValidServiceTargetsNum++;
                    mValidServiceTargetsNum++;
@@ -553,11 +566,21 @@ public class ChooserListAdapter extends ResolverListAdapter {
                }
                }
                parkingTargets.remove(0);
                parkingTargets.remove(0);
            }
            }
                mParkingDirectShareTargets.put(component, new Pair<>(parkingTargets, insertedNum));
            Log.i(TAG, " appendServiceTargetsWithQuota component=" + component
                    + " appendNum=" + (insertedNum - parkingTargetsItem.second));
            if (DEBUG) {
                Log.d(TAG, " appendServiceTargetsWithQuota component=" + component
                        + " score=" + score
                        + " totalScore=" + totalScore
                        + " quota=" + quota);
            }
            if (mShortcutComponents.contains(component)) {
            if (mShortcutComponents.contains(component)) {
                    mNumShortcutResults += insertedNum;
                mNumShortcutResults += insertedNum - parkingTargetsItem.second;
            }
            }
            mParkingDirectShareTargets.put(component, new Pair<>(parkingTargets, insertedNum));
        }
        }
        if (!shouldWaitPendingService) {
            fillAllServiceTargets();
        }
        }
    }
    }


@@ -568,6 +591,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
        if (mParkingDirectShareTargets.isEmpty()) {
        if (mParkingDirectShareTargets.isEmpty()) {
            return;
            return;
        }
        }
        Log.i(TAG, " fillAllServiceTargets");
        int maxRankedTargets = mChooserListCommunicator.getMaxRankedTargets();
        int maxRankedTargets = mChooserListCommunicator.getMaxRankedTargets();
        List<ComponentName> topComponentNames = getTopComponentNames(maxRankedTargets);
        List<ComponentName> topComponentNames = getTopComponentNames(maxRankedTargets);
        // Append all remaining targets of top recommended components into direct share row.
        // Append all remaining targets of top recommended components into direct share row.
@@ -581,7 +605,8 @@ public class ChooserListAdapter extends ResolverListAdapter {
                        if (mShortcutComponents.contains(component)) {
                        if (mShortcutComponents.contains(component)) {
                            mNumShortcutResults++;
                            mNumShortcutResults++;
                        }
                        }
                        mServiceTargets.add(target);
                        mServiceTargets.add(mValidServiceTargetsNum, target);
                        mValidServiceTargetsNum++;
                    });
                    });
            mParkingDirectShareTargets.remove(component);
            mParkingDirectShareTargets.remove(component);
        }
        }
@@ -593,7 +618,8 @@ public class ChooserListAdapter extends ResolverListAdapter {
                .forEach(targets -> {
                .forEach(targets -> {
                    for (ChooserTargetInfo target : targets) {
                    for (ChooserTargetInfo target : targets) {
                        if (!checkDuplicateTarget(target)) {
                        if (!checkDuplicateTarget(target)) {
                            mServiceTargets.add(target);
                            mServiceTargets.add(mValidServiceTargetsNum, target);
                            mValidServiceTargetsNum++;
                            mNumShortcutResults++;
                            mNumShortcutResults++;
                        }
                        }
                    }
                    }
+7 −0
Original line number Original line Diff line number Diff line
@@ -153,6 +153,13 @@ public class ResolverListAdapter extends BaseAdapter {
        return mResolverListController.getScore(target);
        return mResolverListController.getScore(target);
    }
    }


    /**
     * Returns the app share score of the given {@code componentName}.
     */
    public float getScore(ComponentName componentName) {
        return mResolverListController.getScore(componentName);
    }

    /**
    /**
     * Returns the list of top K component names which have highest
     * Returns the list of top K component names which have highest
     * {@link #getScore(DisplayResolveInfo)}
     * {@link #getScore(DisplayResolveInfo)}
+7 −0
Original line number Original line Diff line number Diff line
@@ -377,6 +377,13 @@ public class ResolverListController {
        return mResolverComparator.getScore(target.getResolvedComponentName());
        return mResolverComparator.getScore(target.getResolvedComponentName());
    }
    }


    /**
     * Returns the app share score of the given {@code componentName}.
     */
    public float getScore(ComponentName componentName) {
        return mResolverComparator.getScore(componentName);
    }

    /**
    /**
     * Returns the list of top K component names which have highest
     * Returns the list of top K component names which have highest
     * {@link #getScore(DisplayResolveInfo)}
     * {@link #getScore(DisplayResolveInfo)}