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

Commit 4804c26c authored by Pawan Wagh's avatar Pawan Wagh Committed by Android (Google) Code Review
Browse files

Merge "Delete code and strings for EnableExt4Warning" into main

parents d07cb60d 6f4dd14f
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -13321,15 +13321,6 @@ Data usage charges may apply.</string>
    <!-- Toast message when 16k OTA update fails -->
    <string name="toast_16k_update_failed_text">Failed to update kernel to 16 KB pages compatible kernel.</string>
    <string name="progress_16k_ota_title">Applying change</string>
    <!-- Confirmation dialog title and text to reformat data to ext4 -->
    <string name="confirm_format_ext4_title">Reformat device to ext4? (required for 16 KB mode)</string>
    <string name="confirm_format_ext4_text">This device’s data partition needs to be converted to ext4 before using the 16 KB developer option.
        Software integrity cannot be guaranteed in this mode, and any data stored on the phone while the bootloader is unlocked may be at risk.
        Activating the 16 KB option will require one more reboot after this. Once you are in this mode, you can switch back and forth between 4 KB and 16 KB mode with a single reboot.
        Some features will be disabled in these modes, so some applications may not work. To return the device to production mode, you would need to switch back to 4 KB mode and
        then lock the bootloader, which factory resets the device. After the device successfully boots into Android, disable OEM unlocking in Developer options.
        The device will be wiped and the filesystem will be changed to ext4 after confirmation. After this completes, please come back to enable 16 KB again.
    </string>
    <!-- Text for confirmation buttion for ext4 -->
    <string name="confirm_ext4_button_text">Erase all data and update</string>
    <!-- Toast on failure to reformat data to ext4 -->
+1 −28
Original line number Diff line number Diff line
@@ -68,8 +68,7 @@ import java.util.zip.ZipFile;
public class Enable16kPagesPreferenceController extends DeveloperOptionsPreferenceController
        implements Preference.OnPreferenceChangeListener,
                PreferenceControllerMixin,
                Enable16kbPagesDialogHost,
                EnableExt4DialogHost {
                Enable16kbPagesDialogHost {

    private static final String TAG = "Enable16kPages";
    private static final String REBOOT_REASON = "toggle16k";
@@ -324,27 +323,6 @@ public class Enable16kPagesPreferenceController extends DeveloperOptionsPreferen
        Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onExt4DialogConfirmed() {
        // user has confirmed to wipe the device
        ListenableFuture future = mExecutorService.submit(() -> wipeData());
        Futures.addCallback(
                future,
                new FutureCallback<>() {
                    @Override
                    public void onSuccess(@NonNull Object result) {
                        Log.i(TAG, "Wiping /data  with recovery system.");
                    }

                    @Override
                    public void onFailure(@NonNull Throwable t) {
                        Log.e(TAG, "Failed to change the /data partition to ext4");
                        displayToast(mContext.getString(R.string.format_ext4_failure_toast));
                    }
                },
                ContextCompat.getMainExecutor(mContext));
    }

    private void wipeData() {
        RecoverySystem recoveryService = mContext.getSystemService(RecoverySystem.class);
        try {
@@ -354,11 +332,6 @@ public class Enable16kPagesPreferenceController extends DeveloperOptionsPreferen
        }
    }

    @Override
    public void onExt4DialogDismissed() {
        // Do nothing
    }

    private class OtaUpdateCallback extends UpdateEngineStableCallback {
        UpdateEngineStable mUpdateEngineStable;

+0 −26
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 com.android.settings.development;

/** Interface for EnableExt4DialogHost callbacks. */
public interface EnableExt4DialogHost {
    /** Callback when the user presses ok the warning dialog. */
    void onExt4DialogConfirmed();

    /** Callback when the user cancels or dismisses the warning dialog. */
    void onExt4DialogDismissed();
}
+0 −94
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 com.android.settings.development;

import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.DialogInterface;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.android.internal.annotations.Initializer;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;

/** Dialog when user interacts 16K pages developer option and data is f2fs */
public class EnableExt4WarningDialog extends InstrumentedDialogFragment
        implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {

    public static final String TAG = "EnableExt4WarningDialog";

    private EnableExt4DialogHost mHost;

    @Initializer
    private void setHost(@NonNull EnableExt4DialogHost host) {
        this.mHost = host;
    }

    /** This method is used to show warning dialog to reformat data to /ext4 */
    public static void show(
            @NonNull Fragment hostFragment, @NonNull EnableExt4DialogHost dialogHost) {
        final FragmentManager manager = hostFragment.getActivity().getSupportFragmentManager();
        Fragment existingFragment = manager.findFragmentByTag(TAG);
        if (existingFragment == null) {
            existingFragment = new EnableExt4WarningDialog();
        }

        if (existingFragment instanceof EnableExt4WarningDialog) {
            existingFragment.setTargetFragment(hostFragment, 0 /* requestCode */);
            ((EnableExt4WarningDialog) existingFragment).setHost(dialogHost);
            ((EnableExt4WarningDialog) existingFragment).show(manager, TAG);
        }
    }

    @Override
    public int getMetricsCategory() {
        return SettingsEnums.DIALOG_ENABLE_16K_PAGES;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        return new AlertDialog.Builder(getActivity())
                .setTitle(R.string.confirm_format_ext4_title)
                .setIcon(R.drawable.ic_delete_accent)
                .setMessage(R.string.confirm_format_ext4_text)
                .setPositiveButton(R.string.confirm_ext4_button_text, this /* onClickListener */)
                .setNegativeButton(android.R.string.cancel, this /* onClickListener */)
                .create();
    }

    @Override
    public void onClick(@NonNull DialogInterface dialog, int buttonId) {
        if (buttonId == DialogInterface.BUTTON_POSITIVE) {
            mHost.onExt4DialogConfirmed();
        } else {
            mHost.onExt4DialogDismissed();
        }
    }

    @Override
    public void onDismiss(@NonNull DialogInterface dialog) {
        super.onDismiss(dialog);
        mHost.onExt4DialogDismissed();
    }
}