| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.persistentdata; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.RequiresPermission; |
| 22 |
import android.annotation.SuppressLint; |
| 23 |
import android.annotation.SystemApi; |
| 24 |
import android.annotation.SystemService; |
| 25 |
import android.content.Context; |
| 26 |
import android.os.RemoteException; |
| 27 |
import android.service.oemlock.OemLockManager; |
| 28 |
|
| 29 |
import java.lang.annotation.Retention; |
| 30 |
import java.lang.annotation.RetentionPolicy; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
@SystemApi |
| 51 |
@SystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE) |
| 52 |
public class PersistentDataBlockManager { |
| 53 |
private static final String TAG = PersistentDataBlockManager.class.getSimpleName(); |
| 54 |
private IPersistentDataBlockService sService; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public static final int FLASH_LOCK_UNKNOWN = -1; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public static final int FLASH_LOCK_UNLOCKED = 0; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public static final int FLASH_LOCK_LOCKED = 1; |
| 68 |
|
| 69 |
@IntDef(prefix = { "FLASH_LOCK_" }, value = { |
| 70 |
FLASH_LOCK_UNKNOWN, |
| 71 |
FLASH_LOCK_LOCKED, |
| 72 |
FLASH_LOCK_UNLOCKED, |
| 73 |
}) |
| 74 |
@Retention(RetentionPolicy.SOURCE) |
| 75 |
public @interface FlashLockState {} |
| 76 |
|
| 77 |
|
| 78 |
public PersistentDataBlockManager(IPersistentDataBlockService service) { |
| 79 |
sService = service; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
@SuppressLint("RequiresPermission") |
| 95 |
public int write(byte[] data) { |
| 96 |
try { |
| 97 |
return sService.write(data); |
| 98 |
} catch (RemoteException e) { |
| 99 |
throw e.rethrowFromSystemServer(); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
@SuppressLint("RequiresPermission") |
| 107 |
public byte[] read() { |
| 108 |
try { |
| 109 |
return sService.read(); |
| 110 |
} catch (RemoteException e) { |
| 111 |
throw e.rethrowFromSystemServer(); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
@RequiresPermission(android.Manifest.permission.ACCESS_PDB_STATE) |
| 121 |
public int getDataBlockSize() { |
| 122 |
try { |
| 123 |
return sService.getDataBlockSize(); |
| 124 |
} catch (RemoteException e) { |
| 125 |
throw e.rethrowFromSystemServer(); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
@SuppressLint("RequiresPermission") |
| 135 |
public long getMaximumDataBlockSize() { |
| 136 |
try { |
| 137 |
return sService.getMaximumDataBlockSize(); |
| 138 |
} catch (RemoteException e) { |
| 139 |
throw e.rethrowFromSystemServer(); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
@RequiresPermission(android.Manifest.permission.OEM_UNLOCK_STATE) |
| 150 |
public void wipe() { |
| 151 |
try { |
| 152 |
sService.wipe(); |
| 153 |
} catch (RemoteException e) { |
| 154 |
throw e.rethrowFromSystemServer(); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
@RequiresPermission(android.Manifest.permission.OEM_UNLOCK_STATE) |
| 164 |
public void setOemUnlockEnabled(boolean enabled) { |
| 165 |
try { |
| 166 |
sService.setOemUnlockEnabled(enabled); |
| 167 |
} catch (RemoteException e) { |
| 168 |
throw e.rethrowFromSystemServer(); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
@RequiresPermission(anyOf = { |
| 178 |
android.Manifest.permission.READ_OEM_UNLOCK_STATE, |
| 179 |
android.Manifest.permission.OEM_UNLOCK_STATE |
| 180 |
}) |
| 181 |
public boolean getOemUnlockEnabled() { |
| 182 |
try { |
| 183 |
return sService.getOemUnlockEnabled(); |
| 184 |
} catch (RemoteException e) { |
| 185 |
throw e.rethrowFromSystemServer(); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
@RequiresPermission(anyOf = { |
| 197 |
android.Manifest.permission.READ_OEM_UNLOCK_STATE, |
| 198 |
android.Manifest.permission.OEM_UNLOCK_STATE |
| 199 |
}) |
| 200 |
@FlashLockState |
| 201 |
public int getFlashLockState() { |
| 202 |
try { |
| 203 |
return sService.getFlashLockState(); |
| 204 |
} catch (RemoteException e) { |
| 205 |
throw e.rethrowFromSystemServer(); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
@SystemApi |
| 215 |
@NonNull |
| 216 |
@RequiresPermission(android.Manifest.permission.ACCESS_PDB_STATE) |
| 217 |
public String getPersistentDataPackageName() { |
| 218 |
try { |
| 219 |
return sService.getPersistentDataPackageName(); |
| 220 |
} catch (RemoteException e) { |
| 221 |
throw e.rethrowFromSystemServer(); |
| 222 |
} |
| 223 |
} |
| 224 |
} |