diff options
author | 2024-01-26 12:03:59 -0500 | |
---|---|---|
committer | 2024-01-30 13:04:58 -0500 | |
commit | f0c6a508f930c7dab1ec95fa6b322abdc6609bbe (patch) | |
tree | 3bf332372067cb24a913f5d87bb0527c172c5509 /tests/activity | |
parent | f30cb97a784ba508a82863ef74ea0135355aad0c (diff) |
Rename CallerInfo -> ActivityLaunch and inject
Rename CallerInfo to ActivityLaunch and renames some existing
properties as appropriate for clarity.
Adds the [Intent] from the activity. This completes the set of
info that is needed as inputs from the caller, containing the
extras with all request parameters.
Updates readChooserRequest require only an ActivityLaunchInfo
instance.
Injects ActivityLaunch into usage sites. This removes the direct
link of reading acitivty.intent, and will allow writing test code
which operates directly on inputs without starting an activity.
Introduces an extension method to minimize duplicated code in the
activities: CreationExtras.addDefaultArgs:
Bug: 300157408
Test: atest IntentResolver-tests-activity
Test: atest IntentResolver-tests-unit:ActivityLaunchTest
Change-Id: Ie132cb3d61e139e03316063186c3ad79d2c488ef
Diffstat (limited to 'tests/activity')
3 files changed, 41 insertions, 14 deletions
diff --git a/tests/activity/src/com/android/intentresolver/ChooserWrapperActivity.java b/tests/activity/src/com/android/intentresolver/ChooserWrapperActivity.java index c0121f2e..37bbc6ce 100644 --- a/tests/activity/src/com/android/intentresolver/ChooserWrapperActivity.java +++ b/tests/activity/src/com/android/intentresolver/ChooserWrapperActivity.java @@ -54,13 +54,6 @@ public class ChooserWrapperActivity extends ChooserActivity implements IChooserW static final ChooserActivityOverrideData sOverrides = ChooserActivityOverrideData.getInstance(); private UsageStatsManager mUsm; - // ResolverActivity (the base class of ChooserActivity) inspects the launched-from UID at - // onCreate and needs to see some non-negative value in the test. - @Override - public int getLaunchedFromUid() { - return 1234; - } - @Override public ChooserListAdapter createChooserListAdapter( Context context, diff --git a/tests/activity/src/com/android/intentresolver/v2/ChooserWrapperActivity.java b/tests/activity/src/com/android/intentresolver/v2/ChooserWrapperActivity.java index e7c8cce3..64c8e49d 100644 --- a/tests/activity/src/com/android/intentresolver/v2/ChooserWrapperActivity.java +++ b/tests/activity/src/com/android/intentresolver/v2/ChooserWrapperActivity.java @@ -65,13 +65,6 @@ public class ChooserWrapperActivity extends ChooserActivity implements IChooserW sOverrides.mWorkProfileAvailability); } - // ResolverActivity (the base class of ChooserActivity) inspects the launched-from UID at - // onCreate and needs to see some non-negative value in the test. - @Override - public int getLaunchedFromUid() { - return 1234; - } - @Override public ChooserListAdapter createChooserListAdapter( Context context, diff --git a/tests/activity/src/com/android/intentresolver/v2/ui/model/TestActivityLaunchModule.kt b/tests/activity/src/com/android/intentresolver/v2/ui/model/TestActivityLaunchModule.kt new file mode 100644 index 00000000..d674bbc2 --- /dev/null +++ b/tests/activity/src/com/android/intentresolver/v2/ui/model/TestActivityLaunchModule.kt @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 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.v2.ui.model + +import android.app.Activity +import android.net.Uri +import dagger.Module +import dagger.Provides +import dagger.hilt.android.components.ActivityComponent +import dagger.hilt.android.scopes.ActivityScoped +import dagger.hilt.testing.TestInstallIn + +@Module +@TestInstallIn(components = [ActivityComponent::class], replaces = [ActivityLaunchModule::class]) +class TestActivityLaunchModule { + + @Provides + @ActivityScoped + fun activityLaunch(activity: Activity): ActivityLaunch { + return ActivityLaunch(activity.intent, LAUNCHED_FROM_UID, LAUNCHED_FROM_PACKAGE, REFERRER) + } + + companion object { + const val LAUNCHED_FROM_PACKAGE = "example.com" + const val LAUNCHED_FROM_UID = 1234 + val REFERRER: Uri = Uri.parse("android-app://$LAUNCHED_FROM_PACKAGE") + } +} |