Script for routinely clearing downloads folder in Lockdown mode?

Solved
S
Sam-L
East of England Co-operative

Device: Samsung Galaxy Tab A8
Mobicontrol Agent Version: 15.3.0.1006
OS: Android 11

Hi,

Some users of our tablets in lockdown mode are granted access to admin mode and can download items that they wouldn't be able to in lockdown mode (namely PDF files). In admin mode, tapping these in the browser automatically downloads them to the download folder.

Is there a script or console function whereby we can enforce a daily/weekly/monthly purge of the downloads folder and delete anything in there? 

In Mobicontrol at least, I can't see anything obvious.

Many thanks in advance!

2 years ago
SOTI MobiControl
ANSWERS
MD
Matt Dermody Diamond Contributor
2 years ago

You can create and save a script with the following:

del /sdcard/Download/*

(Test on a sample device first to confirm it works, adjust as necessary)

Then use a Task Scheduler Profile to run this script on a set schedule.

Solution
S
Sam-L
2 years ago

Thanks Matt, I will give that a try and report back.

S
Sam-L
2 years ago

So I've cloned a profile and populated it with a single tablet to test.

This tablet has no SD, so I've adjusted the script slightly to this:

del / internal storage / downloads 

Using task scheduler I've set this to occur every 3 minutes, but so far the files held in internal storage remain there and I'm in administrator mode to monitor if they get wiped.

Is there anything to amend here?

RS
Rafael Schäfer
2 years ago

In android also the internal storage is named sdcard

We use following to clean this up:

del "%sdcard%/Download/*.*"
S
Sam-L
2 years ago

Thanks Rafael, 

The script, with quotations removed, shows as green in the managed scripts editor. However, when enacted, the downloads folder remains untouched. I've enforced this to occur every minute, so as to ensure it's executing what it should. 

Might there be another script to try or factor to consider?

B
Bob
2 years ago

have you checked the logs for any errors? does the agent have manage external storage permission? (request_appops_permission MANAGE_EXTERNAL_STORAGE)

RS
Rafael Schäfer
2 years ago

Do you try it via javascript? I mean this is a legcy script and there's nothing known by me like "showing green". I only know this from javascript and this script won't work there.You have to execute it as a legacy script!

And the quotation marks are needed when you have a path including spaces.

S
Sam-L
2 years ago

Thanks, I think I'd perhaps left it as a JS format, legacy has cleared this up.

ST
Shawn T
2 years ago

Hi There.

This script seems to work just fine to delete all files in the Download folder. 

del /sdcard/Download/*.*

RC
Raymond Chan Diamond Contributor
2 years ago

Hi Sam,

When using script, your own effort to do tests/tunings on your own devices is often required as working solutions often varies with devices brands/models, android firmware versions/builds, device agent versions and the way the script execution is initiated. What works today may fails on the same device tomorrow after a firmware/agent upgrade.

The %sdcard% macro often works as a generic RELATIVE base for referencing targeted file/folder path on different device models, but it might fail for some brands/models.    The recent evolving scoped-storage change for newer Android firmware versions may also add another dimension of impact. Similar uncertainty applies to other MobiControl location and standard macros.    Also, though the macro is literally called "sdcard", it does NOT actually reference any external SD-card mounted in the file system for most devices.

If using ABSOLUTE file path in your legacy scripts, please be aware that different device brand/models may have different path mounted for the "Download" directory (e.g. /sdcard/Download, /storage/emulated/0/Download, ... etc.).  This means that your script might need different customized versions if you are targeting more than one device brand/model/firmware.

RC
Raymond Chan Diamond Contributor
2 years ago

Regarding the granting of some users of tablet in lockdown mode access to admin mode for downloading pdf files to the "Download" folder,  this seems to be an abused use of the device admin mode, as there is high security consequences to casually turn a device to admin mode. Turning on admin mode is much much more than just turning off the lockdown menu.  Many feature-control restrictions and security related policies will be temporarily suspended.   For your use case, I believe there are likely many alternative solutions you can try first. For example, a script kiosk item that temporarily turns off the lockdown menu for say 2 minutes may be used.