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

Commit 3e2e8704 authored by Wenhao Wang's avatar Wenhao Wang Committed by Android (Google) Code Review
Browse files

Merge "Init the App metadata bundles" into main

parents 46cb170e e3a07533
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
}

java_library_host {
    name: "asllib",
    srcs: [
        "src/lib/java/**/*.java",
    ],
    target: {
        windows: {
            enabled: true,
        },
    },
}

java_binary_host {
    name: "aslgen",
    manifest: "src/aslgen/aslgen.mf",
    srcs: [
        "src/aslgen/java/**/*.java",
    ],
    static_libs: [
        "asllib",
    ],
}
+2 −0
Original line number Diff line number Diff line
wenhaowang@google.com
mloh@google.com
+9 −0
Original line number Diff line number Diff line
# App metadata bundles

This project delivers a comprehensive toolchain solution for developers
to efficiently manage app metadata bundles.

The project consists of two subprojects:

  * A pure Java library, and
  * A pure Java command-line tool.
+1 −0
Original line number Diff line number Diff line
Main-Class: com.android.aslgen.Main
 No newline at end of file
+108 −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.aslgen;

import com.android.asllib.AndroidSafetyLabel;
import com.android.asllib.AndroidSafetyLabel.Format;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {

    /**
     * Takes the options to make file conversion.
     */
    public static void main(String[] args) throws IOException {

        String inFile = null;
        String outFile = null;
        Format inFormat = Format.NULL;
        Format outFormat = Format.NULL;


        // Except for "--help", all arguments require a value currently.
        // So just make sure we have an even number and
        // then process them all two at a time.
        if (args.length == 1 && "--help".equals(args[0])) {
            showUsage();
            return;
        }
        if (args.length % 2 != 0) {
            throw new IllegalArgumentException("Argument is missing corresponding value");
        }
        for (int i = 0; i < args.length - 1; i += 2) {
            final String arg = args[i].trim();
            final String argValue = args[i + 1].trim();
            if ("--in-path".equals(arg)) {
                inFile = argValue;
            } else if ("--out-path".equals(arg)) {
                outFile = argValue;
            } else if ("--in-format".equals(arg)) {
                inFormat = getFormat(argValue);
            } else if ("--out-format".equals(arg)) {
                outFormat = getFormat(argValue);
            } else {
                throw new IllegalArgumentException("Unknown argument: " + arg);
            }
        }

        if (inFile == null) {
            throw new IllegalArgumentException("input file is required");
        }

        if (outFile == null) {
            throw new IllegalArgumentException("output file is required");
        }

        if (inFormat == Format.NULL) {
            throw new IllegalArgumentException("input format is required");
        }

        if (outFormat == Format.NULL) {
            throw new IllegalArgumentException("output format is required");
        }


        System.out.println("in path: " + inFile);
        System.out.println("out path: " + outFile);
        System.out.println("in format: " + inFormat);
        System.out.println("out format: " + outFormat);

        var asl = AndroidSafetyLabel.readFromStream(new FileInputStream(inFile),
                Format.HUMAN_READABLE);
        asl.writeToStream(new FileOutputStream(outFile), Format.ON_DEVICE);
    }

    private static Format getFormat(String argValue) {
        if ("hr".equals(argValue)) {
            return Format.HUMAN_READABLE;
        } else if ("od".equals(argValue)) {
            return Format.ON_DEVICE;
        } else {
            return Format.NULL;
        }
    }

    private static void showUsage() {
        AndroidSafetyLabel.test();
        System.err.println(
                "Usage:\n"
        );
    }
}
Loading