From fc0b16df8ba6a4d79e4cc8ad598e1d59a8ac4fda Mon Sep 17 00:00:00 2001 From: lambdadroid Date: Fri, 4 Aug 2017 17:16:53 +0200 Subject: Add option to use ro.serialno for generating device id On some devices (e.g. ASUS Zenfone) the serial number of the device is stored in a file in the /factory partition. Consequently, the only way to load it is using a user space application during the init process, and to update the ro.serialno system property. In most places, TWRP already uses the system property to get the serial number of the device. However, when generating the device ID used for the backup folder name it checks the boot command line directly. On these devices, the serialno is not included on the command line. Add a TW_USE_SERIALNO_PROPERTY_FOR_DEVICE_ID option that enables usage of ro.serialno for generating the device id. It is disabled by default to avoid changing the device id on existing ports. Change-Id: I4a2eeca883f38fdaeb1209507fd8ebe44b1b04a0 --- Android.mk | 3 +++ data.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/Android.mk b/Android.mk index cacd783bb..8ed4c6c3f 100644 --- a/Android.mk +++ b/Android.mk @@ -315,6 +315,9 @@ WITH_CRYPTO_UTILS := \ ifeq ($(TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID), true) LOCAL_CFLAGS += -DTW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID endif +ifeq ($(TW_USE_SERIALNO_PROPERTY_FOR_DEVICE_ID), true) + LOCAL_CFLAGS += -DTW_USE_SERIALNO_PROPERTY_FOR_DEVICE_ID +endif ifneq ($(TW_BRIGHTNESS_PATH),) LOCAL_CFLAGS += -DTW_BRIGHTNESS_PATH=$(TW_BRIGHTNESS_PATH) endif diff --git a/data.cpp b/data.cpp index 4dfbde2d0..978cefea0 100644 --- a/data.cpp +++ b/data.cpp @@ -146,6 +146,16 @@ void DataManager::get_device_id(void) { #endif #ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID +#ifdef TW_USE_SERIALNO_PROPERTY_FOR_DEVICE_ID + // Check serial number system property + if (property_get("ro.serialno", line, "")) { + snprintf(device_id, DEVID_MAX, "%s", line); + sanitize_device_id(device_id); + mConst.SetValue("device_id", device_id); + return; + } +#endif + // Check the cmdline to see if the serial number was supplied fp = fopen("/proc/cmdline", "rt"); if (fp != NULL) { -- cgit v1.2.3