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

Commit 6644a6c0 authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Convert all installstagedata/ 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: I4694787d9a928d2c90cba21ff2a9394107869ffd
parent cb51a9c8
Loading
Loading
Loading
Loading
+23 −100
Original line number Diff line number Diff line
@@ -14,114 +14,37 @@
 * limitations under the License.
 */

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

import android.app.Activity
import android.content.Intent

import android.app.Activity;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class InstallAborted extends InstallStage {

    public static final int ABORT_REASON_INTERNAL_ERROR = 0;
    public static final int ABORT_REASON_POLICY = 1;
    public static final int ABORT_REASON_DONE = 2;
    public static final int DLG_PACKAGE_ERROR = 1;
    private final int mStage = InstallStage.STAGE_ABORTED;
    private final int mAbortReason;

class InstallAborted(
    val abortReason: Int,
    /**
     * It will hold the restriction name, when the restriction was enforced by the system, and not
     * a device admin.
     */
    @NonNull
    private final String mMessage;
    val message: String? = null,
    /**
     * <p>If abort reason is ABORT_REASON_POLICY, then this will hold the Intent
     * * If abort reason is [ABORT_REASON_POLICY], then this will hold the Intent
     * to display a support dialog when a feature was disabled by an admin. It will be
     * {@code null} if the feature is disabled by the system. In this case, the restriction name
     * will be set in {@link #mMessage} </p>
     *
     * <p>If the abort reason is ABORT_REASON_INTERNAL_ERROR, it <b>may</b> hold an
     * intent to be sent as a result to the calling activity.</p>
     * `null` if the feature is disabled by the system. In this case, the restriction name
     * will be set in [message]
     * * If the abort reason is [ABORT_REASON_INTERNAL_ERROR], it **may** hold an
     * intent to be sent as a result to the calling activity.
     */
    @Nullable
    private final Intent mIntent;
    private final int mErrorDialogType;
    private final int mActivityResultCode;

    private InstallAborted(int reason, @NonNull String message, @Nullable Intent intent,
        int activityResultCode, int errorDialogType) {
        mAbortReason = reason;
        mMessage = message;
        mIntent = intent;
        mErrorDialogType = errorDialogType;
        mActivityResultCode = activityResultCode;
    }

    public int getAbortReason() {
        return mAbortReason;
    }

    @NonNull
    public String getMessage() {
        return mMessage;
    }

    @Nullable
    public Intent getResultIntent() {
        return mIntent;
    }

    public int getErrorDialogType() {
        return mErrorDialogType;
    }

    public int getActivityResultCode() {
        return mActivityResultCode;
    }

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

    public static class Builder {

        private final int mAbortReason;
        private String mMessage = "";
        private Intent mIntent = null;
        private int mActivityResultCode = Activity.RESULT_CANCELED;
        private int mErrorDialogType;

        public Builder(int reason) {
            mAbortReason = reason;
        }

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

        public Builder setResultIntent(@NonNull Intent intent) {
            mIntent = intent;
            return this;
        }

        public Builder setErrorDialogType(int dialogType) {
            mErrorDialogType = dialogType;
            return this;
        }

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

        public InstallAborted build() {
            return new InstallAborted(mAbortReason, mMessage, mIntent, mActivityResultCode,
                mErrorDialogType);
        }
    val resultIntent: Intent? = null,
    val activityResultCode: Int = Activity.RESULT_CANCELED,
    val errorDialogType: Int? = 0,
) : InstallStage() {

    override val stageCode = STAGE_ABORTED

    companion object {
        const val ABORT_REASON_INTERNAL_ERROR = 0
        const val ABORT_REASON_POLICY = 1
        const val ABORT_REASON_DONE = 2
        const val DLG_PACKAGE_ERROR = 1
    }
}
+14 −47
Original line number Diff line number Diff line
@@ -14,56 +14,23 @@
 * limitations under the License.
 */

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

import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.packageinstaller.v2.model.PackageUtil.AppSnippet;
import android.graphics.drawable.Drawable
import com.android.packageinstaller.v2.model.PackageUtil

public class InstallFailed extends InstallStage {
class InstallFailed(
    private val appSnippet: PackageUtil.AppSnippet,
    val legacyCode: Int,
    val statusCode: Int,
    val message: String?
) : InstallStage() {

    private final int mStage = InstallStage.STAGE_FAILED;
    @NonNull
    private final AppSnippet mAppSnippet;
    private final int mStatusCode;
    private final int mLegacyCode;
    @Nullable
    private final String mMessage;
    override val stageCode = STAGE_FAILED

    public InstallFailed(@NonNull AppSnippet appSnippet, int statusCode, int legacyCode,
        @Nullable String message) {
        mAppSnippet = appSnippet;
        mLegacyCode = statusCode;
        mStatusCode = legacyCode;
        mMessage = message;
    }

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

    @NonNull
    public Drawable getAppIcon() {
        return mAppSnippet.getIcon();
    }

    @NonNull
    public String getAppLabel() {
        return (String) mAppSnippet.getLabel();
    }

    public int getStatusCode() {
        return mStatusCode;
    }
    val appIcon: Drawable?
        get() = appSnippet.icon

    public int getLegacyCode() {
        return mLegacyCode;
    }

    @Nullable
    public String getMessage() {
        return mMessage;
    }
    val appLabel: String?
        get() = appSnippet.label as String?
}
+9 −25
Original line number Diff line number Diff line
@@ -14,34 +14,18 @@
 * limitations under the License.
 */

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

import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import com.android.packageinstaller.v2.model.PackageUtil.AppSnippet;
import android.graphics.drawable.Drawable
import com.android.packageinstaller.v2.model.PackageUtil

public class InstallInstalling extends InstallStage {
class InstallInstalling(private val appSnippet: PackageUtil.AppSnippet) : InstallStage() {

    private final int mStage = InstallStage.STAGE_INSTALLING;
    @NonNull
    private final AppSnippet mAppSnippet;
    override val stageCode = STAGE_INSTALLING

    public InstallInstalling(@NonNull AppSnippet appSnippet) {
        mAppSnippet = appSnippet;
    }

    @Override
    public int getStageCode() {
        return mStage;
    }
    val appIcon: Drawable?
        get() = appSnippet.icon

    @NonNull
    public Drawable getAppIcon() {
        return mAppSnippet.getIcon();
    }

    @NonNull
    public String getAppLabel() {
        return (String) mAppSnippet.getLabel();
    }
    val appLabel: String?
        get() = appSnippet.label as String?
}
+3 −8
Original line number Diff line number Diff line
@@ -14,14 +14,9 @@
 * limitations under the License.
 */

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

public class InstallReady extends InstallStage{
class InstallReady : InstallStage() {

    private final int mStage = InstallStage.STAGE_READY;

    @Override
    public int getStageCode() {
        return mStage;
    }
    override val stageCode = STAGE_READY
}
+14 −12
Original line number Diff line number Diff line
@@ -14,21 +14,23 @@
 * limitations under the License.
 */

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

public abstract class InstallStage {

    public static final int STAGE_DEFAULT = -1;
    public static final int STAGE_ABORTED = 0;
    public static final int STAGE_STAGING = 1;
    public static final int STAGE_READY = 2;
    public static final int STAGE_USER_ACTION_REQUIRED = 3;
    public static final int STAGE_INSTALLING = 4;
    public static final int STAGE_SUCCESS = 5;
    public static final int STAGE_FAILED = 6;
abstract class InstallStage {

    /**
     * @return the integer value representing current install stage.
     */
    public abstract int getStageCode();
    abstract val stageCode: Int

    companion object {
        const val STAGE_DEFAULT = -1
        const val STAGE_ABORTED = 0
        const val STAGE_STAGING = 1
        const val STAGE_READY = 2
        const val STAGE_USER_ACTION_REQUIRED = 3
        const val STAGE_INSTALLING = 4
        const val STAGE_SUCCESS = 5
        const val STAGE_FAILED = 6
    }
}
Loading