Merge "Wipe FRP partition if OEM unlock enabled" into lmp-mr1-dev automerge: d656955
automerge: c9a7694
* commit 'c9a76941ecca457e6a17b06f557c24e18e3bdafa':
Wipe FRP partition if OEM unlock enabled
This commit is contained in:
@@ -103,9 +103,19 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
enforceChecksumValidity();
|
enforceChecksumValidity();
|
||||||
|
formatIfOemUnlockEnabled();
|
||||||
publishBinderService(Context.PERSISTENT_DATA_BLOCK_SERVICE, mService);
|
publishBinderService(Context.PERSISTENT_DATA_BLOCK_SERVICE, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void formatIfOemUnlockEnabled() {
|
||||||
|
if (doGetOemUnlockEnabled()) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
formatPartitionLocked();
|
||||||
|
doSetOemUnlockEnabledLocked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void enforceOemUnlockPermission() {
|
private void enforceOemUnlockPermission() {
|
||||||
mContext.enforceCallingOrSelfPermission(
|
mContext.enforceCallingOrSelfPermission(
|
||||||
Manifest.permission.OEM_UNLOCK_STATE,
|
Manifest.permission.OEM_UNLOCK_STATE,
|
||||||
@@ -285,6 +295,28 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 native long nativeGetBlockDeviceSize(String path);
|
private native long nativeGetBlockDeviceSize(String path);
|
||||||
private native int nativeWipe(String path);
|
private native int nativeWipe(String path);
|
||||||
|
|
||||||
@@ -410,25 +442,7 @@ public class PersistentDataBlockService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean getOemUnlockEnabled() {
|
public boolean getOemUnlockEnabled() {
|
||||||
enforceOemUnlockPermission();
|
enforceOemUnlockPermission();
|
||||||
DataInputStream inputStream;
|
return doGetOemUnlockEnabled();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user