Loading core/java/android/service/persistentdata/PersistentDataBlockManager.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,9 @@ public class PersistentDataBlockManager { * Returns the number of bytes written or -1 on error. If the block is too big * Returns the number of bytes written or -1 on error. If the block is too big * to fit on the partition, returns -MAX_BLOCK_SIZE. * to fit on the partition, returns -MAX_BLOCK_SIZE. * * * {@link #wipe} will block any further {@link #write} operation until reboot, * in which case -1 will be returned. * * @param data the data to write * @param data the data to write */ */ public int write(byte[] data) { public int write(byte[] data) { Loading Loading @@ -129,6 +132,8 @@ public class PersistentDataBlockManager { /** /** * Zeroes the previously written block in its entirety. Calling this method * Zeroes the previously written block in its entirety. Calling this method * will erase all data written to the persistent data partition. * will erase all data written to the persistent data partition. * It will also prevent any further {@link #write} operation until reboot, * in order to prevent a potential race condition. See b/30352311. */ */ public void wipe() { public void wipe() { try { try { Loading services/core/java/com/android/server/PersistentDataBlockService.java +14 −6 Original line number Original line Diff line number Diff line Loading @@ -53,15 +53,14 @@ import java.util.Arrays; * This data will live across factory resets not initiated via the Settings UI. * This data will live across factory resets not initiated via the Settings UI. * When a device is factory reset through Settings this data is wiped. * When a device is factory reset through Settings this data is wiped. * * * Allows writing one block at a time. Namely, each time * Allows writing one block at a time. Namely, each time {@link IPersistentDataBlockService#write} * {@link android.service.persistentdata.IPersistentDataBlockService}.write(byte[] data) * is called, it will overwrite the data that was previously written on the block. * is called, it will overwite the data that was previously written on the block. * * * Clients can query the size of the currently written block via * Clients can query the size of the currently written block via * {@link android.service.persistentdata.IPersistentDataBlockService}.getTotalDataSize(). * {@link IPersistentDataBlockService#getDataBlockSize} * * * Clients can any number of bytes from the currently written block up to its total size by invoking * Clients can read any number of bytes from the currently written block up to its total size by * {@link android.service.persistentdata.IPersistentDataBlockService}.read(byte[] data) * invoking {@link IPersistentDataBlockService#read} */ */ public class PersistentDataBlockService extends SystemService { public class PersistentDataBlockService extends SystemService { private static final String TAG = PersistentDataBlockService.class.getSimpleName(); private static final String TAG = PersistentDataBlockService.class.getSimpleName(); Loading @@ -84,6 +83,7 @@ public class PersistentDataBlockService extends SystemService { private int mAllowedUid = -1; private int mAllowedUid = -1; private long mBlockDeviceSize; private long mBlockDeviceSize; private boolean mIsWritable = true; public PersistentDataBlockService(Context context) { public PersistentDataBlockService(Context context) { super(context); super(context); Loading Loading @@ -377,6 +377,11 @@ public class PersistentDataBlockService extends SystemService { headerAndData.put(data); headerAndData.put(data); synchronized (mLock) { synchronized (mLock) { if (!mIsWritable) { IoUtils.closeQuietly(outputStream); return -1; } try { try { byte[] checksum = new byte[DIGEST_SIZE_BYTES]; byte[] checksum = new byte[DIGEST_SIZE_BYTES]; outputStream.write(checksum, 0, DIGEST_SIZE_BYTES); outputStream.write(checksum, 0, DIGEST_SIZE_BYTES); Loading Loading @@ -451,6 +456,9 @@ public class PersistentDataBlockService extends SystemService { if (ret < 0) { if (ret < 0) { Slog.e(TAG, "failed to wipe persistent partition"); Slog.e(TAG, "failed to wipe persistent partition"); } else { mIsWritable = false; Slog.i(TAG, "persistent partition now wiped and unwritable"); } } } } } } Loading Loading
core/java/android/service/persistentdata/PersistentDataBlockManager.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,9 @@ public class PersistentDataBlockManager { * Returns the number of bytes written or -1 on error. If the block is too big * Returns the number of bytes written or -1 on error. If the block is too big * to fit on the partition, returns -MAX_BLOCK_SIZE. * to fit on the partition, returns -MAX_BLOCK_SIZE. * * * {@link #wipe} will block any further {@link #write} operation until reboot, * in which case -1 will be returned. * * @param data the data to write * @param data the data to write */ */ public int write(byte[] data) { public int write(byte[] data) { Loading Loading @@ -129,6 +132,8 @@ public class PersistentDataBlockManager { /** /** * Zeroes the previously written block in its entirety. Calling this method * Zeroes the previously written block in its entirety. Calling this method * will erase all data written to the persistent data partition. * will erase all data written to the persistent data partition. * It will also prevent any further {@link #write} operation until reboot, * in order to prevent a potential race condition. See b/30352311. */ */ public void wipe() { public void wipe() { try { try { Loading
services/core/java/com/android/server/PersistentDataBlockService.java +14 −6 Original line number Original line Diff line number Diff line Loading @@ -53,15 +53,14 @@ import java.util.Arrays; * This data will live across factory resets not initiated via the Settings UI. * This data will live across factory resets not initiated via the Settings UI. * When a device is factory reset through Settings this data is wiped. * When a device is factory reset through Settings this data is wiped. * * * Allows writing one block at a time. Namely, each time * Allows writing one block at a time. Namely, each time {@link IPersistentDataBlockService#write} * {@link android.service.persistentdata.IPersistentDataBlockService}.write(byte[] data) * is called, it will overwrite the data that was previously written on the block. * is called, it will overwite the data that was previously written on the block. * * * Clients can query the size of the currently written block via * Clients can query the size of the currently written block via * {@link android.service.persistentdata.IPersistentDataBlockService}.getTotalDataSize(). * {@link IPersistentDataBlockService#getDataBlockSize} * * * Clients can any number of bytes from the currently written block up to its total size by invoking * Clients can read any number of bytes from the currently written block up to its total size by * {@link android.service.persistentdata.IPersistentDataBlockService}.read(byte[] data) * invoking {@link IPersistentDataBlockService#read} */ */ public class PersistentDataBlockService extends SystemService { public class PersistentDataBlockService extends SystemService { private static final String TAG = PersistentDataBlockService.class.getSimpleName(); private static final String TAG = PersistentDataBlockService.class.getSimpleName(); Loading @@ -84,6 +83,7 @@ public class PersistentDataBlockService extends SystemService { private int mAllowedUid = -1; private int mAllowedUid = -1; private long mBlockDeviceSize; private long mBlockDeviceSize; private boolean mIsWritable = true; public PersistentDataBlockService(Context context) { public PersistentDataBlockService(Context context) { super(context); super(context); Loading Loading @@ -377,6 +377,11 @@ public class PersistentDataBlockService extends SystemService { headerAndData.put(data); headerAndData.put(data); synchronized (mLock) { synchronized (mLock) { if (!mIsWritable) { IoUtils.closeQuietly(outputStream); return -1; } try { try { byte[] checksum = new byte[DIGEST_SIZE_BYTES]; byte[] checksum = new byte[DIGEST_SIZE_BYTES]; outputStream.write(checksum, 0, DIGEST_SIZE_BYTES); outputStream.write(checksum, 0, DIGEST_SIZE_BYTES); Loading Loading @@ -451,6 +456,9 @@ public class PersistentDataBlockService extends SystemService { if (ret < 0) { if (ret < 0) { Slog.e(TAG, "failed to wipe persistent partition"); Slog.e(TAG, "failed to wipe persistent partition"); } else { mIsWritable = false; Slog.i(TAG, "persistent partition now wiped and unwritable"); } } } } } } Loading