Merge "Add explicit experimental marker for Linux terminal" into main
diff --git a/ravenwood/tools/hoststubgen/test-tiny-framework/diff-and-update-golden.sh b/ravenwood/tools/hoststubgen/test-tiny-framework/diff-and-update-golden.sh
index 3726ca9..b389a67 100755
--- a/ravenwood/tools/hoststubgen/test-tiny-framework/diff-and-update-golden.sh
+++ b/ravenwood/tools/hoststubgen/test-tiny-framework/diff-and-update-golden.sh
@@ -30,7 +30,7 @@
 EOF
 }
 
-source "${0%/*}"/../../common.sh
+source "${0%/*}"/../common.sh
 
 SCRIPT_NAME="${0##*/}"
 
@@ -61,7 +61,6 @@
 done
 shift $(($OPTIND - 1))
 
-
 # Build the dump files, which are the input of this test.
 run m  dump-jar tiny-framework-dump-test
 
diff --git a/services/core/java/com/android/server/integrity/model/BitInputStream.java b/services/core/java/com/android/server/integrity/model/BitInputStream.java
deleted file mode 100644
index e7cc81e..0000000
--- a/services/core/java/com/android/server/integrity/model/BitInputStream.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2019 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.server.integrity.model;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/** A wrapper class for reading a stream of bits.
- *
- * <p>Note: this class reads from underlying stream byte-by-byte. It is advised to apply buffering
- * to underlying streams.
- */
-public class BitInputStream {
-
-    private long mBitsRead;
-
-    private InputStream mInputStream;
-
-    private byte mCurrentByte;
-
-    public BitInputStream(InputStream inputStream) {
-        mInputStream = inputStream;
-    }
-
-    /**
-     * Read the next number of bits from the stream.
-     *
-     * @param numOfBits The number of bits to read.
-     * @return The value read from the stream.
-     */
-    public int getNext(int numOfBits) throws IOException {
-        int component = 0;
-        int count = 0;
-
-        while (count++ < numOfBits) {
-            if (mBitsRead % 8 == 0) {
-                mCurrentByte = getNextByte();
-            }
-            int offset = 7 - (int) (mBitsRead % 8);
-
-            component <<= 1;
-            component |= (mCurrentByte >>> offset) & 1;
-
-            mBitsRead++;
-        }
-
-        return component;
-    }
-
-    /** Check if there are bits left in the stream. */
-    public boolean hasNext() throws IOException {
-        return mInputStream.available() > 0;
-    }
-
-    private byte getNextByte() throws IOException {
-        return (byte) mInputStream.read();
-    }
-}
diff --git a/services/core/java/com/android/server/integrity/model/BitOutputStream.java b/services/core/java/com/android/server/integrity/model/BitOutputStream.java
deleted file mode 100644
index 14b35fd..0000000
--- a/services/core/java/com/android/server/integrity/model/BitOutputStream.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2019 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.server.integrity.model;
-
-import static com.android.server.integrity.model.ComponentBitSize.BYTE_BITS;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Arrays;
-
-/** A wrapper class for writing a stream of bits. */
-public class BitOutputStream {
-
-    private static final int BUFFER_SIZE = 4 * 1024;
-
-    private int mNextBitIndex;
-
-    private final OutputStream mOutputStream;
-    private final byte[] mBuffer;
-
-    public BitOutputStream(OutputStream outputStream) {
-        mBuffer = new byte[BUFFER_SIZE];
-        mNextBitIndex = 0;
-        mOutputStream = outputStream;
-    }
-
-    /**
-     * Set the next number of bits in the stream to value.
-     *
-     * @param numOfBits The number of bits used to represent the value.
-     * @param value The value to convert to bits.
-     */
-    public void setNext(int numOfBits, int value) throws IOException {
-        if (numOfBits <= 0) {
-            return;
-        }
-
-        // optional: we can do some clever size checking to "OR" an entire segment of bits instead
-        // of setting bits one by one, but it is probably not worth it.
-        int nextBitMask = 1 << (numOfBits - 1);
-        while (numOfBits-- > 0) {
-            setNext((value & nextBitMask) != 0);
-            nextBitMask >>>= 1;
-        }
-    }
-
-    /**
-     * Set the next bit in the stream to value.
-     *
-     * @param value The value to set the bit to
-     */
-    public void setNext(boolean value) throws IOException {
-        int byteToWrite = mNextBitIndex / BYTE_BITS;
-        if (byteToWrite == BUFFER_SIZE) {
-            mOutputStream.write(mBuffer);
-            reset();
-            byteToWrite = 0;
-        }
-        if (value) {
-            mBuffer[byteToWrite] |= 1 << (BYTE_BITS - 1 - (mNextBitIndex % BYTE_BITS));
-        }
-        mNextBitIndex++;
-    }
-
-    /** Set the next bit in the stream to true. */
-    public void setNext() throws IOException {
-        setNext(/* value= */ true);
-    }
-
-    /**
-     * Flush the data written to the underlying {@link java.io.OutputStream}. Any unfinished bytes
-     * will be padded with 0.
-     */
-    public void flush() throws IOException {
-        int endByte = mNextBitIndex / BYTE_BITS;
-        if (mNextBitIndex % BYTE_BITS != 0) {
-            // If next bit is not the first bit of a byte, then mNextBitIndex / BYTE_BITS would be
-            // the byte that includes already written bits. We need to increment it so this byte
-            // gets written.
-            endByte++;
-        }
-        mOutputStream.write(mBuffer, 0, endByte);
-        reset();
-    }
-
-    /** Reset this output stream to start state. */
-    private void reset() {
-        mNextBitIndex = 0;
-        Arrays.fill(mBuffer, (byte) 0);
-    }
-}
diff --git a/services/core/java/com/android/server/integrity/model/ByteTrackedOutputStream.java b/services/core/java/com/android/server/integrity/model/ByteTrackedOutputStream.java
deleted file mode 100644
index ceed054..0000000
--- a/services/core/java/com/android/server/integrity/model/ByteTrackedOutputStream.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2020 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.server.integrity.model;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * An output stream that tracks the total number written bytes since construction and allows
- * querying this value any time during the execution.
- *
- * <p>This class is used for constructing the rule indexing.
- */
-public class ByteTrackedOutputStream extends OutputStream {
-
-    private int mWrittenBytesCount;
-    private final OutputStream mOutputStream;
-
-    public ByteTrackedOutputStream(OutputStream outputStream) {
-        mWrittenBytesCount = 0;
-        mOutputStream = outputStream;
-    }
-
-    @Override
-    public void write(int b) throws IOException {
-        mWrittenBytesCount++;
-        mOutputStream.write(b);
-    }
-
-    /**
-     * Writes the given bytes into the output stream provided in constructor and updates the total
-     * number of written bytes.
-     */
-    @Override
-    public void write(byte[] bytes) throws IOException {
-        write(bytes, 0, bytes.length);
-    }
-
-    @Override
-    public void write(byte[] b, int off, int len) throws IOException {
-        mWrittenBytesCount += len;
-        mOutputStream.write(b, off, len);
-    }
-
-    /** Returns the total number of bytes written into the output stream at the requested time. */
-    public int getWrittenBytesCount() {
-        return mWrittenBytesCount;
-    }
-}
diff --git a/services/core/java/com/android/server/integrity/model/ComponentBitSize.java b/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
deleted file mode 100644
index 94e6708..0000000
--- a/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2019 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.server.integrity.model;
-
-import android.content.integrity.Rule;
-
-/**
- * A helper class containing information about the binary representation of different {@link Rule}
- * components.
- */
-public final class ComponentBitSize {
-    public static final int FORMAT_VERSION_BITS = 8;
-
-    public static final int EFFECT_BITS = 3;
-    public static final int KEY_BITS = 4;
-    public static final int OPERATOR_BITS = 3;
-    public static final int CONNECTOR_BITS = 2;
-    public static final int SEPARATOR_BITS = 3;
-    public static final int VALUE_SIZE_BITS = 8;
-    public static final int IS_HASHED_BITS = 1;
-
-    public static final int ATOMIC_FORMULA_START = 0;
-    public static final int COMPOUND_FORMULA_START = 1;
-    public static final int COMPOUND_FORMULA_END = 2;
-    public static final int INSTALLER_ALLOWED_BY_MANIFEST_START = 3;
-
-    public static final int DEFAULT_FORMAT_VERSION = 1;
-    public static final int SIGNAL_BIT = 1;
-
-    public static final int BYTE_BITS = 8;
-}
diff --git a/services/core/java/com/android/server/integrity/model/IndexingFileConstants.java b/services/core/java/com/android/server/integrity/model/IndexingFileConstants.java
deleted file mode 100644
index 0c4052a..0000000
--- a/services/core/java/com/android/server/integrity/model/IndexingFileConstants.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2020 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.server.integrity.model;
-
-/**  A helper class containing special indexing file constants. */
-public final class IndexingFileConstants {
-    // We empirically experimented with different block sizes and identified that 50 is in the
-    // optimal range of efficient computation.
-    public static final int INDEXING_BLOCK_SIZE = 50;
-
-    public static final String START_INDEXING_KEY = "START_KEY";
-    public static final String END_INDEXING_KEY = "END_KEY";
-}
diff --git a/services/tests/servicestests/src/com/android/server/integrity/model/ByteTrackedOutputStreamTest.java b/services/tests/servicestests/src/com/android/server/integrity/model/ByteTrackedOutputStreamTest.java
deleted file mode 100644
index 57274bf..0000000
--- a/services/tests/servicestests/src/com/android/server/integrity/model/ByteTrackedOutputStreamTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2020 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.server.integrity.model;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.io.ByteArrayOutputStream;
-
-@RunWith(JUnit4.class)
-public class ByteTrackedOutputStreamTest {
-
-    @Test
-    public void testConstructorStartsWithZeroBytesWritten() {
-        ByteTrackedOutputStream byteTrackedOutputStream =
-                new ByteTrackedOutputStream(new ByteArrayOutputStream());
-
-        assertThat(byteTrackedOutputStream.getWrittenBytesCount()).isEqualTo(0);
-    }
-
-    @Test
-    public void testSuccessfulWriteAndValidateWrittenBytesCount_directFromByteArray()
-            throws Exception {
-        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        ByteTrackedOutputStream byteTrackedOutputStream = new ByteTrackedOutputStream(outputStream);
-
-        byte[] outputContent = "This is going to be outputed for tests.".getBytes();
-        byteTrackedOutputStream.write(outputContent);
-
-        assertThat(byteTrackedOutputStream.getWrittenBytesCount()).isEqualTo(outputContent.length);
-        assertThat(outputStream.toByteArray().length).isEqualTo(outputContent.length);
-    }
-
-    @Test
-    public void testSuccessfulWriteAndValidateWrittenBytesCount_fromBitStream() throws Exception {
-        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        ByteTrackedOutputStream byteTrackedOutputStream = new ByteTrackedOutputStream(outputStream);
-
-        BitOutputStream bitOutputStream = new BitOutputStream(byteTrackedOutputStream);
-        bitOutputStream.setNext(/* numOfBits= */5, /* value= */1);
-        bitOutputStream.flush();
-
-        // Even though we wrote 5 bits, this will complete to 1 byte.
-        assertThat(byteTrackedOutputStream.getWrittenBytesCount()).isEqualTo(1);
-
-        // Add a bit less than 2 bytes (10 bits).
-        bitOutputStream.setNext(/* numOfBits= */10, /* value= */1);
-        bitOutputStream.flush();
-        assertThat(byteTrackedOutputStream.getWrittenBytesCount()).isEqualTo(3);
-
-        assertThat(outputStream.toByteArray().length).isEqualTo(3);
-    }
-}