cordova-plugin-kiosk icon indicating copy to clipboard operation
cordova-plugin-kiosk copied to clipboard

Feature "allowedPackages"

Open marc7000 opened this issue 8 years ago • 3 comments

I need help to implement an "allowedPackages" feature like "allowedKeys". So you can enable other packages (e.g. "com.android.chrome") to open from Kiosk App.

KioskPlugin.setAllowedPackages(["com.android.chrome", "com.google.android.youtube" ]);

Is it possible to implement this in the "onWindowFocusChanged" handler in the file "KioskActivity.java"?

Thanks!

marc7000 avatar Nov 03 '17 11:11 marc7000

The activity has no info who has taken the focus - it only gets info that it has lost it. But kiosk also kills only system dialogs, like power off dialog and notifications - if you start new activity using intent, it will be started. (But in this new started activity the user will not be restricted by kiosk anymore - will be able to exit kiosk from chrome/youtube.)

thaarok avatar Nov 03 '17 16:11 thaarok

Ok, thanks, I thought so. Sorry I have no experience with Java and Android. What is the best solution to implement the feature?

marc7000 avatar Nov 03 '17 18:11 marc7000

We had to fork and customize this great plugin to fit our requeriments, something like following inside HomeActivity.java, and specifically for Llolipop and above:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
              UsageStatsManager mUsageStatsManager = (UsageStatsManager)getSystemService("usagestats");
              long time = System.currentTimeMillis();

              List<UsageStats> stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000*10, time);
              // Sort the stats by the last time used
              long recentTime = 0;

              if(stats != null) {
                for (UsageStats stat : stats) {

                  if (stat.getLastTimeStamp() > recentTime) {
                    recentTime = stat.getLastTimeStamp();
                    recentPkg = stat.getPackageName();
                  }
                }
              }

Then comparing recentPkg to the apps we need the users can open. Also it needs to configure Lollipop to allow our App to read Usage Stats. It implies tweaking in some other points.

So you need somebody who knows Java.

Your "allowedPackages" feature is totally possible.

Good luck.

paranoico avatar Nov 03 '17 18:11 paranoico