micky387 | 65d5f7d | 2025-04-24 16:46:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 3 | Copyright (C) 2020 The OmniRom Project. |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are |
| 6 | met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above |
| 10 | copyright notice, this list of conditions and the following |
| 11 | disclaimer in the documentation and/or other materials provided |
| 12 | with the distribution. |
| 13 | * Neither the name of The Linux Foundation nor the names of its |
| 14 | contributors may be used to endorse or promote products derived |
| 15 | from this software without specific prior written permission. |
| 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <unistd.h> |
| 33 | #include <android-base/file.h> |
| 34 | #include <android-base/properties.h> |
| 35 | #include <android-base/logging.h> |
| 36 | #include "property_service.h" |
| 37 | #include <sys/resource.h> |
| 38 | #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ |
| 39 | #include <sys/_system_properties.h> |
| 40 | |
| 41 | #define CUSTOMER_FILE "/mnt/vendor/persist/CUSTOMER" |
| 42 | #define IDCODE_FILE "/mnt/vendor/persist/COLOR" |
| 43 | #define VARIANT_FILE "/mnt/vendor/persist/COUNTRY" |
| 44 | |
| 45 | namespace android { |
| 46 | namespace init { |
| 47 | |
| 48 | using android::base::GetProperty; |
| 49 | using android::base::ReadFileToString; |
| 50 | |
| 51 | void property_override(const std::string& name, const std::string& value) |
| 52 | { |
| 53 | size_t valuelen = value.size(); |
| 54 | |
| 55 | prop_info* pi = (prop_info*) __system_property_find(name.c_str()); |
| 56 | if (pi != nullptr) { |
| 57 | __system_property_update(pi, value.c_str(), valuelen); |
| 58 | } |
| 59 | else { |
| 60 | int rc = __system_property_add(name.c_str(), name.size(), value.c_str(), valuelen); |
| 61 | if (rc < 0) { |
| 62 | LOG(ERROR) << "property_set(\"" << name << "\", \"" << value << "\") failed: " |
| 63 | << "__system_property_add failed"; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void property_override_dual(char const prop[], char const system_prop[], |
| 69 | const std::string& value) |
| 70 | { |
| 71 | property_override(prop, value); |
| 72 | property_override(system_prop, value); |
| 73 | } |
| 74 | |
| 75 | void ro_prop_override(char const source[], char const prop[], |
| 76 | const std::string& value, bool product) |
| 77 | { |
| 78 | std::string prop_name = "ro."; |
| 79 | |
| 80 | if (product) prop_name += "product."; |
| 81 | if (source != nullptr) prop_name += source; |
| 82 | if (!product) prop_name += "build."; |
| 83 | prop_name += prop; |
| 84 | |
| 85 | property_override(prop_name.c_str(), value); |
| 86 | }; |
| 87 | |
| 88 | static const char* RO_PROP_SOURCES[] = { |
| 89 | nullptr, |
| 90 | "bootimage.", |
| 91 | "odm.", |
| 92 | "odm_dlkm.", |
| 93 | "product.", |
| 94 | "system.", |
| 95 | "system_dlkm.", |
| 96 | "system_ext.", |
| 97 | "vendor.", |
| 98 | "vendor_dlkm.", |
| 99 | }; |
| 100 | |
| 101 | /* From Magisk@jni/magiskhide/hide_utils.c */ |
| 102 | static const char *snet_prop_key[] = { |
| 103 | "ro.boot.vbmeta.device_state", |
| 104 | "ro.boot.verifiedbootstate", |
| 105 | "ro.boot.flash.locked", |
| 106 | "ro.boot.veritymode", |
| 107 | "ro.boot.warranty_bit", |
| 108 | "ro.warranty_bit", |
| 109 | NULL |
| 110 | }; |
| 111 | |
| 112 | static const char *snet_prop_value[] = { |
| 113 | "locked", |
| 114 | "green", |
| 115 | "1", |
| 116 | "enforcing", |
| 117 | "0", |
| 118 | "0", |
| 119 | NULL |
| 120 | }; |
| 121 | |
| 122 | static void workaround_snet_properties() { |
| 123 | |
| 124 | // Hide all sensitive props |
| 125 | for (int i = 0; snet_prop_key[i]; ++i) { |
| 126 | property_override(snet_prop_key[i], snet_prop_value[i]); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | static void set_configs() |
| 131 | { |
| 132 | std::string variantValue; |
| 133 | |
| 134 | if (ReadFileToString(CUSTOMER_FILE, &variantValue)) { |
| 135 | property_override("ro.vendor.config.CID", variantValue.c_str()); |
| 136 | } |
| 137 | if (ReadFileToString(IDCODE_FILE, &variantValue)) { |
| 138 | property_override("ro.vendor.config.idcode", variantValue.c_str()); |
| 139 | } |
| 140 | if (ReadFileToString(VARIANT_FILE, &variantValue)) { |
| 141 | property_override("ro.vendor.config.versatility", variantValue.c_str()); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | static void set_fingerprint() |
| 146 | { |
| 147 | std::string build_asus; |
| 148 | std::string build_id; |
| 149 | std::string build_number; |
| 150 | std::ostringstream fp; |
| 151 | std::string fingerprint; |
| 152 | std::string name; |
| 153 | std::string variant; |
| 154 | std::ostringstream desc; |
| 155 | std::string description; |
| 156 | std::ostringstream disp; |
| 157 | std::string display_id; |
| 158 | |
| 159 | LOG(INFO) << "Starting custom init"; |
| 160 | |
| 161 | variant = GetProperty("ro.vendor.config.versatility", ""); |
| 162 | |
| 163 | // Set the default "name" string and below properties based on variant name |
| 164 | if (variant == "EU") { |
| 165 | property_override("ro.product.vendor.name", "EU_I002D"); |
| 166 | property_override("ro.vendor.product.carrier", "EU-ASUS_I002D-WW"); |
| 167 | } else if (variant == "RU") { |
| 168 | property_override("ro.product.vendor.model", "ZS670KS"); |
| 169 | property_override("ro.product.vendor.name", "RU_I002D"); |
| 170 | property_override("ro.vendor.product.carrier", "RU-ASUS_I002D-WW"); |
| 171 | } else { |
| 172 | property_override("ro.product.vendor.name", "WW_I002D"); |
| 173 | property_override("ro.vendor.product.carrier", "WW-ASUS_I002D-WW"); |
| 174 | } |
| 175 | |
| 176 | name = GetProperty("ro.product.vendor.name", ""); |
| 177 | |
| 178 | LOG(INFO) << name; |
| 179 | |
| 180 | // These should be the only things to change for OTA updates |
| 181 | build_asus = "31.0210.0210.324"; |
| 182 | build_id = "SKQ1.210821.001"; |
| 183 | build_number = "31.0210.0210.324"; |
| 184 | |
| 185 | // Create the correct stock props based on the above values |
| 186 | desc << name << "-user 12 " << build_id << " " << build_number << " release-keys"; |
| 187 | description = desc.str(); |
| 188 | |
| 189 | fp << "asus/" << name << "/ASUS_I002D:12/" << build_id << "/" << build_number << ":user/release-keys"; |
| 190 | fingerprint = fp.str(); |
| 191 | |
| 192 | // These properties are the same for all variants |
| 193 | property_override("ro.vendor.build.asus.number", build_number); |
| 194 | property_override("ro.vendor.build.asus.sku", "WW"); |
| 195 | property_override("ro.vendor.build.asus.version", build_asus); |
| 196 | property_override("ro.vendor.build.software.version", build_asus); |
| 197 | property_override("ro.build.description", description); |
| 198 | |
| 199 | for (const auto& source : RO_PROP_SOURCES) { |
| 200 | ro_prop_override(source, "brand", "asus", true); |
| 201 | ro_prop_override(source, "device", "ASUS_I002D", true); |
| 202 | ro_prop_override(source, "manufacturer", "asus", true); |
| 203 | ro_prop_override(source, "model", "ASUS_I002D", true); |
| 204 | ro_prop_override(source, "name", name, true); |
| 205 | |
| 206 | ro_prop_override(source, "fingerprint", fingerprint, false); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | void vendor_load_properties() |
| 211 | { |
| 212 | // SafetyNet workaround |
| 213 | property_override("ro.boot.verifiedbootstate", "green"); |
| 214 | workaround_snet_properties(); |
| 215 | set_configs(); |
| 216 | set_fingerprint(); |
| 217 | } |
| 218 | |
| 219 | } //init |
| 220 | } //android |