diff options
| author | 2023-02-28 21:46:11 +0000 | |
|---|---|---|
| committer | 2023-02-28 21:46:11 +0000 | |
| commit | 0846fd5d14fbbcf7b6dd0e9f2ade30dffaebbe10 (patch) | |
| tree | 216baf924080b2decb176030014fceb4f43b1f7c /java/src | |
| parent | d1bd8b386712c3bf13a08691d907ad76d87c990f (diff) | |
| parent | d859557cf76c33dc74ba568293d9376df31f3c76 (diff) | |
Merge "Extract ResolvedComponentInfo to top-level." into tm-qpr-dev am: 980e476ce2 am: 311863bca9 am: d859557cf7
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/IntentResolver/+/21559909
Change-Id: Ibad5eaf841a1764008b9c2cf097e1f6b81be385c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'java/src')
9 files changed, 136 insertions, 92 deletions
| diff --git a/java/src/com/android/intentresolver/ChooserListAdapter.java b/java/src/com/android/intentresolver/ChooserListAdapter.java index 49b883ae..f0651360 100644 --- a/java/src/com/android/intentresolver/ChooserListAdapter.java +++ b/java/src/com/android/intentresolver/ChooserListAdapter.java @@ -49,7 +49,6 @@ import android.widget.TextView;  import androidx.annotation.WorkerThread; -import com.android.intentresolver.ResolverActivity.ResolvedComponentInfo;  import com.android.intentresolver.chooser.DisplayResolveInfo;  import com.android.intentresolver.chooser.MultiDisplayResolveInfo;  import com.android.intentresolver.chooser.NotSelectableTargetInfo; diff --git a/java/src/com/android/intentresolver/NoAppsAvailableEmptyStateProvider.java b/java/src/com/android/intentresolver/NoAppsAvailableEmptyStateProvider.java index 5bf994d6..c1373f4b 100644 --- a/java/src/com/android/intentresolver/NoAppsAvailableEmptyStateProvider.java +++ b/java/src/com/android/intentresolver/NoAppsAvailableEmptyStateProvider.java @@ -101,9 +101,9 @@ public class NoAppsAvailableEmptyStateProvider implements EmptyStateProvider {          if (mWorkProfileUserHandle == null) {              return false;          } -        List<ResolverActivity.ResolvedComponentInfo> resolversForIntent = +        List<ResolvedComponentInfo> resolversForIntent =                  adapter.getResolversForUser(UserHandle.of(mMyUserIdProvider.getMyUserId())); -        for (ResolverActivity.ResolvedComponentInfo info : resolversForIntent) { +        for (ResolvedComponentInfo info : resolversForIntent) {              ResolveInfo resolveInfo = info.getResolveInfoAt(0);              if (resolveInfo.targetUserId != UserHandle.USER_CURRENT) {                  return true; @@ -151,4 +151,4 @@ public class NoAppsAvailableEmptyStateProvider implements EmptyStateProvider {                      .write();          }      } -}
\ No newline at end of file +} diff --git a/java/src/com/android/intentresolver/ResolvedComponentInfo.java b/java/src/com/android/intentresolver/ResolvedComponentInfo.java new file mode 100644 index 00000000..ecb72cbf --- /dev/null +++ b/java/src/com/android/intentresolver/ResolvedComponentInfo.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *      http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.intentresolver; + +import android.content.ComponentName; +import android.content.Intent; +import android.content.pm.ResolveInfo; + +import java.util.ArrayList; +import java.util.List; + +/** + * Record type to store all resolutions that are deduped to a single target component, along with + * other metadata about the component (which applies to all of the resolutions in the record). + * This record is assembled when we're first processing resolutions, and then later it's used to + * derive the {@link TargetInfo} record(s) that specify how the resolutions will be presented as + * targets in the UI. + */ +public final class ResolvedComponentInfo { +    public final ComponentName name; +    private final List<Intent> mIntents = new ArrayList<>(); +    private final List<ResolveInfo> mResolveInfos = new ArrayList<>(); +    private boolean mPinned; + +    /** +     * @param name the name of the component that owns all the resolutions added to this record. +     * @param intent an initial {@link Intent} to add to this record +     * @param info the {@link ResolveInfo} associated with the given {@code intent}. +     */ +    public ResolvedComponentInfo(ComponentName name, Intent intent, ResolveInfo info) { +        this.name = name; +        add(intent, info); +    } + +    /** +     * Add an {@link Intent} and associated {@link ResolveInfo} as resolutions for this component. +     */ +    public void add(Intent intent, ResolveInfo info) { +        mIntents.add(intent); +        mResolveInfos.add(info); +    } + +    /** @return the number of {@link Intent}/{@link ResolveInfo} pairs added to this record. */ +    public int getCount() { +        return mIntents.size(); +    } + +    /** @return the {@link Intent} at the specified {@code index}, if any, or else null. */ +    public Intent getIntentAt(int index) { +        return (index >= 0) ? mIntents.get(index) : null; +    } + +    /** @return the {@link ResolveInfo} at the specified {@code index}, if any, or else null. */ +    public ResolveInfo getResolveInfoAt(int index) { +        return (index >= 0) ? mResolveInfos.get(index) : null; +    } + +    /** +     * @return the index of the provided {@link Intent} among those that have been added to this +     * {@link ResolvedComponentInfo}, or -1 if it has't been added. +     */ +    public int findIntent(Intent intent) { +        return mIntents.indexOf(intent); +    } + +    /** +     * @return the index of the provided {@link ResolveInfo} among those that have been added to +     * this {@link ResolvedComponentInfo}, or -1 if it has't been added. +     */ +    public int findResolveInfo(ResolveInfo info) { +        return mResolveInfos.indexOf(info); +    } + +    /** +     * @return whether this component was pinned by a call to {@link #setPinned()}. +     * TODO: consolidate sources of pinning data and/or document how this differs from other places +     * we make a "pinning" determination. +     */ +    public boolean isPinned() { +        return mPinned; +    } + +    /** +     * Set whether this component will be considered pinned in future calls to {@link #isPinned()}. +     * TODO: consolidate sources of pinning data and/or document how this differs from other places +     * we make a "pinning" determination. +     */ +    public void setPinned(boolean pinned) { +        mPinned = pinned; +    } +} diff --git a/java/src/com/android/intentresolver/ResolverActivity.java b/java/src/com/android/intentresolver/ResolverActivity.java index 08f42404..7a0c0f1a 100644 --- a/java/src/com/android/intentresolver/ResolverActivity.java +++ b/java/src/com/android/intentresolver/ResolverActivity.java @@ -2214,61 +2214,6 @@ public class ResolverActivity extends FragmentActivity implements          return mMultiProfilePagerAdapter.getInactiveListAdapter().getCount() > 0;      } -    public static final class ResolvedComponentInfo { -        public final ComponentName name; -        private final List<Intent> mIntents = new ArrayList<>(); -        private final List<ResolveInfo> mResolveInfos = new ArrayList<>(); -        private boolean mPinned; - -        public ResolvedComponentInfo(ComponentName name, Intent intent, ResolveInfo info) { -            this.name = name; -            add(intent, info); -        } - -        public void add(Intent intent, ResolveInfo info) { -            mIntents.add(intent); -            mResolveInfos.add(info); -        } - -        public int getCount() { -            return mIntents.size(); -        } - -        public Intent getIntentAt(int index) { -            return index >= 0 ? mIntents.get(index) : null; -        } - -        public ResolveInfo getResolveInfoAt(int index) { -            return index >= 0 ? mResolveInfos.get(index) : null; -        } - -        public int findIntent(Intent intent) { -            for (int i = 0, N = mIntents.size(); i < N; i++) { -                if (intent.equals(mIntents.get(i))) { -                    return i; -                } -            } -            return -1; -        } - -        public int findResolveInfo(ResolveInfo info) { -            for (int i = 0, N = mResolveInfos.size(); i < N; i++) { -                if (info.equals(mResolveInfos.get(i))) { -                    return i; -                } -            } -            return -1; -        } - -        public boolean isPinned() { -            return mPinned; -        } - -        public void setPinned(boolean pinned) { -            mPinned = pinned; -        } -    } -      final class ItemClickListener implements AdapterView.OnItemClickListener,              AdapterView.OnItemLongClickListener {          @Override diff --git a/java/src/com/android/intentresolver/ResolverListAdapter.java b/java/src/com/android/intentresolver/ResolverListAdapter.java index c8a9d5dc..eac275cc 100644 --- a/java/src/com/android/intentresolver/ResolverListAdapter.java +++ b/java/src/com/android/intentresolver/ResolverListAdapter.java @@ -49,7 +49,6 @@ import android.widget.BaseAdapter;  import android.widget.ImageView;  import android.widget.TextView; -import com.android.intentresolver.ResolverActivity.ResolvedComponentInfo;  import com.android.intentresolver.chooser.DisplayResolveInfo;  import com.android.intentresolver.chooser.TargetInfo;  import com.android.internal.annotations.VisibleForTesting; diff --git a/java/src/com/android/intentresolver/ResolverListController.java b/java/src/com/android/intentresolver/ResolverListController.java index 6eb027ea..b4544c43 100644 --- a/java/src/com/android/intentresolver/ResolverListController.java +++ b/java/src/com/android/intentresolver/ResolverListController.java @@ -104,7 +104,11 @@ public class ResolverListController {                  filter, match, intent.getComponent());      } -    public List<ResolverActivity.ResolvedComponentInfo> getResolversForIntentAsUser( +    /** +     * Get data about all the ways the user with the specified handle can resolve any of the +     * provided {@code intents}. +     */ +    public List<ResolvedComponentInfo> getResolversForIntentAsUser(              boolean shouldGetResolvedFilter,              boolean shouldGetActivityMetadata,              boolean shouldGetOnlyDefaultActivities, @@ -118,11 +122,9 @@ public class ResolverListController {          return getResolversForIntentAsUserInternal(intents, userHandle, baseFlags);      } -    private List<ResolverActivity.ResolvedComponentInfo> getResolversForIntentAsUserInternal( -            List<Intent> intents, -            UserHandle userHandle, -            int baseFlags) { -        List<ResolverActivity.ResolvedComponentInfo> resolvedComponents = null; +    private List<ResolvedComponentInfo> getResolversForIntentAsUserInternal( +            List<Intent> intents, UserHandle userHandle, int baseFlags) { +        List<ResolvedComponentInfo> resolvedComponents = null;          for (int i = 0, N = intents.size(); i < N; i++) {              Intent intent = intents.get(i);              int flags = baseFlags; @@ -146,9 +148,8 @@ public class ResolverListController {      }      @VisibleForTesting -    public void addResolveListDedupe(List<ResolverActivity.ResolvedComponentInfo> into, -            Intent intent, -            List<ResolveInfo> from) { +    public void addResolveListDedupe( +            List<ResolvedComponentInfo> into, Intent intent, List<ResolveInfo> from) {          final int fromCount = from.size();          final int intoCount = into.size();          for (int i = 0; i < fromCount; i++) { @@ -156,7 +157,7 @@ public class ResolverListController {              boolean found = false;              // Only loop to the end of into as it was before we started; no dupes in from.              for (int j = 0; j < intoCount; j++) { -                final ResolverActivity.ResolvedComponentInfo rci = into.get(j); +                final ResolvedComponentInfo rci = into.get(j);                  if (isSameResolvedComponent(newInfo, rci)) {                      found = true;                      rci.add(intent, newInfo); @@ -166,8 +167,7 @@ public class ResolverListController {              if (!found) {                  final ComponentName name = new ComponentName(                          newInfo.activityInfo.packageName, newInfo.activityInfo.name); -                final ResolverActivity.ResolvedComponentInfo rci = -                        new ResolverActivity.ResolvedComponentInfo(name, intent, newInfo); +                final ResolvedComponentInfo rci = new ResolvedComponentInfo(name, intent, newInfo);                  rci.setPinned(isComponentPinned(name));                  into.add(rci);              } @@ -187,10 +187,9 @@ public class ResolverListController {      // To preserve the inputList, optionally will return the original list if any modification has      // been made.      @VisibleForTesting -    public ArrayList<ResolverActivity.ResolvedComponentInfo> filterIneligibleActivities( -            List<ResolverActivity.ResolvedComponentInfo> inputList, -            boolean returnCopyOfOriginalListIfModified) { -        ArrayList<ResolverActivity.ResolvedComponentInfo> listToReturn = null; +    public ArrayList<ResolvedComponentInfo> filterIneligibleActivities( +            List<ResolvedComponentInfo> inputList, boolean returnCopyOfOriginalListIfModified) { +        ArrayList<ResolvedComponentInfo> listToReturn = null;          for (int i = inputList.size()-1; i >= 0; i--) {              ActivityInfo ai = inputList.get(i)                      .getResolveInfoAt(0).activityInfo; @@ -216,13 +215,12 @@ public class ResolverListController {      // To preserve the inputList, optionally will return the original list if any modification has      // been made.      @VisibleForTesting -    public ArrayList<ResolverActivity.ResolvedComponentInfo> filterLowPriority( -            List<ResolverActivity.ResolvedComponentInfo> inputList, -            boolean returnCopyOfOriginalListIfModified) { -        ArrayList<ResolverActivity.ResolvedComponentInfo> listToReturn = null; +    public ArrayList<ResolvedComponentInfo> filterLowPriority( +            List<ResolvedComponentInfo> inputList, boolean returnCopyOfOriginalListIfModified) { +        ArrayList<ResolvedComponentInfo> listToReturn = null;          // Only display the first matches that are either of equal          // priority or have asked to be default options. -        ResolverActivity.ResolvedComponentInfo rci0 = inputList.get(0); +        ResolvedComponentInfo rci0 = inputList.get(0);          ResolveInfo r0 = rci0.getResolveInfoAt(0);          int N = inputList.size();          for (int i = 1; i < N; i++) { @@ -247,8 +245,7 @@ public class ResolverListController {          return listToReturn;      } -    private void compute(List<ResolverActivity.ResolvedComponentInfo> inputList) -            throws InterruptedException { +    private void compute(List<ResolvedComponentInfo> inputList) throws InterruptedException {          if (mResolverComparator == null) {              Log.d(TAG, "Comparator has already been destroyed; skipped.");              return; @@ -262,7 +259,7 @@ public class ResolverListController {      @VisibleForTesting      @WorkerThread -    public void sort(List<ResolverActivity.ResolvedComponentInfo> inputList) { +    public void sort(List<ResolvedComponentInfo> inputList) {          try {              long beforeRank = System.currentTimeMillis();              if (!isComputed) { @@ -281,7 +278,7 @@ public class ResolverListController {      @VisibleForTesting      @WorkerThread -    public void topK(List<ResolverActivity.ResolvedComponentInfo> inputList, int k) { +    public void topK(List<ResolvedComponentInfo> inputList, int k) {          if (inputList == null || inputList.isEmpty() || k <= 0) {              return;          } @@ -298,7 +295,7 @@ public class ResolverListController {              }              // Top of this heap has lowest rank. -            PriorityQueue<ResolverActivity.ResolvedComponentInfo> minHeap = new PriorityQueue<>(k, +            PriorityQueue<ResolvedComponentInfo> minHeap = new PriorityQueue<>(k,                      (o1, o2) -> -mResolverComparator.compare(o1, o2));              final int size = inputList.size();              // Use this pointer to keep track of the position of next element @@ -306,7 +303,7 @@ public class ResolverListController {              int pointer = size - 1;              minHeap.addAll(inputList.subList(size - k, size));              for (int i = size - k - 1; i >= 0; --i) { -                ResolverActivity.ResolvedComponentInfo ci = inputList.get(i); +                ResolvedComponentInfo ci = inputList.get(i);                  if (-mResolverComparator.compare(ci, minHeap.peek()) > 0) {                      // When ranked higher than top of heap, remove top of heap,                      // update input list with it, add this new element to heap. @@ -335,8 +332,7 @@ public class ResolverListController {          }      } -    private static boolean isSameResolvedComponent(ResolveInfo a, -            ResolverActivity.ResolvedComponentInfo b) { +    private static boolean isSameResolvedComponent(ResolveInfo a, ResolvedComponentInfo b) {          final ActivityInfo ai = a.activityInfo;          return ai.packageName.equals(b.name.getPackageName())                  && ai.name.equals(b.name.getClassName()); diff --git a/java/src/com/android/intentresolver/model/AbstractResolverComparator.java b/java/src/com/android/intentresolver/model/AbstractResolverComparator.java index 271c6f98..ea767568 100644 --- a/java/src/com/android/intentresolver/model/AbstractResolverComparator.java +++ b/java/src/com/android/intentresolver/model/AbstractResolverComparator.java @@ -30,8 +30,8 @@ import android.os.UserHandle;  import android.util.Log;  import com.android.intentresolver.ChooserActivityLogger; +import com.android.intentresolver.ResolvedComponentInfo;  import com.android.intentresolver.ResolverActivity; -import com.android.intentresolver.ResolverActivity.ResolvedComponentInfo;  import java.text.Collator;  import java.util.ArrayList; diff --git a/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java b/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java index c6bb2b85..c986ef15 100644 --- a/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java +++ b/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java @@ -32,7 +32,7 @@ import android.os.UserHandle;  import android.util.Log;  import com.android.intentresolver.ChooserActivityLogger; -import com.android.intentresolver.ResolverActivity.ResolvedComponentInfo; +import com.android.intentresolver.ResolvedComponentInfo;  import java.util.ArrayList;  import java.util.Comparator; diff --git a/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java b/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java index 4382f109..0431078c 100644 --- a/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java +++ b/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java @@ -38,7 +38,7 @@ import android.service.resolver.ResolverTarget;  import android.util.Log;  import com.android.intentresolver.ChooserActivityLogger; -import com.android.intentresolver.ResolverActivity.ResolvedComponentInfo; +import com.android.intentresolver.ResolvedComponentInfo;  import com.android.internal.logging.MetricsLogger;  import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |