<commit_before>/**
   @file state.c

   This file implements device state policy in DSME.
   <p>
   Copyright (C) 2004-2010 Nokia Corporation.

   @author <NAME> <<EMAIL>>
   @author <NAME> <<EMAIL>>
   @author <NAME> <<EMAIL>>

   This file is part of Dsme.

   Dsme is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License
   version 2.1 as published by the Free Software Foundation.

   Dsme is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with Dsme.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * How to send runlevel change indicator:
 * dbus-send --system --type=signal /com/nokia/startup/signal com.nokia.startup.signal.runlevel_switch_done int32:0
 * where the int32 parameter is either 2 (user) or 5 (actdead).
 */

#define _POSIX_SOURCE
#define _GNU_SOURCE

#include "dbusproxy.h"
#include "dsme_dbus.h"

#include "state-internal.h"
#include "runlevel.h"
#include "malf.h"
#include "dsme/timers.h"
#include "dsme/modules.h"
#include "dsme/logging.h"
#include "dsme/modulebase.h"
#include <dsme/state.h>

#include "dsme/dsme-rd-mode.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>


/**
 * Timer value for actdead shutdown timer. This is how long we wait before doing a
 * shutdown when the charger is disconnected in acting dead state
 */
#define CHARGER_DISCONNECT_TIMEOUT 15

/**
 * Timer value for shutdown timer. This is how long we wait for apps to close.
 */
#define SHUTDOWN_TIMER_TIMEOUT 2

/**
 * Timer value for acting dead timer. This is how long we wait before doing a
 * state change from user to acting dead.
 */
#define ACTDEAD_TIMER_MIN_TIMEOUT 2
#define ACTDEAD_TIMER_MAX_TIMEOUT 15

/**
 * Timer value for user timer. This is how long we wait before doing a
 * state change from acting dead to user.
 */
#define USER_TIMER_MIN_TIMEOUT 2
#define USER_TIMER_MAX_TIMEOUT 15

/* Seconds from overheating or empty battery to the start of shutdown timer */
#define DSME_THERMAL_SHUTDOWN_TIMER       8
#define DSME_BATTERY_EMPTY_SHUTDOWN_TIMER 8


typedef enum {
    CHARGER_STATE_UNKNOWN,
    CHARGER_CONNECTED,
    CHARGER_DISCONNECTED,
} charger_state_t;


/* these are the state bits on which dsme bases its state selection */
charger_state_t charger_state          = CHARGER_STATE_UNKNOWN;
static bool     alarm_set              = false;
static bool     device_overheated      = false;
static bool     emergency_call_ongoing = false;
static bool     mounted_to_pc          = false;
static bool     battery_empty          = false;
static bool     shutdown_requested     = false;
static bool     actdead_requested      = false;
static bool     reboot_requested       = false;
static bool     test                   = false;
static bool     actdead_switch_done    = false;
static bool     user_switch_done       = false;

/* the overall dsme state which was selected based on the above bits */
static dsme_state_t current_state = DSME_STATE_NOT_SET;<commit_msg>Made state change timeouts longer<commit_after>/**
   @file state.c

   This file implements device state policy in DSME.
   <p>
   Copyright (C) 2004-2010 Nokia Corporation.

   @author <NAME> <<EMAIL>>
   @author <NAME> <<EMAIL>>
   @author <NAME> <<EMAIL>>

   This file is part of Dsme.

   Dsme is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License
   version 2.1 as published by the Free Software Foundation.

   Dsme is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with Dsme.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * How to send runlevel change indicator:
 * dbus-send --system --type=signal /com/nokia/startup/signal com.nokia.startup.signal.runlevel_switch_done int32:0
 * where the int32 parameter is either 2 (user) or 5 (actdead).
 */

#define _POSIX_SOURCE
#define _GNU_SOURCE

#include "dbusproxy.h"
#include "dsme_dbus.h"

#include "state-internal.h"
#include "runlevel.h"
#include "malf.h"
#include "dsme/timers.h"
#include "dsme/modules.h"
#include "dsme/logging.h"
#include "dsme/modulebase.h"
#include <dsme/state.h>

#include "dsme/dsme-rd-mode.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>


/**
 * Timer value for actdead shutdown timer. This is how long we wait before doing a
 * shutdown when the charger is disconnected in acting dead state
 */
#define CHARGER_DISCONNECT_TIMEOUT 15

/**
 * Timer value for shutdown timer. This is how long we wait for apps to close.
 */
#define SHUTDOWN_TIMER_TIMEOUT 2

/**
 * Timer value for acting dead timer. This is how long we wait before doing a
 * state change from user to acting dead.
 */
#define ACTDEAD_TIMER_MIN_TIMEOUT 2
#define ACTDEAD_TIMER_MAX_TIMEOUT 45

/**
 * Timer value for user timer. This is how long we wait before doing a
 * state change from acting dead to user.
 */
#define USER_TIMER_MIN_TIMEOUT 2
#define USER_TIMER_MAX_TIMEOUT 45

/* Seconds from overheating or empty battery to the start of shutdown timer */
#define DSME_THERMAL_SHUTDOWN_TIMER       8
#define DSME_BATTERY_EMPTY_SHUTDOWN_TIMER 8


typedef enum {
    CHARGER_STATE_UNKNOWN,
    CHARGER_CONNECTED,
    CHARGER_DISCONNECTED,
} charger_state_t;


/* these are the state bits on which dsme bases its state selection */
charger_state_t charger_state          = CHARGER_STATE_UNKNOWN;
static bool     alarm_set              = false;
static bool     device_overheated      = false;
static bool     emergency_call_ongoing = false;
static bool     mounted_to_pc          = false;
static bool     battery_empty          = false;
static bool     shutdown_requested     = false;
static bool     actdead_requested      = false;
static bool     reboot_requested       = false;
static bool     test                   = false;
static bool     actdead_switch_done    = false;
static bool     user_switch_done       = false;

/* the overall dsme state which was selected based on the above bits */
static dsme_state_t current_state = DSME_STATE_NOT_SET;
{'fraction_non_alphanumeric': 0.07772483621203097, 'fraction_numerical': 0.008338296605122097, 'mean_word_length': 3.451292246520875, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2172932', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2082, 'n_words': 773}