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

Commit b7313ed9 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Re-enable all tests in ShortcutManagerTest1

FileIntegrity.setUpFsVerity will fail when calling with test context,
this CL provides a mock to avoid calling the method in test.

Bug: 385751468
Test: manual
Flag: EXEMPT bugfix
Change-Id: Ic6721a53deb211dafa7e5a5d8dba8470cf9c9585
parent 1ea2afa9
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.security.FileIntegrity;

import libcore.io.IoUtils;
@@ -121,6 +122,11 @@ final class ResilientAtomicFile implements Closeable {
    }

    public void finishWrite(FileOutputStream str) throws IOException {
        finishWrite(str, true /* doFsVerity */);
    }

    @VisibleForTesting
    public void finishWrite(FileOutputStream str, final boolean doFsVerity) throws IOException {
        if (mMainOutStream != str) {
            throw new IllegalStateException("Invalid incoming stream.");
        }
@@ -145,6 +151,7 @@ final class ResilientAtomicFile implements Closeable {
                finalizeOutStream(reserveOutStream);
            }

            if (doFsVerity) {
                // Protect both main and reserve using fs-verity.
                try (ParcelFileDescriptor mainPfd = ParcelFileDescriptor.dup(mainInStream.getFD());
                     ParcelFileDescriptor copyPfd = ParcelFileDescriptor.dup(reserveInStream.getFD())) {
@@ -153,6 +160,7 @@ final class ResilientAtomicFile implements Closeable {
                } catch (IOException e) {
                    Slog.e(LOG_TAG, "Failed to verity-protect " + mDebugName, e);
                }
            }
        } catch (IOException e) {
            Slog.e(LOG_TAG, "Failed to write reserve copy " + mDebugName + ": " + mReserveCopy, e);
        }
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ abstract class ShortcutPackageItem {
                itemOut.endDocument();

                os.flush();
                file.finishWrite(os);
                mShortcutUser.mService.injectFinishWrite(file, os);
            } catch (XmlPullParserException | IOException e) {
                Slog.e(TAG, "Failed to write to file " + file.getBaseFile(), e);
                file.failWrite(os);
+8 −2
Original line number Diff line number Diff line
@@ -1020,7 +1020,7 @@ public class ShortcutService extends IShortcutService.Stub {
                out.endDocument();

                // Close.
                file.finishWrite(outs);
                injectFinishWrite(file, outs);
            } catch (IOException e) {
                Slog.w(TAG, "Failed to write to file " + file.getBaseFile(), e);
                file.failWrite(outs);
@@ -1108,7 +1108,7 @@ public class ShortcutService extends IShortcutService.Stub {
                    saveUserInternalLocked(userId, os, /* forBackup= */ false);
                }

                file.finishWrite(os);
                injectFinishWrite(file, os);

                // Remove all dangling bitmap files.
                cleanupDanglingBitmapDirectoriesLocked(userId);
@@ -5262,6 +5262,12 @@ public class ShortcutService extends IShortcutService.Stub {
        return Build.FINGERPRINT;
    }

    // Injection point.
    void injectFinishWrite(@NonNull final ResilientAtomicFile file,
            @NonNull final FileOutputStream os) throws IOException {
        file.finishWrite(os);
    }

    final void wtf(String message) {
        wtf(message, /* exception= */ null);
    }
+7 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ import org.mockito.stubbing.Answer;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -555,6 +556,12 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
            return mInjectedChooserActivity;
        }

        @Override
        void injectFinishWrite(@NonNull ResilientAtomicFile file,
                @NonNull FileOutputStream os) throws IOException {
            file.finishWrite(os, false /* doFsVerity */);
        }

        @Override
        void wtf(String message, Throwable th) {
            // During tests, WTF is fatal.
+109 −108

File changed.

Preview size limit exceeded, changes collapsed.