Merge changes from topic "cow_pdb" am: 811ad79636 am: fb45477a51
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1549486 Change-Id: I7050d72a6432e3dcc6d6565b1aa1671107246f4f
This commit is contained in:
@@ -23,6 +23,7 @@ import android.app.ActivityManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.FileUtils;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
@@ -37,7 +38,6 @@ import com.android.internal.annotations.GuardedBy;
|
|||||||
|
|
||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -45,7 +45,6 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@@ -105,6 +104,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
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();
|
||||||
|
|
||||||
|
private static final String GSI_SANDBOX = "/data/gsi_persistent_data";
|
||||||
private static final String GSI_RUNNING_PROP = "ro.gsid.image_running";
|
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 String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
|
||||||
@@ -131,13 +131,13 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
private static final String FLASH_LOCK_UNLOCKED = "0";
|
private static final String FLASH_LOCK_UNLOCKED = "0";
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final String mDataBlockFile;
|
|
||||||
private final boolean mIsRunningDSU;
|
private final boolean mIsRunningDSU;
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private final CountDownLatch mInitDoneSignal = new CountDownLatch(1);
|
private final CountDownLatch mInitDoneSignal = new CountDownLatch(1);
|
||||||
|
|
||||||
private int mAllowedUid = -1;
|
private int mAllowedUid = -1;
|
||||||
private long mBlockDeviceSize;
|
private long mBlockDeviceSize;
|
||||||
|
private String mDataBlockFile;
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private boolean mIsWritable = true;
|
private boolean mIsWritable = true;
|
||||||
@@ -290,12 +290,18 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OutputStream getBlockOutputStream() throws IOException {
|
private FileOutputStream getBlockOutputStream() throws IOException {
|
||||||
if (mIsRunningDSU) {
|
if (!mIsRunningDSU) {
|
||||||
Slog.i(TAG, "data is read-only when running a DSU");
|
|
||||||
return new ByteArrayOutputStream();
|
|
||||||
} else {
|
|
||||||
return new FileOutputStream(new File(mDataBlockFile));
|
return new FileOutputStream(new File(mDataBlockFile));
|
||||||
|
} else {
|
||||||
|
File sandbox = new File(GSI_SANDBOX);
|
||||||
|
File realpdb = new File(SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP));
|
||||||
|
if (!sandbox.exists()) {
|
||||||
|
FileUtils.copy(realpdb, sandbox);
|
||||||
|
mDataBlockFile = GSI_SANDBOX;
|
||||||
|
}
|
||||||
|
Slog.i(TAG, "PersistentDataBlock copy-on-write");
|
||||||
|
return new FileOutputStream(sandbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,13 +401,9 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
|
|
||||||
private void doSetOemUnlockEnabledLocked(boolean enabled) {
|
private void doSetOemUnlockEnabledLocked(boolean enabled) {
|
||||||
FileOutputStream outputStream;
|
FileOutputStream outputStream;
|
||||||
if (mIsRunningDSU) {
|
|
||||||
Slog.i(TAG, "data is read-only when running a DSU");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
outputStream = new FileOutputStream(new File(mDataBlockFile));
|
outputStream = getBlockOutputStream();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException e) {
|
||||||
Slog.e(TAG, "partition not available", e);
|
Slog.e(TAG, "partition not available", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -564,7 +566,14 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
enforceOemUnlockWritePermission();
|
enforceOemUnlockWritePermission();
|
||||||
|
|
||||||
if (mIsRunningDSU) {
|
if (mIsRunningDSU) {
|
||||||
Slog.i(TAG, "data is read-only when running a DSU");
|
File sandbox = new File(GSI_SANDBOX);
|
||||||
|
if (sandbox.exists()) {
|
||||||
|
if (sandbox.delete()) {
|
||||||
|
mDataBlockFile = SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP);
|
||||||
|
} else {
|
||||||
|
Slog.e(TAG, "Failed to wipe sandbox persistent data block");
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@@ -725,13 +734,9 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
|
|
||||||
private void writeDataBuffer(long offset, ByteBuffer dataBuffer) {
|
private void writeDataBuffer(long offset, ByteBuffer dataBuffer) {
|
||||||
FileOutputStream outputStream;
|
FileOutputStream outputStream;
|
||||||
if (mIsRunningDSU) {
|
|
||||||
Slog.i(TAG, "data is read-only when running a DSU");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
outputStream = new FileOutputStream(new File(mDataBlockFile));
|
outputStream = getBlockOutputStream();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException e) {
|
||||||
Slog.e(TAG, "partition not available", e);
|
Slog.e(TAG, "partition not available", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user