package com.smartboard.sdms.agent;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.objects.ServiceHelper;
import anywheresoftware.b4a.debug.*;

public class messageservice extends android.app.Service{
	public static class messageservice_BR extends android.content.BroadcastReceiver {

		@Override
		public void onReceive(android.content.Context context, android.content.Intent intent) {
            BA.LogInfo("** Receiver (messageservice) OnReceive **");
			android.content.Intent in = new android.content.Intent(context, messageservice.class);
			if (intent != null)
				in.putExtra("b4a_internal_intent", intent);
            ServiceHelper.StarterHelper.startServiceFromReceiver (context, in, false, BA.class);
		}

	}
    static messageservice mostCurrent;
	public static BA processBA;
    private ServiceHelper _service;
    public static Class<?> getObject() {
		return messageservice.class;
	}
	@Override
	public void onCreate() {
        super.onCreate();
        mostCurrent = this;
        if (processBA == null) {
		    processBA = new BA(this, null, null, "com.smartboard.sdms.agent", "com.smartboard.sdms.agent.messageservice");
            if (BA.isShellModeRuntimeCheck(processBA)) {
                processBA.raiseEvent2(null, true, "SHELL", false);
		    }
            try {
                Class.forName(BA.applicationContext.getPackageName() + ".main").getMethod("initializeProcessGlobals").invoke(null, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            processBA.loadHtSubs(this.getClass());
            ServiceHelper.init();
        }
        _service = new ServiceHelper(this);
        processBA.service = this;
        
        if (BA.isShellModeRuntimeCheck(processBA)) {
			processBA.raiseEvent2(null, true, "CREATE", true, "com.smartboard.sdms.agent.messageservice", processBA, _service, anywheresoftware.b4a.keywords.Common.Density);
		}
        if (!false && ServiceHelper.StarterHelper.startFromServiceCreate(processBA, false) == false) {
				
		}
		else {
            processBA.setActivityPaused(false);
            BA.LogInfo("*** Service (messageservice) Create ***");
            processBA.raiseEvent(null, "service_create");
        }
        processBA.runHook("oncreate", this, null);
        if (false) {
			if (ServiceHelper.StarterHelper.runWaitForLayouts() == false) {
                BA.LogInfo("stopping spontaneous created service");
                stopSelf();
            }
		}
    }
		@Override
	public void onStart(android.content.Intent intent, int startId) {
		onStartCommand(intent, 0, 0);
    }
    @Override
    public int onStartCommand(final android.content.Intent intent, int flags, int startId) {
    	if (ServiceHelper.StarterHelper.onStartCommand(processBA, new Runnable() {
            public void run() {
                handleStart(intent);
            }}))
			;
		else {
			ServiceHelper.StarterHelper.addWaitForLayout (new Runnable() {
				public void run() {
                    processBA.setActivityPaused(false);
                    BA.LogInfo("** Service (messageservice) Create **");
                    processBA.raiseEvent(null, "service_create");
					handleStart(intent);
                    ServiceHelper.StarterHelper.removeWaitForLayout();
				}
			});
		}
        processBA.runHook("onstartcommand", this, new Object[] {intent, flags, startId});
		return android.app.Service.START_STICKY;
    }
    public void onTaskRemoved(android.content.Intent rootIntent) {
        super.onTaskRemoved(rootIntent);
        if (false)
            processBA.raiseEvent(null, "service_taskremoved");
            
    }
    private void handleStart(android.content.Intent intent) {
    	BA.LogInfo("** Service (messageservice) Start **");
    	java.lang.reflect.Method startEvent = processBA.htSubs.get("service_start");
    	if (startEvent != null) {
    		if (startEvent.getParameterTypes().length > 0) {
    			anywheresoftware.b4a.objects.IntentWrapper iw = ServiceHelper.StarterHelper.handleStartIntent(intent, _service, processBA);
    			processBA.raiseEvent(null, "service_start", iw);
    		}
    		else {
    			processBA.raiseEvent(null, "service_start");
    		}
    	}
    }

	public void onTimeout(int startId) {
        BA.LogInfo("** Service (messageservice) Timeout **");
        anywheresoftware.b4a.objects.collections.Map params = new anywheresoftware.b4a.objects.collections.Map();
        params.Initialize();
        params.Put("StartId", startId);
        processBA.raiseEvent(null, "service_timeout", params);
            
    }
	@Override
	public void onDestroy() {
        super.onDestroy();
        if (false) {
            BA.LogInfo("** Service (messageservice) Destroy (ignored)**");
        }
        else {
            BA.LogInfo("** Service (messageservice) Destroy **");
		    processBA.raiseEvent(null, "service_destroy");
            processBA.service = null;
		    mostCurrent = null;
		    processBA.setActivityPaused(true);
            processBA.runHook("ondestroy", this, null);
        }
	}

@Override
	public android.os.IBinder onBind(android.content.Intent intent) {
		return null;
	}public anywheresoftware.b4a.keywords.Common __c = null;
public static String _serverurl = "";
public static String _channelid = "";
public static String _servicechannelid = "";
public static long _heartbeatinterval = 0L;
public static int _retrydelay = 0;
public static anywheresoftware.b4a.objects.Timer _messagetimer = null;
public static anywheresoftware.b4a.objects.Timer _remotesessiontimer = null;
public static boolean _isremotesessionactive = false;
public static int _perm_user = 0;
public static int _perm_system = 0;
public static int _perm_root = 0;
public static int _perm_knox = 0;
public static int _perm_sony = 0;
public static int _currentpermissionlevel = 0;
public static String _manufacturer = "";
public com.smartboard.sdms.agent.main _main = null;
public com.smartboard.sdms.agent.starter _starter = null;
public com.smartboard.sdms.agent.broadcastdisplay _broadcastdisplay = null;
public com.smartboard.sdms.agent.httputils2service _httputils2service = null;
public static String  _acknowledgebroadcast(int _broadcastid) throws Exception{
anywheresoftware.b4a.objects.collections.Map _data = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _json = null;
com.smartboard.sdms.agent.httpjob _job = null;
 //BA.debugLineNum = 436;BA.debugLine="Sub AcknowledgeBroadcast(broadcastId As Int)";
 //BA.debugLineNum = 437;BA.debugLine="Try";
try { //BA.debugLineNum = 438;BA.debugLine="Dim data As Map";
_data = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 439;BA.debugLine="data.Initialize";
_data.Initialize();
 //BA.debugLineNum = 440;BA.debugLine="data.Put(\"broadcast_id\", broadcastId)";
_data.Put((Object)("broadcast_id"),(Object)(_broadcastid));
 //BA.debugLineNum = 441;BA.debugLine="Dim json As JSONGenerator";
_json = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 442;BA.debugLine="json.Initialize(data)";
_json.Initialize(_data);
 //BA.debugLineNum = 443;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 444;BA.debugLine="job.Initialize(\"ack_broadcast\", Me)";
_job._initialize /*String*/ (processBA,"ack_broadcast",messageservice.getObject());
 //BA.debugLineNum = 445;BA.debugLine="job.PostString(ServerURL & \"/broadcasts/ac";
_job._poststring /*String*/ (_serverurl+"/broadcasts/acknowledge",_json.ToString());
 //BA.debugLineNum = 446;BA.debugLine="job.GetRequest.SetHeader(\"Authorization\",";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Authorization","Bearer "+anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt"));
 } 
       catch (Exception e12) {
			processBA.setLastException(e12); //BA.debugLineNum = 448;BA.debugLine="Log(\"Error acknowledging broadcast: \" & La";
anywheresoftware.b4a.keywords.Common.LogImpl("42555916","Error acknowledging broadcast: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 450;BA.debugLine="End Sub";
return "";
}
public static String  _acknowledgecommand(int _commandid,boolean _executed,String _errormessage) throws Exception{
anywheresoftware.b4a.objects.collections.Map _data = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _json = null;
com.smartboard.sdms.agent.httpjob _job = null;
 //BA.debugLineNum = 593;BA.debugLine="Sub AcknowledgeCommand(commandId As Int, executed";
 //BA.debugLineNum = 594;BA.debugLine="If commandId <= 0 Then Return ' Don't acknowle";
if (_commandid<=0) { 
if (true) return "";};
 //BA.debugLineNum = 595;BA.debugLine="Try";
try { //BA.debugLineNum = 596;BA.debugLine="Dim data As Map";
_data = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 597;BA.debugLine="data.Initialize";
_data.Initialize();
 //BA.debugLineNum = 598;BA.debugLine="data.Put(\"command_id\", commandId)";
_data.Put((Object)("command_id"),(Object)(_commandid));
 //BA.debugLineNum = 599;BA.debugLine="data.Put(\"executed\", executed)";
_data.Put((Object)("executed"),(Object)(_executed));
 //BA.debugLineNum = 600;BA.debugLine="If errorMessage <> \"\" Then data.Put(\"error";
if ((_errormessage).equals("") == false) { 
_data.Put((Object)("error"),(Object)(_errormessage));};
 //BA.debugLineNum = 602;BA.debugLine="Dim json As JSONGenerator";
_json = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 603;BA.debugLine="json.Initialize(data)";
_json.Initialize(_data);
 //BA.debugLineNum = 604;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 605;BA.debugLine="job.Initialize(\"ack_command\", Me)";
_job._initialize /*String*/ (processBA,"ack_command",messageservice.getObject());
 //BA.debugLineNum = 606;BA.debugLine="job.PostString(ServerURL & \"/devices/ackno";
_job._poststring /*String*/ (_serverurl+"/devices/acknowledge-command",_json.ToString());
 //BA.debugLineNum = 607;BA.debugLine="job.GetRequest.SetHeader(\"Authorization\",";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Authorization","Bearer "+anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt"));
 //BA.debugLineNum = 608;BA.debugLine="Log(\"Command acknowledgment sent for comma";
anywheresoftware.b4a.keywords.Common.LogImpl("43014671","Command acknowledgment sent for command ID: "+BA.NumberToString(_commandid)+" (Executed: "+BA.ObjectToString(_executed)+")",0);
 } 
       catch (Exception e16) {
			processBA.setLastException(e16); //BA.debugLineNum = 610;BA.debugLine="Log(\"Error acknowledging command: \" & Last";
anywheresoftware.b4a.keywords.Common.LogImpl("43014673","Error acknowledging command: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 612;BA.debugLine="End Sub";
return "";
}
public static void  _capturewithmediaprojection(int _commandid,String _screenshotdir,String _tempfilename) throws Exception{
ResumableSub_CaptureWithMediaProjection rsub = new ResumableSub_CaptureWithMediaProjection(null,_commandid,_screenshotdir,_tempfilename);
rsub.resume(processBA, null);
}
public static class ResumableSub_CaptureWithMediaProjection extends BA.ResumableSub {
public ResumableSub_CaptureWithMediaProjection(com.smartboard.sdms.agent.messageservice parent,int _commandid,String _screenshotdir,String _tempfilename) {
this.parent = parent;
this._commandid = _commandid;
this._screenshotdir = _screenshotdir;
this._tempfilename = _tempfilename;
}
com.smartboard.sdms.agent.messageservice parent;
int _commandid;
String _screenshotdir;
String _tempfilename;
anywheresoftware.b4j.object.JavaObject _jo = null;
anywheresoftware.b4j.object.JavaObject _metrics = null;
int _width = 0;
int _height = 0;
int _screendensity = 0;
anywheresoftware.b4j.object.JavaObject _manager = null;
anywheresoftware.b4j.object.JavaObject _projection = null;
anywheresoftware.b4j.object.JavaObject _readerstatic = null;
anywheresoftware.b4j.object.JavaObject _reader = null;
anywheresoftware.b4j.object.JavaObject _display = null;
anywheresoftware.b4j.object.JavaObject _image = null;
Object[] _planes = null;
anywheresoftware.b4j.object.JavaObject _plane = null;
anywheresoftware.b4j.object.JavaObject _buffer = null;
int _pixelstride = 0;
int _rowstride = 0;
int _rowpadding = 0;
anywheresoftware.b4j.object.JavaObject _bitmapstatic = null;
anywheresoftware.b4j.object.JavaObject _configstatic = null;
Object _config = null;
anywheresoftware.b4j.object.JavaObject _bmpjo = null;
anywheresoftware.b4a.objects.drawable.CanvasWrapper.BitmapWrapper _bmp = null;
anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper _out = null;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
try {

        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
 //BA.debugLineNum = 673;BA.debugLine="Try";
if (true) break;

case 1:
//try
this.state = 16;
this.catchState = 15;
this.state = 3;
if (true) break;

case 3:
//C
this.state = 4;
this.catchState = 15;
 //BA.debugLineNum = 675;BA.debugLine="Dim jo As JavaObject";
_jo = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 676;BA.debugLine="jo.InitializeContext";
_jo.InitializeContext(processBA);
 //BA.debugLineNum = 678;BA.debugLine="Dim metrics As JavaObject = jo.RunMethodJO";
_metrics = new anywheresoftware.b4j.object.JavaObject();
_metrics = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_jo.RunMethodJO("getResources",(Object[])(anywheresoftware.b4a.keywords.Common.Null)).RunMethod("getDisplayMetrics",(Object[])(anywheresoftware.b4a.keywords.Common.Null))));
 //BA.debugLineNum = 679;BA.debugLine="Dim width As Int = metrics.GetField(\"width";
_width = (int)(BA.ObjectToNumber(_metrics.GetField("widthPixels")));
 //BA.debugLineNum = 680;BA.debugLine="Dim height As Int = metrics.GetField(\"heig";
_height = (int)(BA.ObjectToNumber(_metrics.GetField("heightPixels")));
 //BA.debugLineNum = 681;BA.debugLine="Dim screenDensity As Int = metrics.GetFiel";
_screendensity = (int)(BA.ObjectToNumber(_metrics.GetField("densityDpi")));
 //BA.debugLineNum = 683;BA.debugLine="Dim manager As JavaObject = jo.RunMethod(\"";
_manager = new anywheresoftware.b4j.object.JavaObject();
_manager = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_jo.RunMethod("getSystemService",new Object[]{(Object)("media_projection")})));
 //BA.debugLineNum = 684;BA.debugLine="Dim projection As JavaObject = manager.Run";
_projection = new anywheresoftware.b4j.object.JavaObject();
_projection = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_manager.RunMethod("getMediaProjection",new Object[]{(Object)(parent.mostCurrent._starter._projectionresultcode /*int*/ ),(Object)(parent.mostCurrent._starter._projectiondata /*anywheresoftware.b4a.objects.IntentWrapper*/ .getObject())})));
 //BA.debugLineNum = 687;BA.debugLine="Dim readerStatic As JavaObject";
_readerstatic = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 688;BA.debugLine="Dim reader As JavaObject = readerStatic.In";
_reader = new anywheresoftware.b4j.object.JavaObject();
_reader = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_readerstatic.InitializeStatic("android.media.ImageReader").RunMethod("newInstance",new Object[]{(Object)(_width),(Object)(_height),(Object)(1),(Object)(2)})));
 //BA.debugLineNum = 691;BA.debugLine="Dim display As JavaObject = projection.Run";
_display = new anywheresoftware.b4j.object.JavaObject();
_display = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_projection.RunMethod("createVirtualDisplay",new Object[]{(Object)("SDMS_Screenshot"),(Object)(_width),(Object)(_height),(Object)(_screendensity),(Object)(17),_reader.RunMethod("getSurface",(Object[])(anywheresoftware.b4a.keywords.Common.Null)),anywheresoftware.b4a.keywords.Common.Null,anywheresoftware.b4a.keywords.Common.Null})));
 //BA.debugLineNum = 695;BA.debugLine="Sleep(1000)";
anywheresoftware.b4a.keywords.Common.Sleep(processBA,this,(int) (1000));
this.state = 17;
return;
case 17:
//C
this.state = 4;
;
 //BA.debugLineNum = 697;BA.debugLine="Dim image As JavaObject = reader.RunMethod";
_image = new anywheresoftware.b4j.object.JavaObject();
_image = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_reader.RunMethod("acquireLatestImage",(Object[])(anywheresoftware.b4a.keywords.Common.Null))));
 //BA.debugLineNum = 698;BA.debugLine="If image.IsInitialized Then";
if (true) break;

case 4:
//if
this.state = 13;
if (_image.IsInitialized()) { 
this.state = 6;
}else {
this.state = 12;
}if (true) break;

case 6:
//C
this.state = 7;
 //BA.debugLineNum = 700;BA.debugLine="Dim planes() As Object = image.RunMeth";
_planes = (Object[])(_image.RunMethod("getPlanes",(Object[])(anywheresoftware.b4a.keywords.Common.Null)));
 //BA.debugLineNum = 701;BA.debugLine="Dim plane As JavaObject = planes(0)";
_plane = new anywheresoftware.b4j.object.JavaObject();
_plane = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_planes[(int) (0)]));
 //BA.debugLineNum = 702;BA.debugLine="Dim buffer As JavaObject = plane.RunMe";
_buffer = new anywheresoftware.b4j.object.JavaObject();
_buffer = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_plane.RunMethod("getBuffer",(Object[])(anywheresoftware.b4a.keywords.Common.Null))));
 //BA.debugLineNum = 704;BA.debugLine="Dim pixelStride As Int = plane.RunMeth";
_pixelstride = (int)(BA.ObjectToNumber(_plane.RunMethod("getPixelStride",(Object[])(anywheresoftware.b4a.keywords.Common.Null))));
 //BA.debugLineNum = 705;BA.debugLine="Dim rowStride As Int = plane.RunMethod";
_rowstride = (int)(BA.ObjectToNumber(_plane.RunMethod("getRowStride",(Object[])(anywheresoftware.b4a.keywords.Common.Null))));
 //BA.debugLineNum = 706;BA.debugLine="Dim rowPadding As Int = rowStride - (p";
_rowpadding = (int) (_rowstride-(_pixelstride*_width));
 //BA.debugLineNum = 709;BA.debugLine="Dim bitmapStatic As JavaObject";
_bitmapstatic = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 710;BA.debugLine="Dim configStatic As JavaObject";
_configstatic = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 711;BA.debugLine="Dim config As Object = configStatic.In";
_config = _configstatic.InitializeStatic("android.graphics.Bitmap$Config").GetField("ARGB_8888");
 //BA.debugLineNum = 713;BA.debugLine="Dim bmpJO As JavaObject = bitmapStatic";
_bmpjo = new anywheresoftware.b4j.object.JavaObject();
_bmpjo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_bitmapstatic.InitializeStatic("android.graphics.Bitmap").RunMethod("createBitmap",new Object[]{(Object)(_width+(_rowpadding/(double)_pixelstride)),(Object)(_height),_config})));
 //BA.debugLineNum = 717;BA.debugLine="bmpJO.RunMethod(\"copyPixelsFromBuffer\"";
_bmpjo.RunMethod("copyPixelsFromBuffer",new Object[]{(Object)(_buffer.getObject())});
 //BA.debugLineNum = 720;BA.debugLine="image.RunMethod(\"close\", Null)";
_image.RunMethod("close",(Object[])(anywheresoftware.b4a.keywords.Common.Null));
 //BA.debugLineNum = 723;BA.debugLine="Dim bmp As Bitmap = bmpJO";
_bmp = new anywheresoftware.b4a.objects.drawable.CanvasWrapper.BitmapWrapper();
_bmp = (anywheresoftware.b4a.objects.drawable.CanvasWrapper.BitmapWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.drawable.CanvasWrapper.BitmapWrapper(), (android.graphics.Bitmap)(_bmpjo.getObject()));
 //BA.debugLineNum = 726;BA.debugLine="If rowPadding > 0 Then";
if (true) break;

case 7:
//if
this.state = 10;
if (_rowpadding>0) { 
this.state = 9;
}if (true) break;

case 9:
//C
this.state = 10;
 //BA.debugLineNum = 727;BA.debugLine="bmp = bmp.Crop(0, 0, width, height";
_bmp = _bmp.Crop((int) (0),(int) (0),_width,_height);
 if (true) break;

case 10:
//C
this.state = 13;
;
 //BA.debugLineNum = 731;BA.debugLine="Dim out As OutputStream = File.OpenOut";
_out = new anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper();
_out = anywheresoftware.b4a.keywords.Common.File.OpenOutput(_screenshotdir,_tempfilename,anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 732;BA.debugLine="bmp.WriteToStream(out, 100, \"PNG\")";
_bmp.WriteToStream((java.io.OutputStream)(_out.getObject()),(int) (100),BA.getEnumFromString(android.graphics.Bitmap.CompressFormat.class,"PNG"));
 //BA.debugLineNum = 733;BA.debugLine="out.Close";
_out.Close();
 //BA.debugLineNum = 735;BA.debugLine="Log(\"MediaProjection capture successfu";
anywheresoftware.b4a.keywords.Common.LogImpl("43145791","MediaProjection capture successful",0);
 //BA.debugLineNum = 737;BA.debugLine="display.RunMethod(\"release\", Null)";
_display.RunMethod("release",(Object[])(anywheresoftware.b4a.keywords.Common.Null));
 //BA.debugLineNum = 738;BA.debugLine="projection.RunMethod(\"stop\", Null)";
_projection.RunMethod("stop",(Object[])(anywheresoftware.b4a.keywords.Common.Null));
 //BA.debugLineNum = 739;BA.debugLine="reader.RunMethod(\"close\", Null)";
_reader.RunMethod("close",(Object[])(anywheresoftware.b4a.keywords.Common.Null));
 //BA.debugLineNum = 741;BA.debugLine="UploadScreenshot(screenshotDir & \"/\" &";
_uploadscreenshot(_screenshotdir+"/"+_tempfilename,_commandid);
 if (true) break;

case 12:
//C
this.state = 13;
 //BA.debugLineNum = 743;BA.debugLine="display.RunMethod(\"release\", Null)";
_display.RunMethod("release",(Object[])(anywheresoftware.b4a.keywords.Common.Null));
 //BA.debugLineNum = 744;BA.debugLine="projection.RunMethod(\"stop\", Null)";
_projection.RunMethod("stop",(Object[])(anywheresoftware.b4a.keywords.Common.Null));
 //BA.debugLineNum = 745;BA.debugLine="reader.RunMethod(\"close\", Null)";
_reader.RunMethod("close",(Object[])(anywheresoftware.b4a.keywords.Common.Null));
 //BA.debugLineNum = 746;BA.debugLine="Log(\"MediaProjection capture failed: N";
anywheresoftware.b4a.keywords.Common.LogImpl("43145802","MediaProjection capture failed: No image acquired",0);
 //BA.debugLineNum = 747;BA.debugLine="AcknowledgeCommand(commandId, False, \"";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,"MediaProjection failed to acquire image.");
 if (true) break;

case 13:
//C
this.state = 16;
;
 if (true) break;

case 15:
//C
this.state = 16;
this.catchState = 0;
 //BA.debugLineNum = 751;BA.debugLine="Log(\"CaptureWithMediaProjection error: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("43145807","CaptureWithMediaProjection error: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 752;BA.debugLine="AcknowledgeCommand(commandId, False, \"Medi";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,"MediaProjection Capture Error: "+anywheresoftware.b4a.keywords.Common.LastException(processBA).getMessage());
 if (true) break;
if (true) break;

case 16:
//C
this.state = -1;
this.catchState = 0;
;
 //BA.debugLineNum = 754;BA.debugLine="End Sub";
if (true) break;
}} 
       catch (Exception e0) {
			
if (catchState == 0)
    throw e0;
else {
    state = catchState;
processBA.setLastException(e0);}
            }
        }
    }
}
public static String  _checkdeviceregistration() throws Exception{
com.smartboard.sdms.agent.httpjob _job = null;
 //BA.debugLineNum = 181;BA.debugLine="Sub CheckDeviceRegistration";
 //BA.debugLineNum = 182;BA.debugLine="Log(\"Checking device registration...\")";
anywheresoftware.b4a.keywords.Common.LogImpl("42162689","Checking device registration...",0);
 //BA.debugLineNum = 183;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 184;BA.debugLine="job.Initialize(\"check\", Me)";
_job._initialize /*String*/ (processBA,"check",messageservice.getObject());
 //BA.debugLineNum = 185;BA.debugLine="job.Download(ServerURL & \"/devices/check?devic";
_job._download /*String*/ (_serverurl+"/devices/check?device_id="+_getdeviceid());
 //BA.debugLineNum = 186;BA.debugLine="End Sub";
return "";
}
public static boolean  _checkrootaccess() throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.keywords.StringBuilderWrapper _stdout = null;
anywheresoftware.b4a.keywords.StringBuilderWrapper _stderr = null;
 //BA.debugLineNum = 1282;BA.debugLine="Sub CheckRootAccess As Boolean";
 //BA.debugLineNum = 1283;BA.debugLine="Try";
try { //BA.debugLineNum = 1284;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 1285;BA.debugLine="Dim stdOut, stdErr As StringBuilder";
_stdout = new anywheresoftware.b4a.keywords.StringBuilderWrapper();
_stderr = new anywheresoftware.b4a.keywords.StringBuilderWrapper();
 //BA.debugLineNum = 1286;BA.debugLine="stdOut.Initialize";
_stdout.Initialize();
 //BA.debugLineNum = 1287;BA.debugLine="stdErr.Initialize";
_stderr.Initialize();
 //BA.debugLineNum = 1288;BA.debugLine="p.Shell(\"su -c id\", Null, stdOut, stdErr)";
_p.Shell("su -c id",(String[])(anywheresoftware.b4a.keywords.Common.Null),(java.lang.StringBuilder)(_stdout.getObject()),(java.lang.StringBuilder)(_stderr.getObject()));
 //BA.debugLineNum = 1289;BA.debugLine="If stdOut.ToString.Contains(\"uid=0\") Then";
if (_stdout.ToString().contains("uid=0")) { 
 //BA.debugLineNum = 1290;BA.debugLine="Log(\"Root access confirmed\")";
anywheresoftware.b4a.keywords.Common.LogImpl("47733256","Root access confirmed",0);
 //BA.debugLineNum = 1291;BA.debugLine="Return True";
if (true) return anywheresoftware.b4a.keywords.Common.True;
 };
 } 
       catch (Exception e12) {
			processBA.setLastException(e12); //BA.debugLineNum = 1294;BA.debugLine="Log(\"Root check failed: \" & LastException)";
anywheresoftware.b4a.keywords.Common.LogImpl("47733260","Root check failed: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1296;BA.debugLine="Return False";
if (true) return anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 1297;BA.debugLine="End Sub";
return false;
}
public static boolean  _checksamsungknox() throws Exception{
anywheresoftware.b4j.object.JavaObject _jo = null;
anywheresoftware.b4j.object.JavaObject _pm = null;
anywheresoftware.b4a.objects.collections.List _packages = null;
anywheresoftware.b4j.object.JavaObject _pkg = null;
String _pkgname = "";
 //BA.debugLineNum = 1317;BA.debugLine="Sub CheckSamsungKnox As Boolean";
 //BA.debugLineNum = 1318;BA.debugLine="If Manufacturer.Contains(\"samsung\") Then";
if (_manufacturer.contains("samsung")) { 
 //BA.debugLineNum = 1319;BA.debugLine="Try";
try { //BA.debugLineNum = 1320;BA.debugLine="Dim jo As JavaObject";
_jo = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 1321;BA.debugLine="jo.InitializeContext";
_jo.InitializeContext(processBA);
 //BA.debugLineNum = 1323;BA.debugLine="Dim pm As JavaObject = jo.RunMethod(\"g";
_pm = new anywheresoftware.b4j.object.JavaObject();
_pm = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_jo.RunMethod("getPackageManager",(Object[])(anywheresoftware.b4a.keywords.Common.Null))));
 //BA.debugLineNum = 1324;BA.debugLine="Dim packages As List = pm.RunMethod(\"g";
_packages = new anywheresoftware.b4a.objects.collections.List();
_packages = (anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_pm.RunMethod("getInstalledPackages",new Object[]{(Object)(0)})));
 //BA.debugLineNum = 1325;BA.debugLine="For Each pkg As JavaObject In packages";
_pkg = new anywheresoftware.b4j.object.JavaObject();
{
final anywheresoftware.b4a.BA.IterableList group7 = _packages;
final int groupLen7 = group7.getSize()
;int index7 = 0;
;
for (; index7 < groupLen7;index7++){
_pkg = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(group7.Get(index7)));
 //BA.debugLineNum = 1326;BA.debugLine="Dim pkgName As String = pkg.GetFie";
_pkgname = BA.ObjectToString(_pkg.GetField("packageName"));
 //BA.debugLineNum = 1327;BA.debugLine="If pkgName.Contains(\"sec.enterpris";
if (_pkgname.contains("sec.enterprise.knox") || _pkgname.contains("com.samsung.android.knox")) { 
 //BA.debugLineNum = 1328;BA.debugLine="Log(\"Samsung Knox SDK/packages";
anywheresoftware.b4a.keywords.Common.LogImpl("47864331","Samsung Knox SDK/packages detected",0);
 //BA.debugLineNum = 1329;BA.debugLine="Return True";
if (true) return anywheresoftware.b4a.keywords.Common.True;
 };
 }
};
 } 
       catch (Exception e15) {
			processBA.setLastException(e15); //BA.debugLineNum = 1333;BA.debugLine="Log(\"Samsung Knox check failed: \" & La";
anywheresoftware.b4a.keywords.Common.LogImpl("47864336","Samsung Knox check failed: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 };
 //BA.debugLineNum = 1336;BA.debugLine="Return False";
if (true) return anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 1337;BA.debugLine="End Sub";
return false;
}
public static boolean  _checksonyenterprise() throws Exception{
anywheresoftware.b4j.object.JavaObject _jo = null;
anywheresoftware.b4j.object.JavaObject _pm = null;
anywheresoftware.b4a.objects.collections.List _packages = null;
anywheresoftware.b4j.object.JavaObject _pkg = null;
String _pkgname = "";
 //BA.debugLineNum = 1339;BA.debugLine="Sub CheckSonyEnterprise As Boolean";
 //BA.debugLineNum = 1340;BA.debugLine="If Manufacturer.Contains(\"sony\") Then";
if (_manufacturer.contains("sony")) { 
 //BA.debugLineNum = 1341;BA.debugLine="Try";
try { //BA.debugLineNum = 1342;BA.debugLine="Dim jo As JavaObject";
_jo = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 1343;BA.debugLine="jo.InitializeContext";
_jo.InitializeContext(processBA);
 //BA.debugLineNum = 1344;BA.debugLine="Dim pm As JavaObject = jo.RunMethod(\"g";
_pm = new anywheresoftware.b4j.object.JavaObject();
_pm = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_jo.RunMethod("getPackageManager",(Object[])(anywheresoftware.b4a.keywords.Common.Null))));
 //BA.debugLineNum = 1345;BA.debugLine="Dim packages As List = pm.RunMethod(\"g";
_packages = new anywheresoftware.b4a.objects.collections.List();
_packages = (anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_pm.RunMethod("getInstalledPackages",new Object[]{(Object)(0)})));
 //BA.debugLineNum = 1346;BA.debugLine="For Each pkg As JavaObject In packages";
_pkg = new anywheresoftware.b4j.object.JavaObject();
{
final anywheresoftware.b4a.BA.IterableList group7 = _packages;
final int groupLen7 = group7.getSize()
;int index7 = 0;
;
for (; index7 < groupLen7;index7++){
_pkg = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(group7.Get(index7)));
 //BA.debugLineNum = 1347;BA.debugLine="Dim pkgName As String = pkg.GetFie";
_pkgname = BA.ObjectToString(_pkg.GetField("packageName"));
 //BA.debugLineNum = 1348;BA.debugLine="If pkgName.Contains(\"com.sonymobil";
if (_pkgname.contains("com.sonymobile.enterprise")) { 
 //BA.debugLineNum = 1349;BA.debugLine="Log(\"Sony Enterprise packages";
anywheresoftware.b4a.keywords.Common.LogImpl("47929866","Sony Enterprise packages detected",0);
 //BA.debugLineNum = 1350;BA.debugLine="Return True";
if (true) return anywheresoftware.b4a.keywords.Common.True;
 };
 }
};
 } 
       catch (Exception e15) {
			processBA.setLastException(e15); //BA.debugLineNum = 1354;BA.debugLine="Log(\"Sony Enterprise check failed: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("47929871","Sony Enterprise check failed: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 };
 //BA.debugLineNum = 1357;BA.debugLine="Return False";
if (true) return anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 1358;BA.debugLine="End Sub";
return false;
}
public static boolean  _checksystemstatus() throws Exception{
anywheresoftware.b4j.object.JavaObject _jo = null;
anywheresoftware.b4j.object.JavaObject _packageinfo = null;
anywheresoftware.b4j.object.JavaObject _applicationinfo = null;
int _flags = 0;
 //BA.debugLineNum = 1299;BA.debugLine="Sub CheckSystemStatus As Boolean";
 //BA.debugLineNum = 1300;BA.debugLine="Try";
try { //BA.debugLineNum = 1301;BA.debugLine="Dim jo As JavaObject";
_jo = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 1302;BA.debugLine="jo.InitializeContext";
_jo.InitializeContext(processBA);
 //BA.debugLineNum = 1303;BA.debugLine="Dim packageInfo As JavaObject = jo.RunMeth";
_packageinfo = new anywheresoftware.b4j.object.JavaObject();
_packageinfo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_jo.RunMethodJO("getPackageManager",(Object[])(anywheresoftware.b4a.keywords.Common.Null)).RunMethod("getPackageInfo",new Object[]{(Object)(anywheresoftware.b4a.keywords.Common.Application.getPackageName()),(Object)(0)})));
 //BA.debugLineNum = 1304;BA.debugLine="Dim applicationInfo As JavaObject = packag";
_applicationinfo = new anywheresoftware.b4j.object.JavaObject();
_applicationinfo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_packageinfo.GetField("applicationInfo")));
 //BA.debugLineNum = 1305;BA.debugLine="Dim flags As Int = applicationInfo.GetFiel";
_flags = (int)(BA.ObjectToNumber(_applicationinfo.GetField("flags")));
 //BA.debugLineNum = 1307;BA.debugLine="If Bit.And(flags, 1) <> 0 Then";
if (anywheresoftware.b4a.keywords.Common.Bit.And(_flags,(int) (1))!=0) { 
 //BA.debugLineNum = 1308;BA.debugLine="Log(\"App is running as System App\")";
anywheresoftware.b4a.keywords.Common.LogImpl("47798793","App is running as System App",0);
 //BA.debugLineNum = 1309;BA.debugLine="Return True";
if (true) return anywheresoftware.b4a.keywords.Common.True;
 };
 } 
       catch (Exception e12) {
			processBA.setLastException(e12); //BA.debugLineNum = 1312;BA.debugLine="Log(\"System status check failed: \" & LastE";
anywheresoftware.b4a.keywords.Common.LogImpl("47798797","System status check failed: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1314;BA.debugLine="Return False";
if (true) return anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 1315;BA.debugLine="End Sub";
return false;
}
public static anywheresoftware.b4a.objects.IntentWrapper  _createintentfilterandregister(String _action) throws Exception{
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _filter = null;
 //BA.debugLineNum = 1038;BA.debugLine="Private Sub CreateIntentFilterAndRegister(action A";
 //BA.debugLineNum = 1039;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 1040;BA.debugLine="Dim filter As Object = r.CreateObject2(\"androi";
_filter = _r.CreateObject2("android.content.IntentFilter",new Object[]{(Object)(_action)},new String[]{"java.lang.String"});
 //BA.debugLineNum = 1041;BA.debugLine="r.Target = r.GetContext";
_r.Target = (Object)(_r.GetContext(processBA));
 //BA.debugLineNum = 1042;BA.debugLine="Return r.RunMethod4(\"registerReceiver\", Array(";
if (true) return (anywheresoftware.b4a.objects.IntentWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.IntentWrapper(), (android.content.Intent)(_r.RunMethod4("registerReceiver",new Object[]{anywheresoftware.b4a.keywords.Common.Null,_filter},new String[]{"android.content.BroadcastReceiver","android.content.IntentFilter"})));
 //BA.debugLineNum = 1043;BA.debugLine="End Sub";
return null;
}
public static String  _createnotificationchannels() throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _manager = null;
int _importance = 0;
Object _servicechannel = null;
Object _broadcastchannel = null;
 //BA.debugLineNum = 129;BA.debugLine="Sub CreateNotificationChannels";
 //BA.debugLineNum = 130;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 131;BA.debugLine="If p.SdkVersion < 26 Then";
if (_p.getSdkVersion()<26) { 
 //BA.debugLineNum = 132;BA.debugLine="Log(\"Android version < 8, notification cha";
anywheresoftware.b4a.keywords.Common.LogImpl("42031619","Android version < 8, notification channels not needed",0);
 //BA.debugLineNum = 133;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 136;BA.debugLine="Try";
try { //BA.debugLineNum = 137;BA.debugLine="Log(\"Creating notification channels...\")";
anywheresoftware.b4a.keywords.Common.LogImpl("42031624","Creating notification channels...",0);
 //BA.debugLineNum = 138;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 139;BA.debugLine="r.Target = r.GetContext";
_r.Target = (Object)(_r.GetContext(processBA));
 //BA.debugLineNum = 140;BA.debugLine="Dim manager As Object = r.RunMethod2(\"getS";
_manager = _r.RunMethod2("getSystemService","notification","java.lang.String");
 //BA.debugLineNum = 143;BA.debugLine="Dim importance As Int = 3 ' IMPORTANCE_DEF";
_importance = (int) (3);
 //BA.debugLineNum = 144;BA.debugLine="Dim serviceChannel As Object = r.CreateObj";
_servicechannel = _r.CreateObject2("android.app.NotificationChannel",new Object[]{(Object)(_servicechannelid),(Object)("Background Service"),(Object)(_importance)},new String[]{"java.lang.String","java.lang.CharSequence","java.lang.int"});
 //BA.debugLineNum = 148;BA.debugLine="r.Target = serviceChannel";
_r.Target = _servicechannel;
 //BA.debugLineNum = 149;BA.debugLine="r.RunMethod2(\"setDescription\", \"Keeps the";
_r.RunMethod2("setDescription","Keeps the message service running","java.lang.String");
 //BA.debugLineNum = 150;BA.debugLine="r.RunMethod2(\"setShowBadge\", False, \"java.";
_r.RunMethod2("setShowBadge",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.False),"java.lang.boolean");
 //BA.debugLineNum = 152;BA.debugLine="r.Target = manager";
_r.Target = _manager;
 //BA.debugLineNum = 153;BA.debugLine="r.RunMethod4(\"createNotificationChannel\",";
_r.RunMethod4("createNotificationChannel",new Object[]{_servicechannel},new String[]{"android.app.NotificationChannel"});
 //BA.debugLineNum = 154;BA.debugLine="Log(\"Service notification channel created:";
anywheresoftware.b4a.keywords.Common.LogImpl("42031641","Service notification channel created: "+_servicechannelid,0);
 //BA.debugLineNum = 157;BA.debugLine="importance = 4 ' IMPORTANCE_HIGH";
_importance = (int) (4);
 //BA.debugLineNum = 158;BA.debugLine="Dim broadcastChannel As Object = r.CreateO";
_broadcastchannel = _r.CreateObject2("android.app.NotificationChannel",new Object[]{(Object)(_channelid),(Object)("Broadcast Messages"),(Object)(_importance)},new String[]{"java.lang.String","java.lang.CharSequence","java.lang.int"});
 //BA.debugLineNum = 162;BA.debugLine="r.Target = broadcastChannel";
_r.Target = _broadcastchannel;
 //BA.debugLineNum = 163;BA.debugLine="r.RunMethod2(\"setDescription\", \"Important";
_r.RunMethod2("setDescription","Important system broadcast messages","java.lang.String");
 //BA.debugLineNum = 164;BA.debugLine="r.RunMethod2(\"enableLights\", True, \"java.l";
_r.RunMethod2("enableLights",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.True),"java.lang.boolean");
 //BA.debugLineNum = 165;BA.debugLine="r.RunMethod2(\"enableVibration\", True, \"jav";
_r.RunMethod2("enableVibration",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.True),"java.lang.boolean");
 //BA.debugLineNum = 167;BA.debugLine="r.Target = manager";
_r.Target = _manager;
 //BA.debugLineNum = 168;BA.debugLine="r.RunMethod4(\"createNotificationChannel\",";
_r.RunMethod4("createNotificationChannel",new Object[]{_broadcastchannel},new String[]{"android.app.NotificationChannel"});
 //BA.debugLineNum = 169;BA.debugLine="Log(\"Broadcast notification channel create";
anywheresoftware.b4a.keywords.Common.LogImpl("42031656","Broadcast notification channel created: "+_channelid,0);
 } 
       catch (Exception e29) {
			processBA.setLastException(e29); //BA.debugLineNum = 171;BA.debugLine="Log(\"Error creating notification channels:";
anywheresoftware.b4a.keywords.Common.LogImpl("42031658","Error creating notification channels: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 173;BA.debugLine="End Sub";
return "";
}
public static int  _determinepermissionlevel() throws Exception{
 //BA.debugLineNum = 1265;BA.debugLine="Sub DeterminePermissionLevel As Int";
 //BA.debugLineNum = 1267;BA.debugLine="If CheckRootAccess Then Return PERM_ROOT";
if (_checkrootaccess()) { 
if (true) return _perm_root;};
 //BA.debugLineNum = 1270;BA.debugLine="If CheckSamsungKnox Then Return PERM_KNOX";
if (_checksamsungknox()) { 
if (true) return _perm_knox;};
 //BA.debugLineNum = 1273;BA.debugLine="If CheckSonyEnterprise Then Return PERM_SONY";
if (_checksonyenterprise()) { 
if (true) return _perm_sony;};
 //BA.debugLineNum = 1276;BA.debugLine="If CheckSystemStatus Then Return PERM_SYSTEM";
if (_checksystemstatus()) { 
if (true) return _perm_system;};
 //BA.debugLineNum = 1279;BA.debugLine="Return PERM_USER";
if (true) return _perm_user;
 //BA.debugLineNum = 1280;BA.debugLine="End Sub";
return 0;
}
public static String  _displaycontent(String _filepath,String _contenttype) throws Exception{
String _mimetype = "";
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.objects.IntentWrapper _i = null;
anywheresoftware.b4j.object.JavaObject _fileobj = null;
anywheresoftware.b4j.object.JavaObject _fileprovider = null;
anywheresoftware.b4j.object.JavaObject _context = null;
String _authority = "";
Object _uri = null;
anywheresoftware.b4j.object.JavaObject _jo = null;
 //BA.debugLineNum = 930;BA.debugLine="Sub DisplayContent(filePath As String, contentType";
 //BA.debugLineNum = 931;BA.debugLine="Try";
try { //BA.debugLineNum = 932;BA.debugLine="Log(\"Displaying content (\" & contentType &";
anywheresoftware.b4a.keywords.Common.LogImpl("43604482","Displaying content ("+_contenttype+")",0);
 //BA.debugLineNum = 935;BA.debugLine="Dim mimeType As String";
_mimetype = "";
 //BA.debugLineNum = 936;BA.debugLine="Select Case contentType.ToLowerCase";
switch (BA.switchObjectToInt(_contenttype.toLowerCase(),"video","image","pdf","presentation")) {
case 0: {
 //BA.debugLineNum = 938;BA.debugLine="mimeType = \"video/mp4\"";
_mimetype = "video/mp4";
 break; }
case 1: {
 //BA.debugLineNum = 940;BA.debugLine="mimeType = \"image/*\"";
_mimetype = "image/*";
 break; }
case 2: {
 //BA.debugLineNum = 942;BA.debugLine="mimeType = \"application/pdf\"";
_mimetype = "application/pdf";
 break; }
case 3: {
 //BA.debugLineNum = 944;BA.debugLine="mimeType = \"application/vnd.ms-pow";
_mimetype = "application/vnd.ms-powerpoint";
 break; }
default: {
 //BA.debugLineNum = 946;BA.debugLine="mimeType = \"*/*\"";
_mimetype = "*/*";
 break; }
}
;
 //BA.debugLineNum = 950;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 951;BA.debugLine="If p.SdkVersion >= 24 Then";
if (_p.getSdkVersion()>=24) { 
 //BA.debugLineNum = 952;BA.debugLine="Dim i As Intent";
_i = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 953;BA.debugLine="Dim fileObj As JavaObject";
_fileobj = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 954;BA.debugLine="fileObj.InitializeNewInstance(\"java.io";
_fileobj.InitializeNewInstance("java.io.File",new Object[]{(Object)(_filepath)});
 //BA.debugLineNum = 956;BA.debugLine="Dim FileProvider As JavaObject";
_fileprovider = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 957;BA.debugLine="Dim context As JavaObject";
_context = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 958;BA.debugLine="context.InitializeContext";
_context.InitializeContext(processBA);
 //BA.debugLineNum = 961;BA.debugLine="Dim authority As String = Application.";
_authority = anywheresoftware.b4a.keywords.Common.Application.getPackageName()+".provider";
 //BA.debugLineNum = 962;BA.debugLine="Dim uri As Object = FileProvider.Initi";
_uri = _fileprovider.InitializeStatic("androidx.core.content.FileProvider").RunMethod("getUriForFile",new Object[]{(Object)(_context.getObject()),(Object)(_authority),(Object)(_fileobj.getObject())});
 //BA.debugLineNum = 964;BA.debugLine="i.Initialize(i.ACTION_VIEW, \"\")";
_i.Initialize(_i.ACTION_VIEW,"");
 //BA.debugLineNum = 965;BA.debugLine="Dim jo As JavaObject = i";
_jo = new anywheresoftware.b4j.object.JavaObject();
_jo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_i.getObject()));
 //BA.debugLineNum = 966;BA.debugLine="jo.RunMethod(\"setDataAndType\", Array(u";
_jo.RunMethod("setDataAndType",new Object[]{_uri,(Object)(_mimetype)});
 //BA.debugLineNum = 967;BA.debugLine="jo.RunMethod(\"addFlags\", Array(1)) ' F";
_jo.RunMethod("addFlags",new Object[]{(Object)(1)});
 //BA.debugLineNum = 968;BA.debugLine="i.Flags = Bit.Or(i.Flags, 268435456) '";
_i.setFlags(anywheresoftware.b4a.keywords.Common.Bit.Or(_i.getFlags(),(int) (268435456)));
 //BA.debugLineNum = 970;BA.debugLine="StartActivity(i)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_i.getObject()));
 }else {
 //BA.debugLineNum = 973;BA.debugLine="Dim i As Intent";
_i = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 974;BA.debugLine="i.Initialize(i.ACTION_VIEW, \"file://\"";
_i.Initialize(_i.ACTION_VIEW,"file://"+_filepath);
 //BA.debugLineNum = 975;BA.debugLine="i.SetType(mimeType)";
_i.SetType(_mimetype);
 //BA.debugLineNum = 976;BA.debugLine="i.Flags = 268435456 ' FLAG_ACTIVITY_NE";
_i.setFlags((int) (268435456));
 //BA.debugLineNum = 977;BA.debugLine="StartActivity(i)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_i.getObject()));
 };
 //BA.debugLineNum = 980;BA.debugLine="Log(\"Content displayed successfully\")";
anywheresoftware.b4a.keywords.Common.LogImpl("43604530","Content displayed successfully",0);
 } 
       catch (Exception e41) {
			processBA.setLastException(e41); //BA.debugLineNum = 982;BA.debugLine="Log(\"Error displaying content: \" & LastExc";
anywheresoftware.b4a.keywords.Common.LogImpl("43604532","Error displaying content: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 984;BA.debugLine="Log(\"Content saved at: \" & filePath)";
anywheresoftware.b4a.keywords.Common.LogImpl("43604534","Content saved at: "+_filepath,0);
 };
 //BA.debugLineNum = 986;BA.debugLine="End Sub";
return "";
}
public static String  _downloadapp(String _url,int _appid,String _appname,String _packagename,String _version,String _checksum) throws Exception{
String _appdir = "";
com.smartboard.sdms.agent.httpjob _job = null;
anywheresoftware.b4a.objects.collections.Map _metadata = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _json = null;
 //BA.debugLineNum = 1095;BA.debugLine="Sub DownloadApp(url As String, appId As Int, appNa";
 //BA.debugLineNum = 1096;BA.debugLine="Try";
try { //BA.debugLineNum = 1097;BA.debugLine="Log(\"Downloading app: \" & appName & \" from";
anywheresoftware.b4a.keywords.Common.LogImpl("44194306","Downloading app: "+_appname+" from "+_url,0);
 //BA.debugLineNum = 1099;BA.debugLine="Dim appDir As String = File.DirRootExterna";
_appdir = anywheresoftware.b4a.keywords.Common.File.getDirRootExternal()+"/SDMS/Apps";
 //BA.debugLineNum = 1100;BA.debugLine="If Not(File.Exists(appDir, \"\")) Then";
if (anywheresoftware.b4a.keywords.Common.Not(anywheresoftware.b4a.keywords.Common.File.Exists(_appdir,""))) { 
 //BA.debugLineNum = 1101;BA.debugLine="File.MakeDir(appDir, \"\")";
anywheresoftware.b4a.keywords.Common.File.MakeDir(_appdir,"");
 };
 //BA.debugLineNum = 1104;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 1105;BA.debugLine="job.Initialize(\"download_app_\" & appId, Me";
_job._initialize /*String*/ (processBA,"download_app_"+BA.NumberToString(_appid),messageservice.getObject());
 //BA.debugLineNum = 1106;BA.debugLine="job.Download(url)";
_job._download /*String*/ (_url);
 //BA.debugLineNum = 1108;BA.debugLine="Dim metadata As Map";
_metadata = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 1109;BA.debugLine="metadata.Initialize";
_metadata.Initialize();
 //BA.debugLineNum = 1110;BA.debugLine="metadata.Put(\"app_id\", appId)";
_metadata.Put((Object)("app_id"),(Object)(_appid));
 //BA.debugLineNum = 1111;BA.debugLine="metadata.Put(\"app_name\", appName)";
_metadata.Put((Object)("app_name"),(Object)(_appname));
 //BA.debugLineNum = 1112;BA.debugLine="metadata.Put(\"package_name\", packageName)";
_metadata.Put((Object)("package_name"),(Object)(_packagename));
 //BA.debugLineNum = 1113;BA.debugLine="metadata.Put(\"version\", version)";
_metadata.Put((Object)("version"),(Object)(_version));
 //BA.debugLineNum = 1114;BA.debugLine="metadata.Put(\"checksum\", checksum)";
_metadata.Put((Object)("checksum"),(Object)(_checksum));
 //BA.debugLineNum = 1116;BA.debugLine="Dim json As JSONGenerator";
_json = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 1117;BA.debugLine="json.Initialize(metadata)";
_json.Initialize(_metadata);
 //BA.debugLineNum = 1118;BA.debugLine="File.WriteString(File.DirInternal, \"app_me";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"app_meta_"+BA.NumberToString(_appid)+".txt",_json.ToString());
 } 
       catch (Exception e21) {
			processBA.setLastException(e21); //BA.debugLineNum = 1120;BA.debugLine="Log(\"Error starting app download: \" & Last";
anywheresoftware.b4a.keywords.Common.LogImpl("44194329","Error starting app download: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1122;BA.debugLine="End Sub";
return "";
}
public static String  _downloadcontent(String _url,int _contentid,String _contentname,String _contenttype,String _checksum) throws Exception{
String _contentdir = "";
com.smartboard.sdms.agent.httpjob _job = null;
anywheresoftware.b4a.objects.collections.Map _metadata = null;
 //BA.debugLineNum = 841;BA.debugLine="Sub DownloadContent(url As String, contentId As In";
 //BA.debugLineNum = 842;BA.debugLine="Try";
try { //BA.debugLineNum = 843;BA.debugLine="Log(\"Downloading content: \" & contentName";
anywheresoftware.b4a.keywords.Common.LogImpl("43407874","Downloading content: "+_contentname+" from "+_url,0);
 //BA.debugLineNum = 846;BA.debugLine="Dim contentDir As String = File.DirRootExt";
_contentdir = anywheresoftware.b4a.keywords.Common.File.getDirRootExternal()+"/SDMS/Content";
 //BA.debugLineNum = 847;BA.debugLine="If Not(File.Exists(contentDir, \"\")) Then";
if (anywheresoftware.b4a.keywords.Common.Not(anywheresoftware.b4a.keywords.Common.File.Exists(_contentdir,""))) { 
 //BA.debugLineNum = 848;BA.debugLine="File.MakeDir(contentDir, \"\")";
anywheresoftware.b4a.keywords.Common.File.MakeDir(_contentdir,"");
 };
 //BA.debugLineNum = 852;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 853;BA.debugLine="job.Initialize(\"download_content_\" & conte";
_job._initialize /*String*/ (processBA,"download_content_"+BA.NumberToString(_contentid),messageservice.getObject());
 //BA.debugLineNum = 854;BA.debugLine="job.Download(url)";
_job._download /*String*/ (_url);
 //BA.debugLineNum = 857;BA.debugLine="Dim metadata As Map";
_metadata = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 858;BA.debugLine="metadata.Initialize";
_metadata.Initialize();
 //BA.debugLineNum = 859;BA.debugLine="metadata.Put(\"content_id\", contentId)";
_metadata.Put((Object)("content_id"),(Object)(_contentid));
 //BA.debugLineNum = 860;BA.debugLine="metadata.Put(\"content_name\", contentName)";
_metadata.Put((Object)("content_name"),(Object)(_contentname));
 //BA.debugLineNum = 861;BA.debugLine="metadata.Put(\"content_type\", contentType)";
_metadata.Put((Object)("content_type"),(Object)(_contenttype));
 //BA.debugLineNum = 862;BA.debugLine="metadata.Put(\"checksum\", checksum)";
_metadata.Put((Object)("checksum"),(Object)(_checksum));
 //BA.debugLineNum = 865;BA.debugLine="File.WriteString(File.DirInternal, \"conten";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"content_meta_"+BA.NumberToString(_contentid)+".txt",((anywheresoftware.b4a.objects.collections.JSONParser.JSONConverter) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.JSONParser.JSONConverter(), (java.lang.Object)(_metadata.getObject()))).ToString());
 } 
       catch (Exception e18) {
			processBA.setLastException(e18); //BA.debugLineNum = 868;BA.debugLine="Log(\"Error downloading content: \" & LastEx";
anywheresoftware.b4a.keywords.Common.LogImpl("43407899","Error downloading content: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 869;BA.debugLine="ReportContentStatus(contentId, \"failed\")";
_reportcontentstatus(_contentid,"failed");
 };
 //BA.debugLineNum = 871;BA.debugLine="End Sub";
return "";
}
public static String  _executelock(int _commandid) throws Exception{
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _km = null;
 //BA.debugLineNum = 552;BA.debugLine="Sub ExecuteLock(commandId As Int)";
 //BA.debugLineNum = 553;BA.debugLine="Try";
try { //BA.debugLineNum = 554;BA.debugLine="Log(\"Executing LOCK command (ID: \" & comma";
anywheresoftware.b4a.keywords.Common.LogImpl("42818050","Executing LOCK command (ID: "+BA.NumberToString(_commandid)+")",0);
 //BA.debugLineNum = 555;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 556;BA.debugLine="r.Target = r.GetContext";
_r.Target = (Object)(_r.GetContext(processBA));
 //BA.debugLineNum = 557;BA.debugLine="Dim km As Object = r.RunMethod2(\"getSystem";
_km = _r.RunMethod2("getSystemService","keyguard","java.lang.String");
 //BA.debugLineNum = 558;BA.debugLine="r.Target = km";
_r.Target = _km;
 //BA.debugLineNum = 559;BA.debugLine="r.RunMethod2(\"newKeyguardLock\", \"sdms_lock";
_r.RunMethod2("newKeyguardLock","sdms_lock","java.lang.String");
 //BA.debugLineNum = 560;BA.debugLine="Log(\"Lock command executed\")";
anywheresoftware.b4a.keywords.Common.LogImpl("42818056","Lock command executed",0);
 } 
       catch (Exception e10) {
			processBA.setLastException(e10); //BA.debugLineNum = 562;BA.debugLine="Log(\"Lock failed (may require device admin";
anywheresoftware.b4a.keywords.Common.LogImpl("42818058","Lock failed (may require device admin): "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 564;BA.debugLine="End Sub";
return "";
}
public static String  _executereboot(int _commandid) throws Exception{
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _pm = null;
 //BA.debugLineNum = 535;BA.debugLine="Sub ExecuteReboot(commandId As Int)";
 //BA.debugLineNum = 536;BA.debugLine="Try";
try { //BA.debugLineNum = 537;BA.debugLine="Log(\"Executing REBOOT command (ID: \" & com";
anywheresoftware.b4a.keywords.Common.LogImpl("42752514","Executing REBOOT command (ID: "+BA.NumberToString(_commandid)+")",0);
 //BA.debugLineNum = 538;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 539;BA.debugLine="r.Target = r.GetContext";
_r.Target = (Object)(_r.GetContext(processBA));
 //BA.debugLineNum = 540;BA.debugLine="Dim pm As Object = r.RunMethod2(\"getSystem";
_pm = _r.RunMethod2("getSystemService","power","java.lang.String");
 //BA.debugLineNum = 541;BA.debugLine="r.Target = pm";
_r.Target = _pm;
 //BA.debugLineNum = 543;BA.debugLine="r.RunMethod4(\"reboot\", Array(\"SDMS Device";
_r.RunMethod4("reboot",new Object[]{(Object)("SDMS Device Reboot")},new String[]{"java.lang.String"});
 //BA.debugLineNum = 544;BA.debugLine="Log(\"Reboot command executed\")";
anywheresoftware.b4a.keywords.Common.LogImpl("42752521","Reboot command executed",0);
 } 
       catch (Exception e10) {
			processBA.setLastException(e10); //BA.debugLineNum = 546;BA.debugLine="Log(\"Reboot failed (may require root or RE";
anywheresoftware.b4a.keywords.Common.LogImpl("42752523","Reboot failed (may require root or REBOOT permission): "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 548;BA.debugLine="ShowSystemPowerDialog";
_showsystempowerdialog();
 };
 //BA.debugLineNum = 550;BA.debugLine="End Sub";
return "";
}
public static String  _executescreenshot(int _commandid) throws Exception{
String _screenshotdir = "";
String _tempfilename = "";
String _temppath = "";
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.keywords.StringBuilderWrapper _stdout = null;
anywheresoftware.b4a.keywords.StringBuilderWrapper _stderr = null;
long _filesize = 0L;
 //BA.debugLineNum = 614;BA.debugLine="Sub ExecuteScreenshot(commandId As Int)";
 //BA.debugLineNum = 615;BA.debugLine="Try";
try { //BA.debugLineNum = 616;BA.debugLine="Log(\"Executing SCREENSHOT command (ID: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("43080194","Executing SCREENSHOT command (ID: "+BA.NumberToString(_commandid)+")",0);
 //BA.debugLineNum = 619;BA.debugLine="Dim screenshotDir As String = File.DirRoot";
_screenshotdir = anywheresoftware.b4a.keywords.Common.File.getDirRootExternal()+"/SDMS/Screenshot";
 //BA.debugLineNum = 620;BA.debugLine="If Not(File.Exists(screenshotDir, \"\")) The";
if (anywheresoftware.b4a.keywords.Common.Not(anywheresoftware.b4a.keywords.Common.File.Exists(_screenshotdir,""))) { 
 //BA.debugLineNum = 621;BA.debugLine="File.MakeDir(screenshotDir, \"\")";
anywheresoftware.b4a.keywords.Common.File.MakeDir(_screenshotdir,"");
 };
 //BA.debugLineNum = 624;BA.debugLine="Dim tempFileName As String = \"screenshot.p";
_tempfilename = "screenshot.png";
 //BA.debugLineNum = 625;BA.debugLine="Dim tempPath As String = screenshotDir & \"";
_temppath = _screenshotdir+"/"+_tempfilename;
 //BA.debugLineNum = 628;BA.debugLine="If File.Exists(screenshotDir, tempFileName";
if (anywheresoftware.b4a.keywords.Common.File.Exists(_screenshotdir,_tempfilename)) { 
anywheresoftware.b4a.keywords.Common.File.Delete(_screenshotdir,_tempfilename);};
 //BA.debugLineNum = 631;BA.debugLine="If Starter.ProjectionData.IsInitialized Th";
if (mostCurrent._starter._projectiondata /*anywheresoftware.b4a.objects.IntentWrapper*/ .IsInitialized()) { 
 //BA.debugLineNum = 632;BA.debugLine="Log(\"Using MediaProjection API for hig";
anywheresoftware.b4a.keywords.Common.LogImpl("43080210","Using MediaProjection API for high-quality screenshot",0);
 //BA.debugLineNum = 633;BA.debugLine="CaptureWithMediaProjection(commandId,";
_capturewithmediaprojection(_commandid,_screenshotdir,_tempfilename);
 }else {
 //BA.debugLineNum = 635;BA.debugLine="Log(\"MediaProjection not authorized. F";
anywheresoftware.b4a.keywords.Common.LogImpl("43080213","MediaProjection not authorized. Falling back to system screencap (requires root/system perms)...",0);
 //BA.debugLineNum = 637;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 638;BA.debugLine="Dim stdOut As StringBuilder";
_stdout = new anywheresoftware.b4a.keywords.StringBuilderWrapper();
 //BA.debugLineNum = 639;BA.debugLine="Dim stdErr As StringBuilder";
_stderr = new anywheresoftware.b4a.keywords.StringBuilderWrapper();
 //BA.debugLineNum = 640;BA.debugLine="stdOut.Initialize";
_stdout.Initialize();
 //BA.debugLineNum = 641;BA.debugLine="stdErr.Initialize";
_stderr.Initialize();
 //BA.debugLineNum = 644;BA.debugLine="Log(\"Running: screencap -p \" & tempPat";
anywheresoftware.b4a.keywords.Common.LogImpl("43080222","Running: screencap -p "+_temppath,0);
 //BA.debugLineNum = 645;BA.debugLine="p.Shell(\"screencap -p \" & tempPath, Nu";
_p.Shell("screencap -p "+_temppath,(String[])(anywheresoftware.b4a.keywords.Common.Null),(java.lang.StringBuilder)(_stdout.getObject()),(java.lang.StringBuilder)(_stderr.getObject()));
 //BA.debugLineNum = 647;BA.debugLine="Log(\"Screencap StdOut: \" & stdOut.ToSt";
anywheresoftware.b4a.keywords.Common.LogImpl("43080225","Screencap StdOut: "+_stdout.ToString(),0);
 //BA.debugLineNum = 648;BA.debugLine="Log(\"Screencap StdErr: \" & stdErr.ToSt";
anywheresoftware.b4a.keywords.Common.LogImpl("43080226","Screencap StdErr: "+_stderr.ToString(),0);
 //BA.debugLineNum = 650;BA.debugLine="If File.Exists(screenshotDir, tempFile";
if (anywheresoftware.b4a.keywords.Common.File.Exists(_screenshotdir,_tempfilename)) { 
 //BA.debugLineNum = 651;BA.debugLine="Dim fileSize As Long = File.Size(s";
_filesize = anywheresoftware.b4a.keywords.Common.File.Size(_screenshotdir,_tempfilename);
 //BA.debugLineNum = 652;BA.debugLine="Log(\"Screenshot captured via scree";
anywheresoftware.b4a.keywords.Common.LogImpl("43080230","Screenshot captured via screencap. Path: "+_temppath+" Size: "+BA.NumberToString(_filesize)+" bytes",0);
 //BA.debugLineNum = 654;BA.debugLine="If fileSize > 0 Then";
if (_filesize>0) { 
 //BA.debugLineNum = 655;BA.debugLine="UploadScreenshot(tempPath, com";
_uploadscreenshot(_temppath,_commandid);
 }else {
 //BA.debugLineNum = 657;BA.debugLine="Log(\"Screencap produced 0-byte";
anywheresoftware.b4a.keywords.Common.LogImpl("43080235","Screencap produced 0-byte file.",0);
 //BA.debugLineNum = 658;BA.debugLine="AcknowledgeCommand(commandId,";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,"Screencap failed (0 bytes). MediaProjection permission required? StdErr: "+_stderr.ToString());
 };
 }else {
 //BA.debugLineNum = 661;BA.debugLine="Log(\"Screencap failed to create fi";
anywheresoftware.b4a.keywords.Common.LogImpl("43080239","Screencap failed to create file.",0);
 //BA.debugLineNum = 662;BA.debugLine="AcknowledgeCommand(commandId, Fals";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,"Screencap failed. Please grant screen recording permission in the app. StdErr: "+_stderr.ToString());
 };
 };
 } 
       catch (Exception e39) {
			processBA.setLastException(e39); //BA.debugLineNum = 667;BA.debugLine="Log(\"Screenshot execution failed: \" & Last";
anywheresoftware.b4a.keywords.Common.LogImpl("43080245","Screenshot execution failed: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 668;BA.debugLine="AcknowledgeCommand(commandId, False, \"Exec";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,"Execution Error: "+anywheresoftware.b4a.keywords.Common.LastException(processBA).getMessage());
 };
 //BA.debugLineNum = 670;BA.debugLine="End Sub";
return "";
}
public static String  _executeshutdown(int _commandid) throws Exception{
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _pm = null;
 //BA.debugLineNum = 518;BA.debugLine="Sub ExecuteShutdown(commandId As Int)";
 //BA.debugLineNum = 519;BA.debugLine="Try";
try { //BA.debugLineNum = 520;BA.debugLine="Log(\"Executing SHUTDOWN command (ID: \" & c";
anywheresoftware.b4a.keywords.Common.LogImpl("42686978","Executing SHUTDOWN command (ID: "+BA.NumberToString(_commandid)+")",0);
 //BA.debugLineNum = 521;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 522;BA.debugLine="r.Target = r.GetContext";
_r.Target = (Object)(_r.GetContext(processBA));
 //BA.debugLineNum = 523;BA.debugLine="Dim pm As Object = r.RunMethod2(\"getSystem";
_pm = _r.RunMethod2("getSystemService","power","java.lang.String");
 //BA.debugLineNum = 524;BA.debugLine="r.Target = pm";
_r.Target = _pm;
 //BA.debugLineNum = 526;BA.debugLine="r.RunMethod2(\"reboot\", \"shutdown\", \"java.l";
_r.RunMethod2("reboot","shutdown","java.lang.String");
 //BA.debugLineNum = 527;BA.debugLine="Log(\"Shutdown command executed\")";
anywheresoftware.b4a.keywords.Common.LogImpl("42686985","Shutdown command executed",0);
 } 
       catch (Exception e10) {
			processBA.setLastException(e10); //BA.debugLineNum = 529;BA.debugLine="Log(\"Shutdown failed (may require root or";
anywheresoftware.b4a.keywords.Common.LogImpl("42686987","Shutdown failed (may require root or device admin): "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 531;BA.debugLine="ShowSystemPowerDialog";
_showsystempowerdialog();
 };
 //BA.debugLineNum = 533;BA.debugLine="End Sub";
return "";
}
public static String  _executeunlock(int _commandid) throws Exception{
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _km = null;
Object _lockobj = null;
 //BA.debugLineNum = 566;BA.debugLine="Sub ExecuteUnlock(commandId As Int)";
 //BA.debugLineNum = 567;BA.debugLine="Try";
try { //BA.debugLineNum = 568;BA.debugLine="Log(\"Executing UNLOCK command (ID: \" & com";
anywheresoftware.b4a.keywords.Common.LogImpl("42883586","Executing UNLOCK command (ID: "+BA.NumberToString(_commandid)+")",0);
 //BA.debugLineNum = 569;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 570;BA.debugLine="r.Target = r.GetContext";
_r.Target = (Object)(_r.GetContext(processBA));
 //BA.debugLineNum = 571;BA.debugLine="Dim km As Object = r.RunMethod2(\"getSystem";
_km = _r.RunMethod2("getSystemService","keyguard","java.lang.String");
 //BA.debugLineNum = 572;BA.debugLine="r.Target = km";
_r.Target = _km;
 //BA.debugLineNum = 573;BA.debugLine="Dim lockObj As Object = r.RunMethod2(\"newK";
_lockobj = _r.RunMethod2("newKeyguardLock","sdms_unlock","java.lang.String");
 //BA.debugLineNum = 574;BA.debugLine="r.Target = lockObj";
_r.Target = _lockobj;
 //BA.debugLineNum = 575;BA.debugLine="r.RunMethod(\"disableKeyguard\")";
_r.RunMethod("disableKeyguard");
 //BA.debugLineNum = 576;BA.debugLine="Log(\"Unlock command executed\")";
anywheresoftware.b4a.keywords.Common.LogImpl("42883594","Unlock command executed",0);
 } 
       catch (Exception e12) {
			processBA.setLastException(e12); //BA.debugLineNum = 578;BA.debugLine="Log(\"Unlock failed (may require device adm";
anywheresoftware.b4a.keywords.Common.LogImpl("42883596","Unlock failed (may require device admin): "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 580;BA.debugLine="End Sub";
return "";
}
public static String  _getandroidversion() throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
 //BA.debugLineNum = 1069;BA.debugLine="Private Sub GetAndroidVersion As String";
 //BA.debugLineNum = 1070;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 1071;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 1072;BA.debugLine="Return p.SdkVersion & \" (\" & r.GetStaticField(";
if (true) return BA.NumberToString(_p.getSdkVersion())+" ("+BA.ObjectToString(_r.GetStaticField("android.os.Build$VERSION","RELEASE"))+")";
 //BA.debugLineNum = 1073;BA.debugLine="End Sub";
return "";
}
public static int  _getbatterylevel() throws Exception{
anywheresoftware.b4a.objects.IntentWrapper _batteryintent = null;
int _level = 0;
int _scale = 0;
 //BA.debugLineNum = 1027;BA.debugLine="Private Sub GetBatteryLevel As Int";
 //BA.debugLineNum = 1028;BA.debugLine="Dim batteryIntent As Intent";
_batteryintent = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 1029;BA.debugLine="batteryIntent = CreateIntentFilterAndRegister(";
_batteryintent = _createintentfilterandregister("android.intent.action.BATTERY_CHANGED");
 //BA.debugLineNum = 1030;BA.debugLine="If batteryIntent.IsInitialized Then";
if (_batteryintent.IsInitialized()) { 
 //BA.debugLineNum = 1031;BA.debugLine="Dim level As Int = batteryIntent.GetExtra(";
_level = (int)(BA.ObjectToNumber(_batteryintent.GetExtra("level")));
 //BA.debugLineNum = 1032;BA.debugLine="Dim scale As Int = batteryIntent.GetExtra(";
_scale = (int)(BA.ObjectToNumber(_batteryintent.GetExtra("scale")));
 //BA.debugLineNum = 1033;BA.debugLine="If level <> -1 And scale <> -1 Then Return";
if (_level!=-1 && _scale!=-1) { 
if (true) return (int) ((_level*100)/(double)_scale);};
 };
 //BA.debugLineNum = 1035;BA.debugLine="Return -1";
if (true) return (int) (-1);
 //BA.debugLineNum = 1036;BA.debugLine="End Sub";
return 0;
}
public static String  _getdeviceid() throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
 //BA.debugLineNum = 1022;BA.debugLine="Sub GetDeviceID As String";
 //BA.debugLineNum = 1023;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 1024;BA.debugLine="Return p.GetSettings(\"android_id\")";
if (true) return _p.GetSettings("android_id");
 //BA.debugLineNum = 1025;BA.debugLine="End Sub";
return "";
}
public static String  _getfileextension(String _contenttype) throws Exception{
 //BA.debugLineNum = 915;BA.debugLine="Sub GetFileExtension(contentType As String) As Str";
 //BA.debugLineNum = 916;BA.debugLine="Select Case contentType.ToLowerCase";
switch (BA.switchObjectToInt(_contenttype.toLowerCase(),"video","image","pdf","presentation")) {
case 0: {
 //BA.debugLineNum = 918;BA.debugLine="Return \".mp4\"";
if (true) return ".mp4";
 break; }
case 1: {
 //BA.debugLineNum = 920;BA.debugLine="Return \".jpg\"";
if (true) return ".jpg";
 break; }
case 2: {
 //BA.debugLineNum = 922;BA.debugLine="Return \".pdf\"";
if (true) return ".pdf";
 break; }
case 3: {
 //BA.debugLineNum = 924;BA.debugLine="Return \".pptx\"";
if (true) return ".pptx";
 break; }
default: {
 //BA.debugLineNum = 926;BA.debugLine="Return \".dat\"";
if (true) return ".dat";
 break; }
}
;
 //BA.debugLineNum = 928;BA.debugLine="End Sub";
return "";
}
public static long  _getfreestoragebytes() throws Exception{
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _stat = null;
 //BA.debugLineNum = 1045;BA.debugLine="Private Sub GetFreeStorageBytes As Long";
 //BA.debugLineNum = 1046;BA.debugLine="Try";
try { //BA.debugLineNum = 1047;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 1048;BA.debugLine="Dim stat As Object = r.CreateObject2(\"andr";
_stat = _r.CreateObject2("android.os.StatFs",new Object[]{(Object)(anywheresoftware.b4a.keywords.Common.File.getDirInternal())},new String[]{"java.lang.String"});
 //BA.debugLineNum = 1049;BA.debugLine="r.Target = stat";
_r.Target = _stat;
 //BA.debugLineNum = 1050;BA.debugLine="Return r.RunMethod(\"getAvailableBytes\")";
if (true) return BA.ObjectToLongNumber(_r.RunMethod("getAvailableBytes"));
 } 
       catch (Exception e7) {
			processBA.setLastException(e7); //BA.debugLineNum = 1052;BA.debugLine="Log(\"Storage free failed: \" & LastExceptio";
anywheresoftware.b4a.keywords.Common.LogImpl("43932167","Storage free failed: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 1053;BA.debugLine="Return -1";
if (true) return (long) (-1);
 };
 //BA.debugLineNum = 1055;BA.debugLine="End Sub";
return 0L;
}
public static long  _gettotalstoragebytes() throws Exception{
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
Object _stat = null;
 //BA.debugLineNum = 1057;BA.debugLine="Private Sub GetTotalStorageBytes As Long";
 //BA.debugLineNum = 1058;BA.debugLine="Try";
try { //BA.debugLineNum = 1059;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 1060;BA.debugLine="Dim stat As Object = r.CreateObject2(\"andr";
_stat = _r.CreateObject2("android.os.StatFs",new Object[]{(Object)(anywheresoftware.b4a.keywords.Common.File.getDirInternal())},new String[]{"java.lang.String"});
 //BA.debugLineNum = 1061;BA.debugLine="r.Target = stat";
_r.Target = _stat;
 //BA.debugLineNum = 1062;BA.debugLine="Return r.RunMethod(\"getTotalBytes\")";
if (true) return BA.ObjectToLongNumber(_r.RunMethod("getTotalBytes"));
 } 
       catch (Exception e7) {
			processBA.setLastException(e7); //BA.debugLineNum = 1064;BA.debugLine="Log(\"Storage total failed: \" & LastExcepti";
anywheresoftware.b4a.keywords.Common.LogImpl("43997703","Storage total failed: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 1065;BA.debugLine="Return -1";
if (true) return (long) (-1);
 };
 //BA.debugLineNum = 1067;BA.debugLine="End Sub";
return 0L;
}
public static String  _handleappdownloadcomplete(com.smartboard.sdms.agent.httpjob _job,int _appid) throws Exception{
anywheresoftware.b4a.objects.collections.JSONParser _parser = null;
String _filename = "";
String _appdir = "";
anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper _out = null;
 //BA.debugLineNum = 1124;BA.debugLine="Sub HandleAppDownloadComplete(Job As HttpJob, appI";
 //BA.debugLineNum = 1125;BA.debugLine="Try";
try { //BA.debugLineNum = 1126;BA.debugLine="Log(\"App download complete for App ID: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("44259842","App download complete for App ID: "+BA.NumberToString(_appid),0);
 //BA.debugLineNum = 1129;BA.debugLine="Dim parser As JSONParser";
_parser = new anywheresoftware.b4a.objects.collections.JSONParser();
 //BA.debugLineNum = 1130;BA.debugLine="parser.Initialize(File.ReadString(File.Dir";
_parser.Initialize(anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"app_meta_"+BA.NumberToString(_appid)+".txt"));
 //BA.debugLineNum = 1133;BA.debugLine="Dim fileName As String = appId & \".apk\"";
_filename = BA.NumberToString(_appid)+".apk";
 //BA.debugLineNum = 1134;BA.debugLine="Dim appDir As String = File.DirRootExterna";
_appdir = anywheresoftware.b4a.keywords.Common.File.getDirRootExternal()+"/SDMS/Apps";
 //BA.debugLineNum = 1136;BA.debugLine="Dim out As OutputStream = File.OpenOutput(";
_out = new anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper();
_out = anywheresoftware.b4a.keywords.Common.File.OpenOutput(_appdir,_filename,anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 1137;BA.debugLine="File.Copy2(Job.GetInputStream, out)";
anywheresoftware.b4a.keywords.Common.File.Copy2((java.io.InputStream)(_job._getinputstream /*anywheresoftware.b4a.objects.streams.File.InputStreamWrapper*/ ().getObject()),(java.io.OutputStream)(_out.getObject()));
 //BA.debugLineNum = 1138;BA.debugLine="out.Close";
_out.Close();
 //BA.debugLineNum = 1140;BA.debugLine="Log(\"APK saved at: \" & appDir & \"/\" & file";
anywheresoftware.b4a.keywords.Common.LogImpl("44259856","APK saved at: "+_appdir+"/"+_filename,0);
 //BA.debugLineNum = 1142;BA.debugLine="ReportAppStatus(appId, \"downloaded\")";
_reportappstatus(_appid,"downloaded");
 } 
       catch (Exception e13) {
			processBA.setLastException(e13); //BA.debugLineNum = 1144;BA.debugLine="Log(\"Error handling app download: \" & Last";
anywheresoftware.b4a.keywords.Common.LogImpl("44259860","Error handling app download: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 1145;BA.debugLine="ReportAppStatus(appId, \"failed\")";
_reportappstatus(_appid,"failed");
 };
 //BA.debugLineNum = 1148;BA.debugLine="If File.Exists(File.DirInternal, \"app_meta_\" &";
if (anywheresoftware.b4a.keywords.Common.File.Exists(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"app_meta_"+BA.NumberToString(_appid)+".txt")) { 
 //BA.debugLineNum = 1149;BA.debugLine="File.Delete(File.DirInternal, \"app_meta_\"";
anywheresoftware.b4a.keywords.Common.File.Delete(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"app_meta_"+BA.NumberToString(_appid)+".txt");
 };
 //BA.debugLineNum = 1151;BA.debugLine="End Sub";
return "";
}
public static String  _handlecontentdownloadcomplete(com.smartboard.sdms.agent.httpjob _job,int _contentid) throws Exception{
String _metajson = "";
anywheresoftware.b4a.objects.collections.JSONParser _parser = null;
anywheresoftware.b4a.objects.collections.Map _metadata = null;
String _contenttype = "";
String _expectedchecksum = "";
String _filename = "";
String _contentdir = "";
anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper _out = null;
 //BA.debugLineNum = 873;BA.debugLine="Sub HandleContentDownloadComplete(job As HttpJob,";
 //BA.debugLineNum = 874;BA.debugLine="Try";
try { //BA.debugLineNum = 876;BA.debugLine="Dim metaJson As String = File.ReadString(F";
_metajson = anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"content_meta_"+BA.NumberToString(_contentid)+".txt");
 //BA.debugLineNum = 877;BA.debugLine="Dim parser As JSONParser";
_parser = new anywheresoftware.b4a.objects.collections.JSONParser();
 //BA.debugLineNum = 878;BA.debugLine="parser.Initialize(metaJson)";
_parser.Initialize(_metajson);
 //BA.debugLineNum = 879;BA.debugLine="Dim metadata As Map = parser.NextObject";
_metadata = new anywheresoftware.b4a.objects.collections.Map();
_metadata = _parser.NextObject();
 //BA.debugLineNum = 881;BA.debugLine="Dim contentType As String = metadata.Get(\"";
_contenttype = BA.ObjectToString(_metadata.Get((Object)("content_type")));
 //BA.debugLineNum = 882;BA.debugLine="Dim expectedChecksum As String = metadata.";
_expectedchecksum = BA.ObjectToString(_metadata.Get((Object)("checksum")));
 //BA.debugLineNum = 885;BA.debugLine="Dim fileName As String = \"content_\" & cont";
_filename = "content_"+BA.NumberToString(_contentid)+_getfileextension(_contenttype);
 //BA.debugLineNum = 886;BA.debugLine="Dim contentDir As String = File.DirRootExt";
_contentdir = anywheresoftware.b4a.keywords.Common.File.getDirRootExternal()+"/SDMS/Content";
 //BA.debugLineNum = 888;BA.debugLine="Dim out As OutputStream = File.OpenOutput(";
_out = new anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper();
_out = anywheresoftware.b4a.keywords.Common.File.OpenOutput(_contentdir,_filename,anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 889;BA.debugLine="File.Copy2(job.GetInputStream, out)";
anywheresoftware.b4a.keywords.Common.File.Copy2((java.io.InputStream)(_job._getinputstream /*anywheresoftware.b4a.objects.streams.File.InputStreamWrapper*/ ().getObject()),(java.io.OutputStream)(_out.getObject()));
 //BA.debugLineNum = 890;BA.debugLine="out.Close";
_out.Close();
 //BA.debugLineNum = 892;BA.debugLine="Log(\"Content downloaded successfully: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("43473427","Content downloaded successfully: "+_filename,0);
 //BA.debugLineNum = 895;BA.debugLine="If expectedChecksum <> \"\" Then";
if ((_expectedchecksum).equals("") == false) { 
 //BA.debugLineNum = 897;BA.debugLine="Log(\"Checksum verification skipped (no";
anywheresoftware.b4a.keywords.Common.LogImpl("43473432","Checksum verification skipped (not implemented)",0);
 };
 //BA.debugLineNum = 904;BA.debugLine="ReportContentStatus(contentId, \"deployed\")";
_reportcontentstatus(_contentid,"deployed");
 //BA.debugLineNum = 907;BA.debugLine="File.Delete(File.DirInternal, \"content_met";
anywheresoftware.b4a.keywords.Common.File.Delete(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"content_meta_"+BA.NumberToString(_contentid)+".txt");
 } 
       catch (Exception e20) {
			processBA.setLastException(e20); //BA.debugLineNum = 910;BA.debugLine="Log(\"Error handling content download: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("43473445","Error handling content download: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 911;BA.debugLine="ReportContentStatus(contentId, \"failed\")";
_reportcontentstatus(_contentid,"failed");
 };
 //BA.debugLineNum = 913;BA.debugLine="End Sub";
return "";
}
public static String  _handleremotesettingsresponse(com.smartboard.sdms.agent.httpjob _job) throws Exception{
int _cmdid = 0;
anywheresoftware.b4a.objects.collections.JSONParser _parser = null;
anywheresoftware.b4a.objects.collections.Map _root = null;
anywheresoftware.b4a.objects.collections.Map _settings = null;
String _reqperm = "";
 //BA.debugLineNum = 1218;BA.debugLine="Sub HandleRemoteSettingsResponse(Job As HttpJob)";
 //BA.debugLineNum = 1219;BA.debugLine="Try";
try { //BA.debugLineNum = 1220;BA.debugLine="Dim cmdId As Int = Job.JobName.SubString(2";
_cmdid = (int)(Double.parseDouble(_job._jobname /*String*/ .substring((int) (22))));
 //BA.debugLineNum = 1221;BA.debugLine="Dim parser As JSONParser";
_parser = new anywheresoftware.b4a.objects.collections.JSONParser();
 //BA.debugLineNum = 1222;BA.debugLine="parser.Initialize(Job.GetString)";
_parser.Initialize(_job._getstring /*String*/ ());
 //BA.debugLineNum = 1223;BA.debugLine="Dim root As Map = parser.NextObject";
_root = new anywheresoftware.b4a.objects.collections.Map();
_root = _parser.NextObject();
 //BA.debugLineNum = 1224;BA.debugLine="If root.Get(\"success\") = True Then";
if ((_root.Get((Object)("success"))).equals((Object)(anywheresoftware.b4a.keywords.Common.True))) { 
 //BA.debugLineNum = 1225;BA.debugLine="Dim settings As Map = root.Get(\"settin";
_settings = new anywheresoftware.b4a.objects.collections.Map();
_settings = (anywheresoftware.b4a.objects.collections.Map) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), (java.util.Map)(_root.Get((Object)("settings"))));
 //BA.debugLineNum = 1226;BA.debugLine="Dim reqPerm As String = settings.GetDe";
_reqperm = BA.ObjectToString(_settings.GetDefault((Object)("remote_require_permission"),(Object)("no")));
 //BA.debugLineNum = 1228;BA.debugLine="If reqPerm = \"yes\" Then";
if ((_reqperm).equals("yes")) { 
 //BA.debugLineNum = 1229;BA.debugLine="Log(\"Permission required for remot";
anywheresoftware.b4a.keywords.Common.LogImpl("44521995","Permission required for remote control.",0);
 };
 //BA.debugLineNum = 1232;BA.debugLine="IsRemoteSessionActive = True";
_isremotesessionactive = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 1233;BA.debugLine="RemoteSessionTimer.Enabled = True";
_remotesessiontimer.setEnabled(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 1234;BA.debugLine="Log(\"Remote session activated\")";
anywheresoftware.b4a.keywords.Common.LogImpl("44522000","Remote session activated",0);
 //BA.debugLineNum = 1235;BA.debugLine="AcknowledgeCommand(cmdId, True, \"\")";
_acknowledgecommand(_cmdid,anywheresoftware.b4a.keywords.Common.True,"");
 }else {
 //BA.debugLineNum = 1237;BA.debugLine="AcknowledgeCommand(cmdId, False, \"Fail";
_acknowledgecommand(_cmdid,anywheresoftware.b4a.keywords.Common.False,"Failed to fetch settings");
 };
 } 
       catch (Exception e20) {
			processBA.setLastException(e20); //BA.debugLineNum = 1240;BA.debugLine="Log(\"Error parsing settings for remote: \"";
anywheresoftware.b4a.keywords.Common.LogImpl("44522006","Error parsing settings for remote: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1242;BA.debugLine="End Sub";
return "";
}
public static void  _jobdone(com.smartboard.sdms.agent.httpjob _job) throws Exception{
ResumableSub_JobDone rsub = new ResumableSub_JobDone(null,_job);
rsub.resume(processBA, null);
}
public static class ResumableSub_JobDone extends BA.ResumableSub {
public ResumableSub_JobDone(com.smartboard.sdms.agent.messageservice parent,com.smartboard.sdms.agent.httpjob _job) {
this.parent = parent;
this._job = _job;
}
com.smartboard.sdms.agent.messageservice parent;
com.smartboard.sdms.agent.httpjob _job;
int _contentid = 0;
int _appid = 0;
anywheresoftware.b4a.objects.collections.JSONParser _parser = null;
anywheresoftware.b4a.objects.collections.Map _root = null;
String _token = "";
int _isapproved = 0;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
try {

        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
 //BA.debugLineNum = 228;BA.debugLine="If Job.Success Then";
if (true) break;

case 1:
//if
this.state = 105;
if (_job._success /*boolean*/ ) { 
this.state = 3;
}else {
this.state = 100;
}if (true) break;

case 3:
//C
this.state = 4;
 //BA.debugLineNum = 232;BA.debugLine="If Job.JobName.StartsWith(\"download_conten";
if (true) break;

case 4:
//if
this.state = 13;
if (_job._jobname /*String*/ .startsWith("download_content_")) { 
this.state = 6;
}if (true) break;

case 6:
//C
this.state = 7;
 //BA.debugLineNum = 233;BA.debugLine="Try";
if (true) break;

case 7:
//try
this.state = 12;
this.catchState = 11;
this.state = 9;
if (true) break;

case 9:
//C
this.state = 12;
this.catchState = 11;
 //BA.debugLineNum = 234;BA.debugLine="Dim contentId As Int = Job.JobName";
_contentid = (int)(Double.parseDouble(_job._jobname /*String*/ .substring((int) (17))));
 //BA.debugLineNum = 235;BA.debugLine="HandleContentDownloadComplete(Job,";
_handlecontentdownloadcomplete(_job,_contentid);
 if (true) break;

case 11:
//C
this.state = 12;
this.catchState = 0;
 //BA.debugLineNum = 237;BA.debugLine="Log(\"Error handling content downlo";
anywheresoftware.b4a.keywords.Common.LogImpl("42293770","Error handling content download: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 if (true) break;
if (true) break;

case 12:
//C
this.state = 13;
this.catchState = 0;
;
 //BA.debugLineNum = 239;BA.debugLine="Job.Release";
_job._release /*String*/ ();
 //BA.debugLineNum = 240;BA.debugLine="Return";
if (true) return ;
 if (true) break;
;
 //BA.debugLineNum = 244;BA.debugLine="If Job.JobName.StartsWith(\"download_app_\")";

case 13:
//if
this.state = 22;
if (_job._jobname /*String*/ .startsWith("download_app_")) { 
this.state = 15;
}if (true) break;

case 15:
//C
this.state = 16;
 //BA.debugLineNum = 245;BA.debugLine="Try";
if (true) break;

case 16:
//try
this.state = 21;
this.catchState = 20;
this.state = 18;
if (true) break;

case 18:
//C
this.state = 21;
this.catchState = 20;
 //BA.debugLineNum = 246;BA.debugLine="Dim appId As Int = Job.JobName.Sub";
_appid = (int)(Double.parseDouble(_job._jobname /*String*/ .substring((int) (13))));
 //BA.debugLineNum = 247;BA.debugLine="HandleAppDownloadComplete(Job, app";
_handleappdownloadcomplete(_job,_appid);
 if (true) break;

case 20:
//C
this.state = 21;
this.catchState = 0;
 //BA.debugLineNum = 249;BA.debugLine="Log(\"Error handling app download:";
anywheresoftware.b4a.keywords.Common.LogImpl("42293782","Error handling app download: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 if (true) break;
if (true) break;

case 21:
//C
this.state = 22;
this.catchState = 0;
;
 //BA.debugLineNum = 251;BA.debugLine="Job.Release";
_job._release /*String*/ ();
 //BA.debugLineNum = 252;BA.debugLine="Return";
if (true) return ;
 if (true) break;
;
 //BA.debugLineNum = 256;BA.debugLine="If Job.JobName.StartsWith(\"fetch_settings_";

case 22:
//if
this.state = 25;
if (_job._jobname /*String*/ .startsWith("fetch_settings_remote_")) { 
this.state = 24;
}if (true) break;

case 24:
//C
this.state = 25;
 //BA.debugLineNum = 257;BA.debugLine="HandleRemoteSettingsResponse(Job)";
_handleremotesettingsresponse(_job);
 //BA.debugLineNum = 258;BA.debugLine="Job.Release";
_job._release /*String*/ ();
 //BA.debugLineNum = 259;BA.debugLine="Return";
if (true) return ;
 if (true) break;
;
 //BA.debugLineNum = 263;BA.debugLine="Select Job.JobName";

case 25:
//select
this.state = 98;
switch (BA.switchObjectToInt(_job._jobname /*String*/ ,"check","register","heartbeat","ack_broadcast","ack_command","content_status")) {
case 0: 
case 1: 
case 2: 
case 3: 
case 4: {
this.state = 27;
if (true) break;
}
case 5: {
this.state = 97;
if (true) break;
}
}
if (true) break;

case 27:
//C
this.state = 28;
 //BA.debugLineNum = 265;BA.debugLine="Try";
if (true) break;

case 28:
//try
this.state = 95;
this.catchState = 94;
this.state = 30;
if (true) break;

case 30:
//C
this.state = 31;
this.catchState = 94;
 //BA.debugLineNum = 266;BA.debugLine="Dim parser As JSONParser";
_parser = new anywheresoftware.b4a.objects.collections.JSONParser();
 //BA.debugLineNum = 267;BA.debugLine="parser.Initialize(Job.GetStrin";
_parser.Initialize(_job._getstring /*String*/ ());
 //BA.debugLineNum = 268;BA.debugLine="Dim root As Map = parser.NextO";
_root = new anywheresoftware.b4a.objects.collections.Map();
_root = _parser.NextObject();
 //BA.debugLineNum = 270;BA.debugLine="Select Job.JobName";
if (true) break;

case 31:
//select
this.state = 92;
switch (BA.switchObjectToInt(_job._jobname /*String*/ ,"check","register","heartbeat","ack_broadcast","ack_command")) {
case 0: {
this.state = 33;
if (true) break;
}
case 1: {
this.state = 41;
if (true) break;
}
case 2: {
this.state = 49;
if (true) break;
}
case 3: {
this.state = 89;
if (true) break;
}
case 4: {
this.state = 91;
if (true) break;
}
}
if (true) break;

case 33:
//C
this.state = 34;
 //BA.debugLineNum = 272;BA.debugLine="If root.Get(\"registere";
if (true) break;

case 34:
//if
this.state = 39;
if ((_root.Get((Object)("registered"))).equals((Object)(anywheresoftware.b4a.keywords.Common.True))) { 
this.state = 36;
}else {
this.state = 38;
}if (true) break;

case 36:
//C
this.state = 39;
 //BA.debugLineNum = 273;BA.debugLine="Dim token As Strin";
_token = BA.ObjectToString(_root.Get((Object)("token")));
 //BA.debugLineNum = 274;BA.debugLine="File.WriteString(F";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt",_token);
 //BA.debugLineNum = 275;BA.debugLine="File.WriteString(F";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"device_id.txt",BA.ObjectToString(_root.Get((Object)("device_id")))+"");
 //BA.debugLineNum = 276;BA.debugLine="Log(\"Device alread";
anywheresoftware.b4a.keywords.Common.LogImpl("42293809","Device already registered",0);
 //BA.debugLineNum = 277;BA.debugLine="SendHeartbeat";
_sendheartbeat();
 if (true) break;

case 38:
//C
this.state = 39;
 //BA.debugLineNum = 279;BA.debugLine="Log(\"Device not re";
anywheresoftware.b4a.keywords.Common.LogImpl("42293812","Device not registered - registration should be done via main activity",0);
 if (true) break;

case 39:
//C
this.state = 92;
;
 if (true) break;

case 41:
//C
this.state = 42;
 //BA.debugLineNum = 283;BA.debugLine="If root.Get(\"success\")";
if (true) break;

case 42:
//if
this.state = 47;
if ((_root.Get((Object)("success"))).equals((Object)(anywheresoftware.b4a.keywords.Common.True))) { 
this.state = 44;
}else {
this.state = 46;
}if (true) break;

case 44:
//C
this.state = 47;
 //BA.debugLineNum = 284;BA.debugLine="Dim token As Strin";
_token = BA.ObjectToString(_root.Get((Object)("token")));
 //BA.debugLineNum = 285;BA.debugLine="File.WriteString(F";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt",_token);
 //BA.debugLineNum = 286;BA.debugLine="File.WriteString(F";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"device_id.txt",BA.ObjectToString(_root.Get((Object)("device_id")))+"");
 //BA.debugLineNum = 287;BA.debugLine="Log(\"Device regist";
anywheresoftware.b4a.keywords.Common.LogImpl("42293820","Device registered successfully",0);
 //BA.debugLineNum = 288;BA.debugLine="RetryDelay = 30000";
parent._retrydelay = (int) (30000);
 //BA.debugLineNum = 289;BA.debugLine="SendHeartbeat";
_sendheartbeat();
 if (true) break;

case 46:
//C
this.state = 47;
 //BA.debugLineNum = 291;BA.debugLine="Log(\"Registration";
anywheresoftware.b4a.keywords.Common.LogImpl("42293824","Registration failed: "+BA.ObjectToString(_root.Get((Object)("error"))),0);
 if (true) break;

case 47:
//C
this.state = 92;
;
 if (true) break;

case 49:
//C
this.state = 50;
 //BA.debugLineNum = 295;BA.debugLine="If root.Get(\"success\")";
if (true) break;

case 50:
//if
this.state = 87;
if ((_root.Get((Object)("success"))).equals((Object)(anywheresoftware.b4a.keywords.Common.True))) { 
this.state = 52;
}if (true) break;

case 52:
//C
this.state = 53;
 //BA.debugLineNum = 296;BA.debugLine="Log(\"Heartbeat OK\"";
anywheresoftware.b4a.keywords.Common.LogImpl("42293829","Heartbeat OK",0);
 //BA.debugLineNum = 297;BA.debugLine="RetryDelay = 30000";
parent._retrydelay = (int) (30000);
 //BA.debugLineNum = 299;BA.debugLine="Dim isApproved As";
_isapproved = (int) (-1);
 //BA.debugLineNum = 300;BA.debugLine="If root.ContainsKe";
if (true) break;

case 53:
//if
this.state = 56;
if (_root.ContainsKey((Object)("is_approved"))) { 
this.state = 55;
}if (true) break;

case 55:
//C
this.state = 56;
 //BA.debugLineNum = 301;BA.debugLine="isApproved = r";
_isapproved = (int)(BA.ObjectToNumber(_root.Get((Object)("is_approved"))));
 //BA.debugLineNum = 302;BA.debugLine="Log(\"Device ap";
anywheresoftware.b4a.keywords.Common.LogImpl("42293835","Device approval status: "+BA.NumberToString(_isapproved),0);
 //BA.debugLineNum = 303;BA.debugLine="UpdateForegrou";
_updateforegroundnotification("",_isapproved);
 if (true) break;
;
 //BA.debugLineNum = 306;BA.debugLine="If isApproved = 1";

case 56:
//if
this.state = 83;
if (_isapproved==1) { 
this.state = 58;
}if (true) break;

case 58:
//C
this.state = 59;
 //BA.debugLineNum = 307;BA.debugLine="If root.Contai";
if (true) break;

case 59:
//if
this.state = 64;
if (_root.ContainsKey((Object)("broadcasts"))) { 
this.state = 61;
;}if (true) break;

case 61:
//C
this.state = 64;
_processbroadcasts((anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_root.Get((Object)("broadcasts")))));
if (true) break;

case 64:
//C
this.state = 65;
;
 //BA.debugLineNum = 308;BA.debugLine="If root.Contai";
if (true) break;

case 65:
//if
this.state = 70;
if (_root.ContainsKey((Object)("commands"))) { 
this.state = 67;
;}if (true) break;

case 67:
//C
this.state = 70;
_processcommands((anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_root.Get((Object)("commands")))));
if (true) break;

case 70:
//C
this.state = 71;
;
 //BA.debugLineNum = 309;BA.debugLine="If root.Contai";
if (true) break;

case 71:
//if
this.state = 76;
if (_root.ContainsKey((Object)("content"))) { 
this.state = 73;
;}if (true) break;

case 73:
//C
this.state = 76;
_processcontent((anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_root.Get((Object)("content")))));
if (true) break;

case 76:
//C
this.state = 77;
;
 //BA.debugLineNum = 310;BA.debugLine="If root.Contai";
if (true) break;

case 77:
//if
this.state = 82;
if (_root.ContainsKey((Object)("apps"))) { 
this.state = 79;
;}if (true) break;

case 79:
//C
this.state = 82;
_processapps((anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_root.Get((Object)("apps")))));
if (true) break;

case 82:
//C
this.state = 83;
;
 if (true) break;
;
 //BA.debugLineNum = 313;BA.debugLine="If isApproved = 0";

case 83:
//if
this.state = 86;
if (_isapproved==0) { 
this.state = 85;
}if (true) break;

case 85:
//C
this.state = 86;
 //BA.debugLineNum = 314;BA.debugLine="Log(\"Device pe";
anywheresoftware.b4a.keywords.Common.LogImpl("42293847","Device pending approval",0);
 if (true) break;

case 86:
//C
this.state = 87;
;
 if (true) break;

case 87:
//C
this.state = 92;
;
 if (true) break;

case 89:
//C
this.state = 92;
 //BA.debugLineNum = 319;BA.debugLine="Log(\"Broadcast acknowl";
anywheresoftware.b4a.keywords.Common.LogImpl("42293852","Broadcast acknowledged",0);
 if (true) break;

case 91:
//C
this.state = 92;
 //BA.debugLineNum = 322;BA.debugLine="Log(\"Command acknowled";
anywheresoftware.b4a.keywords.Common.LogImpl("42293855","Command acknowledged",0);
 if (true) break;

case 92:
//C
this.state = 95;
;
 if (true) break;

case 94:
//C
this.state = 95;
this.catchState = 0;
 //BA.debugLineNum = 325;BA.debugLine="Log(\"JSON Parse Error: \" & Las";
anywheresoftware.b4a.keywords.Common.LogImpl("42293858","JSON Parse Error: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 326;BA.debugLine="Log(\"Response: \" & Job.GetStri";
anywheresoftware.b4a.keywords.Common.LogImpl("42293859","Response: "+_job._getstring /*String*/ (),0);
 if (true) break;
if (true) break;

case 95:
//C
this.state = 98;
this.catchState = 0;
;
 if (true) break;

case 97:
//C
this.state = 98;
 //BA.debugLineNum = 330;BA.debugLine="Log(\"Content status report respons";
anywheresoftware.b4a.keywords.Common.LogImpl("42293863","Content status report response: "+_job._getstring /*String*/ (),0);
 if (true) break;

case 98:
//C
this.state = 105;
;
 if (true) break;

case 100:
//C
this.state = 101;
 //BA.debugLineNum = 333;BA.debugLine="Log(\"Network Error: \" & Job.ErrorMessage &";
anywheresoftware.b4a.keywords.Common.LogImpl("42293866","Network Error: "+_job._errormessage /*String*/ +" | Job: "+_job._jobname /*String*/ ,0);
 //BA.debugLineNum = 335;BA.debugLine="If Job.JobName = \"heartbeat\" Then";
if (true) break;

case 101:
//if
this.state = 104;
if ((_job._jobname /*String*/ ).equals("heartbeat")) { 
this.state = 103;
}if (true) break;

case 103:
//C
this.state = 104;
 //BA.debugLineNum = 336;BA.debugLine="MessageTimer.Enabled = False";
parent._messagetimer.setEnabled(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 337;BA.debugLine="Sleep(RetryDelay)";
anywheresoftware.b4a.keywords.Common.Sleep(processBA,this,parent._retrydelay);
this.state = 106;
return;
case 106:
//C
this.state = 104;
;
 //BA.debugLineNum = 338;BA.debugLine="RetryDelay = Min(RetryDelay * 2, 30000";
parent._retrydelay = (int) (anywheresoftware.b4a.keywords.Common.Min(parent._retrydelay*2,300000));
 //BA.debugLineNum = 339;BA.debugLine="MessageTimer.Enabled = True";
parent._messagetimer.setEnabled(anywheresoftware.b4a.keywords.Common.True);
 if (true) break;

case 104:
//C
this.state = 105;
;
 if (true) break;

case 105:
//C
this.state = -1;
;
 //BA.debugLineNum = 342;BA.debugLine="Job.Release";
_job._release /*String*/ ();
 //BA.debugLineNum = 343;BA.debugLine="End Sub";
if (true) break;
}} 
       catch (Exception e0) {
			
if (catchState == 0)
    throw e0;
else {
    state = catchState;
processBA.setLastException(e0);}
            }
        }
    }
}
public static String  _messagetimer_tick() throws Exception{
 //BA.debugLineNum = 177;BA.debugLine="Sub MessageTimer_Tick";
 //BA.debugLineNum = 178;BA.debugLine="SendHeartbeat";
_sendheartbeat();
 //BA.debugLineNum = 179;BA.debugLine="End Sub";
return "";
}
public static String  _openurlcontent(String _url) throws Exception{
anywheresoftware.b4a.objects.IntentWrapper _i = null;
 //BA.debugLineNum = 828;BA.debugLine="Public Sub OpenUrlContent(url As String)";
 //BA.debugLineNum = 829;BA.debugLine="Try";
try { //BA.debugLineNum = 830;BA.debugLine="Log(\"Opening URL content: \" & url)";
anywheresoftware.b4a.keywords.Common.LogImpl("43342338","Opening URL content: "+_url,0);
 //BA.debugLineNum = 831;BA.debugLine="Dim i As Intent";
_i = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 832;BA.debugLine="i.Initialize(i.ACTION_VIEW, url)";
_i.Initialize(_i.ACTION_VIEW,_url);
 //BA.debugLineNum = 833;BA.debugLine="i.Flags = 268435456 ' FLAG_ACTIVITY_NEW_TA";
_i.setFlags((int) (268435456));
 //BA.debugLineNum = 834;BA.debugLine="StartActivity(i)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_i.getObject()));
 //BA.debugLineNum = 835;BA.debugLine="Log(\"URL content opened successfully\")";
anywheresoftware.b4a.keywords.Common.LogImpl("43342343","URL content opened successfully",0);
 } 
       catch (Exception e9) {
			processBA.setLastException(e9); //BA.debugLineNum = 837;BA.debugLine="Log(\"Error opening URL content: \" & LastEx";
anywheresoftware.b4a.keywords.Common.LogImpl("43342345","Error opening URL content: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 839;BA.debugLine="End Sub";
return "";
}
public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 7;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 8;BA.debugLine="Private ServerURL As String = \"https://sdms.me";
_serverurl = "https://sdms.merosee.com/api";
 //BA.debugLineNum = 9;BA.debugLine="Private ChannelId As String = \"broadcast_notif";
_channelid = "broadcast_notifications_v2";
 //BA.debugLineNum = 10;BA.debugLine="Private ServiceChannelId As String = \"message_";
_servicechannelid = "message_service_channel";
 //BA.debugLineNum = 11;BA.debugLine="Private Const HeartbeatInterval As Long = 3000";
_heartbeatinterval = (long) (30000);
 //BA.debugLineNum = 12;BA.debugLine="Private RetryDelay As Int = 30000";
_retrydelay = (int) (30000);
 //BA.debugLineNum = 13;BA.debugLine="Private MessageTimer As Timer";
_messagetimer = new anywheresoftware.b4a.objects.Timer();
 //BA.debugLineNum = 14;BA.debugLine="Private RemoteSessionTimer As Timer";
_remotesessiontimer = new anywheresoftware.b4a.objects.Timer();
 //BA.debugLineNum = 15;BA.debugLine="Private IsRemoteSessionActive As Boolean = Fal";
_isremotesessionactive = anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 18;BA.debugLine="Public Const PERM_USER As Int = 1";
_perm_user = (int) (1);
 //BA.debugLineNum = 19;BA.debugLine="Public Const PERM_SYSTEM As Int = 2";
_perm_system = (int) (2);
 //BA.debugLineNum = 20;BA.debugLine="Public Const PERM_ROOT As Int = 3";
_perm_root = (int) (3);
 //BA.debugLineNum = 21;BA.debugLine="Public Const PERM_KNOX As Int = 4";
_perm_knox = (int) (4);
 //BA.debugLineNum = 22;BA.debugLine="Public Const PERM_SONY As Int = 5";
_perm_sony = (int) (5);
 //BA.debugLineNum = 24;BA.debugLine="Private CurrentPermissionLevel As Int = PERM_U";
_currentpermissionlevel = _perm_user;
 //BA.debugLineNum = 25;BA.debugLine="Private Manufacturer As String = \"\"";
_manufacturer = "";
 //BA.debugLineNum = 26;BA.debugLine="End Sub";
return "";
}
public static String  _processapps(anywheresoftware.b4a.objects.collections.List _apps) throws Exception{
anywheresoftware.b4a.objects.collections.Map _item = null;
int _appid = 0;
String _appname = "";
String _packagename = "";
String _version = "";
String _downloadurl = "";
String _checksum = "";
 //BA.debugLineNum = 1077;BA.debugLine="Sub ProcessApps(apps As List)";
 //BA.debugLineNum = 1078;BA.debugLine="For Each item As Map In apps";
_item = new anywheresoftware.b4a.objects.collections.Map();
{
final anywheresoftware.b4a.BA.IterableList group1 = _apps;
final int groupLen1 = group1.getSize()
;int index1 = 0;
;
for (; index1 < groupLen1;index1++){
_item = (anywheresoftware.b4a.objects.collections.Map) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), (java.util.Map)(group1.Get(index1)));
 //BA.debugLineNum = 1079;BA.debugLine="Try";
try { //BA.debugLineNum = 1080;BA.debugLine="Dim appId As Int = item.GetDefault(\"ap";
_appid = (int)(BA.ObjectToNumber(_item.GetDefault((Object)("app_id"),(Object)(0))));
 //BA.debugLineNum = 1081;BA.debugLine="Dim appName As String = item.GetDefaul";
_appname = BA.ObjectToString(_item.GetDefault((Object)("name"),(Object)("Unknown App")));
 //BA.debugLineNum = 1082;BA.debugLine="Dim packageName As String = item.GetDe";
_packagename = BA.ObjectToString(_item.GetDefault((Object)("package_name"),(Object)("")));
 //BA.debugLineNum = 1083;BA.debugLine="Dim version As String = item.GetDefaul";
_version = BA.ObjectToString(_item.GetDefault((Object)("version"),(Object)("")));
 //BA.debugLineNum = 1084;BA.debugLine="Dim downloadUrl As String = item.GetDe";
_downloadurl = BA.ObjectToString(_item.GetDefault((Object)("download_url"),(Object)("")));
 //BA.debugLineNum = 1085;BA.debugLine="Dim checksum As String = item.GetDefau";
_checksum = BA.ObjectToString(_item.GetDefault((Object)("checksum"),(Object)("")));
 //BA.debugLineNum = 1087;BA.debugLine="Log(\"Processing app deployment: \" & ap";
anywheresoftware.b4a.keywords.Common.LogImpl("44128778","Processing app deployment: "+_appname+" ("+_packagename+" v"+_version+")",0);
 //BA.debugLineNum = 1088;BA.debugLine="DownloadApp(downloadUrl, appId, appNam";
_downloadapp(_downloadurl,_appid,_appname,_packagename,_version,_checksum);
 } 
       catch (Exception e12) {
			processBA.setLastException(e12); //BA.debugLineNum = 1090;BA.debugLine="Log(\"Error processing app: \" & LastExc";
anywheresoftware.b4a.keywords.Common.LogImpl("44128781","Error processing app: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 }
};
 //BA.debugLineNum = 1093;BA.debugLine="End Sub";
return "";
}
public static String  _processbroadcasts(anywheresoftware.b4a.objects.collections.List _broadcasts) throws Exception{
anywheresoftware.b4a.objects.collections.Map _broadcast = null;
int _broadcastid = 0;
String _title = "";
String _message = "";
String _priority = "";
 //BA.debugLineNum = 347;BA.debugLine="Sub ProcessBroadcasts(broadcasts As List)";
 //BA.debugLineNum = 348;BA.debugLine="For Each broadcast As Map In broadcasts";
_broadcast = new anywheresoftware.b4a.objects.collections.Map();
{
final anywheresoftware.b4a.BA.IterableList group1 = _broadcasts;
final int groupLen1 = group1.getSize()
;int index1 = 0;
;
for (; index1 < groupLen1;index1++){
_broadcast = (anywheresoftware.b4a.objects.collections.Map) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), (java.util.Map)(group1.Get(index1)));
 //BA.debugLineNum = 349;BA.debugLine="Try";
try { //BA.debugLineNum = 350;BA.debugLine="Dim broadcastId As Int = broadcast.Get";
_broadcastid = (int)(BA.ObjectToNumber(_broadcast.GetDefault((Object)("id"),(Object)(0))));
 //BA.debugLineNum = 351;BA.debugLine="Dim title As String = broadcast.GetDef";
_title = BA.ObjectToString(_broadcast.GetDefault((Object)("title"),(Object)("No Title")));
 //BA.debugLineNum = 352;BA.debugLine="Dim message As String = broadcast.GetD";
_message = BA.ObjectToString(_broadcast.GetDefault((Object)("message"),(Object)("")));
 //BA.debugLineNum = 353;BA.debugLine="Dim priority As String = broadcast.Get";
_priority = BA.ObjectToString(_broadcast.GetDefault((Object)("priority"),(Object)("normal")));
 //BA.debugLineNum = 355;BA.debugLine="Log(\"Processing broadcast: \" & title)";
anywheresoftware.b4a.keywords.Common.LogImpl("42359304","Processing broadcast: "+_title,0);
 //BA.debugLineNum = 358;BA.debugLine="ShowBroadcastNotification(title, messa";
_showbroadcastnotification(_title,_message,_broadcastid,_priority);
 //BA.debugLineNum = 361;BA.debugLine="ShowBroadcastDisplay(title, message, p";
_showbroadcastdisplay(_title,_message,_priority);
 //BA.debugLineNum = 364;BA.debugLine="AcknowledgeBroadcast(broadcastId)";
_acknowledgebroadcast(_broadcastid);
 } 
       catch (Exception e12) {
			processBA.setLastException(e12); //BA.debugLineNum = 366;BA.debugLine="Log(\"Error processing broadcast: \" & L";
anywheresoftware.b4a.keywords.Common.LogImpl("42359315","Error processing broadcast: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 }
};
 //BA.debugLineNum = 369;BA.debugLine="End Sub";
return "";
}
public static String  _processcommands(anywheresoftware.b4a.objects.collections.List _commands) throws Exception{
anywheresoftware.b4a.objects.collections.Map _command = null;
int _commandid = 0;
String _commandtype = "";
String _errormsg = "";
 //BA.debugLineNum = 454;BA.debugLine="Sub ProcessCommands(commands As List)";
 //BA.debugLineNum = 455;BA.debugLine="For Each command As Map In commands";
_command = new anywheresoftware.b4a.objects.collections.Map();
{
final anywheresoftware.b4a.BA.IterableList group1 = _commands;
final int groupLen1 = group1.getSize()
;int index1 = 0;
;
for (; index1 < groupLen1;index1++){
_command = (anywheresoftware.b4a.objects.collections.Map) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), (java.util.Map)(group1.Get(index1)));
 //BA.debugLineNum = 456;BA.debugLine="Try";
try { //BA.debugLineNum = 457;BA.debugLine="Dim commandId As Int = command.GetDefa";
_commandid = (int)(BA.ObjectToNumber(_command.GetDefault((Object)("id"),(Object)(0))));
 //BA.debugLineNum = 458;BA.debugLine="Dim commandType As String = command.Ge";
_commandtype = BA.ObjectToString(_command.GetDefault((Object)("command"),(Object)("")));
 //BA.debugLineNum = 460;BA.debugLine="Log(\"Processing command: \" & commandTy";
anywheresoftware.b4a.keywords.Common.LogImpl("42621446","Processing command: "+_commandtype+" (ID: "+BA.NumberToString(_commandid)+")",0);
 //BA.debugLineNum = 463;BA.debugLine="Select Case commandType.ToUpperCase";
switch (BA.switchObjectToInt(_commandtype.toUpperCase(),"SHUTDOWN","REBOOT","LOCK","UNLOCK","SCREENSHOT","REMOTE_START","REMOTE_STOP")) {
case 0: 
case 1: 
case 2: 
case 3: {
 //BA.debugLineNum = 466;BA.debugLine="If CurrentPermissionLevel >= P";
if (_currentpermissionlevel>=_perm_system) { 
 //BA.debugLineNum = 467;BA.debugLine="If commandType.ToUpperCase";
if ((_commandtype.toUpperCase()).equals("SHUTDOWN")) { 
 //BA.debugLineNum = 468;BA.debugLine="ExecuteShutdown(comman";
_executeshutdown(_commandid);
 }else if((_commandtype.toUpperCase()).equals("REBOOT")) { 
 //BA.debugLineNum = 470;BA.debugLine="ExecuteReboot(commandI";
_executereboot(_commandid);
 }else if((_commandtype.toUpperCase()).equals("LOCK")) { 
 //BA.debugLineNum = 472;BA.debugLine="ExecuteLock(commandId)";
_executelock(_commandid);
 }else if((_commandtype.toUpperCase()).equals("UNLOCK")) { 
 //BA.debugLineNum = 474;BA.debugLine="ExecuteUnlock(commandI";
_executeunlock(_commandid);
 };
 //BA.debugLineNum = 480;BA.debugLine="If CurrentPermissionLevel";
if (_currentpermissionlevel==_perm_sony) { 
 //BA.debugLineNum = 481;BA.debugLine="ToastMessageShow(\"Sony";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Sony Remote Control: Action confirmed by user"),anywheresoftware.b4a.keywords.Common.False);
 };
 }else {
 //BA.debugLineNum = 484;BA.debugLine="Dim errorMsg As String = \"";
_errormsg = "Permission Denied: Command "+_commandtype+" requires System/Root/Knox/Sony permissions.";
 //BA.debugLineNum = 485;BA.debugLine="Log(errorMsg)";
anywheresoftware.b4a.keywords.Common.LogImpl("42621471",_errormsg,0);
 //BA.debugLineNum = 486;BA.debugLine="AcknowledgeCommand(command";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,_errormsg);
 //BA.debugLineNum = 487;BA.debugLine="Return";
if (true) return "";
 };
 break; }
case 4: {
 //BA.debugLineNum = 492;BA.debugLine="ExecuteScreenshot(commandId)";
_executescreenshot(_commandid);
 break; }
case 5: {
 //BA.debugLineNum = 496;BA.debugLine="StartRemoteSession(commandId)";
_startremotesession(_commandid);
 break; }
case 6: {
 //BA.debugLineNum = 499;BA.debugLine="StopRemoteSession(commandId)";
_stopremotesession(_commandid);
 break; }
default: {
 //BA.debugLineNum = 502;BA.debugLine="Log(\"Unknown command type: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("42621488","Unknown command type: "+_commandtype,0);
 break; }
}
;
 //BA.debugLineNum = 508;BA.debugLine="If commandType.ToUpperCase <> \"SCREENS";
if ((_commandtype.toUpperCase()).equals("SCREENSHOT") == false && (_commandtype.toUpperCase()).equals("REMOTE_START") == false) { 
 //BA.debugLineNum = 509;BA.debugLine="AcknowledgeCommand(commandId, True";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.True,"");
 };
 } 
       catch (Exception e40) {
			processBA.setLastException(e40); //BA.debugLineNum = 512;BA.debugLine="Log(\"Error processing command: \" & Las";
anywheresoftware.b4a.keywords.Common.LogImpl("42621498","Error processing command: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 513;BA.debugLine="AcknowledgeCommand(commandId, False, L";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,anywheresoftware.b4a.keywords.Common.LastException(processBA).getMessage());
 };
 }
};
 //BA.debugLineNum = 516;BA.debugLine="End Sub";
return "";
}
public static String  _processcontent(anywheresoftware.b4a.objects.collections.List _content) throws Exception{
anywheresoftware.b4a.objects.collections.Map _item = null;
int _contentid = 0;
String _contentname = "";
String _contenttype = "";
String _downloadurl = "";
String _checksum = "";
 //BA.debugLineNum = 795;BA.debugLine="Sub ProcessContent(content As List)";
 //BA.debugLineNum = 796;BA.debugLine="For Each item As Map In content";
_item = new anywheresoftware.b4a.objects.collections.Map();
{
final anywheresoftware.b4a.BA.IterableList group1 = _content;
final int groupLen1 = group1.getSize()
;int index1 = 0;
;
for (; index1 < groupLen1;index1++){
_item = (anywheresoftware.b4a.objects.collections.Map) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), (java.util.Map)(group1.Get(index1)));
 //BA.debugLineNum = 797;BA.debugLine="Try";
try { //BA.debugLineNum = 798;BA.debugLine="Dim contentId As Int = item.GetDefault";
_contentid = (int)(BA.ObjectToNumber(_item.GetDefault((Object)("content_id"),(Object)(0))));
 //BA.debugLineNum = 799;BA.debugLine="Dim contentName As String = item.GetDe";
_contentname = BA.ObjectToString(_item.GetDefault((Object)("name"),(Object)("Unknown Content")));
 //BA.debugLineNum = 800;BA.debugLine="Dim contentType As String = item.GetDe";
_contenttype = BA.ObjectToString(_item.GetDefault((Object)("type"),(Object)("")));
 //BA.debugLineNum = 801;BA.debugLine="Dim downloadUrl As String = item.GetDe";
_downloadurl = BA.ObjectToString(_item.GetDefault((Object)("download_url"),(Object)("")));
 //BA.debugLineNum = 802;BA.debugLine="Dim checksum As String = item.GetDefau";
_checksum = BA.ObjectToString(_item.GetDefault((Object)("checksum"),(Object)("")));
 //BA.debugLineNum = 804;BA.debugLine="Log(\"Processing content: \" & contentNa";
anywheresoftware.b4a.keywords.Common.LogImpl("43276809","Processing content: "+_contentname+" (Type: "+_contenttype+")",0);
 //BA.debugLineNum = 807;BA.debugLine="Select Case contentType.ToLowerCase";
switch (BA.switchObjectToInt(_contenttype.toLowerCase(),"url","video","image","pdf","presentation")) {
case 0: {
 //BA.debugLineNum = 811;BA.debugLine="ReportContentStatus(contentId,";
_reportcontentstatus(_contentid,"deployed");
 break; }
case 1: 
case 2: 
case 3: 
case 4: {
 //BA.debugLineNum = 815;BA.debugLine="DownloadContent(downloadUrl, c";
_downloadcontent(_downloadurl,_contentid,_contentname,_contenttype,_checksum);
 break; }
default: {
 //BA.debugLineNum = 818;BA.debugLine="Log(\"Unknown content type: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("43276823","Unknown content type: "+_contenttype,0);
 //BA.debugLineNum = 819;BA.debugLine="ReportContentStatus(contentId,";
_reportcontentstatus(_contentid,"failed");
 break; }
}
;
 } 
       catch (Exception e19) {
			processBA.setLastException(e19); //BA.debugLineNum = 823;BA.debugLine="Log(\"Error processing content: \" & Las";
anywheresoftware.b4a.keywords.Common.LogImpl("43276828","Error processing content: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 }
};
 //BA.debugLineNum = 826;BA.debugLine="End Sub";
return "";
}
public static String  _remotesessiontimer_tick() throws Exception{
 //BA.debugLineNum = 1255;BA.debugLine="Sub RemoteSessionTimer_Tick";
 //BA.debugLineNum = 1256;BA.debugLine="If IsRemoteSessionActive Then";
if (_isremotesessionactive) { 
 //BA.debugLineNum = 1259;BA.debugLine="ExecuteScreenshot(0)";
_executescreenshot((int) (0));
 };
 //BA.debugLineNum = 1261;BA.debugLine="End Sub";
return "";
}
public static String  _reportappstatus(int _appid,String _status) throws Exception{
anywheresoftware.b4a.objects.collections.Map _data = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _json = null;
com.smartboard.sdms.agent.httpjob _job = null;
 //BA.debugLineNum = 1182;BA.debugLine="Sub ReportAppStatus(appId As Int, status As String";
 //BA.debugLineNum = 1183;BA.debugLine="Try";
try { //BA.debugLineNum = 1184;BA.debugLine="Log(\"Reporting app status for ID \" & appId";
anywheresoftware.b4a.keywords.Common.LogImpl("44390914","Reporting app status for ID "+BA.NumberToString(_appid)+": "+_status,0);
 //BA.debugLineNum = 1185;BA.debugLine="Dim data As Map";
_data = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 1186;BA.debugLine="data.Initialize";
_data.Initialize();
 //BA.debugLineNum = 1187;BA.debugLine="data.Put(\"app_id\", appId)";
_data.Put((Object)("app_id"),(Object)(_appid));
 //BA.debugLineNum = 1188;BA.debugLine="data.Put(\"status\", status)";
_data.Put((Object)("status"),(Object)(_status));
 //BA.debugLineNum = 1189;BA.debugLine="Dim json As JSONGenerator";
_json = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 1190;BA.debugLine="json.Initialize(data)";
_json.Initialize(_data);
 //BA.debugLineNum = 1191;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 1192;BA.debugLine="job.Initialize(\"app_status\", Me)";
_job._initialize /*String*/ (processBA,"app_status",messageservice.getObject());
 //BA.debugLineNum = 1193;BA.debugLine="job.PostString(ServerURL & \"/apps/status.p";
_job._poststring /*String*/ (_serverurl+"/apps/status.php",_json.ToString());
 //BA.debugLineNum = 1194;BA.debugLine="job.GetRequest.SetHeader(\"Authorization\",";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Authorization","Bearer "+anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt"));
 } 
       catch (Exception e14) {
			processBA.setLastException(e14); //BA.debugLineNum = 1196;BA.debugLine="Log(\"Error reporting app status: \" & LastE";
anywheresoftware.b4a.keywords.Common.LogImpl("44390926","Error reporting app status: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1198;BA.debugLine="End Sub";
return "";
}
public static String  _reportcontentstatus(int _contentid,String _status) throws Exception{
String _token = "";
anywheresoftware.b4a.objects.collections.Map _data = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _json = null;
com.smartboard.sdms.agent.httpjob _job = null;
 //BA.debugLineNum = 988;BA.debugLine="Sub ReportContentStatus(contentId As Int, status A";
 //BA.debugLineNum = 989;BA.debugLine="Try";
try { //BA.debugLineNum = 990;BA.debugLine="Dim token As String = \"\"";
_token = "";
 //BA.debugLineNum = 991;BA.debugLine="If File.Exists(File.DirInternal, \"token.tx";
if (anywheresoftware.b4a.keywords.Common.File.Exists(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt")) { 
 //BA.debugLineNum = 992;BA.debugLine="token = File.ReadString(File.DirIntern";
_token = anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt");
 };
 //BA.debugLineNum = 995;BA.debugLine="If token = \"\" Then";
if ((_token).equals("")) { 
 //BA.debugLineNum = 996;BA.debugLine="Log(\"Cannot report content status - no";
anywheresoftware.b4a.keywords.Common.LogImpl("43670024","Cannot report content status - no token",0);
 //BA.debugLineNum = 997;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 1000;BA.debugLine="Dim data As Map";
_data = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 1001;BA.debugLine="data.Initialize";
_data.Initialize();
 //BA.debugLineNum = 1002;BA.debugLine="data.Put(\"content_id\", contentId)";
_data.Put((Object)("content_id"),(Object)(_contentid));
 //BA.debugLineNum = 1003;BA.debugLine="data.Put(\"status\", status)";
_data.Put((Object)("status"),(Object)(_status));
 //BA.debugLineNum = 1005;BA.debugLine="Dim json As JSONGenerator";
_json = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 1006;BA.debugLine="json.Initialize(data)";
_json.Initialize(_data);
 //BA.debugLineNum = 1008;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 1009;BA.debugLine="job.Initialize(\"content_status\", Me)";
_job._initialize /*String*/ (processBA,"content_status",messageservice.getObject());
 //BA.debugLineNum = 1010;BA.debugLine="job.PostString(ServerURL & \"/content/statu";
_job._poststring /*String*/ (_serverurl+"/content/status.php",_json.ToString());
 //BA.debugLineNum = 1011;BA.debugLine="job.GetRequest.SetContentType(\"application";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetContentType("application/json");
 //BA.debugLineNum = 1012;BA.debugLine="job.GetRequest.SetHeader(\"Authorization\",";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Authorization","Bearer "+_token);
 //BA.debugLineNum = 1014;BA.debugLine="Log(\"Content status reported: \" & status &";
anywheresoftware.b4a.keywords.Common.LogImpl("43670042","Content status reported: "+_status+" for content ID: "+BA.NumberToString(_contentid),0);
 } 
       catch (Exception e23) {
			processBA.setLastException(e23); //BA.debugLineNum = 1016;BA.debugLine="Log(\"Error reporting content status: \" & L";
anywheresoftware.b4a.keywords.Common.LogImpl("43670044","Error reporting content status: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1018;BA.debugLine="End Sub";
return "";
}
public static String  _sendheartbeat() throws Exception{
String _token = "";
int _batterylevel = 0;
long _storagefree = 0L;
long _storagetotal = 0L;
anywheresoftware.b4a.objects.collections.Map _data = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _json = null;
com.smartboard.sdms.agent.httpjob _job = null;
 //BA.debugLineNum = 188;BA.debugLine="Sub SendHeartbeat";
 //BA.debugLineNum = 189;BA.debugLine="Dim token As String = \"\"";
_token = "";
 //BA.debugLineNum = 190;BA.debugLine="If File.Exists(File.DirInternal, \"token.txt\")";
if (anywheresoftware.b4a.keywords.Common.File.Exists(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt")) { 
_token = anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt");};
 //BA.debugLineNum = 191;BA.debugLine="If token = \"\" Then";
if ((_token).equals("")) { 
 //BA.debugLineNum = 192;BA.debugLine="CheckDeviceRegistration";
_checkdeviceregistration();
 //BA.debugLineNum = 193;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 196;BA.debugLine="Dim batteryLevel As Int = GetBatteryLevel";
_batterylevel = _getbatterylevel();
 //BA.debugLineNum = 197;BA.debugLine="Dim storageFree As Long = GetFreeStorageBytes";
_storagefree = _getfreestoragebytes();
 //BA.debugLineNum = 198;BA.debugLine="Dim storageTotal As Long = GetTotalStorageByte";
_storagetotal = _gettotalstoragebytes();
 //BA.debugLineNum = 200;BA.debugLine="Dim data As Map";
_data = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 201;BA.debugLine="data.Initialize";
_data.Initialize();
 //BA.debugLineNum = 202;BA.debugLine="data.Put(\"status\", \"online\")";
_data.Put((Object)("status"),(Object)("online"));
 //BA.debugLineNum = 203;BA.debugLine="data.Put(\"firmware_version\", Application.Versi";
_data.Put((Object)("firmware_version"),(Object)(anywheresoftware.b4a.keywords.Common.Application.getVersionName()));
 //BA.debugLineNum = 204;BA.debugLine="data.Put(\"android_version\", GetAndroidVersion)";
_data.Put((Object)("android_version"),(Object)(_getandroidversion()));
 //BA.debugLineNum = 205;BA.debugLine="data.Put(\"battery_level\", batteryLevel)";
_data.Put((Object)("battery_level"),(Object)(_batterylevel));
 //BA.debugLineNum = 206;BA.debugLine="data.Put(\"storage_free\", storageFree)";
_data.Put((Object)("storage_free"),(Object)(_storagefree));
 //BA.debugLineNum = 207;BA.debugLine="data.Put(\"storage_total\", storageTotal)";
_data.Put((Object)("storage_total"),(Object)(_storagetotal));
 //BA.debugLineNum = 209;BA.debugLine="Dim json As JSONGenerator";
_json = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 210;BA.debugLine="json.Initialize(data)";
_json.Initialize(_data);
 //BA.debugLineNum = 212;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 213;BA.debugLine="job.Initialize(\"heartbeat\", Me)";
_job._initialize /*String*/ (processBA,"heartbeat",messageservice.getObject());
 //BA.debugLineNum = 214;BA.debugLine="job.PostString(ServerURL & \"/devices/status\",";
_job._poststring /*String*/ (_serverurl+"/devices/status",_json.ToString());
 //BA.debugLineNum = 216;BA.debugLine="Try";
try { //BA.debugLineNum = 218;BA.debugLine="job.GetRequest.SetHeader(\"Content-Type\", \"";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Content-Type","application/json");
 //BA.debugLineNum = 219;BA.debugLine="job.GetRequest.SetHeader(\"Authorization\",";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Authorization","Bearer "+_token);
 } 
       catch (Exception e27) {
			processBA.setLastException(e27); //BA.debugLineNum = 221;BA.debugLine="Log(\"Error setting headers: \" & LastExcept";
anywheresoftware.b4a.keywords.Common.LogImpl("42228257","Error setting headers: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 223;BA.debugLine="End Sub";
return "";
}
public static String  _service_create() throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
 //BA.debugLineNum = 28;BA.debugLine="Sub Service_Create";
 //BA.debugLineNum = 29;BA.debugLine="Log(\"MessageService: Service_Create\")";
anywheresoftware.b4a.keywords.Common.LogImpl("41638401","MessageService: Service_Create",0);
 //BA.debugLineNum = 32;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 33;BA.debugLine="Manufacturer = p.Manufacturer.ToLowerCase";
_manufacturer = _p.getManufacturer().toLowerCase();
 //BA.debugLineNum = 34;BA.debugLine="Log(\"Manufacturer: \" & Manufacturer)";
anywheresoftware.b4a.keywords.Common.LogImpl("41638406","Manufacturer: "+_manufacturer,0);
 //BA.debugLineNum = 37;BA.debugLine="CurrentPermissionLevel = DeterminePermissionLe";
_currentpermissionlevel = _determinepermissionlevel();
 //BA.debugLineNum = 38;BA.debugLine="Log(\"Effective Permission Level: \" & CurrentPe";
anywheresoftware.b4a.keywords.Common.LogImpl("41638410","Effective Permission Level: "+BA.NumberToString(_currentpermissionlevel),0);
 //BA.debugLineNum = 40;BA.debugLine="MessageTimer.Initialize(\"MessageTimer\", Heartb";
_messagetimer.Initialize(processBA,"MessageTimer",_heartbeatinterval);
 //BA.debugLineNum = 41;BA.debugLine="RemoteSessionTimer.Initialize(\"RemoteSessionTi";
_remotesessiontimer.Initialize(processBA,"RemoteSessionTimer",(long) (2000));
 //BA.debugLineNum = 42;BA.debugLine="CreateNotificationChannels";
_createnotificationchannels();
 //BA.debugLineNum = 43;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
 //BA.debugLineNum = 61;BA.debugLine="Sub Service_Destroy";
 //BA.debugLineNum = 62;BA.debugLine="Log(\"MessageService: Service_Destroy\")";
anywheresoftware.b4a.keywords.Common.LogImpl("41769473","MessageService: Service_Destroy",0);
 //BA.debugLineNum = 63;BA.debugLine="MessageTimer.Enabled = False";
_messagetimer.setEnabled(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 64;BA.debugLine="RemoteSessionTimer.Enabled = False";
_remotesessiontimer.setEnabled(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 65;BA.debugLine="End Sub";
return "";
}
public static String  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
 //BA.debugLineNum = 45;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
 //BA.debugLineNum = 46;BA.debugLine="Log(\"MessageService: Service_Start\")";
anywheresoftware.b4a.keywords.Common.LogImpl("41703937","MessageService: Service_Start",0);
 //BA.debugLineNum = 49;BA.debugLine="StartForegroundService";
_startforegroundservice();
 //BA.debugLineNum = 52;BA.debugLine="MessageTimer.Enabled = True";
_messagetimer.setEnabled(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 55;BA.debugLine="CheckDeviceRegistration";
_checkdeviceregistration();
 //BA.debugLineNum = 59;BA.debugLine="End Sub";
return "";
}
public static String  _service_taskremoved() throws Exception{
 //BA.debugLineNum = 67;BA.debugLine="Sub Service_TaskRemoved";
 //BA.debugLineNum = 69;BA.debugLine="Log(\"MessageService: Task removed, scheduling";
anywheresoftware.b4a.keywords.Common.LogImpl("41835010","MessageService: Task removed, scheduling restart",0);
 //BA.debugLineNum = 70;BA.debugLine="End Sub";
return "";
}
public static String  _showbroadcastdisplay(String _title,String _message,String _priority) throws Exception{
anywheresoftware.b4a.objects.IntentWrapper _i = null;
 //BA.debugLineNum = 371;BA.debugLine="Sub ShowBroadcastDisplay(title As String, message";
 //BA.debugLineNum = 372;BA.debugLine="Try";
try { //BA.debugLineNum = 373;BA.debugLine="Log(\"Launching BroadcastDisplay activity..";
anywheresoftware.b4a.keywords.Common.LogImpl("42424834","Launching BroadcastDisplay activity...",0);
 //BA.debugLineNum = 374;BA.debugLine="Dim i As Intent";
_i = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 375;BA.debugLine="i.Initialize(\"\", \"\")";
_i.Initialize("","");
 //BA.debugLineNum = 376;BA.debugLine="i.SetComponent(\"com.smartboard.sdms.agent/";
_i.SetComponent("com.smartboard.sdms.agent/.broadcastdisplay");
 //BA.debugLineNum = 377;BA.debugLine="i.PutExtra(\"title\", title)";
_i.PutExtra("title",(Object)(_title));
 //BA.debugLineNum = 378;BA.debugLine="i.PutExtra(\"message\", message)";
_i.PutExtra("message",(Object)(_message));
 //BA.debugLineNum = 379;BA.debugLine="i.PutExtra(\"priority\", priority)";
_i.PutExtra("priority",(Object)(_priority));
 //BA.debugLineNum = 380;BA.debugLine="i.Flags = 268435456 ' FLAG_ACTIVITY_NEW_TA";
_i.setFlags((int) (268435456));
 //BA.debugLineNum = 381;BA.debugLine="StartActivity(i)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_i.getObject()));
 //BA.debugLineNum = 382;BA.debugLine="Log(\"BroadcastDisplay activity launched su";
anywheresoftware.b4a.keywords.Common.LogImpl("42424843","BroadcastDisplay activity launched successfully",0);
 } 
       catch (Exception e13) {
			processBA.setLastException(e13); //BA.debugLineNum = 384;BA.debugLine="Log(\"Error launching BroadcastDisplay: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("42424845","Error launching BroadcastDisplay: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 386;BA.debugLine="End Sub";
return "";
}
public static String  _showbroadcastnotification(String _title,String _message,int _broadcastid,String _priority) throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.objects.NotificationWrapper _n = null;
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
int _notifid = 0;
 //BA.debugLineNum = 388;BA.debugLine="Sub ShowBroadcastNotification(title As String, mes";
 //BA.debugLineNum = 389;BA.debugLine="Try";
try { //BA.debugLineNum = 390;BA.debugLine="Log(\"ShowBroadcastNotification called - Ti";
anywheresoftware.b4a.keywords.Common.LogImpl("42490370","ShowBroadcastNotification called - Title: "+_title+", Message: "+_message+", Priority: "+_priority,0);
 //BA.debugLineNum = 392;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 393;BA.debugLine="Dim n As Notification";
_n = new anywheresoftware.b4a.objects.NotificationWrapper();
 //BA.debugLineNum = 394;BA.debugLine="n.Initialize";
_n.Initialize();
 //BA.debugLineNum = 395;BA.debugLine="n.Icon = \"icon\"";
_n.setIcon("icon");
 //BA.debugLineNum = 396;BA.debugLine="n.AutoCancel = True";
_n.setAutoCancel(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 399;BA.debugLine="Select Case priority.ToLowerCase";
switch (BA.switchObjectToInt(_priority.toLowerCase(),"urgent","high","normal","low")) {
case 0: {
 //BA.debugLineNum = 401;BA.debugLine="n.Sound = True";
_n.setSound(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 402;BA.debugLine="n.Vibrate = True";
_n.setVibrate(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 403;BA.debugLine="n.Light = True";
_n.setLight(anywheresoftware.b4a.keywords.Common.True);
 break; }
case 1: {
 //BA.debugLineNum = 405;BA.debugLine="n.Sound = True";
_n.setSound(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 406;BA.debugLine="n.Vibrate = True";
_n.setVibrate(anywheresoftware.b4a.keywords.Common.True);
 break; }
case 2: {
 //BA.debugLineNum = 408;BA.debugLine="n.Sound = True";
_n.setSound(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 409;BA.debugLine="n.Vibrate = True";
_n.setVibrate(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 410;BA.debugLine="n.Light = True";
_n.setLight(anywheresoftware.b4a.keywords.Common.True);
 break; }
case 3: {
 //BA.debugLineNum = 412;BA.debugLine="n.Sound = False";
_n.setSound(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 413;BA.debugLine="n.Vibrate = False";
_n.setVibrate(anywheresoftware.b4a.keywords.Common.False);
 break; }
}
;
 //BA.debugLineNum = 417;BA.debugLine="If p.SdkVersion >= 26 Then";
if (_p.getSdkVersion()>=26) { 
 //BA.debugLineNum = 418;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 419;BA.debugLine="r.Target = n";
_r.Target = (Object)(_n.getObject());
 //BA.debugLineNum = 420;BA.debugLine="r.RunMethod2(\"setChannelId\", ChannelId";
_r.RunMethod2("setChannelId",_channelid,"java.lang.String");
 //BA.debugLineNum = 421;BA.debugLine="Log(\"Channel ID set: \" & ChannelId)";
anywheresoftware.b4a.keywords.Common.LogImpl("42490401","Channel ID set: "+_channelid,0);
 };
 //BA.debugLineNum = 425;BA.debugLine="n.SetInfo(title, message, Main)";
_n.SetInfoNew(processBA,BA.ObjectToCharSequence(_title),BA.ObjectToCharSequence(_message),(Object)(mostCurrent._main.getObject()));
 //BA.debugLineNum = 428;BA.debugLine="Dim notifId As Int = broadcastId + 1000";
_notifid = (int) (_broadcastid+1000);
 //BA.debugLineNum = 429;BA.debugLine="n.Notify(notifId)";
_n.Notify(_notifid);
 //BA.debugLineNum = 430;BA.debugLine="Log(\"Notification displayed with ID: \" & n";
anywheresoftware.b4a.keywords.Common.LogImpl("42490410","Notification displayed with ID: "+BA.NumberToString(_notifid)+" - Title: "+_title+" - Message: "+_message,0);
 } 
       catch (Exception e35) {
			processBA.setLastException(e35); //BA.debugLineNum = 432;BA.debugLine="Log(\"Error showing notification: \" & LastE";
anywheresoftware.b4a.keywords.Common.LogImpl("42490412","Error showing notification: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 434;BA.debugLine="End Sub";
return "";
}
public static String  _showsystempowerdialog() throws Exception{
anywheresoftware.b4a.objects.IntentWrapper _i = null;
 //BA.debugLineNum = 582;BA.debugLine="Sub ShowSystemPowerDialog";
 //BA.debugLineNum = 583;BA.debugLine="Try";
try { //BA.debugLineNum = 584;BA.debugLine="Log(\"Showing system power dialog (fallback";
anywheresoftware.b4a.keywords.Common.LogImpl("42949122","Showing system power dialog (fallback)",0);
 //BA.debugLineNum = 585;BA.debugLine="Dim i As Intent";
_i = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 586;BA.debugLine="i.Initialize(\"android.intent.action.REBOOT";
_i.Initialize("android.intent.action.REBOOT","");
 //BA.debugLineNum = 587;BA.debugLine="StartActivity(i)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_i.getObject()));
 } 
       catch (Exception e7) {
			processBA.setLastException(e7); //BA.debugLineNum = 589;BA.debugLine="Log(\"Could not show power dialog: \" & Last";
anywheresoftware.b4a.keywords.Common.LogImpl("42949127","Could not show power dialog: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 591;BA.debugLine="End Sub";
return "";
}
public static String  _startforegroundservice() throws Exception{
 //BA.debugLineNum = 74;BA.debugLine="Sub StartForegroundService";
 //BA.debugLineNum = 75;BA.debugLine="UpdateForegroundNotification(\"Monitoring for m";
_updateforegroundnotification("Monitoring for messages...",(int) (-1));
 //BA.debugLineNum = 76;BA.debugLine="End Sub";
return "";
}
public static String  _startremotesession(int _commandid) throws Exception{
com.smartboard.sdms.agent.httpjob _job = null;
 //BA.debugLineNum = 1202;BA.debugLine="Sub StartRemoteSession(commandId As Int)";
 //BA.debugLineNum = 1203;BA.debugLine="Try";
try { //BA.debugLineNum = 1204;BA.debugLine="Log(\"Starting Remote Session (Command ID:";
anywheresoftware.b4a.keywords.Common.LogImpl("44456450","Starting Remote Session (Command ID: "+BA.NumberToString(_commandid)+")",0);
 //BA.debugLineNum = 1205;BA.debugLine="Log(\"Remote View Permission Level: \" & Cur";
anywheresoftware.b4a.keywords.Common.LogImpl("44456451","Remote View Permission Level: "+BA.NumberToString(_currentpermissionlevel),0);
 //BA.debugLineNum = 1208;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 1209;BA.debugLine="job.Initialize(\"fetch_settings_remote_\" &";
_job._initialize /*String*/ (processBA,"fetch_settings_remote_"+BA.NumberToString(_commandid),messageservice.getObject());
 //BA.debugLineNum = 1210;BA.debugLine="job.Download(ServerURL & \"/settings.php\")";
_job._download /*String*/ (_serverurl+"/settings.php");
 //BA.debugLineNum = 1211;BA.debugLine="job.GetRequest.SetHeader(\"Authorization\",";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Authorization","Bearer "+anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt"));
 } 
       catch (Exception e9) {
			processBA.setLastException(e9); //BA.debugLineNum = 1213;BA.debugLine="Log(\"Error initiating remote session start";
anywheresoftware.b4a.keywords.Common.LogImpl("44456459","Error initiating remote session start: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 //BA.debugLineNum = 1214;BA.debugLine="AcknowledgeCommand(commandId, False, \"Erro";
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.False,"Error: "+anywheresoftware.b4a.keywords.Common.LastException(processBA).getMessage());
 };
 //BA.debugLineNum = 1216;BA.debugLine="End Sub";
return "";
}
public static String  _stopremotesession(int _commandid) throws Exception{
 //BA.debugLineNum = 1244;BA.debugLine="Sub StopRemoteSession(commandId As Int)";
 //BA.debugLineNum = 1245;BA.debugLine="Try";
try { //BA.debugLineNum = 1246;BA.debugLine="Log(\"Stopping Remote Session\")";
anywheresoftware.b4a.keywords.Common.LogImpl("44587522","Stopping Remote Session",0);
 //BA.debugLineNum = 1247;BA.debugLine="IsRemoteSessionActive = False";
_isremotesessionactive = anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 1248;BA.debugLine="RemoteSessionTimer.Enabled = False";
_remotesessiontimer.setEnabled(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 1249;BA.debugLine="If commandId > 0 Then AcknowledgeCommand(c";
if (_commandid>0) { 
_acknowledgecommand(_commandid,anywheresoftware.b4a.keywords.Common.True,"");};
 } 
       catch (Exception e7) {
			processBA.setLastException(e7); //BA.debugLineNum = 1251;BA.debugLine="Log(\"Error stopping remote session: \" & La";
anywheresoftware.b4a.keywords.Common.LogImpl("44587527","Error stopping remote session: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1253;BA.debugLine="End Sub";
return "";
}
public static String  _triggerappinstall(String _apkpath) throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.objects.IntentWrapper _i = null;
anywheresoftware.b4j.object.JavaObject _fileobj = null;
anywheresoftware.b4j.object.JavaObject _fileprovider = null;
anywheresoftware.b4j.object.JavaObject _context = null;
String _authority = "";
Object _uri = null;
anywheresoftware.b4j.object.JavaObject _jo = null;
 //BA.debugLineNum = 1153;BA.debugLine="Public Sub TriggerAppInstall(apkPath As String)";
 //BA.debugLineNum = 1154;BA.debugLine="Try";
try { //BA.debugLineNum = 1155;BA.debugLine="Log(\"Triggering installation for: \" & apkP";
anywheresoftware.b4a.keywords.Common.LogImpl("44325378","Triggering installation for: "+_apkpath,0);
 //BA.debugLineNum = 1156;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 1157;BA.debugLine="Dim i As Intent";
_i = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 1158;BA.debugLine="If p.SdkVersion >= 24 Then";
if (_p.getSdkVersion()>=24) { 
 //BA.debugLineNum = 1159;BA.debugLine="Dim fileObj As JavaObject";
_fileobj = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 1160;BA.debugLine="fileObj.InitializeNewInstance(\"java.io";
_fileobj.InitializeNewInstance("java.io.File",new Object[]{(Object)(_apkpath)});
 //BA.debugLineNum = 1161;BA.debugLine="Dim FileProvider As JavaObject";
_fileprovider = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 1162;BA.debugLine="Dim context As JavaObject";
_context = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 1163;BA.debugLine="context.InitializeContext";
_context.InitializeContext(processBA);
 //BA.debugLineNum = 1164;BA.debugLine="Dim authority As String = Application.";
_authority = anywheresoftware.b4a.keywords.Common.Application.getPackageName()+".provider";
 //BA.debugLineNum = 1165;BA.debugLine="Dim uri As Object = FileProvider.Initi";
_uri = _fileprovider.InitializeStatic("androidx.core.content.FileProvider").RunMethod("getUriForFile",new Object[]{(Object)(_context.getObject()),(Object)(_authority),(Object)(_fileobj.getObject())});
 //BA.debugLineNum = 1166;BA.debugLine="i.Initialize(i.ACTION_VIEW, \"\")";
_i.Initialize(_i.ACTION_VIEW,"");
 //BA.debugLineNum = 1167;BA.debugLine="Dim jo As JavaObject = i";
_jo = new anywheresoftware.b4j.object.JavaObject();
_jo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_i.getObject()));
 //BA.debugLineNum = 1168;BA.debugLine="jo.RunMethod(\"setDataAndType\", Array(u";
_jo.RunMethod("setDataAndType",new Object[]{_uri,(Object)("application/vnd.android.package-archive")});
 //BA.debugLineNum = 1169;BA.debugLine="jo.RunMethod(\"addFlags\", Array(1))";
_jo.RunMethod("addFlags",new Object[]{(Object)(1)});
 }else {
 //BA.debugLineNum = 1171;BA.debugLine="i.Initialize(i.ACTION_VIEW, \"file://\"";
_i.Initialize(_i.ACTION_VIEW,"file://"+_apkpath);
 //BA.debugLineNum = 1172;BA.debugLine="i.SetType(\"application/vnd.android.pac";
_i.SetType("application/vnd.android.package-archive");
 };
 //BA.debugLineNum = 1174;BA.debugLine="i.Flags = Bit.Or(i.Flags, 268435456)";
_i.setFlags(anywheresoftware.b4a.keywords.Common.Bit.Or(_i.getFlags(),(int) (268435456)));
 //BA.debugLineNum = 1175;BA.debugLine="StartActivity(i)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_i.getObject()));
 //BA.debugLineNum = 1176;BA.debugLine="Log(\"Install intent started\")";
anywheresoftware.b4a.keywords.Common.LogImpl("44325399","Install intent started",0);
 } 
       catch (Exception e25) {
			processBA.setLastException(e25); //BA.debugLineNum = 1178;BA.debugLine="Log(\"Error triggering install: \" & LastExc";
anywheresoftware.b4a.keywords.Common.LogImpl("44325401","Error triggering install: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 1180;BA.debugLine="End Sub";
return "";
}
public static String  _updateforegroundnotification(String _statusmessage,int _approvalstatus) throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
anywheresoftware.b4a.objects.NotificationWrapper _n = null;
String _title = "";
String _message = "";
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
 //BA.debugLineNum = 78;BA.debugLine="Sub UpdateForegroundNotification(statusMessage As";
 //BA.debugLineNum = 79;BA.debugLine="Try";
try { //BA.debugLineNum = 80;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 81;BA.debugLine="If p.SdkVersion >= 26 Then";
if (_p.getSdkVersion()>=26) { 
 //BA.debugLineNum = 82;BA.debugLine="Dim n As Notification";
_n = new anywheresoftware.b4a.objects.NotificationWrapper();
 //BA.debugLineNum = 83;BA.debugLine="n.Initialize";
_n.Initialize();
 //BA.debugLineNum = 84;BA.debugLine="n.Icon = \"icon\"";
_n.setIcon("icon");
 //BA.debugLineNum = 85;BA.debugLine="n.AutoCancel = False";
_n.setAutoCancel(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 86;BA.debugLine="n.OnGoingEvent = True";
_n.setOnGoingEvent(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 88;BA.debugLine="Dim title As String = \"SDMS Agent\"";
_title = "SDMS Agent";
 //BA.debugLineNum = 89;BA.debugLine="Dim message As String = statusMessage";
_message = _statusmessage;
 //BA.debugLineNum = 93;BA.debugLine="Select approvalStatus";
switch (_approvalstatus) {
case 0: {
 //BA.debugLineNum = 95;BA.debugLine="title = \"SDMS Agent - Pending";
_title = "SDMS Agent - Pending Approval";
 //BA.debugLineNum = 96;BA.debugLine="message = \"Waiting for admin a";
_message = "Waiting for admin approval...";
 break; }
case 1: {
 //BA.debugLineNum = 98;BA.debugLine="title = \"SDMS Agent - Running\"";
_title = "SDMS Agent - Running";
 //BA.debugLineNum = 99;BA.debugLine="message = \"Monitoring for broa";
_message = "Monitoring for broadcasts";
 break; }
case 2: {
 //BA.debugLineNum = 101;BA.debugLine="title = \"SDMS Agent - Rejected";
_title = "SDMS Agent - Rejected";
 //BA.debugLineNum = 102;BA.debugLine="message = \"Device registration";
_message = "Device registration rejected";
 break; }
default: {
 //BA.debugLineNum = 104;BA.debugLine="title = \"SDMS Agent\"";
_title = "SDMS Agent";
 //BA.debugLineNum = 105;BA.debugLine="message = statusMessage";
_message = _statusmessage;
 break; }
}
;
 //BA.debugLineNum = 108;BA.debugLine="n.SetInfo(title, message, Main)";
_n.SetInfoNew(processBA,BA.ObjectToCharSequence(_title),BA.ObjectToCharSequence(_message),(Object)(mostCurrent._main.getObject()));
 //BA.debugLineNum = 111;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
 //BA.debugLineNum = 112;BA.debugLine="r.Target = n";
_r.Target = (Object)(_n.getObject());
 //BA.debugLineNum = 113;BA.debugLine="r.RunMethod2(\"setChannelId\", ServiceCh";
_r.RunMethod2("setChannelId",_servicechannelid,"java.lang.String");
 //BA.debugLineNum = 118;BA.debugLine="Service.StartForeground(1, n)";
mostCurrent._service.StartForeground((int) (1),(android.app.Notification)(_n.getObject()));
 //BA.debugLineNum = 120;BA.debugLine="Log(\"Foreground notification updated:";
anywheresoftware.b4a.keywords.Common.LogImpl("41966122","Foreground notification updated: "+_title+" - "+_message,0);
 };
 } 
       catch (Exception e33) {
			processBA.setLastException(e33); //BA.debugLineNum = 123;BA.debugLine="Log(\"Error updating foreground service: \"";
anywheresoftware.b4a.keywords.Common.LogImpl("41966125","Error updating foreground service: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 125;BA.debugLine="End Sub";
return "";
}
public static String  _uploadscreenshot(String _filepath,int _commandid) throws Exception{
String _token = "";
com.smartboard.sdms.agent.httpjob _job = null;
anywheresoftware.b4a.objects.collections.List _files = null;
com.smartboard.sdms.agent.httpjob._multipartfiledata _fd = null;
int _lastslash = 0;
 //BA.debugLineNum = 756;BA.debugLine="Sub UploadScreenshot(filePath As String, commandId";
 //BA.debugLineNum = 757;BA.debugLine="Try";
try { //BA.debugLineNum = 758;BA.debugLine="Log(\"Uploading screenshot for command ID:";
anywheresoftware.b4a.keywords.Common.LogImpl("43211266","Uploading screenshot for command ID: "+BA.NumberToString(_commandid),0);
 //BA.debugLineNum = 760;BA.debugLine="Dim token As String = \"\"";
_token = "";
 //BA.debugLineNum = 761;BA.debugLine="If File.Exists(File.DirInternal, \"token.tx";
if (anywheresoftware.b4a.keywords.Common.File.Exists(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt")) { 
_token = anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"token.txt");};
 //BA.debugLineNum = 763;BA.debugLine="Dim job As HttpJob";
_job = new com.smartboard.sdms.agent.httpjob();
 //BA.debugLineNum = 764;BA.debugLine="job.Initialize(\"upload_screenshot\", Me)";
_job._initialize /*String*/ (processBA,"upload_screenshot",messageservice.getObject());
 //BA.debugLineNum = 767;BA.debugLine="Dim files As List";
_files = new anywheresoftware.b4a.objects.collections.List();
 //BA.debugLineNum = 768;BA.debugLine="files.Initialize";
_files.Initialize();
 //BA.debugLineNum = 774;BA.debugLine="Dim fd As MultipartFileData";
_fd = new com.smartboard.sdms.agent.httpjob._multipartfiledata();
 //BA.debugLineNum = 775;BA.debugLine="fd.Initialize";
_fd.Initialize();
 //BA.debugLineNum = 777;BA.debugLine="Dim lastSlash As Int = filePath.LastIndexO";
_lastslash = _filepath.lastIndexOf("/");
 //BA.debugLineNum = 778;BA.debugLine="fd.Dir = filePath.SubString2(0, lastSlash)";
_fd.Dir /*String*/  = _filepath.substring((int) (0),_lastslash);
 //BA.debugLineNum = 779;BA.debugLine="fd.FileName = filePath.SubString(lastSlash";
_fd.FileName /*String*/  = _filepath.substring((int) (_lastslash+1));
 //BA.debugLineNum = 780;BA.debugLine="fd.KeyName = \"screenshot\"";
_fd.KeyName /*String*/  = "screenshot";
 //BA.debugLineNum = 781;BA.debugLine="fd.ContentType = \"image/png\"";
_fd.ContentType /*String*/  = "image/png";
 //BA.debugLineNum = 782;BA.debugLine="files.Add(fd)";
_files.Add((Object)(_fd));
 //BA.debugLineNum = 784;BA.debugLine="job.PostMultipart(ServerURL & \"/devices/up";
_job._postmultipart /*String*/ (_serverurl+"/devices/upload-screenshot.php",anywheresoftware.b4a.keywords.Common.createMap(new Object[] {(Object)("command_id"),(Object)(_commandid)}),_files);
 //BA.debugLineNum = 785;BA.debugLine="job.GetRequest.SetHeader(\"Authorization\",";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Authorization","Bearer "+_token);
 //BA.debugLineNum = 787;BA.debugLine="Log(\"Screenshot upload job started\")";
anywheresoftware.b4a.keywords.Common.LogImpl("43211295","Screenshot upload job started",0);
 } 
       catch (Exception e21) {
			processBA.setLastException(e21); //BA.debugLineNum = 789;BA.debugLine="Log(\"Error starting screenshot upload: \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("43211297","Error starting screenshot upload: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
 };
 //BA.debugLineNum = 791;BA.debugLine="End Sub";
return "";
}
}
