<commit_before>package org.rootio.services;

import org.rootio.tools.utils.Utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.esotericsoftware.kryo.util.Util;

/**
 * This class listens for boot incidents and restores the services to the state
 * they were in before the phone shut down
 *
 * @author <NAME>
 */
public class BootMonitor extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent arg1) {
        if(arg1.getBooleanExtra("isRestart", false))
        {
            this.stopAllServices(context);
        }
        startAllServices(context);

    }

    private void startAllServices(Context context) {
        if(Utils.isConnectedToStation(context)) {
            for (int serviceId : new int[]{1, 2, 3, 4, 5, 6}) {
                ServiceState serviceState = new ServiceState(context, serviceId);
                if (serviceState.getServiceState() > 0)// service was started
                {
                    Intent intent = this.getIntentToLaunch(context, serviceId);
                    context.startForegroundService(intent);
                }
            }
        }
    }

    /**
     * Gets the intent to be used to launch the service with the specified
     * serviceId
     *
     * @param context   The context to be used in creating the intent
     * @param serviceId The ID of the service for which to create the intent
     * @return
     */
    private Intent getIntentToLaunch(Context context, int serviceId) {
        Intent intent = null;
        switch (serviceId) {
            case 1: // telephony service
                intent = new Intent(context, TelephonyService.class);
                break;
            case 2: // SMS service
                intent = new Intent(context, SMSService.class);
                break;
            case 3: // Diagnostic Service
                intent = new Intent(context, DiagnosticsService.class);
                break;
            case 4: // Program Service
                intent = new Intent(context, ProgramService.class);
                break;
            case 5: // Sync Service
                intent = new Intent(context, SynchronizationService.class);
                break;
            case 6: // SIP Service
                intent = new Intent(context, LinSipService.class);
                break;
        }
        return intent;
    }

    private void stopAllServices(Context context)
    {
        if(Utils.isConnectedToStation(context)) {
            for (int serviceId : new int[]{1, 2, 3, 4, 5, 6}) {
                ServiceState serviceState = new ServiceState(context, serviceId);
                // if (serviceState.getServiceState() > 0)// service was started
                // {
                Intent intent = this.getIntentToLaunch(context, serviceId);
                context.stopService(intent);
                // }
            }
        }
    }

}
<commit_msg>More accomodations on midnight restart - sleep for a bit<commit_after>package org.rootio.services;

import org.rootio.tools.utils.Utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.esotericsoftware.kryo.util.Util;

/**
 * This class listens for boot incidents and restores the services to the state
 * they were in before the phone shut down
 *
 * @author <NAME>
 */
public class BootMonitor extends BroadcastReceiver {

    @Override
    public synchronized void onReceive(Context context, Intent arg1) {
        if(arg1.getBooleanExtra("isRestart", false))
        {
            this.stopAllServices(context);
        }
        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        startAllServices(context, arg1.getBooleanExtra("isRestart", false));

    }

    private void startAllServices(Context context, boolean isRestart) {
        if(Utils.isConnectedToStation(context)) {
            for (int serviceId : new int[]{1, 2, 3, 4, 5, 6}) {
                ServiceState serviceState = new ServiceState(context, serviceId);
                if (isRestart || serviceState.getServiceState() > 0)// service was started
                {
                    Intent intent = this.getIntentToLaunch(context, serviceId);
                    context.startForegroundService(intent);
                }
            }
        }
    }

    /**
     * Gets the intent to be used to launch the service with the specified
     * serviceId
     *
     * @param context   The context to be used in creating the intent
     * @param serviceId The ID of the service for which to create the intent
     * @return
     */
    private Intent getIntentToLaunch(Context context, int serviceId) {
        Intent intent = null;
        switch (serviceId) {
            case 1: // telephony service
                intent = new Intent(context, TelephonyService.class);
                break;
            case 2: // SMS service
                intent = new Intent(context, SMSService.class);
                break;
            case 3: // Diagnostic Service
                intent = new Intent(context, DiagnosticsService.class);
                break;
            case 4: // Program Service
                intent = new Intent(context, ProgramService.class);
                break;
            case 5: // Sync Service
                intent = new Intent(context, SynchronizationService.class);
                break;
            case 6: // SIP Service
                intent = new Intent(context, LinSipService.class);
                break;
        }
        return intent;
    }

    private void stopAllServices(Context context)
    {
        if(Utils.isConnectedToStation(context)) {
            for (int serviceId : new int[]{1, 2, 3, 4, 5, 6}) {
                ServiceState serviceState = new ServiceState(context, serviceId);
                serviceState.setServiceState(0);
                serviceState.save();
                // if (serviceState.getServiceState() > 0)// service was started
                // {
                Intent intent = this.getIntentToLaunch(context, serviceId);
                context.stopService(intent);
                // }
            }
        }
    }

}

{'fraction_non_alphanumeric': 0.08585938739882558, 'fraction_numerical': 0.008093953340739566, 'mean_word_length': 1.8272768057424855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7055102', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1544, 'n_words': 460}