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

Commit ef1337ac authored by Diego Perez's avatar Diego Perez Committed by Android (Google) Code Review
Browse files

Merge "Rename android.os.Build so it can be dynamically generated"

parents 9ac082f8 9a7be3a3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;

import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
import static android.os._Original_Build.VERSION_CODES.JELLY_BEAN_MR1;
import static com.android.layoutlib.bridge.android.RenderParamsFlags.FLAG_KEY_APPLICATION_PACKAGE;

/**
+2 −2
Original line number Diff line number Diff line
@@ -16,13 +16,13 @@

package com.android.layoutlib.bridge.bars;

import android.os.Build.VERSION_CODES;
import android.os._Original_Build.VERSION_CODES;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static android.os.Build.VERSION_CODES.*;
import static android.os._Original_Build.VERSION_CODES.*;

/**
 * Various helper methods to simulate older versions of platform.
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;

import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os._Original_Build.VERSION_CODES.LOLLIPOP;

/**
 * Base "bar" class for the window decor around the the edited layout.
+9 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import java.util.TreeMap;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Class that generates a new JAR from a list of classes, some of which are to be kept as-is
@@ -127,7 +128,10 @@ public class AsmGenerator {
        // Create the map of classes to rename.
        mRenameClasses = new HashMap<>();
        mClassesNotRenamed = new HashSet<>();
        String[] renameClasses = createInfo.getRenamedClasses();
        String[] renameClasses = Stream.concat(
                Arrays.stream(createInfo.getRenamedClasses()),
                Arrays.stream(createInfo.getRefactoredClasses()))
                .toArray(String[]::new);
        int n = renameClasses.length;
        for (int i = 0; i < n; i += 2) {
            assert i + 1 < n;
@@ -140,7 +144,10 @@ public class AsmGenerator {

        // Create a map of classes to be refactored.
        mRefactorClasses = new HashMap<>();
        String[] refactorClasses = createInfo.getJavaPkgClasses();
        String[] refactorClasses = Stream.concat(
                Arrays.stream(createInfo.getJavaPkgClasses()),
                Arrays.stream(createInfo.getRefactoredClasses()))
                .toArray(String[]::new);
        n = refactorClasses.length;
        for (int i = 0; i < n; i += 2) {
            assert i + 1 < n;
+18 −30
Original line number Diff line number Diff line
@@ -36,65 +36,41 @@ import java.util.Set;
 */
public final class CreateInfo implements ICreateInfo {

    /**
     * Returns the list of class from layoutlib_create to inject in layoutlib.
     * The list can be empty but must not be null.
     */
    @Override
    public Class<?>[] getInjectedClasses() {
        return INJECTED_CLASSES;
    }

    /**
     * Returns the list of methods to rewrite as delegates.
     * The list can be empty but must not be null.
     */
    @Override
    public String[] getDelegateMethods() {
        return DELEGATE_METHODS;
    }

    /**
     * Returns the list of classes on which to delegate all native methods.
     * The list can be empty but must not be null.
     */
    @Override
    public String[] getDelegateClassNatives() {
        return DELEGATE_CLASS_NATIVES;
    }

    /**
     * Returns the list of classes to rename, must be an even list: the binary FQCN
     * of class to replace followed by the new FQCN.
     * The list can be empty but must not be null.
     */
    @Override
    public String[] getRenamedClasses() {
        return RENAMED_CLASSES;
    }

    /**
     * Returns the list of classes for which the methods returning them should be deleted.
     * The array contains a list of null terminated section starting with the name of the class
     * to rename in which the methods are deleted, followed by a list of return types identifying
     * the methods to delete.
     * The list can be empty but must not be null.
     */
    @Override
    public String[] getDeleteReturns() {
        return DELETE_RETURNS;
    }

    /**
     * Returns the list of classes to refactor, must be an even list: the binary FQCN of class to
     * replace followed by the new FQCN. All references to the old class should be updated to the
     * new class. The list can be empty but must not be null.
     */
    @Override
    public String[] getJavaPkgClasses() {
      return JAVA_PKG_CLASSES;
    }

    @Override
    public String[] getRefactoredClasses() {
        return REFACTOR_CLASSES;
    }

    @Override
    public Set<String> getExcludedClasses() {
        String[] refactoredClasses = getJavaPkgClasses();
@@ -333,10 +309,22 @@ public final class CreateInfo implements ICreateInfo {
            "java.text.SimpleDateFormat",                      "android.icu.text.SimpleDateFormat",
        };

    /**
     * List of classes to refactor. This is similar to combining {@link #getRenamedClasses()} and
     * {@link #getJavaPkgClasses()}.
     * Classes included here will be renamed and then all their references in any other classes
     * will be also modified.
     * FQCN of class to refactor followed by its new FQCN.
     */
    private final static String[] REFACTOR_CLASSES =
            new String[] {
                    "android.os.Build",                                "android.os._Original_Build",
            };

    private final static String[] EXCLUDED_CLASSES =
        new String[] {
            "android.preference.PreferenceActivity",
            "org.kxml2.io.KXmlParser"
            "org.kxml2.io.KXmlParser",
        };

    /**
Loading