MraidController { @TargetApi(VERSION_CODES.HONEYCOMB_MR2) @VisibleForTesting boolean shouldAllowForceOrientation(final MraidOrientation newOrientation) { if (newOrientation == MraidOrientation.NONE) { return true; } if (mActivity == null) { return false; } final ActivityInfo activityInfo; try { activityInfo = mActivity.getPackageManager().getActivityInfo( new ComponentName(mActivity, mActivity.getClass()), 0); } catch (PackageManager.NameNotFoundException e) { return false; } final int activityOrientation = activityInfo.screenOrientation; if (activityOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { return activityOrientation == newOrientation.getActivityInfoOrientation(); } boolean containsNecessaryConfigChanges = bitMaskContainsFlag(activityInfo.configChanges, CONFIG_ORIENTATION); if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR2) { containsNecessaryConfigChanges = containsNecessaryConfigChanges && bitMaskContainsFlag(activityInfo.configChanges, CONFIG_SCREEN_SIZE); } return containsNecessaryConfigChanges; } MraidController(@NonNull Context context, @NonNull AdConfiguration adConfiguration,
            @NonNull PlacementType placementType); @VisibleForTesting  MraidController(@NonNull Context context, @NonNull AdConfiguration adConfiguration,
            @NonNull PlacementType placementType,
            @NonNull MraidBridge bridge, @NonNull MraidBridge twoPartBridge,
            @NonNull ScreenMetricsWaiter screenMetricsWaiter); void setMraidListener(@Nullable MraidListener mraidListener); void setUseCustomCloseListener(@Nullable UseCustomCloseListener listener); void setDebugListener(@Nullable MraidWebViewDebugListener debugListener); void loadContent(@NonNull String htmlData); void pause(); void resume(); void destroy(); @NonNull FrameLayout getAdContainer(); void loadJavascript(@NonNull String javascript); @NonNull Context getContext();  }
@Test public void shouldAllowForceOrientation_withNoneOrientation_shouldReturnTrue() throws PackageManager.NameNotFoundException { setMockActivityInfo(true, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, ActivityInfo.CONFIG_ORIENTATION | ActivityInfo.CONFIG_SCREEN_SIZE); final boolean result = subject.shouldAllowForceOrientation(MraidOrientation.NONE); assertThat(result).isTrue(); }
@Test public void shouldAllowForceOrientation_withApplicationContext_shouldReturnFalse() throws PackageManager.NameNotFoundException { setMockActivityInfo(true, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, ActivityInfo.CONFIG_ORIENTATION | ActivityInfo.CONFIG_SCREEN_SIZE); subject = new MraidController( activity.getApplicationContext(), mockAdConfiguration, PlacementType.INLINE, mockBridge, mockTwoPartBridge, mockScreenMetricsWaiter); final boolean result = subject.shouldAllowForceOrientation(MraidOrientation.PORTRAIT); assertThat(result).isFalse(); }