We are developing secure application for Android. It's required for users to keep filesystems of their devices encrypted, but we have to check this fact and forbid to use app. Is it possible to check if filesystem is encrypted? Also there are some devices with Android < 3.0 that supports encryption, for example Motorola RAZR. It would be interesting to know about encryption on such devices.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If your app is registered as a device admin, you can call getStorageEncryptionStatus()
on DevicePolicyManager
to find out the encryption status of the device, for API Level 11 and higher.
For any whole-device encryption on lower API levels, please contact the device manufacturer.
回答2:
Just to clarify CommonsWare's answer, you can read the device encryption status without any Android permissions.
/**
* Returns the encryption status of the device. Prior to Honeycomb, whole device encryption was
* not supported by Android, and this method returns ENCRYPTION_STATUS_UNSUPPORTED.
*
* @return One of the following constants from DevicePolicyManager:
* ENCRYPTION_STATUS_UNSUPPORTED, ENCRYPTION_STATUS_INACTIVE,
* ENCRYPTION_STATUS_ACTIVATING, or ENCRYPTION_STATUS_ACTIVE.
*/
@TargetApi(11)
private int getDeviceEncryptionStatus() {
int status = DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
if (Build.VERSION.SDK_INT >= 11) {
final DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm != null) {
status = dpm.getStorageEncryptionStatus();
}
}
return status;
}
回答3:
to clarify previous answers
on API < 23 getStorageEncryptionStatus()
returns ENCRYPTION_STATUS_INACTIVE
when device is encrypted but passcode was't enabled.
On API >= 23 it returns ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY
in this case.