Support PersistentDataBlockService in DSU

Currently the PersistentDataBlockService does not start when
running a Dynamic System Update. This CL adds a sandbox-mode
PersistentDataBlockService when running a DSU for the test_harness
environment.

Bug: 175852148
Bug: 175078763
Test: gsi_tool install & \
  finish the vts_kernel_net_tests w/o suspension
Test: gts-tradefed run gts -m GtsOemLockServiceTestCases -t com.google.android.oemlock.gts.OemLockServiceTest
Test: cts-tradefed run cts -m CtsPermission2TestCases -t android.permission2.cts.PrivappPermissionsTest
Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest
Test: atest com.android.server.devicepolicy.FactoryResetProtectionPolicyTest
Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testFactoryResetProtectionPolicy
Test: atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testFactoryResetProtectionPolicy
Test: atest LockSettingsStorageTests
Test: atest frameworks/base/core/tests/coretests/src/com/android/internal/widget/LockPatternUtilsTest.java
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/LockSettingsStorageTests.java
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java

Change-Id: I0547d757cf023443d9a00bec962db3f2aad3ff04
This commit is contained in:
Howard Chen
2020-12-23 15:55:59 +08:00
parent a8d51aac66
commit 649c198cf3
2 changed files with 34 additions and 11 deletions

View File

@@ -37,6 +37,7 @@ 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;
@@ -44,6 +45,7 @@ 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;
@@ -103,6 +105,8 @@ 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_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";
private static final int HEADER_SIZE = 8; private static final int HEADER_SIZE = 8;
// Magic number to mark block device as adhering to the format consumed by this service // Magic number to mark block device as adhering to the format consumed by this service
@@ -128,6 +132,7 @@ public class PersistentDataBlockService extends SystemService {
private final Context mContext; private final Context mContext;
private final String mDataBlockFile; private final String mDataBlockFile;
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);
@@ -141,6 +146,7 @@ public class PersistentDataBlockService extends SystemService {
super(context); super(context);
mContext = context; mContext = context;
mDataBlockFile = SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP); mDataBlockFile = SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP);
mIsRunningDSU = SystemProperties.getBoolean(GSI_RUNNING_PROP, false);
mBlockDeviceSize = -1; // Load lazily mBlockDeviceSize = -1; // Load lazily
} }
@@ -284,14 +290,22 @@ public class PersistentDataBlockService extends SystemService {
return true; 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() { private boolean computeAndWriteDigestLocked() {
byte[] digest = computeDigestLocked(null); byte[] digest = computeDigestLocked(null);
if (digest != null) { if (digest != null) {
DataOutputStream outputStream; DataOutputStream outputStream;
try { try {
outputStream = new DataOutputStream( outputStream = new DataOutputStream(getBlockOutputStream());
new FileOutputStream(new File(mDataBlockFile))); } catch (IOException e) {
} catch (FileNotFoundException e) {
Slog.e(TAG, "partition not available?", e); Slog.e(TAG, "partition not available?", e);
return false; return false;
} }
@@ -356,8 +370,8 @@ public class PersistentDataBlockService extends SystemService {
private void formatPartitionLocked(boolean setOemUnlockEnabled) { private void formatPartitionLocked(boolean setOemUnlockEnabled) {
DataOutputStream outputStream; DataOutputStream outputStream;
try { try {
outputStream = new DataOutputStream(new FileOutputStream(new File(mDataBlockFile))); outputStream = new DataOutputStream(getBlockOutputStream());
} catch (FileNotFoundException e) { } catch (IOException e) {
Slog.e(TAG, "partition not available?", e); Slog.e(TAG, "partition not available?", e);
return; return;
} }
@@ -381,6 +395,10 @@ 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 = new FileOutputStream(new File(mDataBlockFile));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@@ -459,8 +477,8 @@ public class PersistentDataBlockService extends SystemService {
DataOutputStream outputStream; DataOutputStream outputStream;
try { try {
outputStream = new DataOutputStream(new FileOutputStream(new File(mDataBlockFile))); outputStream = new DataOutputStream(getBlockOutputStream());
} catch (FileNotFoundException e) { } catch (IOException e) {
Slog.e(TAG, "partition not available?", e); Slog.e(TAG, "partition not available?", e);
return -1; return -1;
} }
@@ -545,6 +563,10 @@ public class PersistentDataBlockService extends SystemService {
public void wipe() { public void wipe() {
enforceOemUnlockWritePermission(); enforceOemUnlockWritePermission();
if (mIsRunningDSU) {
Slog.i(TAG, "data is read-only when running a DSU");
return;
}
synchronized (mLock) { synchronized (mLock) {
int ret = nativeWipe(mDataBlockFile); int ret = nativeWipe(mDataBlockFile);
@@ -703,6 +725,10 @@ 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 = new FileOutputStream(new File(mDataBlockFile));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

View File

@@ -331,8 +331,6 @@ public final class SystemServer {
private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file"; 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 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 // maximum number of binder threads used for system_server
// will be higher than the system default // will be higher than the system default
private static final int sMaxBinderThreads = 31; private static final int sMaxBinderThreads = 31;
@@ -1441,8 +1439,7 @@ public final class SystemServer {
t.traceEnd(); t.traceEnd();
final boolean hasPdb = !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals(""); final boolean hasPdb = !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
final boolean hasGsi = SystemProperties.getInt(GSI_RUNNING_PROP, 0) > 0; if (hasPdb) {
if (hasPdb && !hasGsi) {
t.traceBegin("StartPersistentDataBlock"); t.traceBegin("StartPersistentDataBlock");
mSystemServiceManager.startService(PersistentDataBlockService.class); mSystemServiceManager.startService(PersistentDataBlockService.class);
t.traceEnd(); t.traceEnd();