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

Commit c513070f authored by Nick Chalko's avatar Nick Chalko
Browse files

Set system property from list of backported fixes

Because the caluculation of a BitSet is
to compicated for make a genrule and java are
used to ro.build.backported_fixes.alias_bitset.long_list to the end of
the system property file.

This part of the API for backported fixes.  See go/android-backported-fixes-spec

Bug: 377727445
Test: atest applied_backported_fixes_test backported_fixes_common_test
Change-Id: I2621e2fb52401495f796a5a4db330c5dfafbda40
parent 03b57b0f
Loading
Loading
Loading
Loading
+115 −0
Original line number Diff line number Diff line
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_applicable_licenses: ["Android-Apache-2.0"],
    default_team: "trendy_team_android_media_reliability",
}

genrule {
    name: "applied_backported_fixes",
    tools: ["applied_backported_fixes_main"],
    srcs: [":applied_backported_fix_binpbs"],
    out: ["applied_backported_fixes.prop"],
    cmd: "$(location applied_backported_fixes_main)" +
        " -p $(location applied_backported_fixes.prop)" +
        " $(in)",
}

java_library {
    name: "backported_fixes_proto",
    srcs: [
        "backported_fixes.proto",
    ],
    host_supported: true,
}

java_library {
    name: "backported_fixes_common",
    srcs: ["src/java/com/android/build/backportedfixes/common/*.java"],
    static_libs: [
        "backported_fixes_proto",
        "guava",
    ],
    host_supported: true,
}

java_test_host {
    name: "backported_fixes_common_test",
    srcs: ["tests/java/com/android/build/backportedfixes/common/*.java"],
    static_libs: [
        "backported_fixes_common",
        "backported_fixes_proto",
        "junit",
        "truth",
        "truth-liteproto-extension",
        "truth-proto-extension",
    ],
    test_options: {
        unit_test: true,
    },
    test_suites: ["general-tests"],
}

java_library {
    name: "applied_backported_fixes_lib",
    srcs: ["src/java/com/android/build/backportedfixes/*.java"],
    static_libs: [
        "backported_fixes_common",
        "backported_fixes_proto",
        "jcommander",
        "guava",
    ],
    host_supported: true,
}

java_binary_host {
    name: "applied_backported_fixes_main",
    main_class: "com.android.build.backportedfixes.Main",
    static_libs: [
        "applied_backported_fixes_lib",
    ],
}

java_test_host {
    name: "applied_backported_fixes_test",
    srcs: ["tests/java/com/android/build/backportedfixes/*.java"],
    static_libs: [
        "applied_backported_fixes_lib",
        "backported_fixes_proto",
        "junit",
        "truth",
    ],
    test_options: {
        unit_test: true,
    },
    test_suites: ["general-tests"],
}

gensrcs {
    name: "applied_backported_fix_binpbs",
    tools: ["aprotoc"],
    srcs: [
        "applied_fixes/*.txtpb",
    ],
    tool_files: [
        "backported_fixes.proto",
    ],
    output_extension: "binpb",
    cmd: "$(location aprotoc)  " +
        " --encode=com.android.build.backportedfixes.BackportedFix" +
        "  $(location backported_fixes.proto)" +
        " < $(in)" +
        " > $(out); echo $(out)",
}
+3 −0
Original line number Diff line number Diff line
essick@google.com
nchalko@google.com
portmannc@google.com
+19 −0
Original line number Diff line number Diff line
# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# proto-file: ../backported_fixes.proto
# proto-message: BackportedFix

known_issue: 350037023
alias: 1
+37 −0
Original line number Diff line number Diff line
// Copyright (C) 2024 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto2";

package com.android.build.backportedfixes;

option java_multiple_files = true;

// A list of backported fixes.
message BackportedFixes {
  repeated BackportedFix fixes = 1;
}

// A known issue approved for reporting Build.getBackportedFixStatus
message BackportedFix {

  // The issue id from the public bug tracker
  // https://issuetracker.google.com/issues/{known_issue}
  optional int64 known_issue = 1;
  // The alias for the known issue.
  // 1 - 1023 are valid aliases
  // Must be unique across all backported fixes.
  optional int32 alias = 2;
}
+79 −0
Original line number Diff line number Diff line

/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.build.backportedfixes;

import static java.nio.charset.StandardCharsets.UTF_8;

import com.android.build.backportedfixes.common.ClosableCollection;
import com.android.build.backportedfixes.common.Parser;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.converters.FileConverter;
import com.google.common.io.Files;

import java.io.File;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public final class Main {
    @Parameter(description = "BackportedFix proto binary files", converter = FileConverter.class,
            required = true)
    List<File> fixFiles;
    @Parameter(description = "The file to write the property value to.",
            names = {"--property_file", "-p"}, converter = FileConverter.class, required = true)
    File propertyFile;

    public static void main(String... argv) throws Exception {
        Main main = new Main();
        JCommander.newBuilder().addObject(main).build().parse(argv);
        main.run();
    }

    Main() {
    }

    private void run() throws Exception {
        try (var fixStreams = ClosableCollection.wrap(Parser.getFileInputStreams(fixFiles));
             var out = Files.newWriter(propertyFile, UTF_8)) {
            var fixes = Parser.parseBackportedFixes(fixStreams.getCollection());
            writeFixesAsAliasBitSet(fixes, out);
        }
    }

    static void writeFixesAsAliasBitSet(BackportedFixes fixes, Writer out) {
        PrintWriter printWriter = new PrintWriter(out);
        printWriter.println("# The following backported fixes have been applied");
        for (var f : fixes.getFixesList()) {
            printWriter.printf("# https://issuetracker.google.com/issues/%d with alias %d",
                    f.getKnownIssue(), f.getAlias());
            printWriter.println();
        }
        var bsArray = Parser.getBitSetArray(
                fixes.getFixesList().stream().mapToInt(BackportedFix::getAlias).toArray());
        String bsString = Arrays.stream(bsArray).mapToObj(Long::toString).collect(
                Collectors.joining(","));
        printWriter.printf("ro.build.backported_fixes.alias_bitset.long_list=%s", bsString);
        printWriter.println();
        if (printWriter.checkError()) {
            throw new RuntimeException("There was an error writing to " + out.toString());
        }
    }
}
Loading