package b4a.bbb;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.objects.ServiceHelper;
import anywheresoftware.b4a.debug.*;

public class starter extends  android.app.Service{
	public static class starter_BR extends android.content.BroadcastReceiver {

		@Override
		public void onReceive(android.content.Context context, android.content.Intent intent) {
            BA.LogInfo("** Receiver (starter) OnReceive **");
			android.content.Intent in = new android.content.Intent(context, starter.class);
			if (intent != null)
				in.putExtra("b4a_internal_intent", intent);
            ServiceHelper.StarterHelper.startServiceFromReceiver (context, in, true, anywheresoftware.b4a.ShellBA.class);
		}

	}
    static starter mostCurrent;
	public static BA processBA;
    private ServiceHelper _service;
    public static Class<?> getObject() {
		return starter.class;
	}
	@Override
	public void onCreate() {
        super.onCreate();
        mostCurrent = this;
        if (processBA == null) {
		    processBA = new anywheresoftware.b4a.ShellBA(this, null, null, "b4a.bbb", "b4a.bbb.starter");
            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, "b4a.bbb.starter", processBA, _service, anywheresoftware.b4a.keywords.Common.Density);
		}
        if (!true && ServiceHelper.StarterHelper.startFromServiceCreate(processBA, false) == false) {
				
		}
		else {
            processBA.setActivityPaused(false);
            BA.LogInfo("*** Service (starter) Create ***");
            processBA.raiseEvent(null, "service_create");
        }
        processBA.runHook("oncreate", this, null);
        if (true) {
			ServiceHelper.StarterHelper.runWaitForLayouts();
		}
    }
		@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 (starter) 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_NOT_STICKY;
    }
    public void onTaskRemoved(android.content.Intent rootIntent) {
        super.onTaskRemoved(rootIntent);
        if (true)
            processBA.raiseEvent(null, "service_taskremoved");
            
    }
    private void handleStart(android.content.Intent intent) {
    	BA.LogInfo("** Service (starter) 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");
    		}
    	}
    }
	
	@Override
	public void onDestroy() {
        super.onDestroy();
        if (true) {
            BA.LogInfo("** Service (starter) Destroy (ignored)**");
        }
        else {
            BA.LogInfo("** Service (starter) 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 anywheresoftware.b4a.objects.BleManager2 _manager = null;
public static String _currentstatetext = "";
public static int _currentstate = 0;
public static boolean _connected = false;
public static String _connectedname = "";
public static anywheresoftware.b4a.objects.collections.List _connectedservices = null;
public static anywheresoftware.b4a.objects.RuntimePermissions _rp = null;
public static anywheresoftware.b4a.agraham.byteconverter.ByteConverter _bc = null;
public b4a.bbb.main _main = null;
public b4a.bbb.param _param = null;
public b4a.bbb.setup _setup = null;
public b4a.bbb.cockpit _cockpit = null;
public b4a.bbb.collecte_data_sensor _collecte_data_sensor = null;
public b4a.bbb.httputils2service _httputils2service = null;
public static String  _disconnect() throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "disconnect", false))
	 {return ((String) Debug.delegate(processBA, "disconnect", null));}
RDebugUtils.currentLine=1310720;
 //BA.debugLineNum = 1310720;BA.debugLine="Public Sub Disconnect";
RDebugUtils.currentLine=1310721;
 //BA.debugLineNum = 1310721;BA.debugLine="manager.Disconnect";
_manager.Disconnect();
RDebugUtils.currentLine=1310722;
 //BA.debugLineNum = 1310722;BA.debugLine="Manager_Disconnected";
_manager_disconnected();
RDebugUtils.currentLine=1310723;
 //BA.debugLineNum = 1310723;BA.debugLine="End Sub";
return "";
}
public static String  _readdata() throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "readdata", false))
	 {return ((String) Debug.delegate(processBA, "readdata", null));}
String _s = "";
RDebugUtils.currentLine=1245184;
 //BA.debugLineNum = 1245184;BA.debugLine="Public Sub ReadData";
RDebugUtils.currentLine=1245185;
 //BA.debugLineNum = 1245185;BA.debugLine="For Each s As String In ConnectedServices";
{
final anywheresoftware.b4a.BA.IterableList group1 = _connectedservices;
final int groupLen1 = group1.getSize()
;int index1 = 0;
;
for (; index1 < groupLen1;index1++){
_s = BA.ObjectToString(group1.Get(index1));
RDebugUtils.currentLine=1245186;
 //BA.debugLineNum = 1245186;BA.debugLine="manager.ReadData(s)";
_manager.ReadData(_s);
 }
};
RDebugUtils.currentLine=1245188;
 //BA.debugLineNum = 1245188;BA.debugLine="End Sub";
return "";
}
public static String  _startscan() throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "startscan", false))
	 {return ((String) Debug.delegate(processBA, "startscan", null));}
RDebugUtils.currentLine=1507328;
 //BA.debugLineNum = 1507328;BA.debugLine="Public Sub StartScan";
RDebugUtils.currentLine=1507329;
 //BA.debugLineNum = 1507329;BA.debugLine="If manager.State <> manager.STATE_POWERED_ON Then";
if (_manager.getState()!=_manager.STATE_POWERED_ON) { 
RDebugUtils.currentLine=1507330;
 //BA.debugLineNum = 1507330;BA.debugLine="Log(\"Not powered on.\")";
anywheresoftware.b4a.keywords.Common.LogImpl("61507330","Not powered on.",0);
 }else 
{RDebugUtils.currentLine=1507331;
 //BA.debugLineNum = 1507331;BA.debugLine="Else If rp.Check(rp.PERMISSION_ACCESS_COARSE_LOCA";
if (_rp.Check(_rp.PERMISSION_ACCESS_COARSE_LOCATION)==anywheresoftware.b4a.keywords.Common.False) { 
RDebugUtils.currentLine=1507332;
 //BA.debugLineNum = 1507332;BA.debugLine="Log(\"No location permission.\")";
anywheresoftware.b4a.keywords.Common.LogImpl("61507332","No location permission.",0);
 }else {
RDebugUtils.currentLine=1507334;
 //BA.debugLineNum = 1507334;BA.debugLine="manager.Scan2(Null, False)";
_manager.Scan2((anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(anywheresoftware.b4a.keywords.Common.Null)),anywheresoftware.b4a.keywords.Common.False);
 }}
;
RDebugUtils.currentLine=1507336;
 //BA.debugLineNum = 1507336;BA.debugLine="End Sub";
return "";
}
public static boolean  _application_error(anywheresoftware.b4a.objects.B4AException _error,String _stacktrace) throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "application_error", false))
	 {return ((Boolean) Debug.delegate(processBA, "application_error", new Object[] {_error,_stacktrace}));}
RDebugUtils.currentLine=1769472;
 //BA.debugLineNum = 1769472;BA.debugLine="Sub Application_Error (Error As Exception, StackTr";
RDebugUtils.currentLine=1769473;
 //BA.debugLineNum = 1769473;BA.debugLine="Return True";
if (true) return anywheresoftware.b4a.keywords.Common.True;
RDebugUtils.currentLine=1769474;
 //BA.debugLineNum = 1769474;BA.debugLine="End Sub";
return false;
}
public static String  _manager_disconnected() throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "manager_disconnected", false))
	 {return ((String) Debug.delegate(processBA, "manager_disconnected", null));}
RDebugUtils.currentLine=1638400;
 //BA.debugLineNum = 1638400;BA.debugLine="Sub Manager_Disconnected";
RDebugUtils.currentLine=1638401;
 //BA.debugLineNum = 1638401;BA.debugLine="Log(\"Disconnected\")";
anywheresoftware.b4a.keywords.Common.LogImpl("61638401","Disconnected",0);
RDebugUtils.currentLine=1638402;
 //BA.debugLineNum = 1638402;BA.debugLine="connected = False";
_connected = anywheresoftware.b4a.keywords.Common.False;
RDebugUtils.currentLine=1638403;
 //BA.debugLineNum = 1638403;BA.debugLine="CallSub(Main, \"StateChanged\")";
anywheresoftware.b4a.keywords.Common.CallSubDebug(processBA,(Object)(mostCurrent._main.getObject()),"StateChanged");
RDebugUtils.currentLine=1638404;
 //BA.debugLineNum = 1638404;BA.debugLine="End Sub";
return "";
}
public static String  _manager_connected(anywheresoftware.b4a.objects.collections.List _services) throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "manager_connected", false))
	 {return ((String) Debug.delegate(processBA, "manager_connected", new Object[] {_services}));}
RDebugUtils.currentLine=1703936;
 //BA.debugLineNum = 1703936;BA.debugLine="Sub Manager_Connected (services As List)";
RDebugUtils.currentLine=1703937;
 //BA.debugLineNum = 1703937;BA.debugLine="Log(\"Connected\")";
anywheresoftware.b4a.keywords.Common.LogImpl("61703937","Connected",0);
RDebugUtils.currentLine=1703938;
 //BA.debugLineNum = 1703938;BA.debugLine="connected = True";
_connected = anywheresoftware.b4a.keywords.Common.True;
RDebugUtils.currentLine=1703939;
 //BA.debugLineNum = 1703939;BA.debugLine="ConnectedServices = services";
_connectedservices = _services;
RDebugUtils.currentLine=1703940;
 //BA.debugLineNum = 1703940;BA.debugLine="CallSub(Main, \"StateChanged\")";
anywheresoftware.b4a.keywords.Common.CallSubDebug(processBA,(Object)(mostCurrent._main.getObject()),"StateChanged");
RDebugUtils.currentLine=1703941;
 //BA.debugLineNum = 1703941;BA.debugLine="End Sub";
return "";
}
public static String  _manager_dataavailable(String _serviceid,anywheresoftware.b4a.objects.collections.Map _characteristics) throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "manager_dataavailable", false))
	 {return ((String) Debug.delegate(processBA, "manager_dataavailable", new Object[] {_serviceid,_characteristics}));}
RDebugUtils.currentLine=1572864;
 //BA.debugLineNum = 1572864;BA.debugLine="Sub Manager_DataAvailable (ServiceId As String, Ch";
RDebugUtils.currentLine=1572865;
 //BA.debugLineNum = 1572865;BA.debugLine="CallSub3(Main, \"DataAvailable\", ServiceId, Charac";
anywheresoftware.b4a.keywords.Common.CallSubDebug3(processBA,(Object)(mostCurrent._main.getObject()),"DataAvailable",(Object)(_serviceid),(Object)(_characteristics));
RDebugUtils.currentLine=1572866;
 //BA.debugLineNum = 1572866;BA.debugLine="End Sub";
return "";
}
public static String  _manager_devicefound(String _name,String _id,anywheresoftware.b4a.objects.collections.Map _advertisingdata,double _rssi) throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "manager_devicefound", false))
	 {return ((String) Debug.delegate(processBA, "manager_devicefound", new Object[] {_name,_id,_advertisingdata,_rssi}));}
RDebugUtils.currentLine=1441792;
 //BA.debugLineNum = 1441792;BA.debugLine="Sub Manager_DeviceFound (Name As String, Id As Str";
RDebugUtils.currentLine=1441793;
 //BA.debugLineNum = 1441793;BA.debugLine="Log(\"Found: \" & Name & \", \" & Id & \", RSSI = \" &";
anywheresoftware.b4a.keywords.Common.LogImpl("61441793","Found: "+_name+", "+_id+", RSSI = "+BA.NumberToString(_rssi)+", "+BA.ObjectToString(_advertisingdata),0);
RDebugUtils.currentLine=1441795;
 //BA.debugLineNum = 1441795;BA.debugLine="If Name=\"MJ_HT_V1\" Then 'filtre sur le model de s";
if ((_name).equals("MJ_HT_V1")) { 
RDebugUtils.currentLine=1441797;
 //BA.debugLineNum = 1441797;BA.debugLine="CallSub3(Setup,\"add_list_service\",Name,Id & \";\"";
anywheresoftware.b4a.keywords.Common.CallSubDebug3(processBA,(Object)(mostCurrent._setup.getObject()),"add_list_service",(Object)(_name),(Object)(_id+";"+BA.NumberToString(_rssi)));
 };
RDebugUtils.currentLine=1441810;
 //BA.debugLineNum = 1441810;BA.debugLine="End Sub";
return "";
}
public static String  _manager_statechanged(int _state) throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "manager_statechanged", false))
	 {return ((String) Debug.delegate(processBA, "manager_statechanged", new Object[] {_state}));}
RDebugUtils.currentLine=1376256;
 //BA.debugLineNum = 1376256;BA.debugLine="Sub Manager_StateChanged (State As Int)";
RDebugUtils.currentLine=1376257;
 //BA.debugLineNum = 1376257;BA.debugLine="Select State";
switch (BA.switchObjectToInt(_state,_manager.STATE_POWERED_OFF,_manager.STATE_POWERED_ON,_manager.STATE_UNSUPPORTED)) {
case 0: {
RDebugUtils.currentLine=1376259;
 //BA.debugLineNum = 1376259;BA.debugLine="currentStateText = \"POWERED OFF\"";
_currentstatetext = "POWERED OFF";
 break; }
case 1: {
RDebugUtils.currentLine=1376261;
 //BA.debugLineNum = 1376261;BA.debugLine="currentStateText = \"POWERED ON\"";
_currentstatetext = "POWERED ON";
 break; }
case 2: {
RDebugUtils.currentLine=1376263;
 //BA.debugLineNum = 1376263;BA.debugLine="currentStateText = \"UNSUPPORTED\"";
_currentstatetext = "UNSUPPORTED";
 break; }
}
;
RDebugUtils.currentLine=1376265;
 //BA.debugLineNum = 1376265;BA.debugLine="currentState = State";
_currentstate = _state;
RDebugUtils.currentLine=1376266;
 //BA.debugLineNum = 1376266;BA.debugLine="CallSub(Setup, \"StateChanged\")";
anywheresoftware.b4a.keywords.Common.CallSubDebug(processBA,(Object)(mostCurrent._setup.getObject()),"StateChanged");
RDebugUtils.currentLine=1376267;
 //BA.debugLineNum = 1376267;BA.debugLine="End Sub";
return "";
}
public static String  _service_create() throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "service_create", false))
	 {return ((String) Debug.delegate(processBA, "service_create", null));}
RDebugUtils.currentLine=1114112;
 //BA.debugLineNum = 1114112;BA.debugLine="Sub Service_Create";
RDebugUtils.currentLine=1114113;
 //BA.debugLineNum = 1114113;BA.debugLine="manager.Initialize(\"manager\")";
_manager.Initialize(processBA,"manager");
RDebugUtils.currentLine=1114114;
 //BA.debugLineNum = 1114114;BA.debugLine="StartService(Collecte_data_sensor)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._collecte_data_sensor.getObject()));
RDebugUtils.currentLine=1114115;
 //BA.debugLineNum = 1114115;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "service_destroy", false))
	 {return ((String) Debug.delegate(processBA, "service_destroy", null));}
RDebugUtils.currentLine=1835008;
 //BA.debugLineNum = 1835008;BA.debugLine="Sub Service_Destroy";
RDebugUtils.currentLine=1835010;
 //BA.debugLineNum = 1835010;BA.debugLine="End Sub";
return "";
}
public static String  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
RDebugUtils.currentModule="starter";
if (Debug.shouldDelegate(processBA, "service_start", false))
	 {return ((String) Debug.delegate(processBA, "service_start", new Object[] {_startingintent}));}
RDebugUtils.currentLine=1179648;
 //BA.debugLineNum = 1179648;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
RDebugUtils.currentLine=1179650;
 //BA.debugLineNum = 1179650;BA.debugLine="End Sub";
return "";
}
}