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

Commit 8cdd0899 authored by Howard Chen's avatar Howard Chen Committed by Automerger Merge Worker
Browse files

Support PersistentDataBlockService in DSU am: 649c198c am: 0680e947 am: 2d73582c

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1549485

Change-Id: Id11dfb6ad38e81977f4047edd289d575de9ecd3a
parents 717e9eea 2d73582c
Loading
Loading
Loading
Loading
+33 −7
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.internal.annotations.GuardedBy;

import libcore.io.IoUtils;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
@@ -45,6 +46,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
@@ -104,6 +106,8 @@ import java.util.concurrent.TimeUnit;
public class PersistentDataBlockService extends SystemService {
    private static final String TAG = PersistentDataBlockService.class.getSimpleName();

    private static final String GSI_RUNNING_PROP = "ro.gsid.image_running";

    private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
    private static final int HEADER_SIZE = 8;
    // Magic number to mark block device as adhering to the format consumed by this service
@@ -129,6 +133,7 @@ public class PersistentDataBlockService extends SystemService {

    private final Context mContext;
    private final String mDataBlockFile;
    private final boolean mIsRunningDSU;
    private final Object mLock = new Object();
    private final CountDownLatch mInitDoneSignal = new CountDownLatch(1);

@@ -142,6 +147,7 @@ public class PersistentDataBlockService extends SystemService {
        super(context);
        mContext = context;
        mDataBlockFile = SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP);
        mIsRunningDSU = SystemProperties.getBoolean(GSI_RUNNING_PROP, false);
        mBlockDeviceSize = -1; // Load lazily
    }

@@ -286,14 +292,22 @@ public class PersistentDataBlockService extends SystemService {
        return true;
    }

    private OutputStream getBlockOutputStream() throws IOException {
        if (mIsRunningDSU) {
            Slog.i(TAG, "data is read-only when running a DSU");
            return new ByteArrayOutputStream();
        } else {
            return new FileOutputStream(new File(mDataBlockFile));
        }
    }

    private boolean computeAndWriteDigestLocked() {
        byte[] digest = computeDigestLocked(null);
        if (digest != null) {
            DataOutputStream outputStream;
            try {
                outputStream = new DataOutputStream(
                        new FileOutputStream(new File(mDataBlockFile)));
            } catch (FileNotFoundException e) {
                outputStream = new DataOutputStream(getBlockOutputStream());
            } catch (IOException e) {
                Slog.e(TAG, "partition not available?", e);
                return false;
            }
@@ -358,8 +372,8 @@ public class PersistentDataBlockService extends SystemService {
    private void formatPartitionLocked(boolean setOemUnlockEnabled) {
        DataOutputStream outputStream;
        try {
            outputStream = new DataOutputStream(new FileOutputStream(new File(mDataBlockFile)));
        } catch (FileNotFoundException e) {
            outputStream = new DataOutputStream(getBlockOutputStream());
        } catch (IOException e) {
            Slog.e(TAG, "partition not available?", e);
            return;
        }
@@ -383,6 +397,10 @@ public class PersistentDataBlockService extends SystemService {

    private void doSetOemUnlockEnabledLocked(boolean enabled) {
        FileOutputStream outputStream;
        if (mIsRunningDSU) {
            Slog.i(TAG, "data is read-only when running a DSU");
            return;
        }
        try {
            outputStream = new FileOutputStream(new File(mDataBlockFile));
        } catch (FileNotFoundException e) {
@@ -461,8 +479,8 @@ public class PersistentDataBlockService extends SystemService {

            DataOutputStream outputStream;
            try {
                outputStream = new DataOutputStream(new FileOutputStream(new File(mDataBlockFile)));
            } catch (FileNotFoundException e) {
                outputStream = new DataOutputStream(getBlockOutputStream());
            } catch (IOException e) {
                Slog.e(TAG, "partition not available?", e);
                return -1;
            }
@@ -547,6 +565,10 @@ public class PersistentDataBlockService extends SystemService {
        public void wipe() {
            enforceOemUnlockWritePermission();

            if (mIsRunningDSU) {
                Slog.i(TAG, "data is read-only when running a DSU");
                return;
            }
            synchronized (mLock) {
                int ret = nativeWipe(mDataBlockFile);

@@ -705,6 +727,10 @@ public class PersistentDataBlockService extends SystemService {

        private void writeDataBuffer(long offset, ByteBuffer dataBuffer) {
            FileOutputStream outputStream;
            if (mIsRunningDSU) {
                Slog.i(TAG, "data is read-only when running a DSU");
                return;
            }
            try {
                outputStream = new FileOutputStream(new File(mDataBlockFile));
            } catch (FileNotFoundException e) {
+1 −4
Original line number Diff line number Diff line
@@ -390,8 +390,6 @@ public final class SystemServer implements Dumpable {
    private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file";
    private static final String BLOCK_MAP_FILE = "/cache/recovery/block.map";

    private static final String GSI_RUNNING_PROP = "ro.gsid.image_running";

    // maximum number of binder threads used for system_server
    // will be higher than the system default
    private static final int sMaxBinderThreads = 31;
@@ -1662,8 +1660,7 @@ public final class SystemServer implements Dumpable {
            t.traceEnd();

            final boolean hasPdb = !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
            final boolean hasGsi = SystemProperties.getInt(GSI_RUNNING_PROP, 0) > 0;
            if (hasPdb && !hasGsi) {
            if (hasPdb) {
                t.traceBegin("StartPersistentDataBlock");
                mSystemServiceManager.startService(PersistentDataBlockService.class);
                t.traceEnd();