~ycheng-twn/powerd/powerd_allow-non-root-dbus-cmd

« back to all changes in this revision

Viewing changes to src/power-source.c

  • Committer: Tarmac
  • Author(s): Seth Forshee
  • Date: 2013-09-04 01:10:48 UTC
  • mfrom: (84.2.7 dump-stats)
  • Revision ID: tarmac-20130904011048-rb3vi03vqjqh2yyy
Dump statistics to syslog on low battery.

Approved by Michael Frey, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "log.h"
26
26
 
27
27
static UpClient *up_client;
28
 
double shutdown_temp = 68.0f;
 
28
static double shutdown_temp = 68.0f;
 
29
static double battery_log_level = 4.0f;
 
30
static gboolean stats_logged;
29
31
 
30
32
static void up_device_changed_cb(UpClient *client, UpDevice *device,
31
33
                                 gpointer unused)
33
35
    gboolean on_battery;
34
36
    GPtrArray *devices;
35
37
    int i;
 
38
    gboolean log_stats = TRUE;
36
39
    gboolean low_batt_shutdown = TRUE;
37
40
    gboolean thermal_shutdown = FALSE;
38
41
 
56
59
                         "percentage", &percentage,
57
60
                         "temperature", &temp,
58
61
                         NULL);
 
62
 
 
63
            /*
 
64
             * Log battery stats a little before emergency
 
65
             * shutdown is triggered to avoid any delays
 
66
             * when we actually need to shut down.
 
67
             */
 
68
            if (percentage > battery_log_level) {
 
69
                log_stats = FALSE;
 
70
                stats_logged = FALSE;
 
71
            }
 
72
 
59
73
            /*
60
74
             * Android shuts down when percentage reaches 0. We
61
75
             * use 1% to leave a little more headroom.
69
83
            }
70
84
        }
71
85
    }
 
86
    if (log_stats && !stats_logged) {
 
87
        powerd_log_stats();
 
88
        stats_logged = TRUE;
 
89
    }
72
90
    if (low_batt_shutdown || thermal_shutdown) {
73
91
        powerd_warn("Initiating emergency shutdown");
74
92
        powerd_shutdown();
90
108
        g_value_unset(&v);
91
109
    }
92
110
 
 
111
    if (!device_config_get("criticalBatteryWarningLevel", &v) &&
 
112
        G_VALUE_HOLDS_UINT(&v)) {
 
113
        battery_log_level = (double)g_value_get_uint(&v);
 
114
        g_value_unset(&v);
 
115
    }
 
116
 
93
117
    up_client = up_client_new();
94
118
    if (!up_client) {
95
119
        powerd_warn("Could not allocate upower client");