| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 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 |  */ | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 16 | #include <stdio.h> | 
| Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 17 | #include <stdlib.h> | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 18 |  | 
 | 19 | #include <cutils/android_reboot.h> | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 20 | #include <cutils/properties.h> | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 21 |  | 
| Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 22 | #define TAG "android_reboot" | 
| Mark Salyzyn | 2b94cc2 | 2013-11-22 07:36:45 -0800 | [diff] [blame] | 23 |  | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 24 | int android_reboot(int cmd, int flags __unused, const char* arg) { | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 25 |     int ret; | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 26 |     const char* restart_cmd = NULL; | 
 | 27 |     char* prop_value; | 
| Todd Poynor | eac33da | 2017-01-30 17:28:55 -0800 | [diff] [blame] | 28 |  | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 29 |     switch (cmd) { | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 30 |         case ANDROID_RB_RESTART:  // deprecated | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 31 |         case ANDROID_RB_RESTART2: | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 32 |             restart_cmd = "reboot"; | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 33 |             break; | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 34 |         case ANDROID_RB_POWEROFF: | 
 | 35 |             restart_cmd = "shutdown"; | 
 | 36 |             break; | 
| Todd Poynor | 37bba3b | 2017-01-30 17:27:39 -0800 | [diff] [blame] | 37 |         case ANDROID_RB_THERMOFF: | 
| Mark Salyzyn | 73e6b49 | 2017-08-14 15:56:53 -0700 | [diff] [blame] | 38 |             restart_cmd = "shutdown,thermal"; | 
| Todd Poynor | 37bba3b | 2017-01-30 17:27:39 -0800 | [diff] [blame] | 39 |             break; | 
| Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 40 |     } | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 41 |     if (!restart_cmd) return -1; | 
| Mark Salyzyn | 73e6b49 | 2017-08-14 15:56:53 -0700 | [diff] [blame] | 42 |     if (arg && arg[0]) { | 
| Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 43 |         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 Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 50 |     return ret; | 
 | 51 | } |