summaryrefslogtreecommitdiffstats
path: root/core/java/android/service/persistentdata/PersistentDataBlockManager.java
diff options
context:
space:
mode:
authorAndres Morales <anmorales@google.com>2014-07-10 15:40:24 -0700
committerAndres Morales <anmorales@google.com>2014-07-17 20:42:04 +0000
commit963295ea105314e28e4ca9563aa09cb7440de4c3 (patch)
tree1428bba4ecdab8cb7c0f7e143b8a8bf096402197 /core/java/android/service/persistentdata/PersistentDataBlockManager.java
parentdcb743e276926e31e219000be5f6c8ad801b5367 (diff)
downloadframeworks_base-963295ea105314e28e4ca9563aa09cb7440de4c3.zip
frameworks_base-963295ea105314e28e4ca9563aa09cb7440de4c3.tar.gz
frameworks_base-963295ea105314e28e4ca9563aa09cb7440de4c3.tar.bz2
Permit settings to "wipe" the persistent partition
One of the requirements is that when the user does a factory reset through settings, all data on the persistent partition should be cleared. This adds one last API method that allows settings to wipe the partition. Bug: 14288780 Change-Id: Ib87ee741d1e5195814516ae1d66eb7c4cf754dcf
Diffstat (limited to 'core/java/android/service/persistentdata/PersistentDataBlockManager.java')
-rw-r--r--core/java/android/service/persistentdata/PersistentDataBlockManager.java76
1 files changed, 61 insertions, 15 deletions
diff --git a/core/java/android/service/persistentdata/PersistentDataBlockManager.java b/core/java/android/service/persistentdata/PersistentDataBlockManager.java
index afcf717..42a2e57 100644
--- a/core/java/android/service/persistentdata/PersistentDataBlockManager.java
+++ b/core/java/android/service/persistentdata/PersistentDataBlockManager.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package android.service.persistentdata;
import android.os.RemoteException;
@@ -7,14 +23,16 @@ import android.util.Slog;
* Interface for reading and writing data blocks to a persistent partition.
*
* Allows writing one block at a time. Namely, each time
- * {@link android.service.persistentdata.PersistentDataBlockManager}.write(byte[] data)
+ * {@link PersistentDataBlockManager#write(byte[])}
* 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
- * {@link android.service.persistentdata.PersistentDataBlockManager}.getTotalDataSize().
+ * {@link PersistentDataBlockManager#getDataBlockSize()}.
+ *
+ * Clients can query the maximum size for a block via
*
- * Clients can any number of bytes from the currently written block up to its total size by invoking
- * {@link android.service.persistentdata.PersistentDataBlockManager}.read(byte[] data).
+ * Clients can read the currently written block by invoking
+ * {@link PersistentDataBlockManager#read()}.
*
* @hide
*/
@@ -30,41 +48,69 @@ public class PersistentDataBlockManager {
* Writes {@code data} to the persistent partition. Previously written data
* will be overwritten. This data will persist across factory resets.
*
+ * 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.
+ *
* @param data the data to write
*/
- public void write(byte[] data) {
+ public int write(byte[] data) {
try {
- sService.write(data);
+ return sService.write(data);
} catch (RemoteException e) {
onError("writing data");
+ return -1;
}
}
/**
- * Tries to read {@code data.length} bytes into {@code data}. Call {@code getDataBlockSize()}
- * to determine the total size of the block currently residing in the persistent partition.
- *
- * @param data the buffer in which to read the data
- * @return the actual number of bytes read
+ * Returns the data block stored on the persistent partition.
*/
- public int read(byte[] data) {
+ public byte[] read() {
try {
- return sService.read(data);
+ return sService.read();
} catch (RemoteException e) {
onError("reading data");
- return -1;
+ return null;
}
}
/**
* Retrieves the size of the block currently written to the persistent partition.
+ *
+ * Return -1 on error.
*/
public int getDataBlockSize() {
try {
return sService.getDataBlockSize();
} catch (RemoteException e) {
onError("getting data block size");
- return 0;
+ return -1;
+ }
+ }
+
+ /**
+ * Retrieves the maximum size allowed for a data block.
+ *
+ * Returns -1 on error.
+ */
+ public long getMaximumDataBlockSize() {
+ try {
+ return sService.getMaximumDataBlockSize();
+ } catch (RemoteException e) {
+ onError("getting maximum data block size");
+ return -1;
+ }
+ }
+
+ /**
+ * Zeroes the previously written block in its entirety. Calling this method
+ * will erase all data written to the persistent data partition.
+ */
+ public void wipe() {
+ try {
+ sService.wipe();
+ } catch (RemoteException e) {
+ onError("wiping persistent partition");
}
}