diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.kt index 47921ce401..4735b506dd 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.kt @@ -56,6 +56,7 @@ import org.dolphinemu.dolphinemu.overlay.InputOverlayPointer import org.dolphinemu.dolphinemu.ui.main.MainPresenter import org.dolphinemu.dolphinemu.ui.main.ThemeProvider import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner +import org.dolphinemu.dolphinemu.utils.DirectoryInitialization import org.dolphinemu.dolphinemu.utils.FileBrowserHelper import org.dolphinemu.dolphinemu.utils.ThemeHelper import kotlin.math.roundToInt @@ -109,8 +110,6 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider { settings = Settings() settings.loadSettings() - updateOrientation() - // Set these options now so that the SurfaceView the game renders into is the right size. enableFullscreenImmersive() @@ -203,22 +202,20 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider { super.onResume() - // Only android 9+ support this feature. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - val attributes = window.attributes - - attributes.layoutInDisplayCutoutMode = - if (BooleanSetting.MAIN_EXPAND_TO_CUTOUT_AREA.boolean) { - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES - } else { - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER - } - - window.attributes = attributes + // If the whole app process was recreated, directory initialization might not be done yet. + // If that's the case, we can't read settings, so skip reading the settings for now and do + // it once onTitleChanged runs instead. + if (DirectoryInitialization.areDolphinDirectoriesReady()) { + updateDisplaySettings(); + } else { + // If the process was recreated and DolphinApplication.onStart didn't think it should + // start directory initialization, we have to start it, otherwise emulation will never + // start. Technically it would be nicer to ask the user for write permission first, + // but because this problem can only happen in very convoluted situations, this code is + // going to get essentially no testing, so let's go with the simplest possible fix. + DirectoryInitialization.start(this); } - updateOrientation() - DolphinSensorEventListener.setDeviceRotation(windowManager.defaultDisplay.rotation) } @@ -238,6 +235,8 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider { title = NativeLibrary.GetCurrentTitleDescription() emulationFragment?.refreshInputOverlay() + + updateDisplaySettings() } catch (_: IllegalStateException) { // Most likely the core delivered an onTitleChanged while emulation was shutting down. // Let's just ignore it, since we're about to shut down anyway. @@ -338,7 +337,20 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider { View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY } - private fun updateOrientation() { + private fun updateDisplaySettings() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val attributes = window.attributes + + attributes.layoutInDisplayCutoutMode = + if (BooleanSetting.MAIN_EXPAND_TO_CUTOUT_AREA.boolean) { + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + } else { + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER + } + + window.attributes = attributes + } + requestedOrientation = IntSetting.MAIN_EMULATION_ORIENTATION.int } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt index e403e7ef5d..637f4fb924 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt @@ -16,6 +16,7 @@ import org.dolphinemu.dolphinemu.databinding.FragmentEmulationBinding import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting import org.dolphinemu.dolphinemu.features.settings.model.Settings import org.dolphinemu.dolphinemu.overlay.InputOverlay +import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner import org.dolphinemu.dolphinemu.utils.Log import java.io.File @@ -100,7 +101,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { if (NativeLibrary.IsGameMetadataValid()) inputOverlay?.refreshControls() - run(emulationActivity!!.isActivityRecreated) + AfterDirectoryInitializationRunner().runWithLifecycle(this) { + run(emulationActivity!!.isActivityRecreated) + } } override fun onPause() {