summaryrefslogtreecommitdiff
path: root/init/init_oplus.cpp
blob: e50187a350f8c10ca2b73f3140799dd2d7b7d03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2022 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

#include <android-base/logging.h>
#include <android-base/properties.h>

#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>

using android::base::GetProperty;

/*
 * SetProperty does not allow updating read only properties and as a result
 * does not work for our use case. Write "OverrideProperty" to do practically
 * the same thing as "SetProperty" without this restriction.
 */
void OverrideProperty(const char* name, const char* value) {
    size_t valuelen = strlen(value);

    prop_info* pi = (prop_info*)__system_property_find(name);
    if (pi != nullptr) {
        __system_property_update(pi, value, valuelen);
    } else {
        __system_property_add(name, strlen(name), value, valuelen);
    }
}

/*
 * Only for read-only properties. Properties that can be wrote to more
 * than once should be set in a typical init script (e.g. init.oplus.hw.rc)
 * after the original property has been set.
 */
void vendor_load_properties() {
    auto device = GetProperty("ro.product.product.device", "");
    auto rf_version = std::stoi(GetProperty("ro.boot.rf_version", "0"));

    switch (rf_version) {
        case 11: // CN
            if (device == "OnePlus8") {
                OverrideProperty("ro.product.product.model", "IN2010");
            } else if (device == "OnePlus8T") {
                OverrideProperty("ro.product.product.model", "KB2000");
            } else if (device == "OnePlus8Pro") {
                OverrideProperty("ro.product.product.model", "IN2020");
            } else if (device == "OnePlus9R") {
                OverrideProperty("ro.product.product.model", "LE2100");
            }
            break;
        case 12: // TMO
            if (device == "OnePlus8") {
                OverrideProperty("ro.product.product.model", "IN2017");
            } else if (device == "OnePlus8T") {
                OverrideProperty("ro.product.product.model", "KB2007");
            } else if (device == "OnePlus8Pro") {
                OverrideProperty("ro.product.product.model", "IN2027");
            }
            break;
        case 13: // IN
            if (device == "OnePlus8") {
                OverrideProperty("ro.product.product.model", "IN2011");
            } else if (device == "OnePlus8T") {
                OverrideProperty("ro.product.product.model", "KB2001");
            } else if (device == "OnePlus8Pro") {
                OverrideProperty("ro.product.product.model", "IN2021");
            } else if (device == "OnePlus9R") {
                OverrideProperty("ro.product.product.model", "LE2101");
            }
            break;
        case 14: // EU
            if (device == "OnePlus8") {
                OverrideProperty("ro.product.product.model", "IN2013");
            } else if (device == "OnePlus8T") {
                OverrideProperty("ro.product.product.model", "KB2003");
            } else if (device == "OnePlus8Pro") {
                OverrideProperty("ro.product.product.model", "IN2023");
            }
            break;
        case 15: // NA
            if (device == "OnePlus8") {
                OverrideProperty("ro.product.product.model", "IN2015");
            } else if (device == "OnePlus8T") {
                OverrideProperty("ro.product.product.model", "KB2005");
            } else if (device == "OnePlus8Pro") {
                OverrideProperty("ro.product.product.model", "IN2025");
            }
            break;
        default:
            LOG(ERROR) << "Unexpected RF version: " << rf_version;
    }
}