Skip to content

Commit

Permalink
Use Activity's member Instrumentation in ActivityController
Browse files Browse the repository at this point in the history
Previously, ActivityController was using the global Instrumentation object,
which is replaced after each test. This contributed to an issue where an
Activity that leaked across tests caused illegal states to exist in
ActivityLifecycleMonitor. Instead, use the Activity's own Instrumentation
object, which will have a consistent view of the Activity's lifecycle.

PiperOrigin-RevId: 410271639
  • Loading branch information
hoisie committed Nov 17, 2021
1 parent 326991f commit 228f7a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -7,7 +7,6 @@
import static org.robolectric.util.reflector.Reflector.reflector;

import android.app.Activity;
import android.app.ActivityThread;
import android.app.Application;
import android.app.Instrumentation;
import android.content.ComponentName;
Expand Down Expand Up @@ -502,8 +501,9 @@ public ActivityController<T> recreate() {
}
}

private static Instrumentation getInstrumentation() {
return ((ActivityThread) RuntimeEnvironment.getActivityThread()).getInstrumentation();
// Get the Instrumentation object scoped to the Activity.
private Instrumentation getInstrumentation() {
return _component_.getInstrumentation();
}

/** Accessor interface for android.app.Activity.NonConfigurationInstances's internals. */
Expand Down
Expand Up @@ -372,4 +372,7 @@ void setVoiceInteractor(

@Accessor("mConfigChangeFlags")
void setConfigChangeFlags(int value);

@Accessor("mInstrumentation")
Instrumentation getInstrumentation();
}

0 comments on commit 228f7a7

Please sign in to comment.