package reparto_izca.keymon.lat;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.objects.ServiceHelper;
import anywheresoftware.b4a.debug.*;

public class appupdater extends android.app.Service{
	public static class appupdater_BR extends android.content.BroadcastReceiver {

		@Override
		public void onReceive(android.content.Context context, android.content.Intent intent) {
            BA.LogInfo("** Receiver (appupdater) OnReceive **");
			android.content.Intent in = new android.content.Intent(context, appupdater.class);
			if (intent != null)
				in.putExtra("b4a_internal_intent", intent);
            ServiceHelper.StarterHelper.startServiceFromReceiver (context, in, false, BA.class);
		}

	}
    static appupdater mostCurrent;
	public static BA processBA;
    private ServiceHelper _service;
    public static Class<?> getObject() {
		return appupdater.class;
	}
	@Override
	public void onCreate() {
        super.onCreate();
        mostCurrent = this;
        if (processBA == null) {
		    processBA = new BA(this, null, null, "reparto_izca.keymon.lat", "reparto_izca.keymon.lat.appupdater");
            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, "reparto_izca.keymon.lat.appupdater", processBA, _service, anywheresoftware.b4a.keywords.Common.Density);
		}
        if (!false && ServiceHelper.StarterHelper.startFromServiceCreate(processBA, false) == false) {
				
		}
		else {
            processBA.setActivityPaused(false);
            BA.LogInfo("*** Service (appupdater) 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 (appupdater) 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 (false)
            processBA.raiseEvent(null, "service_taskremoved");
            
    }
    private void handleStart(android.content.Intent intent) {
    	BA.LogInfo("** Service (appupdater) 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 (false) {
            BA.LogInfo("** Service (appupdater) Destroy (ignored)**");
        }
        else {
            BA.LogInfo("** Service (appupdater) 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 _lnk = "";
public static anywheresoftware.b4a.objects.NotificationWrapper _nnewapp = null;
public static int _nnewappnid = 0;
public static anywheresoftware.b4j.object.JavaObject _nativeme = null;
public static anywheresoftware.b4a.objects.NotificationWrapper _n2 = null;
public static int _n2id = 0;
public static String _sharedfolder = "";
public static boolean _usefileprovider = false;
public static anywheresoftware.b4a.objects.RuntimePermissions _rp = null;
public static reparto_izca.keymon.lat.appupdater._mnewversion _newapp = null;
public b4a.example.dateutils _dateutils = null;
public reparto_izca.keymon.lat.main _main = null;
public reparto_izca.keymon.lat.foto _foto = null;
public reparto_izca.keymon.lat.mapa_cliente _mapa_cliente = null;
public reparto_izca.keymon.lat.mapa_rutas _mapa_rutas = null;
public reparto_izca.keymon.lat.starter _starter = null;
public reparto_izca.keymon.lat.subs _subs = null;
public reparto_izca.keymon.lat.tracker _tracker = null;
public reparto_izca.keymon.lat.newinst2 _newinst2 = null;
public reparto_izca.keymon.lat.b4xpages _b4xpages = null;
public reparto_izca.keymon.lat.b4xcollections _b4xcollections = null;
public reparto_izca.keymon.lat.httputils2service _httputils2service = null;
public reparto_izca.keymon.lat.xuiviewsutils _xuiviewsutils = null;
public static class _mnewversion{
public boolean IsInitialized;
public boolean update;
public boolean nonewAPP;
public boolean notifyUser;
public String version;
public String newMsg;
public String okMsg;
public String appLink;
public void Initialize() {
IsInitialized = true;
update = false;
nonewAPP = false;
notifyUser = false;
version = "";
newMsg = "";
okMsg = "";
appLink = "";
}
@Override
		public String toString() {
			return BA.TypeToString(this, false);
		}}
public static anywheresoftware.b4a.objects.NotificationWrapper  _createnotification(String _title,String _content,String _icon,Object _targetactivity,boolean _sound,boolean _vibrate) throws Exception{
 //BA.debugLineNum = 222;BA.debugLine="Private Sub CreateNotification(Title As String, Co";
 //BA.debugLineNum = 223;BA.debugLine="n2.Initialize";
_n2.Initialize();
 //BA.debugLineNum = 224;BA.debugLine="n2.Light = False";
_n2.setLight(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 225;BA.debugLine="n2.Vibrate = Vibrate";
_n2.setVibrate(_vibrate);
 //BA.debugLineNum = 226;BA.debugLine="n2.Sound = Sound";
_n2.setSound(_sound);
 //BA.debugLineNum = 227;BA.debugLine="n2.OnGoingEvent = True";
_n2.setOnGoingEvent(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 228;BA.debugLine="n2.Icon = Icon";
_n2.setIcon(_icon);
 //BA.debugLineNum = 229;BA.debugLine="n2.SetInfo(Title, Content, TargetActivity)";
_n2.SetInfoNew(processBA,BA.ObjectToCharSequence(_title),BA.ObjectToCharSequence(_content),_targetactivity);
 //BA.debugLineNum = 230;BA.debugLine="n2.Notify(nNewAppnID)";
_n2.Notify(_nnewappnid);
 //BA.debugLineNum = 231;BA.debugLine="End Sub";
return null;
}
public static anywheresoftware.b4a.objects.NotificationWrapper  _createnotification2(String _title,String _content,String _icon,Object _targetactivity,boolean _sound,boolean _vibrate,anywheresoftware.b4a.objects.NotificationWrapper _pn,int _pnid) throws Exception{
 //BA.debugLineNum = 206;BA.debugLine="Private Sub CreateNotification2(Title As String, C";
 //BA.debugLineNum = 209;BA.debugLine="pN.Initialize2(pN.IMPORTANCE_HIGH)";
_pn.Initialize2(_pn.IMPORTANCE_HIGH);
 //BA.debugLineNum = 212;BA.debugLine="pN.Vibrate = Vibrate";
_pn.setVibrate(_vibrate);
 //BA.debugLineNum = 213;BA.debugLine="pN.Sound = Sound";
_pn.setSound(_sound);
 //BA.debugLineNum = 215;BA.debugLine="pN.Icon = Icon";
_pn.setIcon(_icon);
 //BA.debugLineNum = 216;BA.debugLine="pN.AutoCancel = True";
_pn.setAutoCancel(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 217;BA.debugLine="pN.SetInfo(Title, Content, TargetActivity)";
_pn.SetInfoNew(processBA,BA.ObjectToCharSequence(_title),BA.ObjectToCharSequence(_content),_targetactivity);
 //BA.debugLineNum = 218;BA.debugLine="pN.Notify(pNID)";
_pn.Notify(_pnid);
 //BA.debugLineNum = 219;BA.debugLine="Return pN";
if (true) return _pn;
 //BA.debugLineNum = 220;BA.debugLine="End Sub";
return null;
}
public static reparto_izca.keymon.lat.httpjob  _download(Object _callback,String _link) throws Exception{
reparto_izca.keymon.lat.httpjob _j = null;
 //BA.debugLineNum = 199;BA.debugLine="Sub Download (Callback As Object, link As String)";
 //BA.debugLineNum = 200;BA.debugLine="Dim j As HttpJob";
_j = new reparto_izca.keymon.lat.httpjob();
 //BA.debugLineNum = 201;BA.debugLine="j.Initialize(\"\", Callback)";
_j._initialize /*String*/ (processBA,"",_callback);
 //BA.debugLineNum = 202;BA.debugLine="j.Download(link)";
_j._download /*String*/ (_link);
 //BA.debugLineNum = 203;BA.debugLine="Return j";
if (true) return _j;
 //BA.debugLineNum = 204;BA.debugLine="End Sub";
return null;
}
public static String  _download_destroy() throws Exception{
 //BA.debugLineNum = 194;BA.debugLine="Sub download_Destroy";
 //BA.debugLineNum = 195;BA.debugLine="n2.Cancel(n2ID)";
_n2.Cancel(_n2id);
 //BA.debugLineNum = 196;BA.debugLine="Service.StopForeground(n2ID)";
mostCurrent._service.StopForeground(_n2id);
 //BA.debugLineNum = 197;BA.debugLine="End Sub";
return "";
}
public static void  _download_newapk() throws Exception{
ResumableSub_download_newApk rsub = new ResumableSub_download_newApk(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_download_newApk extends BA.ResumableSub {
public ResumableSub_download_newApk(reparto_izca.keymon.lat.appupdater parent) {
this.parent = parent;
}
reparto_izca.keymon.lat.appupdater parent;
reparto_izca.keymon.lat.httpjob _job_newapp = null;
anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper _outnewapk = null;
anywheresoftware.b4a.objects.IntentWrapper _in = null;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
 //BA.debugLineNum = 159;BA.debugLine="Log(\"Descargando actualización\")";
anywheresoftware.b4a.keywords.Common.LogImpl("5851971","Descargando actualización",0);
 //BA.debugLineNum = 160;BA.debugLine="B4XPages.ShowPage(\"login\")";
parent.mostCurrent._b4xpages._showpage /*String*/ (processBA,"login");
 //BA.debugLineNum = 161;BA.debugLine="B4XPages.MainPage.muestraProgreso(\"Descargando ac";
parent.mostCurrent._b4xpages._mainpage /*reparto_izca.keymon.lat.b4xmainpage*/ (processBA)._muestraprogreso /*String*/ ("Descargando actualización");
 //BA.debugLineNum = 162;BA.debugLine="Starter.muestraProgreso = 1";
parent.mostCurrent._starter._muestraprogreso /*String*/  = BA.NumberToString(1);
 //BA.debugLineNum = 163;BA.debugLine="Dim job_newAPP As HttpJob";
_job_newapp = new reparto_izca.keymon.lat.httpjob();
 //BA.debugLineNum = 164;BA.debugLine="job_newAPP.Initialize(\"job_newAPP\",Me)";
_job_newapp._initialize /*String*/ (processBA,"job_newAPP",appupdater.getObject());
 //BA.debugLineNum = 165;BA.debugLine="job_newAPP.Download(newApp.appLink)";
_job_newapp._download /*String*/ (parent._newapp.appLink /*String*/ );
 //BA.debugLineNum = 166;BA.debugLine="Wait for (job_newAPP) JobDone (job_newAPP As Http";
anywheresoftware.b4a.keywords.Common.WaitFor("jobdone", processBA, this, (Object)(_job_newapp));
this.state = 9;
return;
case 9:
//C
this.state = 1;
_job_newapp = (reparto_izca.keymon.lat.httpjob) result[0];
;
 //BA.debugLineNum = 167;BA.debugLine="If job_newAPP.Success = True Then";
if (true) break;

case 1:
//if
this.state = 8;
if (_job_newapp._success /*boolean*/ ==anywheresoftware.b4a.keywords.Common.True) { 
this.state = 3;
}if (true) break;

case 3:
//C
this.state = 4;
 //BA.debugLineNum = 169;BA.debugLine="If File.Exists(SharedFolder,\"newapp.apk\") Then";
if (true) break;

case 4:
//if
this.state = 7;
if (anywheresoftware.b4a.keywords.Common.File.Exists(parent._sharedfolder,"newapp.apk")) { 
this.state = 6;
}if (true) break;

case 6:
//C
this.state = 7;
 //BA.debugLineNum = 170;BA.debugLine="File.Delete(SharedFolder,\"newapp.apk\")";
anywheresoftware.b4a.keywords.Common.File.Delete(parent._sharedfolder,"newapp.apk");
 if (true) break;

case 7:
//C
this.state = 8;
;
 //BA.debugLineNum = 173;BA.debugLine="Dim outNewAPK As OutputStream = File.OpenOutput(";
_outnewapk = new anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper();
_outnewapk = anywheresoftware.b4a.keywords.Common.File.OpenOutput(parent._sharedfolder,"newapp.apk",anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 174;BA.debugLine="File.Copy2(job_newAPP.GetInputStream, outNewAPK)";
anywheresoftware.b4a.keywords.Common.File.Copy2((java.io.InputStream)(_job_newapp._getinputstream /*anywheresoftware.b4a.objects.streams.File.InputStreamWrapper*/ ().getObject()),(java.io.OutputStream)(_outnewapk.getObject()));
 //BA.debugLineNum = 175;BA.debugLine="outNewAPK.Close";
_outnewapk.Close();
 //BA.debugLineNum = 177;BA.debugLine="B4XPages.MainPage.ocultaProgreso";
parent.mostCurrent._b4xpages._mainpage /*reparto_izca.keymon.lat.b4xmainpage*/ (processBA)._ocultaprogreso /*String*/ ();
 //BA.debugLineNum = 178;BA.debugLine="Log(\"ocultamos prigreso DOWNLOAD APK\")";
anywheresoftware.b4a.keywords.Common.LogImpl("5851990","ocultamos prigreso DOWNLOAD APK",0);
 if (true) break;

case 8:
//C
this.state = -1;
;
 //BA.debugLineNum = 180;BA.debugLine="job_newAPP.Release";
_job_newapp._release /*String*/ ();
 //BA.debugLineNum = 182;BA.debugLine="Dim in As Intent";
_in = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 183;BA.debugLine="in.Initialize(in.ACTION_VIEW,\"\" )";
_in.Initialize(_in.ACTION_VIEW,"");
 //BA.debugLineNum = 184;BA.debugLine="SetFileUriAsIntentData(in, \"newapp.apk\")";
_setfileuriasintentdata(_in,"newapp.apk");
 //BA.debugLineNum = 186;BA.debugLine="in.SetType(\"application/vnd.android.package-archi";
_in.SetType("application/vnd.android.package-archive");
 //BA.debugLineNum = 187;BA.debugLine="StartActivity(in)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_in.getObject()));
 //BA.debugLineNum = 188;BA.debugLine="n2.Cancel(nNewAppnID)";
parent._n2.Cancel(parent._nnewappnid);
 //BA.debugLineNum = 190;BA.debugLine="StopService(Me)";
anywheresoftware.b4a.keywords.Common.StopService(processBA,appupdater.getObject());
 //BA.debugLineNum = 192;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static void  _jobdone(reparto_izca.keymon.lat.httpjob _job_newapp) throws Exception{
}
public static String  _download_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
 //BA.debugLineNum = 152;BA.debugLine="Sub download_Start (StartingIntent As Intent)";
 //BA.debugLineNum = 153;BA.debugLine="download_newApk";
_download_newapk();
 //BA.debugLineNum = 154;BA.debugLine="End Sub";
return "";
}
public static String  _fileprovider_init() throws Exception{
anywheresoftware.b4a.phone.Phone _p = null;
 //BA.debugLineNum = 237;BA.debugLine="Sub fileProvider_init";
 //BA.debugLineNum = 238;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 239;BA.debugLine="If p.SdkVersion >= 24 Or File.ExternalWritable =";
if (_p.getSdkVersion()>=24 || anywheresoftware.b4a.keywords.Common.File.getExternalWritable()==anywheresoftware.b4a.keywords.Common.False) { 
 //BA.debugLineNum = 240;BA.debugLine="UseFileProvider = True";
_usefileprovider = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 241;BA.debugLine="SharedFolder = File.Combine(File.DirInternal, \"s";
_sharedfolder = anywheresoftware.b4a.keywords.Common.File.Combine(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"shared");
 //BA.debugLineNum = 242;BA.debugLine="If Not(File.IsDirectory(File.DirInternal,\"shared";
if (anywheresoftware.b4a.keywords.Common.Not(anywheresoftware.b4a.keywords.Common.File.IsDirectory(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"shared"))) { 
 //BA.debugLineNum = 243;BA.debugLine="File.MakeDir(\"\", SharedFolder)";
anywheresoftware.b4a.keywords.Common.File.MakeDir("",_sharedfolder);
 };
 }else {
 //BA.debugLineNum = 246;BA.debugLine="UseFileProvider = False";
_usefileprovider = anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 247;BA.debugLine="SharedFolder = rp.GetSafeDirDefaultExternal(\"sha";
_sharedfolder = _rp.GetSafeDirDefaultExternal("shared");
 };
 //BA.debugLineNum = 249;BA.debugLine="Log($\"Using FileProvider? - ${UseFileProvider}\"$)";
anywheresoftware.b4a.keywords.Common.LogImpl("51245196",("Using FileProvider? - "+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(_usefileprovider))+""),0);
 //BA.debugLineNum = 250;BA.debugLine="End Sub";
return "";
}
public static Object  _getfileuri(String _filename) throws Exception{
anywheresoftware.b4j.object.JavaObject _uri = null;
anywheresoftware.b4j.object.JavaObject _f = null;
anywheresoftware.b4j.object.JavaObject _fp = null;
anywheresoftware.b4j.object.JavaObject _context = null;
 //BA.debugLineNum = 253;BA.debugLine="Sub GetFileUri (FileName As String) As Object";
 //BA.debugLineNum = 254;BA.debugLine="Try";
try { //BA.debugLineNum = 255;BA.debugLine="If Not(UseFileProvider) Then";
if (anywheresoftware.b4a.keywords.Common.Not(_usefileprovider)) { 
 //BA.debugLineNum = 256;BA.debugLine="Dim uri As JavaObject";
_uri = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 257;BA.debugLine="Return uri.InitializeStatic(\"android.net.Uri\").";
if (true) return _uri.InitializeStatic("android.net.Uri").RunMethod("parse",new Object[]{(Object)("file://"+anywheresoftware.b4a.keywords.Common.File.Combine(_sharedfolder,_filename))});
 };
 //BA.debugLineNum = 259;BA.debugLine="Dim f As JavaObject";
_f = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 260;BA.debugLine="f.InitializeNewInstance(\"java.io.File\", Array(Sh";
_f.InitializeNewInstance("java.io.File",new Object[]{(Object)(_sharedfolder),(Object)(_filename)});
 //BA.debugLineNum = 261;BA.debugLine="Dim fp As JavaObject";
_fp = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 262;BA.debugLine="Dim context As JavaObject";
_context = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 263;BA.debugLine="context.InitializeContext";
_context.InitializeContext(processBA);
 //BA.debugLineNum = 264;BA.debugLine="fp.InitializeStatic(\"android.support.v4.content.";
_fp.InitializeStatic("androidx.core.content.FileProvider");
 //BA.debugLineNum = 265;BA.debugLine="Return fp.RunMethod(\"getUriForFile\", Array(conte";
if (true) return _fp.RunMethod("getUriForFile",new Object[]{(Object)(_context.getObject()),(Object)(anywheresoftware.b4a.keywords.Common.Application.getPackageName()+".provider"),(Object)(_f.getObject())});
 } 
       catch (Exception e14) {
			processBA.setLastException(e14); //BA.debugLineNum = 267;BA.debugLine="Log(\"FileProvider::GetFileUri - error - \" & Last";
anywheresoftware.b4a.keywords.Common.LogImpl("51310734","FileProvider::GetFileUri - error - "+anywheresoftware.b4a.keywords.Common.LastException(processBA).getMessage(),0);
 //BA.debugLineNum = 268;BA.debugLine="Return \"\"";
if (true) return (Object)("");
 };
 //BA.debugLineNum = 270;BA.debugLine="End Sub";
return null;
}
public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 70;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 75;BA.debugLine="Public lnk As String = \"https://keymon.net/movil/";
_lnk = "https://keymon.net/movil/izca/izca_reparto.ver";
 //BA.debugLineNum = 85;BA.debugLine="Public nNewApp As Notification";
_nnewapp = new anywheresoftware.b4a.objects.NotificationWrapper();
 //BA.debugLineNum = 86;BA.debugLine="Public nNewAppnID As Int = 16";
_nnewappnid = (int) (16);
 //BA.debugLineNum = 88;BA.debugLine="Dim nativeMe 		As JavaObject";
_nativeme = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 89;BA.debugLine="Dim n2				As Notification";
_n2 = new anywheresoftware.b4a.objects.NotificationWrapper();
 //BA.debugLineNum = 90;BA.debugLine="Dim n2ID			As Int = 16";
_n2id = (int) (16);
 //BA.debugLineNum = 92;BA.debugLine="Public SharedFolder As String";
_sharedfolder = "";
 //BA.debugLineNum = 93;BA.debugLine="Public UseFileProvider As Boolean";
_usefileprovider = false;
 //BA.debugLineNum = 94;BA.debugLine="Private rp As RuntimePermissions";
_rp = new anywheresoftware.b4a.objects.RuntimePermissions();
 //BA.debugLineNum = 96;BA.debugLine="Type mNewVersion(update As Boolean, nonewAPP As B";
;
 //BA.debugLineNum = 98;BA.debugLine="Public newApp 	As mNewVersion";
_newapp = new reparto_izca.keymon.lat.appupdater._mnewversion();
 //BA.debugLineNum = 99;BA.debugLine="End Sub";
return "";
}
public static String  _service_create() throws Exception{
 //BA.debugLineNum = 101;BA.debugLine="Sub Service_Create";
 //BA.debugLineNum = 102;BA.debugLine="Log(\"appUpdater(), Service_Create\")";
anywheresoftware.b4a.keywords.Common.LogImpl("5655361","appUpdater(), Service_Create",0);
 //BA.debugLineNum = 103;BA.debugLine="newApp.Initialize";
_newapp.Initialize();
 //BA.debugLineNum = 104;BA.debugLine="Service.AutomaticForegroundMode = Service.AUTOMAT";
mostCurrent._service.AutomaticForegroundMode = mostCurrent._service.AUTOMATIC_FOREGROUND_NEVER;
 //BA.debugLineNum = 105;BA.debugLine="n2.Initialize";
_n2.Initialize();
 //BA.debugLineNum = 106;BA.debugLine="nativeMe.InitializeContext";
_nativeme.InitializeContext(processBA);
 //BA.debugLineNum = 107;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
 //BA.debugLineNum = 233;BA.debugLine="Sub Service_Destroy";
 //BA.debugLineNum = 234;BA.debugLine="Log(\"appUpdater(), Service_Destroy\")";
anywheresoftware.b4a.keywords.Common.LogImpl("51179649","appUpdater(), Service_Destroy",0);
 //BA.debugLineNum = 235;BA.debugLine="End Sub";
return "";
}
public static void  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
ResumableSub_Service_Start rsub = new ResumableSub_Service_Start(null,_startingintent);
rsub.resume(processBA, null);
}
public static class ResumableSub_Service_Start extends BA.ResumableSub {
public ResumableSub_Service_Start(reparto_izca.keymon.lat.appupdater parent,anywheresoftware.b4a.objects.IntentWrapper _startingintent) {
this.parent = parent;
this._startingintent = _startingintent;
}
reparto_izca.keymon.lat.appupdater parent;
anywheresoftware.b4a.objects.IntentWrapper _startingintent;
reparto_izca.keymon.lat.httpjob _j = null;
String[] _app = 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 = 110;BA.debugLine="Log(\"appUpdater(), Service_Start\")";
anywheresoftware.b4a.keywords.Common.LogImpl("5720897","appUpdater(), Service_Start",0);
 //BA.debugLineNum = 112;BA.debugLine="B4XPages.MainPage.muestraProgreso(\"Buscando actua";
parent.mostCurrent._b4xpages._mainpage /*reparto_izca.keymon.lat.b4xmainpage*/ (processBA)._muestraprogreso /*String*/ ("Buscando actualización");
 //BA.debugLineNum = 113;BA.debugLine="Log(\"Buscando actualización\")";
anywheresoftware.b4a.keywords.Common.LogImpl("5720900","Buscando actualización",0);
 //BA.debugLineNum = 114;BA.debugLine="fileProvider_init";
_fileprovider_init();
 //BA.debugLineNum = 115;BA.debugLine="Wait For (Download(Me, lnk)) JobDone (j As HttpJo";
anywheresoftware.b4a.keywords.Common.WaitFor("jobdone", processBA, this, (Object)(_download(appupdater.getObject(),parent._lnk)));
this.state = 20;
return;
case 20:
//C
this.state = 1;
_j = (reparto_izca.keymon.lat.httpjob) result[0];
;
 //BA.debugLineNum = 116;BA.debugLine="If j.Success Then";
if (true) break;

case 1:
//if
this.state = 19;
if (_j._success /*boolean*/ ) { 
this.state = 3;
}else {
this.state = 18;
}if (true) break;

case 3:
//C
this.state = 4;
 //BA.debugLineNum = 117;BA.debugLine="Try";
if (true) break;

case 4:
//try
this.state = 16;
this.catchState = 15;
this.state = 6;
if (true) break;

case 6:
//C
this.state = 7;
this.catchState = 15;
 //BA.debugLineNum = 118;BA.debugLine="Dim app() As String = Regex.Split(Chr(9),j.GetS";
_app = anywheresoftware.b4a.keywords.Common.Regex.Split(BA.ObjectToString(anywheresoftware.b4a.keywords.Common.Chr((int) (9))),_j._getstring /*String*/ ());
 //BA.debugLineNum = 120;BA.debugLine="newApp.appLink = app(3)	'Liga a nueva app";
parent._newapp.appLink /*String*/  = _app[(int) (3)];
 //BA.debugLineNum = 121;BA.debugLine="newApp.newMsg = app(1)	'Texto de que hay actual";
parent._newapp.newMsg /*String*/  = _app[(int) (1)];
 //BA.debugLineNum = 122;BA.debugLine="newApp.okMsg = app(2)	'Texto de app al corrient";
parent._newapp.okMsg /*String*/  = _app[(int) (2)];
 //BA.debugLineNum = 123;BA.debugLine="newApp.version = app(0)	'Version actual";
parent._newapp.version /*String*/  = _app[(int) (0)];
 //BA.debugLineNum = 125;BA.debugLine="Log($\"Application.VersionName=${Application.Ver";
anywheresoftware.b4a.keywords.Common.LogImpl("5720912",("Application.VersionName="+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(anywheresoftware.b4a.keywords.Common.Application.getVersionName()))+", newApp="+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(parent._newapp))+""),0);
 //BA.debugLineNum = 128;BA.debugLine="If newApp.version = Application.VersionName  Th";
if (true) break;

case 7:
//if
this.state = 10;
if ((parent._newapp.version /*String*/ ).equals(anywheresoftware.b4a.keywords.Common.Application.getVersionName())) { 
this.state = 9;
}if (true) break;

case 9:
//C
this.state = 10;
 //BA.debugLineNum = 129;BA.debugLine="newApp.update = False";
parent._newapp.update /*boolean*/  = anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 130;BA.debugLine="Log(\"No new app\")";
anywheresoftware.b4a.keywords.Common.LogImpl("5720917","No new app",0);
 //BA.debugLineNum = 131;BA.debugLine="B4XPages.ShowPage(\"updateAvailable\")";
parent.mostCurrent._b4xpages._showpage /*String*/ (processBA,"updateAvailable");
 //BA.debugLineNum = 133;BA.debugLine="CreateNotification2(\"Aplicacion al corriente\",";
_createnotification2("Aplicacion al corriente","No hay actualizaciones disponibles","ic_file_download_white_24dp",(Object)(parent.mostCurrent._main.getObject()),anywheresoftware.b4a.keywords.Common.True,anywheresoftware.b4a.keywords.Common.True,parent._nnewapp,parent._nnewappnid);
 if (true) break;
;
 //BA.debugLineNum = 135;BA.debugLine="If newApp.version <> Application.VersionName  T";

case 10:
//if
this.state = 13;
if ((parent._newapp.version /*String*/ ).equals(anywheresoftware.b4a.keywords.Common.Application.getVersionName()) == false) { 
this.state = 12;
}if (true) break;

case 12:
//C
this.state = 13;
 //BA.debugLineNum = 136;BA.debugLine="newApp.update = True";
parent._newapp.update /*boolean*/  = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 137;BA.debugLine="Log(\"New app true\")";
anywheresoftware.b4a.keywords.Common.LogImpl("5720924","New app true",0);
 //BA.debugLineNum = 138;BA.debugLine="B4XPages.ShowPage(\"updateAvailable\")";
parent.mostCurrent._b4xpages._showpage /*String*/ (processBA,"updateAvailable");
 if (true) break;

case 13:
//C
this.state = 16;
;
 if (true) break;

case 15:
//C
this.state = 16;
this.catchState = 0;
 //BA.debugLineNum = 143;BA.debugLine="Log(\"appUpdater(), Job Failed, error  \" & LastE";
anywheresoftware.b4a.keywords.Common.LogImpl("5720930","appUpdater(), Job Failed, error  "+anywheresoftware.b4a.keywords.Common.LastException(processBA).getMessage(),0);
 if (true) break;
if (true) break;

case 16:
//C
this.state = 19;
this.catchState = 0;
;
 if (true) break;

case 18:
//C
this.state = 19;
 //BA.debugLineNum = 146;BA.debugLine="Log(\"appUpdater(), Job Failed \" & lnk)";
anywheresoftware.b4a.keywords.Common.LogImpl("5720933","appUpdater(), Job Failed "+parent._lnk,0);
 if (true) break;

case 19:
//C
this.state = -1;
;
 //BA.debugLineNum = 148;BA.debugLine="j.Release";
_j._release /*String*/ ();
 //BA.debugLineNum = 150;BA.debugLine="End Sub";
if (true) break;
}} 
       catch (Exception e0) {
			
if (catchState == 0)
    throw e0;
else {
    state = catchState;
processBA.setLastException(e0);}
            }
        }
    }
}
public static String  _setfileuriasintentdata(anywheresoftware.b4a.objects.IntentWrapper _intent,String _filename) throws Exception{
anywheresoftware.b4j.object.JavaObject _jo = null;
 //BA.debugLineNum = 274;BA.debugLine="Sub SetFileUriAsIntentData (Intent As Intent, File";
 //BA.debugLineNum = 275;BA.debugLine="Dim jo As JavaObject = Intent";
_jo = new anywheresoftware.b4j.object.JavaObject();
_jo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_intent.getObject()));
 //BA.debugLineNum = 276;BA.debugLine="jo.RunMethod(\"setData\", Array(GetFileUri(FileName";
_jo.RunMethod("setData",new Object[]{_getfileuri(_filename)});
 //BA.debugLineNum = 277;BA.debugLine="Intent.Flags = Bit.Or(Intent.Flags, 1) 'FLAG_GRAN";
_intent.setFlags(anywheresoftware.b4a.keywords.Common.Bit.Or(_intent.getFlags(),(int) (1)));
 //BA.debugLineNum = 278;BA.debugLine="End Sub";
return "";
}
}
