blob: 996d89d9b68d4debe63e8c37e88a81cbd04c742e [file] [log] [blame]
Ken Sumralle3aeeb42011-03-07 23:29:42 -08001/*
2 * Copyright 2011, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ken Sumralle3aeeb42011-03-07 23:29:42 -080016#include <stdio.h>
Yusuke Sato0df08272015-07-08 14:57:07 -070017#include <stdlib.h>
Ken Sumralle3aeeb42011-03-07 23:29:42 -080018
19#include <cutils/android_reboot.h>
Keun-young Park8d01f632017-03-13 11:54:47 -070020#include <cutils/properties.h>
Ken Sumralle3aeeb42011-03-07 23:29:42 -080021
Yusuke Sato0df08272015-07-08 14:57:07 -070022#define TAG "android_reboot"
Mark Salyzyn2b94cc22013-11-22 07:36:45 -080023
Keun-young Park8d01f632017-03-13 11:54:47 -070024int android_reboot(int cmd, int flags __unused, const char* arg) {
Ken Sumralle3aeeb42011-03-07 23:29:42 -080025 int ret;
Keun-young Park8d01f632017-03-13 11:54:47 -070026 const char* restart_cmd = NULL;
27 char* prop_value;
Todd Poynoreac33da2017-01-30 17:28:55 -080028
Ken Sumralle3aeeb42011-03-07 23:29:42 -080029 switch (cmd) {
Keun-young Park8d01f632017-03-13 11:54:47 -070030 case ANDROID_RB_RESTART: // deprecated
Ken Sumralle3aeeb42011-03-07 23:29:42 -080031 case ANDROID_RB_RESTART2:
Keun-young Park8d01f632017-03-13 11:54:47 -070032 restart_cmd = "reboot";
Ken Sumralle3aeeb42011-03-07 23:29:42 -080033 break;
Keun-young Park8d01f632017-03-13 11:54:47 -070034 case ANDROID_RB_POWEROFF:
35 restart_cmd = "shutdown";
36 break;
Todd Poynor37bba3b2017-01-30 17:27:39 -080037 case ANDROID_RB_THERMOFF:
Mark Salyzyn73e6b492017-08-14 15:56:53 -070038 restart_cmd = "shutdown,thermal";
Todd Poynor37bba3b2017-01-30 17:27:39 -080039 break;
Ken Sumralle3aeeb42011-03-07 23:29:42 -080040 }
Keun-young Park8d01f632017-03-13 11:54:47 -070041 if (!restart_cmd) return -1;
Mark Salyzyn73e6b492017-08-14 15:56:53 -070042 if (arg && arg[0]) {
Keun-young Park8d01f632017-03-13 11:54:47 -070043 ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg);
44 } else {
45 ret = asprintf(&prop_value, "%s", restart_cmd);
46 }
47 if (ret < 0) return -1;
48 ret = property_set(ANDROID_RB_PROPERTY, prop_value);
49 free(prop_value);
Ken Sumralle3aeeb42011-03-07 23:29:42 -080050 return ret;
51}