Actually check if an OTA is encrypted

This commit is contained in:
Gabriele M
2017-07-26 11:57:32 +02:00
parent d854c6377b
commit 13f3849b96
2 changed files with 5 additions and 8 deletions

View File

@@ -181,8 +181,7 @@ public class UpdaterService extends Service {
update.getFile().getAbsolutePath() + Constants.UNCRYPT_FILE_EXT); update.getFile().getAbsolutePath() + Constants.UNCRYPT_FILE_EXT);
update.getFile().renameTo(uncrytpFile); update.getFile().renameTo(uncrytpFile);
installPackage(uncrytpFile); installPackage(uncrytpFile);
} else if (update.getFile().getAbsolutePath().startsWith("/data/") && } else if (Utils.isEncrypted(this, update.getFile())) {
Utils.isDeviceEncrypted(this)) {
// uncrypt rewrites the file so that it can be read without mounting // uncrypt rewrites the file so that it can be read without mounting
// the filesystem, so create a copy of it. // the filesystem, so create a copy of it.
File uncrytpFile = new File( File uncrytpFile = new File(

View File

@@ -15,7 +15,6 @@
*/ */
package org.lineageos.updater.misc; package org.lineageos.updater.misc;
import android.app.admin.DevicePolicyManager;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
@@ -26,6 +25,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Environment; import android.os.Environment;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.storage.StorageManager;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@@ -327,10 +327,8 @@ public class Utils {
Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show(); Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show();
} }
public static boolean isDeviceEncrypted(Context context) { public static boolean isEncrypted(Context context, File file) {
DevicePolicyManager dpm = StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); return sm.isEncrypted(file);
int status = dpm.getStorageEncryptionStatus();
return status == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
} }
} }