Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f77a07df authored by Yi Jin's avatar Yi Jin
Browse files

Create a new stream option which generates field name to id mapping

recursively for all its submessages.

Also fix the wrong prefix for ro.build.version.XXX in proto.

It is safe to adjust proto number for now since it is not used yet.

Bug: 68774852
Test: atest incident_helper_test
Change-Id: I46e43a407da6efc393eb3c39733aaf25a5cceb13
parent d04c00a4
Loading
Loading
Loading
Loading
+14 −3
Original line number Original line Diff line number Diff line
@@ -53,10 +53,16 @@ SystemPropertiesParser::Parse(const int in, const int out) const
                SystemPropertiesProto::_FIELD_COUNT);
                SystemPropertiesProto::_FIELD_COUNT);
    Message sysProp(&sysPropTable);
    Message sysProp(&sysPropTable);


    Table aaudioT(SystemPropertiesProto::Aaudio::_FIELD_NAMES,
    Table aacDrcTable(SystemPropertiesProto::AacDrc::_FIELD_NAMES,
            SystemPropertiesProto::AacDrc::_FIELD_IDS,
            SystemPropertiesProto::AacDrc::_FIELD_COUNT);
    Message aacDrc(&aacDrcTable);
    sysProp.addSubMessage(SystemPropertiesProto::AAC_DRC, &aacDrc);

    Table aaudioTable(SystemPropertiesProto::Aaudio::_FIELD_NAMES,
            SystemPropertiesProto::Aaudio::_FIELD_IDS,
            SystemPropertiesProto::Aaudio::_FIELD_IDS,
            SystemPropertiesProto::Aaudio::_FIELD_COUNT);
            SystemPropertiesProto::Aaudio::_FIELD_COUNT);
    Message aaudio(&aaudioT);
    Message aaudio(&aaudioTable);
    sysProp.addSubMessage(SystemPropertiesProto::AAUDIO, &aaudio);
    sysProp.addSubMessage(SystemPropertiesProto::AAUDIO, &aaudio);


    Table cameraTable(SystemPropertiesProto::Camera::_FIELD_NAMES,
    Table cameraTable(SystemPropertiesProto::Camera::_FIELD_NAMES,
@@ -142,8 +148,13 @@ SystemPropertiesParser::Parse(const int in, const int out) const
                   SystemPropertiesProto::Ro::Product::_FIELD_IDS,
                   SystemPropertiesProto::Ro::Product::_FIELD_IDS,
                   SystemPropertiesProto::Ro::Product::_FIELD_COUNT);
                   SystemPropertiesProto::Ro::Product::_FIELD_COUNT);
    Message product(&productTable);
    Message product(&productTable);
    ro.addSubMessage(SystemPropertiesProto::Ro::PRODUCT, &product);


    Table vendorTable(SystemPropertiesProto::Ro::Product::Vendor::_FIELD_NAMES,
            SystemPropertiesProto::Ro::Product::Vendor::_FIELD_IDS,
            SystemPropertiesProto::Ro::Product::Vendor::_FIELD_COUNT);
    Message vendor(&vendorTable);
    product.addSubMessage(SystemPropertiesProto::Ro::Product::VENDOR, &vendor);
    ro.addSubMessage(SystemPropertiesProto::Ro::PRODUCT, &product);
    sysProp.addSubMessage(SystemPropertiesProto::RO, &ro);
    sysProp.addSubMessage(SystemPropertiesProto::RO, &ro);


    Table sysTable(SystemPropertiesProto::Sys::_FIELD_NAMES,
    Table sysTable(SystemPropertiesProto::Sys::_FIELD_NAMES,
+3 −0
Original line number Original line Diff line number Diff line
[aac_drc_cut]: [123]
[aaudio.hw_burst_min_usec]: [2000]
[aaudio.hw_burst_min_usec]: [2000]
[aaudio.mmap_exclusive_policy]: [2]
[aaudio.mmap_exclusive_policy]: [2]
[dalvik.vm.appimageformat]: [lz4]
[dalvik.vm.appimageformat]: [lz4]
@@ -10,4 +11,6 @@
[ro.bootimage.build.fingerprint]: [google/marlin/marlin:P/MASTER/jinyithu10301320:eng/dev-keys]
[ro.bootimage.build.fingerprint]: [google/marlin/marlin:P/MASTER/jinyithu10301320:eng/dev-keys]
[ro.hardware]: [marlin]
[ro.hardware]: [marlin]
[ro.hardware.power]: [marlin-profile]
[ro.hardware.power]: [marlin-profile]
[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.product.vendor.brand]: [google]
[ro.wifi.channels]: []
[ro.wifi.channels]: []
+23 −28
Original line number Original line Diff line number Diff line
@@ -61,38 +61,33 @@ TEST_F(SystemPropertiesParserTest, HasSwapInfo) {
    SystemPropertiesParser parser;
    SystemPropertiesParser parser;
    SystemPropertiesProto expected;
    SystemPropertiesProto expected;


    SystemPropertiesProto::Aaudio* aaudio = expected.mutable_aaudio();
    expected.mutable_aac_drc()->set_cut(123);
    aaudio->set_hw_burst_min_usec(2000);
    expected.mutable_aaudio()->set_hw_burst_min_usec(2000);
    aaudio->set_mmap_exclusive_policy(2);
    expected.mutable_aaudio()->set_mmap_exclusive_policy(2);

    expected.mutable_dalvik_vm()->set_appimageformat("lz4");
    SystemPropertiesProto::DalvikVm* dalvikVm = expected.mutable_dalvik_vm();
    dalvikVm->set_appimageformat("lz4");

    expected.set_drm_64bit_enabled(false);
    expected.set_drm_64bit_enabled(false);

    expected.mutable_init_svc()->set_adbd(
    SystemPropertiesProto::InitSvc* initSvc = expected.mutable_init_svc();
        SystemPropertiesProto_InitSvc_Status_STATUS_RUNNING);
    initSvc->set_adbd(SystemPropertiesProto_InitSvc_Status_STATUS_RUNNING);
    expected.mutable_init_svc()->set_lmkd(
    initSvc->set_lmkd(SystemPropertiesProto_InitSvc_Status_STATUS_STOPPED);
        SystemPropertiesProto_InitSvc_Status_STATUS_STOPPED);

    expected.set_media_mediadrmservice_enable(true);
    expected.set_media_mediadrmservice_enable(true);


    SystemPropertiesProto::Ro* ro = expected.mutable_ro();
    SystemPropertiesProto::Ro* ro = expected.mutable_ro();

    ro->mutable_boot()->add_boottime("1BLL:85");
    SystemPropertiesProto::Ro::Boot* boot = ro->mutable_boot();
    ro->mutable_boot()->add_boottime("1BLE:898");
    boot->add_boottime("1BLL:85");
    ro->mutable_boot()->add_boottime("2BLL:0");
    boot->add_boottime("1BLE:898");
    ro->mutable_boot()->add_boottime("2BLE:862");
    boot->add_boottime("2BLL:0");
    ro->mutable_boot()->add_boottime("SW:6739");
    boot->add_boottime("2BLE:862");
    ro->mutable_boot()->add_boottime("KL:340");
    boot->add_boottime("SW:6739");
    ro->mutable_bootimage()->set_build_date_utc(1509394807LL);
    boot->add_boottime("KL:340");
    ro->mutable_bootimage()->set_build_fingerprint(

        "google/marlin/marlin:P/MASTER/jinyithu10301320:eng/dev-keys");
    SystemPropertiesProto::Ro::BootImage* bootimage = ro->mutable_bootimage();
    ro->mutable_hardware()->set_value("marlin");
    bootimage->set_build_date_utc(1509394807LL);
    ro->mutable_hardware()->set_power("marlin-profile");
    bootimage->set_build_fingerprint("google/marlin/marlin:P/MASTER/jinyithu10301320:eng/dev-keys");
    ro->mutable_product()->add_cpu_abilist("arm64-v8a");

    ro->mutable_product()->add_cpu_abilist("armeabi-v7a");
    SystemPropertiesProto::Ro::Hardware* hardware = ro->mutable_hardware();
    ro->mutable_product()->add_cpu_abilist("armeabi");
    hardware->set_value("marlin");
    ro->mutable_product()->mutable_vendor()->set_brand("google");
    hardware->set_power("marlin-profile");


    int fd = open(testFile.c_str(), O_RDONLY);
    int fd = open(testFile.c_str(), O_RDONLY);
    ASSERT_TRUE(fd != -1);
    ASSERT_TRUE(fd != -1);
+59 −86
Original line number Original line Diff line number Diff line
@@ -26,7 +26,7 @@ package android.os;
// Android Platform Exported System Properties
// Android Platform Exported System Properties
// TODO: This is not the completed list, new properties need to be whitelisted.
// TODO: This is not the completed list, new properties need to be whitelisted.
message SystemPropertiesProto {
message SystemPropertiesProto {
    option (stream_proto.stream_msg).enable_fields_mapping = true;
    option (stream_proto.stream_msg).enable_fields_mapping_recursively = true;


    // Properties that are not specified below would be appended here.
    // Properties that are not specified below would be appended here.
    // These values stay on device only.
    // These values stay on device only.
@@ -38,15 +38,16 @@ message SystemPropertiesProto {
    }
    }
    repeated Property extra_properties = 1;
    repeated Property extra_properties = 1;


    optional int32  aac_drc_boost = 2;
    message AacDrc {
    optional int32  aac_drc_cut = 3;
        optional int32  boost = 1;
    optional int32  aac_drc_enc_target_level = 4;
        optional int32  cut = 2;
    optional int32  aac_drc_heavy = 5;
        optional int32  enc_target_level = 3;
    optional int32  aac_drc_reference_level = 6;
        optional int32  heavy = 4;
        optional int32  reference_level = 5;
    }
    optional AacDrc aac_drc = 2;


    message Aaudio {
    message Aaudio {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional int32  hw_burst_min_usec = 1;
        optional int32  hw_burst_min_usec = 1;
        optional int32  minimum_sleep_usec = 2;
        optional int32  minimum_sleep_usec = 2;
        optional int32  mixer_bursts = 3;
        optional int32  mixer_bursts = 3;
@@ -56,23 +57,19 @@ message SystemPropertiesProto {


        // Next Tag: 7
        // Next Tag: 7
    }
    }
    optional Aaudio aaudio = 7;
    optional Aaudio aaudio = 3;


    optional int32  af_fast_track_multiplier = 8;
    optional int32  af_fast_track_multiplier = 4;


    message Camera {
    message Camera {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional bool   disable_zsl_mode = 1;
        optional bool   disable_zsl_mode = 1;
        optional int32  fifo_disable = 2;
        optional int32  fifo_disable = 2;


        // Next Tag: 3
        // Next Tag: 3
    }
    }
    optional Camera camera = 9;
    optional Camera camera = 5;


    message DalvikVm {
    message DalvikVm {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional string appimageformat = 1;
        optional string appimageformat = 1;
        optional string backgroundgctype = 2;
        optional string backgroundgctype = 2;
        optional bool   checkjni = 3;
        optional bool   checkjni = 3;
@@ -130,17 +127,15 @@ message SystemPropertiesProto {


        // Next Tag: 55
        // Next Tag: 55
    }
    }
    optional DalvikVm dalvik_vm = 10;
    optional DalvikVm dalvik_vm = 6;


    optional bool   drm_64bit_enabled = 11;
    optional bool   drm_64bit_enabled = 7;
    optional bool   drm_service_enabled = 12;
    optional bool   drm_service_enabled = 8;
    optional bool   dumpstate_dry_run = 13;
    optional bool   dumpstate_dry_run = 9;
    optional string gsm_sim_operator_numeric = 14;
    optional string gsm_sim_operator_numeric = 10;
    optional bool   hal_instrumentation_enable = 15;
    optional bool   hal_instrumentation_enable = 11;


    message InitSvc {
    message InitSvc {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        enum Status {
        enum Status {
            STATUS_UNKNOWN = 0;
            STATUS_UNKNOWN = 0;
            STATUS_RUNNING = 1;
            STATUS_RUNNING = 1;
@@ -190,28 +185,24 @@ message SystemPropertiesProto {


        // Next Tag: 42
        // Next Tag: 42
    }
    }
    optional InitSvc init_svc = 16;
    optional InitSvc init_svc = 12;


    optional bool   keyguard_no_require_sim = 17;
    optional bool   keyguard_no_require_sim = 13;
    optional string libc_debug_malloc_options = 18;
    optional string libc_debug_malloc_options = 14;
    optional string libc_debug_malloc_program = 19;
    optional string libc_debug_malloc_program = 15;


    message Log {
    message Log {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional string tag_WifiHAL = 1;
        optional string tag_WifiHAL = 1;
        optional string tag_stats_log = 2;
        optional string tag_stats_log = 2;


        // Next Tag: 3
        // Next Tag: 3
    }
    }
    optional Log log = 20;
    optional Log log = 16;


    optional bool   media_mediadrmservice_enable = 21;
    optional bool   media_mediadrmservice_enable = 17;
    optional bool   media_recorder_show_manufacturer_and_model = 22;
    optional bool   media_recorder_show_manufacturer_and_model = 18;


    message Persist {
    message Persist {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional string config_calibration_fac = 1;
        optional string config_calibration_fac = 1;
        optional int32  dbg_volte_avail_ovr = 2;
        optional int32  dbg_volte_avail_ovr = 2;
        optional int32  dbg_vt_avail_ovr = 3;
        optional int32  dbg_vt_avail_ovr = 3;
@@ -226,11 +217,9 @@ message SystemPropertiesProto {


        // Next Tag: 12
        // Next Tag: 12
    }
    }
    optional Persist persist = 23;
    optional Persist persist = 19;


    message PmDexopt {
    message PmDexopt {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional string ab_ota = 1;
        optional string ab_ota = 1;
        optional string bg_dexopt = 2;
        optional string bg_dexopt = 2;
        optional string boot = 3;
        optional string boot = 3;
@@ -239,11 +228,9 @@ message SystemPropertiesProto {


        // Next Tag: 6
        // Next Tag: 6
    }
    }
    optional PmDexopt pm_dexopt = 24;
    optional PmDexopt pm_dexopt = 20;


    message Ro {
    message Ro {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional int32  adb_secure = 1;
        optional int32  adb_secure = 1;
        optional string arch = 2;
        optional string arch = 2;
        optional bool   audio_ignore_effects = 3;
        optional bool   audio_ignore_effects = 3;
@@ -252,8 +239,6 @@ message SystemPropertiesProto {
        optional string board_platform = 6;
        optional string board_platform = 6;


        message Boot {
        message Boot {
            option (stream_proto.stream_msg).enable_fields_mapping = true;

            optional string avb_version = 1;
            optional string avb_version = 1;
            optional string baseband = 2;
            optional string baseband = 2;
            optional string bootdevice = 3;
            optional string bootdevice = 3;
@@ -280,8 +265,6 @@ message SystemPropertiesProto {
        optional Boot boot = 7;
        optional Boot boot = 7;


        message BootImage {
        message BootImage {
            option (stream_proto.stream_msg).enable_fields_mapping = true;

            optional string build_date = 1;
            optional string build_date = 1;
            optional int32  build_date_utc = 2;
            optional int32  build_date_utc = 2;
            optional string build_fingerprint = 3;
            optional string build_fingerprint = 3;
@@ -294,8 +277,6 @@ message SystemPropertiesProto {
        optional string bootmode = 10;
        optional string bootmode = 10;


        message Build {
        message Build {
            option (stream_proto.stream_msg).enable_fields_mapping = true;

            optional string date = 1;
            optional string date = 1;
            optional int32  date_utc = 2;
            optional int32  date_utc = 2;
            optional string description = 3;
            optional string description = 3;
@@ -309,15 +290,13 @@ message SystemPropertiesProto {
            optional string user = 11;
            optional string user = 11;


            message Version {
            message Version {
                option (stream_proto.stream_msg).enable_fields_mapping = true;
                optional string base_os = 1;

                optional string codename = 2;
                optional string version_base_os = 1;
                optional string incremental = 3;
                optional string version_codename = 2;
                optional int32  preview_sdk = 4;
                optional string version_incremental = 3;
                optional string release = 5;
                optional int32  version_preview_sdk = 4;
                optional int32  sdk = 6;
                optional string version_release = 5;
                optional string security_patch = 7;
                optional int32  version_sdk = 6;
                optional string version_security_patch = 7;


                // Next Tag: 8
                // Next Tag: 8
            }
            }
@@ -334,8 +313,6 @@ message SystemPropertiesProto {
        optional string com_google_clientidbase = 16;
        optional string com_google_clientidbase = 16;


        message Config {
        message Config {
            option (stream_proto.stream_msg).enable_fields_mapping = true;

            optional string alarm_alert = 1;
            optional string alarm_alert = 1;
            optional int32  media_vol_steps = 2;
            optional int32  media_vol_steps = 2;
            optional string notification_sound = 3;
            optional string notification_sound = 3;
@@ -357,8 +334,6 @@ message SystemPropertiesProto {
        optional string gfx_driver_0 = 26;
        optional string gfx_driver_0 = 26;


        message Hardware {
        message Hardware {
            option (stream_proto.stream_msg).enable_fields_mapping = true;

            optional string value = 1; // value of ro.hardware itself
            optional string value = 1; // value of ro.hardware itself


            optional string activity_recognition = 2;
            optional string activity_recognition = 2;
@@ -410,26 +385,28 @@ message SystemPropertiesProto {
        optional int32  opengles_version = 31;
        optional int32  opengles_version = 31;


        message Product {
        message Product {
            option (stream_proto.stream_msg).enable_fields_mapping = true;

            optional string board = 1;
            optional string board = 1;
            optional string brand = 2;
            optional string brand = 2;
            optional string cpu_abi = 3;
            optional string cpu_abi = 3;
            optional string cpu_abilist = 4;
            repeated string cpu_abilist = 4;
            optional string cpu_abilist32 = 5;
            repeated string cpu_abilist32 = 5;
            optional string cpu_abilist64 = 6;
            repeated string cpu_abilist64 = 6;
            optional string device = 7;
            optional string device = 7;
            optional int32  first_api_level = 8;
            optional int32  first_api_level = 8;
            optional string manufacturer = 9;
            optional string manufacturer = 9;
            optional string model = 10;
            optional string model = 10;
            optional string name = 11;
            optional string name = 11;
            optional string vendor_brand = 12;
            optional string vendor_device = 13;
            optional string vendor_manufacturer = 14;
            optional string vendor_model = 15;
            optional string vendor_name = 16;


            // Next Tag: 17
            message Vendor {
                optional string brand = 1;
                optional string device = 2;
                optional string manufacturer = 3;
                optional string model = 4;
                optional string name = 5;
            }
            optional Vendor vendor = 12;

            // Next Tag: 13
        }
        }
        optional Product product = 32;
        optional Product product = 32;


@@ -452,22 +429,18 @@ message SystemPropertiesProto {


        // Next Tag: 49
        // Next Tag: 49
    }
    }
    optional Ro ro = 25;
    optional Ro ro = 21;


    optional string sendbug_preferred_domain = 26;
    optional string sendbug_preferred_domain = 22;
    optional int32  service_bootanim_exit = 27;
    optional int32  service_bootanim_exit = 23;


    message Sys {
    message Sys {
        option (stream_proto.stream_msg).enable_fields_mapping = true;

        optional int32  boot_completed = 1;
        optional int32  boot_completed = 1;
        optional int32  boot_from_charger_mode = 2;
        optional int32  boot_from_charger_mode = 2;
        optional int32  retaildemo_enabled = 3;
        optional int32  retaildemo_enabled = 3;
        optional string shutdown_requested = 4;
        optional string shutdown_requested = 4;


        message Usb {
        message Usb {
            option (stream_proto.stream_msg).enable_fields_mapping = true;

            optional string config = 1;
            optional string config = 1;
            optional int32  configfs = 2;
            optional int32  configfs = 2;
            optional string controller = 3;
            optional string controller = 3;
@@ -484,16 +457,16 @@ message SystemPropertiesProto {


        // Next Tag: 6
        // Next Tag: 6
    }
    }
    optional Sys sys = 28;
    optional Sys sys = 24;


    optional int32  telephony_lteOnCdmaDevice = 29;
    optional int32  telephony_lteOnCdmaDevice = 25;
    optional int32  tombstoned_max_tombstone_count = 30;
    optional int32  tombstoned_max_tombstone_count = 26;
    optional string vold_decrypt = 31;
    optional string vold_decrypt = 27;
    optional int32  vold_post_fs_data_done = 32;
    optional int32  vold_post_fs_data_done = 28;
    optional int32  vts_native_server_on = 33;
    optional int32  vts_native_server_on = 29;
    optional string wifi_direct_interface = 34;
    optional string wifi_direct_interface = 30;
    optional string wifi_interface = 35;
    optional string wifi_interface = 31;


    // Next Tag: 36
    // Next Tag: 32
}
}
+10 −4
Original line number Original line Diff line number Diff line
@@ -85,11 +85,17 @@ should_generate_fields_mapping(const DescriptorProto& message)
    return message.options().GetExtension(stream_msg).enable_fields_mapping();
    return message.options().GetExtension(stream_msg).enable_fields_mapping();
}
}


static inline bool
should_generate_fields_mapping_recursively(const DescriptorProto& message) {
    return message.options().GetExtension(stream_msg).enable_fields_mapping_recursively();
}

static void
static void
write_message(stringstream& text, const DescriptorProto& message, const string& indent)
write_message(stringstream& text, const DescriptorProto& message, const string& indent, bool genMapping)
{
{
    int N;
    int N;
    const string indented = indent + INDENT;
    const string indented = indent + INDENT;
    genMapping |= should_generate_fields_mapping_recursively(message);


    text << indent << "// message " << message.name() << endl;
    text << indent << "// message " << message.name() << endl;
    text << indent << "namespace " << message.name() << " {" << endl;
    text << indent << "namespace " << message.name() << " {" << endl;
@@ -103,7 +109,7 @@ write_message(stringstream& text, const DescriptorProto& message, const string&
    // Nested classes
    // Nested classes
    N = message.nested_type_size();
    N = message.nested_type_size();
    for (int i=0; i<N; i++) {
    for (int i=0; i<N; i++) {
        write_message(text, message.nested_type(i), indented);
        write_message(text, message.nested_type(i), indented, genMapping);
    }
    }


    // Fields
    // Fields
@@ -112,7 +118,7 @@ write_message(stringstream& text, const DescriptorProto& message, const string&
        write_field(text, message.field(i), indented);
        write_field(text, message.field(i), indented);
    }
    }


    if (should_generate_fields_mapping(message)) {
    if (genMapping | should_generate_fields_mapping(message)) {
        N = message.field_size();
        N = message.field_size();
        text << indented << "const int _FIELD_COUNT = " << N << ";" << endl;
        text << indented << "const int _FIELD_COUNT = " << N << ";" << endl;
        text << indented << "const char* _FIELD_NAMES[" << N << "] = {" << endl;
        text << indented << "const char* _FIELD_NAMES[" << N << "] = {" << endl;
@@ -161,7 +167,7 @@ write_header_file(CodeGeneratorResponse* response, const FileDescriptorProto& fi


    N = file_descriptor.message_type_size();
    N = file_descriptor.message_type_size();
    for (size_t i=0; i<N; i++) {
    for (size_t i=0; i<N; i++) {
        write_message(text, file_descriptor.message_type(i), "");
        write_message(text, file_descriptor.message_type(i), "", false);
    }
    }


    for (vector<string>::iterator it = namespaces.begin(); it != namespaces.end(); it++) {
    for (vector<string>::iterator it = namespaces.begin(); it != namespaces.end(); it++) {
Loading