From deb9ddfb590c7533e1be565c40f9a522071c19a9 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Thu, 20 Oct 2022 09:18:06 -0400 Subject: Rename & pull `getTargets` up to base `TargetInfo` This was originally only offered on `MultiDisplayResolveInfo` but that just resulted in some type-checked conditional logic where the caller (`ChooserActivity`) took responsibility for implementing the other cases. Thus this CL is mainly based on the "Replace Conditional with Polymorphism" item in Fowler's _Refactoring_. (It also separates one piece of unrelated conditional behavior from the call site in `ChooserActivity` but leaves any further cleanup of that separate behavior out of scope.) The method rename is an attempt to call attention to the use of the legacy `DisplayResolveInfo` type (as distinguished from other types of "targets" i.e. `ChooserTargetInfo`), in advance of any cleanup of that design. This both simplifies the call site (in `ChooserActivity`) and consolidates `TargetInfo` requirements that were previously diffuse. It also progresses several of our tactical goals in the ongoing `TargetInfo` cleanup (go/chooser-targetinfo-cleanup): * In order to unify the types, all methods offered by any `TargetInfo` implementation have to be pulled up to the base interface; this CL prioritizes one method of particular benefit to callers in its new location, but it was going to have to move eventually regardless. * This encapsulates one of the two call sites of `TargetInfo.getDisplayResolveInfo()`. That API assumes callers have an understanding of the semantics of the legacy `DisplayResolveInfo` implementation, along with the semantics of the (legacy) concrete type of any other `TargetInfo` they might hold (in order to know whether they can use it as-is vs. descending through its `getDisplayResolveInfo()`). The new API focuses (slightly) more on the application requirements that client is trying to fulfill. * More broadly, this reduces call sites where clients depend on the (new-but-deprecated) `TargetInfo` methods that query the legacy type information. These usages _all_ need to be replaced with new APIs that are more expressive in the application domain. Test: atest IntentResolverUnitTests Bug: 202167050 Change-Id: Ibc6cbfb01f323db4b820053babfeb5f7c8024f26 --- java/tests/src/com/android/intentresolver/chooser/TargetInfoTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'java/tests/src') diff --git a/java/tests/src/com/android/intentresolver/chooser/TargetInfoTest.kt b/java/tests/src/com/android/intentresolver/chooser/TargetInfoTest.kt index 8494e296..4a5e1baf 100644 --- a/java/tests/src/com/android/intentresolver/chooser/TargetInfoTest.kt +++ b/java/tests/src/com/android/intentresolver/chooser/TargetInfoTest.kt @@ -122,7 +122,8 @@ class TargetInfoTest { assertThat(multiTargetInfo.getExtendedInfo()).isNull() - assertThat(multiTargetInfo.getTargets()).containsExactly(firstTargetInfo, secondTargetInfo) + assertThat(multiTargetInfo.getAllDisplayTargets()) + .containsExactly(firstTargetInfo, secondTargetInfo) assertThat(multiTargetInfo.hasSelected()).isFalse() assertThat(multiTargetInfo.getSelectedTarget()).isNull() -- cgit v1.2.3-59-g8ed1b