Methods Summary |
---|
private boolean | computeAndWriteDigestLocked()
byte[] digest = computeDigestLocked(null);
if (digest != null) {
DataOutputStream outputStream;
try {
outputStream = new DataOutputStream(
new FileOutputStream(new File(mDataBlockFile)));
} catch (FileNotFoundException e) {
Slog.e(TAG, "partition not available?", e);
return false;
}
try {
outputStream.write(digest, 0, DIGEST_SIZE_BYTES);
outputStream.flush();
} catch (IOException e) {
Slog.e(TAG, "failed to write block checksum", e);
return false;
} finally {
IoUtils.closeQuietly(outputStream);
}
return true;
} else {
return false;
}
|
private byte[] | computeDigestLocked(byte[] storedDigest)
DataInputStream inputStream;
try {
inputStream = new DataInputStream(new FileInputStream(new File(mDataBlockFile)));
} catch (FileNotFoundException e) {
Slog.e(TAG, "partition not available?", e);
return null;
}
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
// won't ever happen -- every implementation is required to support SHA-256
Slog.e(TAG, "SHA-256 not supported?", e);
IoUtils.closeQuietly(inputStream);
return null;
}
try {
if (storedDigest != null && storedDigest.length == DIGEST_SIZE_BYTES) {
inputStream.read(storedDigest);
} else {
inputStream.skipBytes(DIGEST_SIZE_BYTES);
}
int read;
byte[] data = new byte[1024];
md.update(data, 0, DIGEST_SIZE_BYTES); // include 0 checksum in digest
while ((read = inputStream.read(data)) != -1) {
md.update(data, 0, read);
}
} catch (IOException e) {
Slog.e(TAG, "failed to read partition", e);
return null;
} finally {
IoUtils.closeQuietly(inputStream);
}
return md.digest();
|
private boolean | doGetOemUnlockEnabled()
DataInputStream inputStream;
try {
inputStream = new DataInputStream(new FileInputStream(new File(mDataBlockFile)));
} catch (FileNotFoundException e) {
Slog.e(TAG, "partition not available");
return false;
}
try {
synchronized (mLock) {
inputStream.skip(getBlockDeviceSize() - 1);
return inputStream.readByte() != 0;
}
} catch (IOException e) {
Slog.e(TAG, "unable to access persistent partition", e);
return false;
} finally {
IoUtils.closeQuietly(inputStream);
}
|
private void | doSetOemUnlockEnabledLocked(boolean enabled)
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream(new File(mDataBlockFile));
} catch (FileNotFoundException e) {
Slog.e(TAG, "partition not available", e);
return;
}
try {
FileChannel channel = outputStream.getChannel();
channel.position(getBlockDeviceSize() - 1);
ByteBuffer data = ByteBuffer.allocate(1);
data.put(enabled ? (byte) 1 : (byte) 0);
data.flip();
channel.write(data);
outputStream.flush();
} catch (IOException e) {
Slog.e(TAG, "unable to access persistent partition", e);
return;
} finally {
IoUtils.closeQuietly(outputStream);
}
|
private boolean | enforceChecksumValidity()
byte[] storedDigest = new byte[DIGEST_SIZE_BYTES];
synchronized (mLock) {
byte[] digest = computeDigestLocked(storedDigest);
if (digest == null || !Arrays.equals(storedDigest, digest)) {
Slog.i(TAG, "Formatting FRP partition...");
formatPartitionLocked();
return false;
}
}
return true;
|
private void | enforceIsOwner()
if (!Binder.getCallingUserHandle().isOwner()) {
throw new SecurityException("Only the Owner is allowed to change OEM unlock state");
}
|
private void | enforceOemUnlockPermission()
mContext.enforceCallingOrSelfPermission(
Manifest.permission.OEM_UNLOCK_STATE,
"Can't access OEM unlock state");
|
private void | enforceUid(int callingUid)
if (callingUid != mAllowedUid) {
throw new SecurityException("uid " + callingUid + " not allowed to access PST");
}
|
private void | formatIfOemUnlockEnabled()
if (doGetOemUnlockEnabled()) {
synchronized (mLock) {
formatPartitionLocked();
doSetOemUnlockEnabledLocked(true);
}
}
|
private void | formatPartitionLocked()
DataOutputStream outputStream;
try {
outputStream = new DataOutputStream(new FileOutputStream(new File(mDataBlockFile)));
} catch (FileNotFoundException e) {
Slog.e(TAG, "partition not available?", e);
return;
}
byte[] data = new byte[DIGEST_SIZE_BYTES];
try {
outputStream.write(data, 0, DIGEST_SIZE_BYTES);
outputStream.writeInt(PARTITION_TYPE_MARKER);
outputStream.writeInt(0); // data size
outputStream.flush();
} catch (IOException e) {
Slog.e(TAG, "failed to format block", e);
return;
} finally {
IoUtils.closeQuietly(outputStream);
}
doSetOemUnlockEnabledLocked(false);
computeAndWriteDigestLocked();
|
private int | getAllowedUid(int userHandle)
String allowedPackage = mContext.getResources()
.getString(R.string.config_persistentDataPackageName);
PackageManager pm = mContext.getPackageManager();
int allowedUid = -1;
try {
allowedUid = pm.getPackageUid(allowedPackage, userHandle);
} catch (PackageManager.NameNotFoundException e) {
// not expected
Slog.e(TAG, "not able to find package " + allowedPackage, e);
}
return allowedUid;
|
private long | getBlockDeviceSize()
synchronized (mLock) {
if (mBlockDeviceSize == -1) {
mBlockDeviceSize = nativeGetBlockDeviceSize(mDataBlockFile);
}
}
return mBlockDeviceSize;
|
private int | getTotalDataSizeLocked(java.io.DataInputStream inputStream)
// skip over checksum
inputStream.skipBytes(DIGEST_SIZE_BYTES);
int totalDataSize;
int blockId = inputStream.readInt();
if (blockId == PARTITION_TYPE_MARKER) {
totalDataSize = inputStream.readInt();
} else {
totalDataSize = 0;
}
return totalDataSize;
|
private native long | nativeGetBlockDeviceSize(java.lang.String path)
|
private native int | nativeWipe(java.lang.String path)
|
public void | onStart()
enforceChecksumValidity();
formatIfOemUnlockEnabled();
publishBinderService(Context.PERSISTENT_DATA_BLOCK_SERVICE, mService);
|