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

Commit 7d2250f7 authored by Pawan Wagh's avatar Pawan Wagh
Browse files

Combine OTA and /data formatting

/data gets formatted to ext4 first and then
16 KB OTA is applied. Combine both steps into single
step. Apply OTA and wipe device when update engine
provides callback.

Test: atest -c Enable16KbTest
Flag: build.RELEASE_GOOGLE_TEGU_16K_DEVELOPER_OPTION
Bug: 402778695
Change-Id: I93d10b90525319c7f3f388d8e290504cb178cd30
parent a13e7291
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -13288,6 +13288,14 @@ Data usage charges may apply.</string>
    <!-- Confirmation dialog title to ensure user wishes to enable 16 KB page size -->
    <string name="confirm_enable_16k_pages_title">Switch from 4 KB mode to 16 KB mode</string>
    <!-- Warning dialog message to confirm user wishes to enable 16 KB page size -->
    <string name="confirm_enable_16k_pages_update_wipe"> This device’s data partition needs to be converted to ext4 before using the 16 KB developer option.
        The device will be wiped and the filesystem will be changed to ext4 after confirmation. You are in production mode running a 4 KB kernel,
        and you are switching to the 16 KB mode. Once you are in this mode, you can switch back and forth between 4 KB and 16 KB mode with a single reboot.
        Software integrity cannot be guaranteed in this mode, and any data stored on the phone while the bootloader is unlocked may be at risk.
        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 then switch back to the 4 KB mode and lock the bootloader, which factory resets the device.
        After the device successfully boots into Android, disable OEM unlocking in Developer options.
        To proceed, click on \'Erase all data and update\'. This will reboot the device.</string>
    <string name="confirm_enable_16k_pages_text">You are in the page-agnostic mode running a 4 KB kernel, and you are switching to the 16 KB mode.
        Software integrity cannot be guaranteed in this mode, and any data stored on the phone while the bootloader is unlocked may be at risk.
        This will reboot the device. Some features will be disabled in these modes, so some applications may not work.
@@ -13313,7 +13321,7 @@ Data usage charges may apply.</string>
        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</string>
    <string name="confirm_ext4_button_text">Erase all data and update</string>
    <!-- Toast on failure to reformat data to ext4 -->
    <string name="format_ext4_failure_toast">Failed to reformat and wipe the data partition to ext4.</string>
    <!-- Dialog to OEM unlock the device before using 16K developer option -->
+8 −7
Original line number Diff line number Diff line
@@ -121,10 +121,6 @@ public class Enable16kPagesPreferenceController extends DeveloperOptionsPreferen
            return false;
        }

        if (!Enable16kUtils.isDataExt4()) {
            EnableExt4WarningDialog.show(mFragment, this);
            return false;
        }
        Enable16kPagesWarningDialog.show(mFragment, this, mEnable16k);
        return true;
    }
@@ -397,9 +393,14 @@ public class Enable16kPagesPreferenceController extends DeveloperOptionsPreferen
                        createUpdateInfo(SystemUpdateManager.STATUS_WAITING_REBOOT);
                manager.updateSystemUpdateInfo(info);

                if (!Enable16kUtils.isDataExt4()) {
                    wipeData();
                } else {
                    // Restart device to complete update
                    PowerManager pm = mContext.getSystemService(PowerManager.class);
                    pm.reboot(REBOOT_REASON);
                }

            } else {
                Log.e(TAG, "applyPayload failed, error code: " + errorCode);
                displayToast(mContext.getString(R.string.toast_16k_update_failed_text));
+11 −2
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public class Enable16kPagesWarningDialog extends InstrumentedDialogFragment
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        final Bundle bundle = getArguments();
        boolean is16kDialog = bundle.getBoolean(DIALOG_BUNDLE_KEY);
        boolean isDataExt4 = Enable16kUtils.isDataExt4();
        return new AlertDialog.Builder(getActivity())
                .setTitle(
                        is16kDialog
@@ -81,9 +82,17 @@ public class Enable16kPagesWarningDialog extends InstrumentedDialogFragment
                                : R.string.confirm_enable_4k_pages_title)
                .setMessage(
                        is16kDialog
                                ? (isDataExt4
                                        ? R.string.confirm_enable_16k_pages_text
                                        : R.string.confirm_enable_16k_pages_update_wipe)
                                : R.string.confirm_enable_4k_pages_text)
                .setPositiveButton(android.R.string.ok, this /* onClickListener */)
                .setPositiveButton(
                        is16kDialog
                                ? (isDataExt4
                                        ? android.R.string.ok
                                        : R.string.confirm_ext4_button_text)
                                : android.R.string.ok,
                        this /* onClickListener */)
                .setNegativeButton(android.R.string.cancel, this /* onClickListener */)
                .create();
    }
+10 −14
Original line number Diff line number Diff line
@@ -41,15 +41,13 @@ public class Enable16KbTest extends BaseHostJUnit4Test {

    private static final String TEST_NAME = "Enable16KbDeviceTest";

    private static final String SWITCH_TO_EXT4 = "enable16k_switchToExt4";

    private static final String SWITCH_TO_16KB = "enable16k_switchTo16Kb";

    private static final String ERASE_AND_SWITCH_TO_16KB = "enable16k_eraseAndSwitchTo16kb";
    private static final String SWITCH_TO_4KB = "enable16k_switchTo4Kb";
    private static final String DISABLE_DEV_OPTION = "enable16k_disableDeveloperOption";

    private static final int DEVICE_WAIT_TIMEOUT = 120000;
    private static final int DEVICE_UPDATE_TIMEOUT = 180000;
    private static final int DEVICE_WIPE_AND_UPDATE_TIMEOUT = 240000;

    @Test
    @AppModeFull
@@ -73,21 +71,19 @@ public class Enable16KbTest extends BaseHostJUnit4Test {

        getDevice().executeShellCommand("am start -a com.android.setupwizard.FOUR_CORNER_EXIT");

        // Enables developer option and switch to ext4
        runTestAndWait(SWITCH_TO_EXT4);
        // Enables developer option and switch to ext4, apply 16 KB OTA
        runTestAndWait(ERASE_AND_SWITCH_TO_16KB, DEVICE_WIPE_AND_UPDATE_TIMEOUT);
        getDevice().executeShellCommand("am start -a com.android.setupwizard.FOUR_CORNER_EXIT");
        assertTrue(verifyExt4());

        // Device will wiped. need to install test package again.
        installTestApp();

        // Enable developer option and switch to 16kb kernel and Check page size
        runTestAndWait(SWITCH_TO_16KB);
        result = getDevice().executeShellCommand("getconf PAGE_SIZE");
        assertEquals("16384", result.strip());

        // Device will wiped. need to install test package again.
        installTestApp();

        // switch back to 4kb kernel and check page size
        runTestAndWait(SWITCH_TO_4KB);
        runTestAndWait(SWITCH_TO_4KB, DEVICE_UPDATE_TIMEOUT);
        result = getDevice().executeShellCommand("getconf PAGE_SIZE");
        assertEquals("4096", result.strip());

@@ -103,11 +99,11 @@ public class Enable16KbTest extends BaseHostJUnit4Test {
        assertTrue(isPackageInstalled(APP_PACKAGE));
    }

    private void runTestAndWait(String testMethodName) throws Exception {
    private void runTestAndWait(String testMethodName, int timeout) throws Exception {
        prepareDevice();
        runDeviceTests(APP_PACKAGE, APP_PACKAGE + "." + TEST_NAME, testMethodName);
        // Device is either formatting or applying update. It usually takes 3 minutes to boot.
        RunUtil.getDefault().sleep(DEVICE_UPDATE_TIMEOUT);
        RunUtil.getDefault().sleep(timeout);

        // make sure it is available again after the test
        prepareDevice();
+7 −22
Original line number Diff line number Diff line
@@ -46,8 +46,7 @@ public class Enable16KbDeviceTest {
    private static final String ENABLE_16K_TOGGLE = "Boot with 16 KB page size";
    private static final String BUILD_NUMBER = "Build number";
    private static final String USE_DEVELOPER_OPTIONS = "Use developer options";
    private static final String EXT4_CONFIRMATION = "Erase all data";
    private static final String EXT4_TITLE = "Reformat device to ext4? (required for 16 KB mode)";
    private static final String DATA_WIPE_AND_UPDATE = "Erase all data and update";
    private static final String TOGGLE_16K_TITLE = "Switch from 4 KB mode to 16 KB mode";
    private static final String TOGGLE_4K_TITLE = "Switch from 16 KB mode to 4 KB mode";
    private static final String ANDROID_WIDGET_SCROLLVIEW = "android.widget.ScrollView";
@@ -85,45 +84,31 @@ public class Enable16KbDeviceTest {
    }

    @Test
    public void enable16k_switchToExt4() throws Exception {
    public void enable16k_eraseAndSwitchTo16kb() throws Exception {
        unlockDeveloperOptions();
        SettingsHelper.launchSettingsPage(
                mContext, Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
        clickOnObject(By.text(ENABLE_16K_TOGGLE));

        // Verify that ext4 toggle is visible
        verifyTextOnScreen(EXT4_TITLE);
        // Verify that ext4 + ota dialog is visible
        verifyTextOnScreen(TOGGLE_16K_TITLE);

        UiObject2 confirmationObject =
            mDevice.wait(Until.findObject(By.text(EXT4_CONFIRMATION)), TIMEOUT);
                mDevice.wait(Until.findObject(By.text(DATA_WIPE_AND_UPDATE)), TIMEOUT);
        if (confirmationObject == null) {
            // Workaround for (b/390535191). AOSP targets display the string in all caps.
            confirmationObject = mDevice.wait(
                Until.findObject(By.text(EXT4_CONFIRMATION.toUpperCase(Locale.ROOT))), TIMEOUT);
                Until.findObject(By.text(DATA_WIPE_AND_UPDATE.toUpperCase(Locale.ROOT))), TIMEOUT);
        }
        assertTrue(confirmationObject != null);
        confirmationObject.click();
    }

    @Test
    public void enable16k_switchTo16Kb() throws Exception {
        // Device will be in 4kb mode
        openPersistentNotification(NOTIFICATION_TITLE_4K);
        unlockDeveloperOptions();
        SettingsHelper.launchSettingsPage(
                mContext, Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);

        clickOnObject(By.text(ENABLE_16K_TOGGLE));
        // Verify that text is displayed to switch to 16kb
        verifyTextOnScreen(TOGGLE_16K_TITLE);

        mDevice.wait(Until.findObject(By.text(OKAY)), TIMEOUT).click();
    }

    @Test
    public void enable16k_switchTo4Kb() throws Exception {
        // Device will be in 16kb mode
        openPersistentNotification(NOTIFICATION_TITLE_16K);
        unlockDeveloperOptions();
        SettingsHelper.launchSettingsPage(
                mContext, Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);