use of org.robolectric.shadows.ShadowActivity in project android_packages_apps_Settings by LineageOS.
the class SetNewPasswordActivityTest method testChooseLockGeneric.
@Test
public void testChooseLockGeneric() {
Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
SetNewPasswordActivity activity = Robolectric.buildActivity(SetNewPasswordActivity.class).get();
activity.launchChooseLock(new Bundle());
ShadowActivity shadowActivity = shadowOf(activity);
Intent intent = shadowActivity.getNextStartedActivityForResult().intent;
assertThat(intent.getComponent()).isEqualTo(new ComponentName(activity, ChooseLockGeneric.class));
}
use of org.robolectric.shadows.ShadowActivity in project android_packages_apps_Settings by omnirom.
the class ChooseLockSettingsHelperTest method testLaunchConfirmationActivityInternalAndChallenge.
@Test
public void testLaunchConfirmationActivityInternalAndChallenge() {
final int userId = UserHandle.myUserId();
final int request = 100;
final long challenge = 10000L;
final Activity activity = Robolectric.setupActivity(Activity.class);
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
helper.launchConfirmationActivityWithExternalAndChallenge(request, "title", "header", "description", // external
false, challenge, userId);
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
Intent startedIntent = shadowActivity.getNextStartedActivity();
assertEquals(new ComponentName("com.android.settings", ConfirmLockPattern.InternalActivity.class.getName()), startedIntent.getComponent());
assertFalse(startedIntent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_RETURN_CREDENTIALS, false));
assertTrue(startedIntent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false));
assertEquals(challenge, startedIntent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0L));
assertEquals(false, (startedIntent.getFlags() & Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0);
assertEquals(false, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.ALLOW_FP_AUTHENTICATION, false));
assertEquals(false, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.DARK_THEME, false));
assertEquals(false, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.SHOW_CANCEL_BUTTON, false));
assertEquals(false, startedIntent.getBooleanExtra(ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, false));
}
use of org.robolectric.shadows.ShadowActivity in project robolectric by robolectric.
the class LocalActivityInvoker method getActivityResult.
@Override
public ActivityResult getActivityResult() {
checkNotNull(controller);
checkState(controller.get().isFinishing(), "You must finish your Activity first");
ShadowActivity shadowActivity = Shadow.extract(controller.get());
return new ActivityResult(shadowActivity.getResultCode(), shadowActivity.getResultIntent());
}
use of org.robolectric.shadows.ShadowActivity in project robolectric by robolectric.
the class RoboMonitoringInstrumentation method execStartActivity.
/**
* {@inheritDoc}
*/
@Override
public ActivityResult execStartActivity(Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) {
intentMonitor.signalIntent(intent);
ActivityResult ar = stubResultFor(intent);
if (ar != null) {
Log.i(TAG, String.format("Stubbing intent %s", intent));
} else {
ar = super.execStartActivity(who, contextThread, token, target, intent, requestCode, options);
}
if (ar != null && target != null) {
ShadowActivity shadowActivity = extract(target);
postDispatchActivityResult(shadowActivity, null, requestCode, ar);
}
return ar;
}
use of org.robolectric.shadows.ShadowActivity in project robolectric by robolectric.
the class ActivityController method configurationChange.
/**
* Performs a configuration change on the Activity.
*
* <p>If the activity is configured to handle changes without being recreated, {@link
* Activity#onConfigurationChanged(Configuration)} will be called. Otherwise, the activity is
* recreated as described <a
* href="https://developer.android.com/guide/topics/resources/runtime-changes.html">here</a>.
*
* @param newConfiguration The new configuration to be set.
* @return ActivityController instance
*/
public ActivityController<T> configurationChange(final Configuration newConfiguration) {
final Configuration currentConfig = component.getResources().getConfiguration();
final int changedBits = currentConfig.diff(newConfiguration);
currentConfig.setTo(newConfiguration);
// Can the activity handle itself ALL configuration changes?
if ((getActivityInfo(component.getApplication()).configChanges & changedBits) == changedBits) {
shadowMainLooper.runPaused(() -> {
component.onConfigurationChanged(newConfiguration);
ViewRootImpl root = getViewRoot();
if (root != null) {
if (RuntimeEnvironment.getApiLevel() <= N_MR1) {
ReflectionHelpers.callInstanceMethod(root, "updateConfiguration", ClassParameter.from(Configuration.class, newConfiguration), ClassParameter.from(boolean.class, false));
} else {
root.updateConfiguration(Display.INVALID_DISPLAY);
}
}
});
return this;
} else {
@SuppressWarnings("unchecked") final T recreatedActivity = (T) ReflectionHelpers.callConstructor(component.getClass());
final _Activity_ _recreatedActivity_ = reflector(_Activity_.class, recreatedActivity);
shadowMainLooper.runPaused(() -> {
// Set flags
_component_.setChangingConfigurations(true);
_component_.setConfigChangeFlags(changedBits);
// Perform activity destruction
final Bundle outState = new Bundle();
// The order of onPause/onStop/onSaveInstanceState is undefined, but is usually:
// onPause -> onSaveInstanceState -> onStop before API P, and onPause -> onStop ->
// onSaveInstanceState from API P.
// See
// https://developer.android.com/reference/android/app/Activity#onSaveInstanceState(android.os.Bundle) for documentation explained.
// And see ActivityThread#callActivityOnStop for related code.
_component_.performPause();
if (RuntimeEnvironment.getApiLevel() < P) {
_component_.performSaveInstanceState(outState);
if (RuntimeEnvironment.getApiLevel() <= M) {
_component_.performStop();
} else {
// API from N to O_MR1(both including)
_component_.performStop(true);
}
} else {
_component_.performStop(true, "configurationChange");
_component_.performSaveInstanceState(outState);
}
// This is the true and complete retained state, including loaders and retained
// fragments.
final Object nonConfigInstance = _component_.retainNonConfigurationInstances();
// This is the activity's "user" state
final Object activityConfigInstance = nonConfigInstance == null ? // No framework or user state.
null : reflector(_NonConfigurationInstances_.class, nonConfigInstance).getActivity();
_component_.performDestroy();
makeActivityEligibleForGc();
// Restore theme in case it was set in the test manually.
// This is not technically what happens but is purely to make this easier to use in
// Robolectric.
ShadowContextThemeWrapper shadowContextThemeWrapper = Shadow.extract(component);
int theme = shadowContextThemeWrapper.callGetThemeResId();
// Setup controller for the new activity
attached = false;
component = recreatedActivity;
_component_ = _recreatedActivity_;
// TODO: Pass nonConfigurationInstance here instead of setting
// mLastNonConfigurationInstances directly below. This field must be set before
// attach. Since current implementation sets it after attach(), initialization is not
// done correctly. For instance, fragment marked as retained is not retained.
attach(/* activityOptions= */
null, /* lastNonConfigurationInstances= */
null);
if (theme != 0) {
recreatedActivity.setTheme(theme);
}
// Set saved non config instance
_recreatedActivity_.setLastNonConfigurationInstances(nonConfigInstance);
ShadowActivity shadowActivity = Shadow.extract(recreatedActivity);
shadowActivity.setLastNonConfigurationInstance(activityConfigInstance);
// Create lifecycle
_recreatedActivity_.performCreate(outState);
if (RuntimeEnvironment.getApiLevel() <= O_MR1) {
_recreatedActivity_.performStart();
} else {
_recreatedActivity_.performStart("configurationChange");
}
_recreatedActivity_.performRestoreInstanceState(outState);
_recreatedActivity_.onPostCreate(outState);
if (RuntimeEnvironment.getApiLevel() <= O_MR1) {
_recreatedActivity_.performResume();
} else {
_recreatedActivity_.performResume(true, "configurationChange");
}
_recreatedActivity_.onPostResume();
// TODO: Call visible() too.
});
}
return this;
}
Aggregations