blob: e40c7f443e1aeb6b8e17e330a35e83fb6ded4cce [file] [log] [blame]
yq.wang6c876f52025-05-17 16:56:50 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file reboot_reason.c
4 @brief set reboot reason
5*/
6/*-----------------------------------------------------------------------------------------------*/
7
8/*-------------------------------------------------------------------------------------------------
9 Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved.
10 mobiletek Wireless Solution Proprietary and Confidential.
11-------------------------------------------------------------------------------------------------*/
12
13/*-------------------------------------------------------------------------------------------------
14 EDIT HISTORY
15 This section contains comments describing changes made to the file.
16 Notice that changes are listed in reverse chronological order.
17 $Header: $
18 when who what, where, why
19 -------- --------- -----------------------------------------------------------------
20 20250515 yq.wang Created .
21-------------------------------------------------------------------------------------------------*/
22#include <stdio.h>
23#include <stdint.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include <errno.h>
27#include <fcntl.h>
28#include <cutils/properties.h>
29
30#include "mbtk_type.h"
31#include "reboot_reason.h"
32#include "mbtk_log.h"
33#include "mbtk_device.h"
34
35int reboot_reason_init(void)
36{
37 int ret = 0;
38 char buff[32] = {0};
39 mbtk_device_info_reboot_flag_enum reboot_reason = MBTK_REBOOT_FLAG_NORMAL;
40 mbtk_device_info_basic_t info_basic = {0};
41 memset(&info_basic, 0, sizeof(mbtk_device_info_basic_t));
42
43
44 ret = mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_BASIC, &(info_basic), sizeof(mbtk_device_info_basic_t));
45 if(ret != 0)
46 {
47 LOGE("[%s] mbtk_dev_info_read(BASIC) fail.", __func__);
48 reboot_reason = MBTK_REBOOT_FLAG_UNKNOWN;
49 }
50 else
51 {
52 reboot_reason = info_basic.reboot_flag;
53 if(info_basic.reboot_flag != MBTK_REBOOT_FLAG_NORMAL)
54 {
55 info_basic.reboot_flag = MBTK_REBOOT_FLAG_NORMAL;
56 ret = mbtk_dev_info_write(MBTK_DEVICE_INFO_ITEM_BASIC, &info_basic, sizeof(mbtk_device_info_basic_t));
57 if(ret != 0) {
58 LOGE("[%s] mbtk_dev_info_write(BASIC) fail.", __func__);
59 }
60 }
61 }
62
63 LOGD("[%s] reboot reason [%d].", __func__, reboot_reason);
64 memset(buff, 0x0, 32);
65 sprintf(buff, "%d", reboot_reason);
66 property_set("persist.mbtk.reboot_reason", buff);
67
68 LOGD("[%s] reboot reason exit.", __func__);
69
70 return 0;
71}
72