Add Home Screen Item which sends script to device

Solved
LW

Hello,

sometimes our devices have an internet connection via WIFI or mobile but they are shown as disconnected in the mobicontrol console. I think that the script '_resetfailedrcdetectionflag restartagent' would help in this instance but as there is no connection from the console to the device I can't send the script.

My idea was to create a home screen item which execute the script but I don't know which action need to be chosen or how to build the intent for the script.

The devices are enrolled via AE and we are using the activity suppression in our lockscreen.

Kind regards,

Lucas

a year ago
Android
ANSWERS
ÖC
Ömercan C.
a year ago

Hi

You can create a script and deploy it to the device using the FileSync rule. Then you can deploy it as a lockdown app.

  • File: "example.cmd" (you can simply save the script using Notepad)
  • Lockdown: script://%sdcard%/Download/example.cmd
    • Item: Custom

Another alternative might be the 'Out of Contact' feature, which you can find under profile configurations.

LW
Lucas Wortmann
a year ago

Thanks for the fast help.
The 'Out of Contact' feature was previously unknown to me, I will definitely try this out. An option for the user to activly restart the agent would be ideal. I tried the script with FileSync you mentioned an it works. Unfortunatley I can't use Javascript as my device response with "script command is not supported by device". I would like to have a popup so the user needs to confirm the restart, do you have another solution to this in mind?

script from this thread i've tried (https://discussions.soti.net/thread/send-message-and-open-app-after-ckick-ok): 
mobicontrol.message.createYesNoDialog('Wollen Sie die Verbindng zum SOTI neustarten?').withCallback(onConfirm).show();

function onConfirm(result) {
    if (result.isYesButton) {
        mobicontrol.log.info('The Yes button was clicked');
         mobicontrol.agent.restart();         
    } else if (result.isNoButton) {
        mobicontrol.log.info('The No button was clicked');
    } else if (result.isDismissed) {
        mobicontrol.log.info('The dialog was dismissed');
    }
}

M
Marcel
a year ago

I'm not sure about this but I thought I might mention it anyway since I can run javascript through a link on my Lockdown with AE devices (Panasonic with Android 11). Try adding this line on the top of your script if you haven't already:

#!/usr/bin/env js

If it isn't working or if you already have it, it might be as you say, not supported by the device.


This is the whole script that I am using and there is pop-ups on the screen to confirm etc.

#!/usr/bin/env js
 
var UpgradeOSVersion = '11';
var MobiMinVersion = 15131071;
var PCGFilePath = '/sdcard/OSUpdateNeededFiles/TriggerOSUpdate.pcg';
 
mobicontrol.log.info('Starting FOTA upgrade script.');
if (CheckMobiVersion(MobiMinVersion) && CheckDeviceOSVersion(UpgradeOSVersion) && CheckBatteryLevel()) {
mobicontrol.log.info('MobiControl version, OS and Battery OK to continue running the script.');
mobicontrol.message.createYesNoDialog('Uppdatering av enhet kommer starta när du trycker på Ja, det tar cirka 10-15 minuter.')
    .withCallback(onConfirm).show();
} else {
mobicontrol.message.createInfoDialog('Enheten uppfyller inte alla krav för att kunna påbörja uppdatering. Kontrollera att batterinivån är minst 50%. Om det här meddelandet kommer trots det kontakta IT-supporten')
.show();
 
function CheckMobiVersion(MobiMinVersion) {
if (mobicontrol.agent.versionCode >= MobiMinVersion) {
mobicontrol.log.info("Script is supported on agent with version code " + mobicontrol.agent.versionCode);
return true;
} else {
mobicontrol.log.warn("Script is not supported on agent with version code " + mobicontrol.agent.versionCode + "Minimum API: " +MobiMinVersion);
return false;
}
}
 
function CheckDeviceOSVersion(UpgradeOSVersion) {
if (mobicontrol.os.version != UpgradeOSVersion) {
mobicontrol.log.info("Device not upgraded to Android 11 has " + mobicontrol.os.version);
return true;
} else {
mobicontrol.log.warn("Device already upgraded to Android: " + mobicontrol.os.version);
return false;
}
}
 
function CheckBatteryLevel() {
if (mobicontrol.battery.level >= 0.5 || mobicontrol.battery.isCharging) {
mobicontrol.log.info("Charging = " + mobicontrol.battery.isCharging + " , battery level = " + mobicontrol.battery.level + ". Device is charging or battery level OK." );
return true;
} else {
mobicontrol.log.warn("Device is not plugged in " + mobicontrol.battery.isCharging + " or battery level to low " + mobicontrol.battery.level + ".");
return false;
}
}
 
function onConfirm(result) {
if (result.isYesButton){
mobicontrol.log.info('Upgrade is starting');
mobicontrol.packages.install(PCGFilePath);
mobicontrol.agent.checkIn();
} else if (result.isNoButton) {
mobicontrol.log.info('The No button was clicked');
} else if (result.isDismissed) {
mobicontrol.log.info('The dialog was dismissed');
}
}
Solution
LW
Lucas Wortmann
a year ago

Thanks for the hint with the first line, our scripts are working. 

I don't think that the _resetfailedrcdetectionflag will help, so ou need only the restartagent.

But you could also try to just turn off the mobile data connection (don't know if you use LTE or Wifi or both, just choose the right one) and re-enable it. If you haven't locked the statusbar this should be possible the easiest.

If you still need a script to be executed Ömercan has already posted possible solutions (or just do a device reboot).

But in general if you see this more often, ensure that you disabled doze mode, so that the agent is running all the time (feature control profile) and not going to sleep.

ZC
Zafer Cigdem
a year ago

You may use .cmd/.bat file method by using Out of Contact Policy, but I'd prefer using the connect -f instead of restartagent as a script, feel free to test first. Thank you

Zafer

LW
Lucas Wortmann
a year ago

Hey, thanks for the suggestion. We have deployed a script for the agent restart. Would you be so kind and explain me the difference between 'connect' and 'restartagent'? After executing the Device is unavailable for max. 10sec but should also perform the connect or may we encounter problems with the restart?

For the future I try to also add the Out of Contact Policy but I need to find a good time after when it should apply.

Kind regards,
Lucas

S
SGMOD@SOTI
a year ago

Hi Lucas Wortmann,

Thanks for posting on SOTI Pulse, Thanks Ömercan,Marcel and Rafael for responding to the post, your expertise and willingness to help are greatly appreciated!

Have you had an opportunity to test the suggested solutions by Ömercan, Marcel and Rafael, and has it successfully addressed your query?

If not, or If you have any additional questions or concerns, please don't hesitate to reach out. We're dedicated to providing assistance and support.

LW
Lucas Wortmann
a year ago

Sorry for the late answer, I haven't had time to test these things. The hint from Marcel with the line '#!/usr/bin/env js' let our devices execute the script. 
So now I'm using the FileSync rule with a custom Lockdown item which calls the script file. 
My only problem is how could I implement an error message if the script file isn't available on the device? Per default the user will get a message 'script execution failed'