summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libcutils/android_reboot.cpp')
-rw-r--r--libcutils/android_reboot.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/libcutils/android_reboot.cpp b/libcutils/android_reboot.cpp
new file mode 100644
index 000000000..5e864d442
--- /dev/null
+++ b/libcutils/android_reboot.cpp
@@ -0,0 +1,53 @@
1/*
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 */
16
17#include <cutils/android_reboot.h>
18
19#include <stdio.h>
20#include <stdlib.h>
21
22#include <cutils/properties.h>
23
24#define TAG "android_reboot"
25
26int android_reboot(int cmd, int flags __unused, const char* arg) {
27 int ret;
28 const char* restart_cmd = NULL;
29 char* prop_value;
30
31 switch (static_cast<unsigned>(cmd)) {
32 case ANDROID_RB_RESTART: // deprecated
33 case ANDROID_RB_RESTART2:
34 restart_cmd = "reboot";
35 break;
36 case ANDROID_RB_POWEROFF:
37 restart_cmd = "shutdown";
38 break;
39 case ANDROID_RB_THERMOFF:
40 restart_cmd = "shutdown,thermal";
41 break;
42 }
43 if (!restart_cmd) return -1;
44 if (arg && arg[0]) {
45 ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg);
46 } else {
47 ret = asprintf(&prop_value, "%s", restart_cmd);
48 }
49 if (ret < 0) return -1;
50 ret = property_set(ANDROID_RB_PROPERTY, prop_value);
51 free(prop_value);
52 return ret;
53}