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

Commit beffe958 authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Convert all uninstallstagedata/ classes from Java to Kotlin

This is the 2nd CL in a 2-part change from Java to Kotlin. This CL
changes java code to kotlin.

Bug: 182205982
Test: builds successfully
Change-Id: I98e72542f8c0592ba4e04a820626a898fbea0175
parent ade592be
Loading
Loading
Loading
Loading
+25 −42
Original line number Diff line number Diff line
@@ -14,58 +14,41 @@
 * limitations under the License.
 */

package com.android.packageinstaller.v2.model.uninstallstagedata;
package com.android.packageinstaller.v2.model.uninstallstagedata

import android.app.Activity;
import com.android.packageinstaller.R;
import android.app.Activity
import com.android.packageinstaller.R

public class UninstallAborted extends UninstallStage {
class UninstallAborted(val abortReason: Int) : UninstallStage() {

    public static final int ABORT_REASON_GENERIC_ERROR = 0;
    public static final int ABORT_REASON_APP_UNAVAILABLE = 1;
    public static final int ABORT_REASON_USER_NOT_ALLOWED = 2;
    private final int mStage = UninstallStage.STAGE_ABORTED;
    private final int mAbortReason;
    private final int mDialogTitleResource;
    private final int mDialogTextResource;
    private final int mActivityResultCode = Activity.RESULT_FIRST_USER;
    var dialogTitleResource = 0
    var dialogTextResource = 0
    val activityResultCode = Activity.RESULT_FIRST_USER

    public UninstallAborted(int abortReason) {
        mAbortReason = abortReason;
        switch (abortReason) {
            case ABORT_REASON_APP_UNAVAILABLE -> {
                mDialogTitleResource = R.string.app_not_found_dlg_title;
                mDialogTextResource = R.string.app_not_found_dlg_text;
            }
            case ABORT_REASON_USER_NOT_ALLOWED -> {
                mDialogTitleResource = 0;
                mDialogTextResource = R.string.user_is_not_allowed_dlg_text;
            }
            default -> {
                mDialogTitleResource = 0;
                mDialogTextResource = R.string.generic_error_dlg_text;
            }
        }
    init {
        when (abortReason) {
            ABORT_REASON_APP_UNAVAILABLE -> {
                dialogTitleResource = R.string.app_not_found_dlg_title
                dialogTextResource = R.string.app_not_found_dlg_text
            }

    public int getAbortReason() {
        return mAbortReason;
            ABORT_REASON_USER_NOT_ALLOWED -> {
                dialogTitleResource = 0
                dialogTextResource = R.string.user_is_not_allowed_dlg_text
            }

    public int getActivityResultCode() {
        return mActivityResultCode;
            else -> {
                dialogTitleResource = 0
                dialogTextResource = R.string.generic_error_dlg_text
            }

    public int getDialogTitleResource() {
        return mDialogTitleResource;
        }

    public int getDialogTextResource() {
        return mDialogTextResource;
    }

    @Override
    public int getStageCode() {
        return mStage;
    override val stageCode = STAGE_ABORTED

    companion object {
        const val ABORT_REASON_GENERIC_ERROR = 0
        const val ABORT_REASON_APP_UNAVAILABLE = 1
        const val ABORT_REASON_USER_NOT_ALLOWED = 2
    }
}
+20 −88
Original line number Diff line number Diff line
@@ -14,106 +14,38 @@
 * limitations under the License.
 */

package com.android.packageinstaller.v2.model.uninstallstagedata;
package com.android.packageinstaller.v2.model.uninstallstagedata

import android.app.Activity;
import android.app.Notification;
import android.content.Intent;
import android.app.Activity
import android.app.Notification
import android.content.Intent

public class UninstallFailed extends UninstallStage {

    private final int mStage = UninstallStage.STAGE_FAILED;
    private final boolean mReturnResult;
class UninstallFailed(
    val returnResult: Boolean,
    /**
     * If the caller wants the result back, the intent will hold the uninstall failure status code
     * and legacy code.
     */
    private final Intent mResultIntent;
    /**
     * When the user does not request a result back, this notification will be shown indicating the
     * reason for uninstall failure.
     */
    private final Notification mUninstallNotification;
    /**
     * ID used to show {@link #mUninstallNotification}
     */
    private final int mUninstallId;
    private final int mActivityResultCode;

    public UninstallFailed(boolean returnResult, Intent resultIntent, int activityResultCode,
        int uninstallId, Notification uninstallNotification) {
        mReturnResult = returnResult;
        mResultIntent = resultIntent;
        mActivityResultCode = activityResultCode;
        mUninstallId = uninstallId;
        mUninstallNotification = uninstallNotification;
    }

    public boolean returnResult() {
        return mReturnResult;
    }

    public Intent getResultIntent() {
        return mResultIntent;
    }

    public int getActivityResultCode() {
        return mActivityResultCode;
    }

    public Notification getUninstallNotification() {
        return mUninstallNotification;
    }

    public int getUninstallId() {
        return mUninstallId;
    }

    @Override
    public int getStageCode() {
        return mStage;
    }

    public static class Builder {

        private final boolean mReturnResult;
        private int mActivityResultCode = Activity.RESULT_CANCELED;
        /**
         * See {@link UninstallFailed#mResultIntent}
         */
        private Intent mResultIntent = null;
    val resultIntent: Intent? = null,
    val activityResultCode: Int = Activity.RESULT_CANCELED,
    /**
         * See {@link UninstallFailed#mUninstallNotification}
     * ID used to show [uninstallNotification]
     */
        private Notification mUninstallNotification;
    val uninstallNotificationId: Int? = null,
    /**
         * See {@link UninstallFailed#mUninstallId}
     * When the user does not request a result back, this notification will be shown indicating the
     * reason for uninstall failure.
     */
        private int mUninstallId;

        public Builder(boolean returnResult) {
            mReturnResult = returnResult;
        }

        public Builder setUninstallNotification(int uninstallId, Notification notification) {
            mUninstallId = uninstallId;
            mUninstallNotification = notification;
            return this;
        }

        public Builder setResultIntent(Intent intent) {
            mResultIntent = intent;
            return this;
        }
    val uninstallNotification: Notification? = null,
) : UninstallStage() {

        public Builder setActivityResultCode(int resultCode) {
            mActivityResultCode = resultCode;
            return this;
        }
    override val stageCode = STAGE_FAILED

        public UninstallFailed build() {
            return new UninstallFailed(mReturnResult, mResultIntent, mActivityResultCode,
                mUninstallId, mUninstallNotification);
    init {
        if (uninstallNotification != null && uninstallNotificationId == null) {
            throw IllegalArgumentException(
                "uninstallNotification cannot be set without uninstallNotificationId"
            )
        }
    }
}
+3 −9
Original line number Diff line number Diff line
@@ -13,15 +13,9 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.packageinstaller.v2.model.uninstallstagedata

package com.android.packageinstaller.v2.model.uninstallstagedata;
class UninstallReady : UninstallStage() {

public class UninstallReady extends UninstallStage {

    private final int mStage = UninstallStage.STAGE_READY;

    @Override
    public int getStageCode() {
        return mStage;
    }
    override val stageCode = STAGE_READY
}
+12 −11
Original line number Diff line number Diff line
@@ -13,18 +13,19 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.packageinstaller.v2.model.uninstallstagedata

package com.android.packageinstaller.v2.model.uninstallstagedata;
abstract class UninstallStage {

public abstract class UninstallStage {
    abstract val stageCode: Int

    public static final int STAGE_DEFAULT = -1;
    public static final int STAGE_ABORTED = 0;
    public static final int STAGE_READY = 1;
    public static final int STAGE_USER_ACTION_REQUIRED = 2;
    public static final int STAGE_UNINSTALLING = 3;
    public static final int STAGE_SUCCESS = 4;
    public static final int STAGE_FAILED = 5;

    public abstract int getStageCode();
    companion object {
        const val STAGE_DEFAULT = -1
        const val STAGE_ABORTED = 0
        const val STAGE_READY = 1
        const val STAGE_USER_ACTION_REQUIRED = 2
        const val STAGE_UNINSTALLING = 3
        const val STAGE_SUCCESS = 4
        const val STAGE_FAILED = 5
    }
}
+8 −60
Original line number Diff line number Diff line
@@ -13,67 +13,15 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.packageinstaller.v2.model.uninstallstagedata

package com.android.packageinstaller.v2.model.uninstallstagedata;
import android.content.Intent

import android.content.Intent;
class UninstallSuccess(
    val resultIntent: Intent? = null,
    val activityResultCode: Int = 0,
    val message: String? = null
) : UninstallStage() {

public class UninstallSuccess extends UninstallStage {

    private final int mStage = UninstallStage.STAGE_SUCCESS;
    private final String mMessage;
    private final Intent mResultIntent;
    private final int mActivityResultCode;

    public UninstallSuccess(Intent resultIntent, int activityResultCode, String message) {
        mResultIntent = resultIntent;
        mActivityResultCode = activityResultCode;
        mMessage = message;
    }

    public String getMessage() {
        return mMessage;
    }

    public Intent getResultIntent() {
        return mResultIntent;
    }

    public int getActivityResultCode() {
        return mActivityResultCode;
    }

    @Override
    public int getStageCode() {
        return mStage;
    }

    public static class Builder {

        private Intent mResultIntent;
        private int mActivityResultCode;
        private String mMessage;

        public Builder() {
        }

        public Builder setResultIntent(Intent intent) {
            mResultIntent = intent;
            return this;
        }

        public Builder setActivityResultCode(int resultCode) {
            mActivityResultCode = resultCode;
            return this;
        }

        public Builder setMessage(String message) {
            mMessage = message;
            return this;
        }

        public UninstallSuccess build() {
            return new UninstallSuccess(mResultIntent, mActivityResultCode, mMessage);
        }
    }
    override val stageCode = STAGE_SUCCESS
}
Loading