|
| 1 | +package androidx.test.internal.platform.app; |
| 2 | + |
| 3 | +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; |
| 4 | + |
| 5 | +import android.app.Activity; |
| 6 | +import android.content.ComponentName; |
| 7 | +import android.content.Intent; |
| 8 | +import androidx.annotation.RestrictTo; |
| 9 | +import androidx.annotation.RestrictTo.Scope; |
| 10 | + |
| 11 | +/** |
| 12 | + * Handles default implementation for ActivityInvoker#getIntentForActivity |
| 13 | + * |
| 14 | + * <p>See the {@link ActivityInvoker$$CC} javadoc for prior history. |
| 15 | + * |
| 16 | + * <p>Starting in androidx.test:monitor:1.6.X, a new version of the desugar tooling was used that |
| 17 | + * generated a ActivityInvoker$-CC class. Class names with hyphens are rejected by javac, so we |
| 18 | + * cannot directly declare a ActivityInvoker$-CC class here. So instead we use a placeholder name, |
| 19 | + * and use jarjar to rename the class after the javac step. |
| 20 | + * |
| 21 | + * @hide |
| 22 | + */ |
| 23 | +@RestrictTo(Scope.LIBRARY_GROUP) |
| 24 | +public final class ActivityInvokerDesugar { |
| 25 | + |
| 26 | + private ActivityInvokerDesugar() {} |
| 27 | + |
| 28 | + // the method name must exactly match the name generated by desugar |
| 29 | + @SuppressWarnings("MethodName") |
| 30 | + public static Intent $default$getIntentForActivity( |
| 31 | + ActivityInvoker invoker, Class<? extends Activity> activityClass) { |
| 32 | + Intent intent = |
| 33 | + Intent.makeMainActivity( |
| 34 | + new ComponentName(getInstrumentation().getTargetContext(), activityClass)); |
| 35 | + if (getInstrumentation().getTargetContext().getPackageManager().resolveActivity(intent, 0) |
| 36 | + != null) { |
| 37 | + return intent; |
| 38 | + } |
| 39 | + return Intent.makeMainActivity( |
| 40 | + new ComponentName(getInstrumentation().getContext(), activityClass)); |
| 41 | + } |
| 42 | +} |
0 commit comments