Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44df047c authored by Paul Lawrence's avatar Paul Lawrence Committed by Android (Google) Code Review
Browse files

Merge "Make Convert To File Encryption work"

parents 8edd4c1f 0e1a46cf
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -2009,14 +2009,17 @@
    <!-- Option to convert userdata to file encryption on Nexus M devices -->
    <string name="convert_to_file_encryption">Convert to file encryption</string>
    <string name="convert_to_file_encryption_enabled">Convert ...</string>
    <string name="convert_to_file_encryption_enabled">Convert\u2026</string>
    <string name="convert_to_file_encryption_done">Already file encrypted</string>
    <!-- Title used on dialog with final prompt for converting to file encryption -->
    <string name="title_convert_fbe">Converting to file based encryption</string>
    <!-- Warning displayed on dialog with final prompt for converting to file encryption -->
    <string name="convert_to_fbe_warning">
      Convert data partition to file based encryption.\n
      !!Warning!! This will erase all your data.\n
      This feature is alpha, and may not work correctly.\n
      Press \'Wipe and convert...\' to continue.</string>
    <string name="button_convert_fbe">Wipe and convert...</string>
      Press \'Wipe and convert\u2026\' to continue.</string>
    <string name="button_convert_fbe">Wipe and convert\u2026</string>
    <!-- Sound & display settings screen, setting option name to change screen timeout -->
    <string name="screen_timeout">Sleep</string>
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@
        android:key="convert_to_file_encryption"
        android:title="@string/convert_to_file_encryption"
        android:summary="@string/convert_to_file_encryption_enabled"
        android:fragment="com.android.settings.applications.ConvertToFBE" />
        android:fragment="com.android.settings.applications.ConvertToFbe" />

    <com.android.settings.ColorModePreference
        android:key="color_mode"
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public final class ChooseLockSettingsHelper {
     * @return true if one exists and we launched an activity to confirm it
     * @see Activity#onActivityResult(int, int, android.content.Intent)
     */
    boolean launchConfirmationActivity(int request, CharSequence title) {
    public boolean launchConfirmationActivity(int request, CharSequence title) {
        return launchConfirmationActivity(request, title, null, null, false, false);
    }

+7 −0
Original line number Diff line number Diff line
@@ -409,11 +409,18 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            removePreferenceForProduction(hdcpChecking);
        }

        PreferenceScreen convertFbePreference =
            (PreferenceScreen) findPreference(KEY_CONVERT_FBE);

        try {
            IBinder service = ServiceManager.getService("mount");
            IMountService mountService = IMountService.Stub.asInterface(service);
            if (!mountService.isConvertibleToFBE()) {
                removePreference(KEY_CONVERT_FBE);
            } else if (mountService.isPerUserEncryptionEnabled()) {
                convertFbePreference.setEnabled(false);
                convertFbePreference.setSummary(getResources()
                                   .getString(R.string.convert_to_file_encryption_done));
            }
        } catch(RemoteException e) {
            removePreference(KEY_CONVERT_FBE);
+88 −0
Original line number Diff line number Diff line
@@ -15,18 +15,37 @@
 */
package com.android.settings.applications;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.RecoverySystem;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.android.settings.ChooseLockSettingsHelper;
import com.android.settings.SettingsActivity;
import com.android.settings.R;

import java.io.IOException;

/* Class to prompt for conversion of userdata to file based encryption
 */
public class ConvertToFBE extends Fragment {
public class ConvertToFbe extends Fragment {
    static final String TAG = "ConvertToFBE";
    static final String CONVERT_FBE_EXTRA = "ConvertFBE";
    private static final int KEYGUARD_REQUEST = 55;

    private boolean runKeyguardConfirmation(int request) {
        Resources res = getActivity().getResources();
        return new ChooseLockSettingsHelper(getActivity(), this)
            .launchConfirmationActivity(request,
                                        res.getText(R.string.convert_to_file_encryption));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -36,10 +55,34 @@ public class ConvertToFBE extends Fragment {
        final Button button = (Button) rootView.findViewById(R.id.button_convert_fbe);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                    // Perform action on click
                if(!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
                    convert();
                }
            }
        });

        return rootView;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode != KEYGUARD_REQUEST) {
            return;
        }

        // If the user entered a valid keyguard credential, start the conversion
        // process
        if (resultCode == Activity.RESULT_OK) {
            convert();
        }
    }

    private void convert() {
        Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        intent.putExtra(Intent.EXTRA_REASON, "convert_fbe");
        getActivity().sendBroadcast(intent);
    }
}
Loading