diff options
author | Andreas Ludviksen <andreas.e.ludviksen@stericsson.com> | 2011-05-19 12:16:58 -0700 |
---|---|---|
committer | Sverre Vegge <sverre.vegge@stericsson.com> | 2011-07-25 09:51:55 +0200 |
commit | 85d772b28efe23ea78af14e53e4c11329a8497d2 (patch) | |
tree | a0cb0b4824adc029c9bacd312db4f58087d0bc6e | |
parent | 97a8222f0d97fb87cd8f7f20f380d84fc763277e (diff) | |
download | u300-85d772b28efe23ea78af14e53e4c11329a8497d2.tar.gz |
SHUTDOWN: Support Android initiated system shutdown
Check system property 'sys.shutdown.requested' to determine
if Android plans on shutting down system. In this case we
send CFUN=100 (Prepare shutdown) to the modem.
Signed-off-by: Sverre Vegge <sverre.vegge@stericsson.com>
-rw-r--r-- | u300-ril-information.c | 29 | ||||
-rw-r--r-- | u300-ril-information.h | 3 | ||||
-rw-r--r-- | u300-ril-manager.c | 5 |
3 files changed, 36 insertions, 1 deletions
diff --git a/u300-ril-information.c b/u300-ril-information.c index 82f1fb8..5ecd214 100644 --- a/u300-ril-information.c +++ b/u300-ril-information.c @@ -25,6 +25,7 @@ #include <pthread.h> #include <string.h> #include <assert.h> +#include <cutils/properties.h> #include "u300-ril-information.h" #include "u300-ril-network.h" @@ -34,6 +35,7 @@ #define LOG_TAG "RILV" #include <utils/Log.h> +bool g_shutdownCompleted; /** * RIL_REQUEST_GET_IMSI */ @@ -190,6 +192,9 @@ void requestRadioPower(void *data, size_t datalen, RIL_Token t) int onOff; int err; ATResponse *atresponse = NULL; + const char *property = "sys.shutdown.requested"; + char systemShutdown[PROPERTY_VALUE_MAX + 1]; + int getRet = -1; if(datalen < sizeof(int)) goto error; @@ -197,7 +202,29 @@ void requestRadioPower(void *data, size_t datalen, RIL_Token t) onOff = ((int *) data)[0]; if (onOff == 0 && getCurrentState() != RADIO_STATE_OFF) { - err = at_send_command("AT+CFUN=4", &atresponse); + + /* + * Check Android system property if system is shutting down. + * Note: Android sets sys.shutdown.requested=0 when shutting down. + */ + getRet = property_get(property, systemShutdown, NULL); + + if (getRet > 0 && !strncmp(systemShutdown, "0", 1)) { + /* Modem shutdown */ + LOGI("Android shutdown received. Shutting down modem."); + err = at_send_command("AT+CFUN=100", &atresponse); + if (err < 0 || atresponse->success == 0) + LOGE("Failed to perform modem shutdown"); + + /* loop until MID reports that modem is shut down */ + while (g_shutdownCompleted == false) { + usleep(100*1000); + } + } else { + /* Turn radio off */ + err = at_send_command("AT+CFUN=4", &atresponse); + } + if (err < 0 || atresponse->success == 0) goto error; setRadioState(RADIO_STATE_OFF); diff --git a/u300-ril-information.h b/u300-ril-information.h index 68d49cb..2b25aeb 100644 --- a/u300-ril-information.h +++ b/u300-ril-information.h @@ -23,6 +23,7 @@ #ifndef _U300_RIL_INFORMATION_H #define _U300_RIL_INFORMATION_H 1 +#include <stdbool.h> #include "atchannel.h" void requestGetIMSI(void *data, size_t datalen, RIL_Token t); @@ -34,4 +35,6 @@ void requestScreenState(void *data, size_t datalen, RIL_Token t); void requestBasebandVersion(void *data, size_t datalen, RIL_Token t); void pollAndDispatchSignalStrength(void *param); + +extern bool g_shutdownCompleted; #endif diff --git a/u300-ril-manager.c b/u300-ril-manager.c index 867ab54..e5e0d7d 100644 --- a/u300-ril-manager.c +++ b/u300-ril-manager.c @@ -36,6 +36,7 @@ #include "u300-ril.h" #include "u300-ril-pdp.h" +#include "u300-ril-information.h" #define LOG_TAG "RILV" #include <utils/Log.h> @@ -143,6 +144,7 @@ static DBusHandlerResult midSignalHandler(DBusConnection *dbcon, DBusMessage "for \"on\"...", __func__); } } else if (strncmp(signame, "off", 3) == 0) { + g_shutdownCompleted = true; if (managerRelease) { LOGD("%s(): Signal queueRunner threads and prepare to go " "back to initial state...", __func__); @@ -698,6 +700,8 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, mgrArgs.channels = 2; mgrArgs.type = NULL; mgrArgs.xarg = NULL; + /* Initialize shutdown flag */ + g_shutdownCompleted = true; LOGI("**************************************************\n" "Starting ST-Ericsson RIL...\n" @@ -799,6 +803,7 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, } else { LOGI("[DBUS]: Connected to system dbus."); dbusIsHere = true; + g_shutdownCompleted = false; err = pthread_attr_init(&attr); if (err != 0) LOGW("%s(): Failed to initialize dbus pthread attribute: %s", |