thaarok / cordova-plugin-kiosk

Cordova plugin to use Cordova application "in kiosk mode" and as Android launcher
Apache License 2.0
142 stars 101 forks source link

KioskPlugin.exitKiosk() does not seem to work #46

Open wiserweb opened 6 years ago

wiserweb commented 6 years ago

This issue is occurring using Genymotion v2.12.0 Android emulator with S7 Android 6.0.0 API 23 image.

The app has a button, 'Exit Kiosk Mode' when it is clicked I can see the KioskPlugin.exitKiosk(); firing but still cannot switch app or access settings to change default launcher.

If the command KioskPlugin.exitKiosk(); is run directly in the console it returns undefined.

Any suggestions?

Thanks.

thaarok commented 6 years ago

Does KioskPlugin.isInKiosk(function(isInKiosk){ alert(isInKiosk); }); returns true for you? (=is activity from this plugin running?) Does KioskPlugin.isSetAsLauncher(function(isLauncher){ alert(isLauncher); }); returns true for you? (=is that activity set as launcher?)

wiserweb commented 6 years ago

Hi, yes they are both returning true. The app is definitely in Kiosk mode.

I'm not sure what the normal behavior of exitKiosk should be.

Would it simply allow me to switch apps or display a menu to choose a new Launcher?

thaarok commented 6 years ago

exitKiosk shows menu to choose launcher to start - typically to go into standard launcher of the phone. Is some menu like that shown? If yes, just choose your usual launcher to get into phone menu. Just note that it allows to go into phone menu to set something (change default launcher in phone settings), but when press Home button, you will be returned back into the kiosk app - if you will not change launcher in settings manually.

wiserweb commented 6 years ago

Thanks for clarification.

I went into that menu to manually set the launcher to the app initially. When exitKiosk is fired though there is no menu displayed to choose a launcher.

The Android image mentioned above provide the choice of two launchers by default, Pixel Launcher and Google Launcher.

After setting the app as default launcher I cannot get back into settings or anything so I have to delete the image.

Have you tried it with Genymotion? Perhaps the root cause of this issue has to do with the android image that is supplied by the emulator. Just speculation at this point.

If you test with Genymotion, probably a good idea to clone the test image you use to test the plugin to avoid having to recreate the image from scratch.

wiserweb commented 6 years ago

Hi, we can rule out that this issue is caused by using a Genymotion android image.

I have tried with POP7 Alcatel Tablet and able to reproduce the issue. I can confirm no launch selector menu is displayed when using this function on this device.

KioskPlugin.exitKiosk();

thaarok commented 6 years ago

Can you obtain list of installed launchers (activities for using in intent) on your testing device/emulator?

wiserweb commented 6 years ago

Yes, launchers on Genymotion Android S7 image are 'Google Now Launcher' and 'Pixel Launcher'.

I did some more testing today and was able to get the Select launcher dialog to display using this plugin (https://github.com/guatedude2/cordova-plugin-kiosk-launcher) which is a based on your plugin.

In your codebase the function is exitKiosk and guatedude2 it is switchLauncher.

Comparing the two native Android calls they seem nearly identical except for one line.

KioskActivity.kioskModeEnabled = false;

guatedude2

       } else if (SWITCH_LAUNCHER.equals(action)) {
                KioskActivity.kioskModeEnabled = false;
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                Intent chooser = Intent.createChooser(intent, "Select destination...");
                if (intent.resolveActivity(cordova.getActivity().getPackageManager()) != null) {
                    cordova.getActivity().startActivity(chooser);
                }

                callbackContext.success();
                return true;
            }

hkalina

           } else if (EXIT_KIOSK.equals(action)) {

                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                Intent chooser = Intent.createChooser(intent, "Select destination...");
                if (intent.resolveActivity(cordova.getActivity().getPackageManager()) != null) {
                    cordova.getActivity().startActivity(chooser);
                }

                callbackContext.success();
                return true;               
thaarok commented 6 years ago

That is weird - both projects use identical code for existKiosk... Can you record and provide log from adb logcat ? If you can, try to add following additional debug output into the plugin code and re-add plugin:

                if (intent.resolveActivity(cordova.getActivity().getPackageManager()) != null) {
                    cordova.getActivity().startActivity(chooser);
                    System.out.println("Kiosk: activity chooser started"); // this
                } else {
                    System.out.println("Kiosk: unable to resolve launcher activity"); // and this
                }
thaarok commented 6 years ago

Please retest with latest version. I just tested on Windows 10 + latest Genymotion + Android you mention and kiosk exiting works ok: https://ctrlv.cz/E3a9 If problem persists, test with demo application: https://github.com/hkalina/cordova-kiosk-demo

thaarok commented 6 years ago

Unable to reproduce - closing - feel free to reopen if will find steps to reproduce the issue.

wiserweb commented 6 years ago

Haven't had a chance to test yet. I will test again with screen recording and share results here. Thanks.

thaarok commented 6 years ago

No screen recording needed - I need way to reproduce the issue on my machine or more info at least. Please, try to compile and run the demo app: https://github.com/hkalina/cordova-kiosk-demo If there WILL be the same problem, check your build environment/downloaded Android image - it is working for me on image you mentioned. If there WILL NOT be the same problem, try to find what is different in your project - send source of minimal failing project here.

wiserweb commented 6 years ago

I will be using Meteor sample Todo application (https://github.com/meteor/todos) to replicate. Actual project which would not display Launch screen is also Meteor-based application. I'll commit code to a new repo so that it can be reproduced on your end.

The Meteor app is built with same HTML/CSS/Javascript so very similar the sample kiosk-demo you created for this plugin.

I'm as puzzled as your are as to why this issue is occurring. I'll do a screen record just so we're completely on the same page as to what might be the root cause.

LucaColombi commented 6 years ago

Hello, similar proplem, exitKiosk does nothing.

But if I read correctly, in my case I wuld need a real exit kiosk: Some way to disable kiosk, or prevent it from starting, actually I can only exit the application and no send it in background, how could I achieve it?

thaarok commented 6 years ago

@LucaColombi the exitKiosk() should show launcher selection - which allows to switch to regular lanuncher and the current task is sent to background. Can you provide steps to reproducing?

posipunk commented 6 years ago

@hkalina @LucaColombi I'm developing an Ionic application and had the same issue where the exitKiosk does nothing (isInKiosk returns true, isSetAsLauncher returns true). Tested on a Samsung Note 8 My workaround for now is this.platform.exitApp(); which closes the application and gives me the opportunity to switch launchers