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

Commit 250c9b25 authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Replace if..else-if with a switch

To enhance readability, use a switch instead of multiple else-ifs.

Bug: 182205982
Test: builds successfully
Test: No CTS Tests. Flag to use new app is turned off by default

Change-Id: Id8ca634b683e17984dc67fd273a6a356e467b2f8
parent 8ace2222
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -168,7 +168,8 @@ public class InstallRepository {
            return new InstallAborted.Builder(ABORT_REASON_INTERNAL_ERROR).build();
        }

        if (!isCallerSessionOwner(mPackageInstaller, originatingUid, mSessionId)) {
        if (mSessionId != SessionInfo.INVALID_ID &&
            !isCallerSessionOwner(mPackageInstaller, originatingUid, mSessionId)) {
            return new InstallAborted.Builder(ABORT_REASON_INTERNAL_ERROR).build();
        }

@@ -256,8 +257,7 @@ public class InstallRepository {
        Uri uri = mIntent.getData();
        if (mIsSessionInstall || (uri != null && SCHEME_PACKAGE.equals(uri.getScheme()))) {
            // For a session based install or installing with a package:// URI, there is no file
            // for us to stage. Setting the mStagingResult as null will signal InstallViewModel to
            // proceed with user confirmation stage.
            // for us to stage.
            mStagingResult.setValue(new InstallReady());
            return;
        }
+0 −3
Original line number Diff line number Diff line
@@ -205,9 +205,6 @@ public class PackageUtil {
     */
    public static boolean isCallerSessionOwner(PackageInstaller pi, int originatingUid,
        int sessionId) {
        if (sessionId == SessionInfo.INVALID_ID) {
            return false;
        }
        if (originatingUid == Process.ROOT_UID) {
            return true;
        }
+59 −48
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ package com.android.packageinstaller.v2.ui;
import static android.content.Intent.CATEGORY_LAUNCHER;
import static android.content.Intent.FLAG_ACTIVITY_NO_HISTORY;
import static android.os.Process.INVALID_UID;
import static com.android.packageinstaller.v2.model.installstagedata.InstallAborted.ABORT_REASON_INTERNAL_ERROR;
import static com.android.packageinstaller.v2.model.installstagedata.InstallAborted.ABORT_REASON_POLICY;

import android.app.Activity;
import android.app.AppOpsManager;
@@ -108,40 +106,50 @@ public class InstallLaunch extends FragmentActivity implements InstallActionList
     * Main controller of the UI. This method shows relevant dialogs based on the install stage
     */
    private void onInstallStageChange(InstallStage installStage) {
        if (installStage.getStageCode() == InstallStage.STAGE_STAGING) {
        switch (installStage.getStageCode()) {
            case InstallStage.STAGE_STAGING -> {
                InstallStagingFragment stagingDialog = new InstallStagingFragment();
                showDialogInner(stagingDialog);
                mInstallViewModel.getStagingProgress().observe(this, stagingDialog::setProgress);
        } else if (installStage.getStageCode() == InstallStage.STAGE_ABORTED) {
            }
            case InstallStage.STAGE_ABORTED -> {
                InstallAborted aborted = (InstallAborted) installStage;
                switch (aborted.getAbortReason()) {
                    // TODO: check if any dialog is to be shown for ABORT_REASON_INTERNAL_ERROR
                case InstallAborted.ABORT_REASON_DONE, InstallAborted.ABORT_REASON_INTERNAL_ERROR ->
                    case InstallAborted.ABORT_REASON_DONE,
                        InstallAborted.ABORT_REASON_INTERNAL_ERROR ->
                        setResult(aborted.getActivityResultCode(), aborted.getResultIntent(), true);
                    case InstallAborted.ABORT_REASON_POLICY -> showPolicyRestrictionDialog(aborted);
                    default -> setResult(RESULT_CANCELED, null, true);
                }
        } else if (installStage.getStageCode() == InstallStage.STAGE_USER_ACTION_REQUIRED) {
            }
            case InstallStage.STAGE_USER_ACTION_REQUIRED -> {
                InstallUserActionRequired uar = (InstallUserActionRequired) installStage;
                switch (uar.getActionReason()) {
                case InstallUserActionRequired.USER_ACTION_REASON_INSTALL_CONFIRMATION:
                    InstallConfirmationFragment actionDialog = new InstallConfirmationFragment(uar);
                    case InstallUserActionRequired.USER_ACTION_REASON_INSTALL_CONFIRMATION -> {
                        InstallConfirmationFragment actionDialog =
                            new InstallConfirmationFragment(uar);
                        showDialogInner(actionDialog);
                    break;
                case InstallUserActionRequired.USER_ACTION_REASON_UNKNOWN_SOURCE:
                    }
                    case InstallUserActionRequired.USER_ACTION_REASON_UNKNOWN_SOURCE -> {
                        ExternalSourcesBlockedFragment externalSourceDialog =
                            new ExternalSourcesBlockedFragment(uar);
                        showDialogInner(externalSourceDialog);
                    break;
                case InstallUserActionRequired.USER_ACTION_REASON_ANONYMOUS_SOURCE:
                    AnonymousSourceFragment anonymousSourceDialog = new AnonymousSourceFragment();
                    }
                    case InstallUserActionRequired.USER_ACTION_REASON_ANONYMOUS_SOURCE -> {
                        AnonymousSourceFragment anonymousSourceDialog =
                            new AnonymousSourceFragment();
                        showDialogInner(anonymousSourceDialog);
                    }
        } else if (installStage.getStageCode() == InstallStage.STAGE_INSTALLING) {
                }
            }
            case InstallStage.STAGE_INSTALLING -> {
                InstallInstalling installing = (InstallInstalling) installStage;
            InstallInstallingFragment installingDialog = new InstallInstallingFragment(installing);
                InstallInstallingFragment installingDialog =
                    new InstallInstallingFragment(installing);
                showDialogInner(installingDialog);
        } else if (installStage.getStageCode() == InstallStage.STAGE_SUCCESS) {
            }
            case InstallStage.STAGE_SUCCESS -> {
                InstallSuccess success = (InstallSuccess) installStage;
                if (success.shouldReturnResult()) {
                    Intent successIntent = success.getResultIntent();
@@ -150,15 +158,18 @@ public class InstallLaunch extends FragmentActivity implements InstallActionList
                    InstallSuccessFragment successFragment = new InstallSuccessFragment(success);
                    showDialogInner(successFragment);
                }
        } else if (installStage.getStageCode() == InstallStage.STAGE_FAILED) {
            }
            case InstallStage.STAGE_FAILED -> {
                InstallFailed failed = (InstallFailed) installStage;
                InstallFailedFragment failedDialog = new InstallFailedFragment(failed);
                showDialogInner(failedDialog);
        } else {
            }
            default -> {
                Log.d(TAG, "Unimplemented stage: " + installStage.getStageCode());
                showDialogInner(null);
            }
        }
    }

    private void showPolicyRestrictionDialog(InstallAborted aborted) {
        String restriction = aborted.getMessage();