diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 0ef4d627c..b92697a40 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -40,6 +40,7 @@ #if defined(__ANDROID__) #include "InputOverlay.h" +#include "utils/PlatformUtilAndroid.h" #endif #include @@ -76,8 +77,11 @@ GuiMenu::GuiMenu() if (!Settings::getInstance()->getBool("ForceKiosk") && Settings::getInstance()->getString("UIMode") != "kiosk") { -#if defined(__APPLE__) || defined(__ANDROID__) +#if defined(__APPLE__) addEntry("QUIT ES-DE", mMenuColorPrimary, false, [this] { openQuitMenu(); }); +#elif defined(__ANDROID__) + if (!AndroidVariables::sIsHomeApp) + addEntry("QUIT ES-DE", mMenuColorPrimary, false, [this] { openQuitMenu(); }); #else if (Settings::getInstance()->getBool("ShowQuitMenu")) addEntry("QUIT", mMenuColorPrimary, true, [this] { openQuitMenu(); }); @@ -1791,16 +1795,31 @@ void GuiMenu::openOtherOptions() #endif #if defined(__ANDROID__) - // Whether swiping or pressing back should exit the application. - auto backEventAppExit = std::make_shared(); - backEventAppExit->setState(Settings::getInstance()->getBool("BackEventAppExit")); - s->addWithLabel("BACK BUTTON/BACK SWIPE EXITS APP", backEventAppExit); - s->addSaveFunc([backEventAppExit, s] { - if (backEventAppExit->getState() != Settings::getInstance()->getBool("BackEventAppExit")) { - Settings::getInstance()->setBool("BackEventAppExit", backEventAppExit->getState()); - s->setNeedsSaving(); - } - }); + if (!AndroidVariables::sIsHomeApp) { + // Whether swiping or pressing back should exit the application. + auto backEventAppExit = std::make_shared(); + backEventAppExit->setState(Settings::getInstance()->getBool("BackEventAppExit")); + s->addWithLabel("BACK BUTTON/BACK SWIPE EXITS APP", backEventAppExit); + s->addSaveFunc([backEventAppExit, s] { + if (backEventAppExit->getState() != + Settings::getInstance()->getBool("BackEventAppExit")) { + Settings::getInstance()->setBool("BackEventAppExit", backEventAppExit->getState()); + s->setNeedsSaving(); + } + }); + } + else { + // If we're running as the Android home app then we don't allow the application to quit, + // so simply add a disabled dummy switch in this case. + auto backEventAppExit = std::make_shared(); + s->addWithLabel("BACK BUTTON/BACK SWIPE EXITS APP", backEventAppExit); + backEventAppExit->setEnabled(false); + backEventAppExit->setState(false); + backEventAppExit->setOpacity(DISABLED_OPACITY); + backEventAppExit->getParent() + ->getChild(backEventAppExit->getChildIndex() - 1) + ->setOpacity(DISABLED_OPACITY); + } #endif if (Settings::getInstance()->getBool("DebugFlag")) { diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index c1e90562f..4d7983701 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -701,6 +701,14 @@ int main(int argc, char* argv[]) LOG(LogInfo) << applicationName << " " << PROGRAM_VERSION_STRING << "-" << ANDROID_VERSION_CODE << " (r" << PROGRAM_RELEASE_NUMBER << "), built " << PROGRAM_BUILT_STRING; + + if (AndroidVariables::sIsHomeApp) { + LOG(LogInfo) << "Running as the Android home app"; + } + else { + LOG(LogInfo) << "Running as a regular Android app"; + } + #else LOG(LogInfo) << applicationName << " " << PROGRAM_VERSION_STRING << " (r" << PROGRAM_RELEASE_NUMBER << "), built " << PROGRAM_BUILT_STRING; diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index ed40c1fa2..d0e9d078e 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -26,6 +26,7 @@ #if defined(__ANDROID__) #define TOUCH_GUID_STRING "-3" +#include "utils/PlatformUtilAndroid.h" #endif namespace @@ -477,9 +478,11 @@ bool InputManager::parseEvent(const SDL_Event& event) return false; #if defined(__ANDROID__) - // Quit application if the back button is pressed or if the back gesture is used. + // Quit application if the back button is pressed or if the back gesture is used, + // unless we're set as the Android home app. if (event.key.keysym.sym == SDLK_AC_BACK && - Settings::getInstance()->getBool("BackEventAppExit")) { + Settings::getInstance()->getBool("BackEventAppExit") && + !AndroidVariables::sIsHomeApp) { SDL_Event quit {}; quit.type = SDL_QUIT; SDL_PushEvent(&quit); @@ -493,7 +496,7 @@ bool InputManager::parseEvent(const SDL_Event& event) #if defined(__APPLE__) if (quitShortcut != "CmdQ") { #elif defined(__ANDROID__) - if (true) { + if (!AndroidVariables::sIsHomeApp) { #else if (quitShortcut != "AltF4") { #endif