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 #include <stdio.h> 17 #include <stdlib.h> 18 19 #include <cutils/android_reboot.h> 20 #include <cutils/properties.h> 21 22 #define TAG "android_reboot" 23 24 int android_reboot(int cmd, int flags __unused, const char* arg) { 25 int ret; 26 const char* restart_cmd = NULL; 27 char* prop_value; 28 29 switch (cmd) { 30 case ANDROID_RB_RESTART: // deprecated 31 case ANDROID_RB_RESTART2: 32 restart_cmd = "reboot"; 33 break; 34 case ANDROID_RB_POWEROFF: 35 restart_cmd = "shutdown"; 36 break; 37 case ANDROID_RB_THERMOFF: 38 restart_cmd = "thermal-shutdown"; 39 break; 40 } 41 if (!restart_cmd) return -1; 42 if (arg) { 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); 50 return ret; 51 } 52