2011-03-08 08:29:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2011, The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
2015-07-08 23:57:07 +02:00
|
|
|
#include <stdlib.h>
|
2011-03-08 08:29:42 +01:00
|
|
|
|
|
|
|
#include <cutils/android_reboot.h>
|
2017-03-13 19:54:47 +01:00
|
|
|
#include <cutils/properties.h>
|
2011-03-08 08:29:42 +01:00
|
|
|
|
2015-07-08 23:57:07 +02:00
|
|
|
#define TAG "android_reboot"
|
2011-03-08 08:29:42 +01:00
|
|
|
|
2017-03-13 19:54:47 +01:00
|
|
|
int android_reboot(int cmd, int flags __unused, const char* arg) {
|
2011-03-08 08:29:42 +01:00
|
|
|
int ret;
|
2017-03-13 19:54:47 +01:00
|
|
|
const char* restart_cmd = NULL;
|
|
|
|
char* prop_value;
|
2017-01-31 02:28:55 +01:00
|
|
|
|
2011-03-08 08:29:42 +01:00
|
|
|
switch (cmd) {
|
2017-03-13 19:54:47 +01:00
|
|
|
case ANDROID_RB_RESTART: // deprecated
|
|
|
|
case ANDROID_RB_RESTART2:
|
|
|
|
restart_cmd = "reboot";
|
2011-03-08 08:29:42 +01:00
|
|
|
break;
|
|
|
|
case ANDROID_RB_POWEROFF:
|
2017-03-13 19:54:47 +01:00
|
|
|
restart_cmd = "shutdown";
|
2011-03-08 08:29:42 +01:00
|
|
|
break;
|
2017-01-31 02:27:39 +01:00
|
|
|
case ANDROID_RB_THERMOFF:
|
2017-03-13 19:54:47 +01:00
|
|
|
restart_cmd = "thermal-shutdown";
|
2017-01-31 02:27:39 +01:00
|
|
|
break;
|
2011-03-08 08:29:42 +01:00
|
|
|
}
|
2017-03-13 19:54:47 +01:00
|
|
|
if (!restart_cmd) return -1;
|
|
|
|
if (arg) {
|
|
|
|
ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg);
|
|
|
|
} else {
|
|
|
|
ret = asprintf(&prop_value, "%s", restart_cmd);
|
|
|
|
}
|
|
|
|
if (ret < 0) return -1;
|
|
|
|
ret = property_set(ANDROID_RB_PROPERTY, prop_value);
|
|
|
|
free(prop_value);
|
2011-03-08 08:29:42 +01:00
|
|
|
return ret;
|
|
|
|
}
|