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

Commit 890bfdd2 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge changes from topic "nov15d" into main

* changes:
  Support TextUtils for Ravenwood, with CTS.
  Build `ravenwood-junit` against `test_current`.
parents c2cad757 cb4a047e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ android_ravenwood_libgroup {
        "hoststubgen-helper-framework-runtime.ravenwood",
        "junit",
        "truth",
        "ravenwood-junit",
        "ravenwood-junit-impl",
        "android.test.mock",
    ],
}
+50 −5
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
import android.text.style.UpdateAppearance;
import android.util.EmptyArray;
import android.util.Log;
import android.util.Printer;
import android.view.View;
@@ -141,9 +142,9 @@ public class TextUtils {
        return (method == TextUtils.TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS : ELLIPSIS_NORMAL;
    }


    private TextUtils() { /* cannot be instantiated */ }

    @android.ravenwood.annotation.RavenwoodKeep
    public static void getChars(CharSequence s, int start, int end,
                                char[] dest, int destoff) {
        Class<? extends CharSequence> c = s.getClass();
@@ -162,10 +163,12 @@ public class TextUtils {
        }
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int indexOf(CharSequence s, char ch) {
        return indexOf(s, ch, 0);
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int indexOf(CharSequence s, char ch, int start) {
        Class<? extends CharSequence> c = s.getClass();

@@ -175,6 +178,7 @@ public class TextUtils {
        return indexOf(s, ch, start, s.length());
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int indexOf(CharSequence s, char ch, int start, int end) {
        Class<? extends CharSequence> c = s.getClass();

@@ -212,10 +216,12 @@ public class TextUtils {
        return -1;
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int lastIndexOf(CharSequence s, char ch) {
        return lastIndexOf(s, ch, s.length() - 1);
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int lastIndexOf(CharSequence s, char ch, int last) {
        Class<? extends CharSequence> c = s.getClass();

@@ -225,6 +231,7 @@ public class TextUtils {
        return lastIndexOf(s, ch, 0, last);
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int lastIndexOf(CharSequence s, char ch,
                                  int start, int last) {
        if (last < 0)
@@ -270,14 +277,17 @@ public class TextUtils {
        return -1;
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int indexOf(CharSequence s, CharSequence needle) {
        return indexOf(s, needle, 0, s.length());
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int indexOf(CharSequence s, CharSequence needle, int start) {
        return indexOf(s, needle, start, s.length());
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static int indexOf(CharSequence s, CharSequence needle,
                              int start, int end) {
        int nlen = needle.length();
@@ -305,6 +315,7 @@ public class TextUtils {
        return -1;
    }

    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean regionMatches(CharSequence one, int toffset,
                                        CharSequence two, int ooffset,
                                        int len) {
@@ -337,6 +348,7 @@ public class TextUtils {
     * in that it does not preserve any style runs in the source sequence,
     * allowing a more efficient implementation.
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String substring(CharSequence source, int start, int end) {
        if (source instanceof String)
            return ((String) source).substring(start, end);
@@ -409,6 +421,7 @@ public class TextUtils {
     *     calling object.toString(). If tokens is null, a NullPointerException will be thrown. If
     *     tokens is an empty array, an empty string will be returned.
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String join(@NonNull CharSequence delimiter, @NonNull Object[] tokens) {
        final int length = tokens.length;
        if (length == 0) {
@@ -432,6 +445,7 @@ public class TextUtils {
     *     calling object.toString(). If tokens is null, a NullPointerException will be thrown. If
     *     tokens is empty, an empty string will be returned.
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens) {
        final Iterator<?> it = tokens.iterator();
        if (!it.hasNext()) {
@@ -464,9 +478,10 @@ public class TextUtils {
     *
     * @throws NullPointerException if expression or text is null
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String[] split(String text, String expression) {
        if (text.length() == 0) {
            return EMPTY_STRING_ARRAY;
            return EmptyArray.STRING;
        } else {
            return text.split(expression, -1);
        }
@@ -489,9 +504,10 @@ public class TextUtils {
     *
     * @throws NullPointerException if expression or text is null
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String[] split(String text, Pattern pattern) {
        if (text.length() == 0) {
            return EMPTY_STRING_ARRAY;
            return EmptyArray.STRING;
        } else {
            return pattern.split(text, -1);
        }
@@ -526,6 +542,7 @@ public class TextUtils {
     * be returned for the empty string after that delimeter. That is, splitting <tt>"a,b,"</tt> on
     * comma will return <tt>"a", "b"</tt>, not <tt>"a", "b", ""</tt>.
     */
    @android.ravenwood.annotation.RavenwoodKeepWholeClass
    public static class SimpleStringSplitter implements StringSplitter, Iterator<String> {
        private String mString;
        private char mDelimiter;
@@ -589,26 +606,31 @@ public class TextUtils {
     * @param str the string to be examined
     * @return true if str is null or zero length
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isEmpty(@Nullable CharSequence str) {
        return str == null || str.length() == 0;
    }

    /** {@hide} */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String nullIfEmpty(@Nullable String str) {
        return isEmpty(str) ? null : str;
    }

    /** {@hide} */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String emptyIfNull(@Nullable String str) {
        return str == null ? "" : str;
    }

    /** {@hide} */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String firstNotEmpty(@Nullable String a, @NonNull String b) {
        return !isEmpty(a) ? a : Preconditions.checkStringNotEmpty(b);
    }

    /** {@hide} */
    @android.ravenwood.annotation.RavenwoodKeep
    public static int length(@Nullable String s) {
        return s != null ? s.length() : 0;
    }
@@ -617,6 +639,7 @@ public class TextUtils {
     * @return interned string if it's null.
     * @hide
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String safeIntern(String s) {
        return (s != null) ? s.intern() : null;
    }
@@ -626,6 +649,7 @@ public class TextUtils {
     * spaces and ASCII control characters were trimmed from the start and end,
     * as by {@link String#trim}.
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static int getTrimmedLength(CharSequence s) {
        int len = s.length();

@@ -650,6 +674,7 @@ public class TextUtils {
     * @param b second CharSequence to check
     * @return true if a and b are equal
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean equals(CharSequence a, CharSequence b) {
        if (a == b) return true;
        int length;
@@ -1679,6 +1704,7 @@ public class TextUtils {
        return true;
    }

    @android.ravenwood.annotation.RavenwoodReplace
    /* package */ static char[] obtain(int len) {
        char[] buf;

@@ -1693,6 +1719,11 @@ public class TextUtils {
        return buf;
    }

    /* package */ static char[] obtain$ravenwood(int len) {
        return new char[len];
    }

    @android.ravenwood.annotation.RavenwoodReplace
    /* package */ static void recycle(char[] temp) {
        if (temp.length > 1000)
            return;
@@ -1702,11 +1733,16 @@ public class TextUtils {
        }
    }

    /* package */ static void recycle$ravenwood(char[] temp) {
        // Handled by typical GC
    }

    /**
     * Html-encode the string.
     * @param s the string to be encoded
     * @return the encoded string
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static String htmlEncode(String s) {
        StringBuilder sb = new StringBuilder();
        char c;
@@ -1793,6 +1829,7 @@ public class TextUtils {
    /**
     * Returns whether the given CharSequence contains any printable characters.
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isGraphic(CharSequence str) {
        final int len = str.length();
        for (int cp, i=0; i<len; i+=Character.charCount(cp)) {
@@ -1819,6 +1856,7 @@ public class TextUtils {
     * @deprecated Use {@link #isGraphic(CharSequence)} instead.
     */
    @Deprecated
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isGraphic(char c) {
        int gc = Character.getType(c);
        return     gc != Character.CONTROL
@@ -1833,6 +1871,7 @@ public class TextUtils {
    /**
     * Returns whether the given CharSequence contains only digits.
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isDigitsOnly(CharSequence str) {
        final int len = str.length();
        for (int cp, i = 0; i < len; i += Character.charCount(cp)) {
@@ -1847,6 +1886,7 @@ public class TextUtils {
    /**
     * @hide
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isPrintableAscii(final char c) {
        final int asciiFirst = 0x20;
        final int asciiLast = 0x7E;  // included
@@ -1857,6 +1897,7 @@ public class TextUtils {
     * @hide
     */
    @UnsupportedAppUsage
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isPrintableAsciiOnly(final CharSequence str) {
        final int len = str.length();
        for (int i = 0; i < len; i++) {
@@ -1908,6 +1949,7 @@ public class TextUtils {
     * {@link #CAP_MODE_CHARACTERS}, {@link #CAP_MODE_WORDS}, and
     * {@link #CAP_MODE_SENTENCES}.
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static int getCapsMode(CharSequence cs, int off, int reqModes) {
        if (off < 0) {
            return 0;
@@ -2153,6 +2195,7 @@ public class TextUtils {
     *             match the supported grammar described above.
     * @hide
     */
    @android.ravenwood.annotation.RavenwoodKeep
    public static @NonNull String formatSimple(@NonNull String format, Object... args) {
        final StringBuilder sb = new StringBuilder(format);
        int j = 0;
@@ -2342,6 +2385,7 @@ public class TextUtils {
    }

    /** @hide */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isNewline(int codePoint) {
        int type = Character.getType(codePoint);
        return type == Character.PARAGRAPH_SEPARATOR || type == Character.LINE_SEPARATOR
@@ -2349,16 +2393,19 @@ public class TextUtils {
    }

    /** @hide */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isWhitespace(int codePoint) {
        return Character.isWhitespace(codePoint) || codePoint == NBSP_CODE_POINT;
    }

    /** @hide */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isWhitespaceExceptNewline(int codePoint) {
        return isWhitespace(codePoint) && !isNewline(codePoint);
    }

    /** @hide */
    @android.ravenwood.annotation.RavenwoodKeep
    public static boolean isPunctuation(int codePoint) {
        int type = Character.getType(codePoint);
        return type == Character.CONNECTOR_PUNCTUATION
@@ -2608,6 +2655,4 @@ public class TextUtils {
    private static Object sLock = new Object();

    private static char[] sTemp = null;

    private static String[] EMPTY_STRING_ARRAY = new String[]{};
}
+22 −2
Original line number Diff line number Diff line
@@ -25,12 +25,32 @@ java_library {
}

java_library {
    name: "ravenwood-junit",
    srcs: ["junit-src/**/*.java"],
    name: "ravenwood-junit-impl",
    srcs: [
        "junit-src/**/*.java",
        "junit-impl-src/**/*.java",
    ],
    libs: [
        "framework-minus-apex.ravenwood",
        "junit",
    ],
    visibility: ["//frameworks/base"],
}

// Carefully compiles against only test_current to support tests that
// want to verify they're unbundled.  The "impl" library above is what
// ships inside the Ravenwood environment to actually drive any API
// access to implementation details.
java_library {
    name: "ravenwood-junit",
    srcs: [
        "junit-src/**/*.java",
        "junit-stub-src/**/*.java",
    ],
    sdk_version: "test_current",
    libs: [
        "junit",
    ],
    visibility: ["//visibility:public"],
}

+0 −4
Original line number Diff line number Diff line
@@ -129,7 +129,3 @@ class android.net.UriCodec stubclass
# Context: just enough to support wrapper, no further functionality
class android.content.Context stub
    method <init> ()V stub

# Text
class android.text.TextUtils stub
    method isEmpty (Ljava/lang/CharSequence;)Z stub
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 android.platform.test.ravenwood;

public class RavenwoodRuleImpl {
    public static void init(RavenwoodRule rule) {
        android.os.Process.init$ravenwood(rule.mUid, rule.mPid);
        android.os.Binder.init$ravenwood();
    }

    public static void reset(RavenwoodRule rule) {
        android.os.Process.reset$ravenwood();
        android.os.Binder.reset$ravenwood();
    }
}
Loading