From 8046148e83998422fc4555757e6e03f4659027c3 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Fri, 22 Nov 2024 18:19:08 +0000 Subject: Skip "last-chosen" query for Chooser `getLastChosen()` is invoked in the course of the generic/"base-class" `ResolverListAdapter::rebuildList()`, and the result is cached as `mLastChosen`. By inspection, `mLastChosen` is *only* ever read by `ResolverListAdapter` methods that are gated on `mFilterLastUsed` (except when it's used internally to derive `mLastChosenPosition`, but that field is *also* only used in conjunction with `mFilterLastUsed`). `mFilterLastUsed` is final and false in all instances of the `ChooserListAdapter` subclass (i.e., any `ChooserActivity` configuration): go/chooser-mfilterlastused-false. In some cases (for unknown reason, b/335196436), the call to `getLastChosen()` crashes in Chooser; this CL should safely workaround that problem. Even if it wasn't failing, we could expect some performance boost by omitting the unnecessary system call. Note that Chooser configurations will still call `setLastChosen()` (via the base `ResolverActivity::onTargetSelected()`) to *write* this setting in the system, so it'll still be reflected in subsequent *ResolverActivity* sessions -- it's just never *read* in Chooser. Writing from Chooser probably has only "marginal" user value, but there's no need to change that legacy behavior at this time. Test: existing `IntentForwarder` & CTS tests. Bug: 335196436 Flag: EXEMPT bugfix Change-Id: Ieaf4bc713d51494a6a3ada89810f232b8875108f --- .../android/intentresolver/ResolverListAdapter.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'java') diff --git a/java/src/com/android/intentresolver/ResolverListAdapter.java b/java/src/com/android/intentresolver/ResolverListAdapter.java index fc5514b6..f29553eb 100644 --- a/java/src/com/android/intentresolver/ResolverListAdapter.java +++ b/java/src/com/android/intentresolver/ResolverListAdapter.java @@ -404,14 +404,18 @@ public class ResolverListAdapter extends BaseAdapter { ); } else { mOtherProfile = null; - try { - mLastChosen = mResolverListController.getLastChosen(); - // TODO: does this also somehow need to update mLastChosenPosition? If so, maybe - // the current method should also take responsibility for re-initializing - // mLastChosenPosition, where it's currently done at the start of rebuildList()? - // (Why is this related to the presence of mOtherProfile in fhe first place?) - } catch (RemoteException re) { - Log.d(TAG, "Error calling getLastChosenActivity\n" + re); + // If `mFilterLastUsed` is (`final`) false, we'll never read `mLastChosen`, so don't + // bother making the system query. + if (mFilterLastUsed) { + try { + mLastChosen = mResolverListController.getLastChosen(); + // TODO: does this also somehow need to update mLastChosenPosition? If so, maybe + // the current method should also take responsibility for re-initializing + // mLastChosenPosition, where it's currently done at the start of rebuildList()? + // (Why is this related to the presence of mOtherProfile in fhe first place?) + } catch (RemoteException re) { + Log.d(TAG, "Error calling getLastChosenActivity\n" + re); + } } } } -- cgit v1.2.3-59-g8ed1b