2011-03-08 15:29:42 +08: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.
|
|
|
|
*/
|
2017-11-11 02:22:07 +08:00
|
|
|
|
|
|
|
#include <cutils/android_reboot.h>
|
|
|
|
|
2011-03-08 15:29:42 +08:00
|
|
|
#include <stdio.h>
|
2015-07-09 05:57:07 +08:00
|
|
|
#include <stdlib.h>
|
2011-03-08 15:29:42 +08:00
|
|
|
|
2017-03-14 02:54:47 +08:00
|
|
|
#include <cutils/properties.h>
|
2011-03-08 15:29:42 +08:00
|
|
|
|
2015-07-09 05:57:07 +08:00
|
|
|
#define TAG "android_reboot"
|
2011-03-08 15:29:42 +08:00
|
|
|
|
2017-12-01 08:23:51 +08:00
|
|
|
int android_reboot(int cmd, int /*flags*/, const char* arg) {
|
2011-03-08 15:29:42 +08:00
|
|
|
int ret;
|
2017-03-14 02:54:47 +08:00
|
|
|
const char* restart_cmd = NULL;
|
|
|
|
char* prop_value;
|
2017-01-31 09:28:55 +08:00
|
|
|
|
2017-11-11 02:22:07 +08:00
|
|
|
switch (static_cast<unsigned>(cmd)) {
|
2017-03-14 02:54:47 +08:00
|
|
|
case ANDROID_RB_RESTART: // deprecated
|
|
|
|
case ANDROID_RB_RESTART2:
|
|
|
|
restart_cmd = "reboot";
|
2011-03-08 15:29:42 +08:00
|
|
|
break;
|
|
|
|
case ANDROID_RB_POWEROFF:
|
2017-03-14 02:54:47 +08:00
|
|
|
restart_cmd = "shutdown";
|
2011-03-08 15:29:42 +08:00
|
|
|
break;
|
2017-01-31 09:27:39 +08:00
|
|
|
case ANDROID_RB_THERMOFF:
|
2017-08-15 06:56:53 +08:00
|
|
|
restart_cmd = "shutdown,thermal";
|
2017-01-31 09:27:39 +08:00
|
|
|
break;
|
2011-03-08 15:29:42 +08:00
|
|
|
}
|
2017-03-14 02:54:47 +08:00
|
|
|
if (!restart_cmd) return -1;
|
2017-08-15 06:56:53 +08:00
|
|
|
if (arg && arg[0]) {
|
2017-03-14 02:54:47 +08:00
|
|
|
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 15:29:42 +08:00
|
|
|
return ret;
|
|
|
|
}
|