summaryrefslogtreecommitdiff
path: root/java/src/com
diff options
context:
space:
mode:
author Mark Renouf <mrenouf@google.com> 2023-10-10 12:28:19 -0400
committer Mark Renouf <mrenouf@google.com> 2023-10-10 23:06:07 +0000
commit3b306cbbce743466212778fdda51cd1600b0711d (patch)
treee365e10b21405ee4b0b01909e7fa9fd67b185f2c /java/src/com
parent8b603b79c904adeaaa65e70b709d5d54e752e857 (diff)
Decouple initialization from framework lifecycle call chain
This change decouples onCreate from the actual work of setting up the application, while maintaining independent function of ResolverActivity. This allows deferring initialization work until returning from super.onCreate, when injected members are available. Bug: 300157408 Bug: 302113519 Test: atest IntentResolverUnitTests#ResolverActivityTest Change-Id: I8ed34f44d4040dce8a1292f1490fe2e724dc8473
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/intentresolver/v2/ChooserActivity.java7
-rw-r--r--java/src/com/android/intentresolver/v2/ResolverActivity.java87
2 files changed, 32 insertions, 62 deletions
diff --git a/java/src/com/android/intentresolver/v2/ChooserActivity.java b/java/src/com/android/intentresolver/v2/ChooserActivity.java
index 12e708f6..f13d87ce 100644
--- a/java/src/com/android/intentresolver/v2/ChooserActivity.java
+++ b/java/src/com/android/intentresolver/v2/ChooserActivity.java
@@ -251,6 +251,8 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
Tracer.INSTANCE.markLaunched();
+ super.onCreate(savedInstanceState);
+
final long intentReceivedTime = System.currentTimeMillis();
mLatencyTracker.onActionStart(ACTION_LOAD_SHARE_SHEET);
@@ -262,7 +264,6 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
} catch (IllegalArgumentException e) {
Log.e(TAG, "Caller provided invalid Chooser request parameters", e);
finish();
- super_onCreate(null);
return;
}
mPinnedSharedPrefs = getPinnedSharedPrefs(this);
@@ -278,9 +279,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
mChooserRequest.getTargetIntentFilter()),
mChooserRequest.getTargetIntentFilter());
-
- super.onCreate(
- savedInstanceState,
+ init(
mChooserRequest.getTargetIntent(),
mChooserRequest.getAdditionalTargets(),
mChooserRequest.getTitle(),
diff --git a/java/src/com/android/intentresolver/v2/ResolverActivity.java b/java/src/com/android/intentresolver/v2/ResolverActivity.java
index 03221c6c..9e6a15a8 100644
--- a/java/src/com/android/intentresolver/v2/ResolverActivity.java
+++ b/java/src/com/android/intentresolver/v2/ResolverActivity.java
@@ -350,57 +350,38 @@ public class ResolverActivity extends FragmentActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
- // Use a specialized prompt when we're handling the 'Home' app startActivity()
- final Intent intent = makeMyIntent();
- final Set<String> categories = intent.getCategories();
- if (Intent.ACTION_MAIN.equals(intent.getAction())
- && categories != null
- && categories.size() == 1
- && categories.contains(Intent.CATEGORY_HOME)) {
- // Note: this field is not set to true in the compatibility version.
- mResolvingHome = true;
- }
-
- onCreate(
- savedInstanceState,
- intent,
- /* additionalTargets= */ null,
- /* title= */ null,
- /* defaultTitleRes= */ 0,
- /* initialIntents= */ null,
- /* resolutionList= */ null,
- /* supportsAlwaysUseOption= */ true,
- createIconLoader(),
- /* safeForwardingMode= */ true);
- }
+ super.onCreate(savedInstanceState);
+ if (isFinishing()) {
+ // Performing a clean exit:
+ // Skip initializing any additional resources.
+ return;
+ }
+ if (mIsIntentPicker) {
+ // Use a specialized prompt when we're handling the 'Home' app startActivity()
+ final Intent intent = makeMyIntent();
+ final Set<String> categories = intent.getCategories();
+ if (Intent.ACTION_MAIN.equals(intent.getAction())
+ && categories != null
+ && categories.size() == 1
+ && categories.contains(Intent.CATEGORY_HOME)) {
+ // Note: this field is not set to true in the compatibility version.
+ mResolvingHome = true;
+ }
- /**
- * Compatibility version for other bundled services that use this overload without
- * a default title resource
- */
- protected void onCreate(
- Bundle savedInstanceState,
- Intent intent,
- CharSequence title,
- Intent[] initialIntents,
- List<ResolveInfo> resolutionList,
- boolean supportsAlwaysUseOption,
- boolean safeForwardingMode) {
- onCreate(
- savedInstanceState,
- intent,
- null,
- title,
- 0,
- initialIntents,
- resolutionList,
- supportsAlwaysUseOption,
- createIconLoader(),
- safeForwardingMode);
+ init(
+ intent,
+ /* additionalTargets= */ null,
+ /* title= */ null,
+ /* defaultTitleRes= */ 0,
+ /* initialIntents= */ null,
+ /* resolutionList= */ null,
+ /* supportsAlwaysUseOption= */ true,
+ createIconLoader(),
+ /* safeForwardingMode= */ true);
+ }
}
- protected void onCreate(
- Bundle savedInstanceState,
+ protected void init(
Intent intent,
Intent[] additionalTargets,
CharSequence title,
@@ -411,7 +392,6 @@ public class ResolverActivity extends FragmentActivity implements
TargetDataLoader targetDataLoader,
boolean safeForwardingMode) {
setTheme(appliedThemeResId());
- super.onCreate(savedInstanceState);
// Determine whether we should show that intent is forwarded
// from managed profile to owner or other way around.
@@ -1192,15 +1172,6 @@ public class ResolverActivity extends FragmentActivity implements
return intent;
}
- /**
- * Call {@link Activity#onCreate} without initializing anything further. This should
- * only be used when the activity is about to be immediately finished to avoid wasting
- * initializing steps and leaking resources.
- */
- protected final void super_onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
private ResolverMultiProfilePagerAdapter
createResolverMultiProfilePagerAdapterForOneProfile(
Intent[] initialIntents,