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

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

Merge all uninstall stages in a single file

In Kotlin, we can use a sealed class to define a super class and keep all its
subclasses in the same file. As such, merge all files in the
uninstallstagedata/ inside UninstallStages.kt. Accordingly, import the right
classes where required.

Bug: 182205982
Test: builds successfully
Change-Id: I9a0bcdb34e2f00cd6a4da80469293adf43b740e7
parent 418ee825
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -50,13 +50,6 @@ import com.android.packageinstaller.v2.model.PackageUtil.getMaxTargetSdkVersionF
import com.android.packageinstaller.v2.model.PackageUtil.getPackageNameForUid
import com.android.packageinstaller.v2.model.PackageUtil.isPermissionGranted
import com.android.packageinstaller.v2.model.PackageUtil.isProfileOfOrSame
import com.android.packageinstaller.v2.model.uninstallstagedata.UninstallAborted
import com.android.packageinstaller.v2.model.uninstallstagedata.UninstallFailed
import com.android.packageinstaller.v2.model.uninstallstagedata.UninstallReady
import com.android.packageinstaller.v2.model.uninstallstagedata.UninstallStage
import com.android.packageinstaller.v2.model.uninstallstagedata.UninstallSuccess
import com.android.packageinstaller.v2.model.uninstallstagedata.UninstallUninstalling
import com.android.packageinstaller.v2.model.uninstallstagedata.UninstallUserActionRequired

class UninstallRepository(private val context: Context) {

+112 −0
Original line number Diff line number Diff line
@@ -13,13 +13,72 @@
 * 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

import android.app.Activity
import android.app.Notification
import android.content.Intent
import com.android.packageinstaller.R

class UninstallAborted(val abortReason: Int) : UninstallStage() {
sealed class UninstallStage(val stageCode: Int) {

    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
    }
}

class UninstallReady : UninstallStage(STAGE_READY)

data class UninstallUserActionRequired(
    val title: String? = null,
    val message: String? = null,
    val appDataSize: Long = 0
) : UninstallStage(STAGE_USER_ACTION_REQUIRED)

data class UninstallUninstalling(val appLabel: CharSequence, val isCloneUser: Boolean) :
    UninstallStage(STAGE_UNINSTALLING)

data class UninstallSuccess(
    val resultIntent: Intent? = null,
    val activityResultCode: Int = 0,
    val message: String? = null,
) : UninstallStage(STAGE_SUCCESS)

data class UninstallFailed(
    val returnResult: Boolean,
    /**
     * If the caller wants the result back, the intent will hold the uninstall failure status code
     * and legacy code.
     */
    val resultIntent: Intent? = null,
    val activityResultCode: Int = Activity.RESULT_CANCELED,
    /**
     * ID used to show [uninstallNotification]
     */
    val uninstallNotificationId: Int? = null,
    /**
     * When the user does not request a result back, this notification will be shown indicating the
     * reason for uninstall failure.
     */
    val uninstallNotification: Notification? = null,
) : UninstallStage(STAGE_FAILED) {

    init {
        if (uninstallNotification != null && uninstallNotificationId == null) {
            throw IllegalArgumentException(
                "uninstallNotification cannot be set without uninstallNotificationId"
            )
        }
    }
}

data class UninstallAborted(val abortReason: Int) : UninstallStage(STAGE_ABORTED) {

    var dialogTitleResource = 0
    var dialogTextResource = 0
@@ -44,11 +103,10 @@ class UninstallAborted(val abortReason: Int) : UninstallStage() {
        }
    }

    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
    }
}
+0 −51
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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
 *
 *      https://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.packageinstaller.v2.model.uninstallstagedata

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

class UninstallFailed(
    val returnResult: Boolean,
    /**
     * If the caller wants the result back, the intent will hold the uninstall failure status code
     * and legacy code.
     */
    val resultIntent: Intent? = null,
    val activityResultCode: Int = Activity.RESULT_CANCELED,
    /**
     * ID used to show [uninstallNotification]
     */
    val uninstallNotificationId: Int? = null,
    /**
     * When the user does not request a result back, this notification will be shown indicating the
     * reason for uninstall failure.
     */
    val uninstallNotification: Notification? = null,
) : UninstallStage() {

    override val stageCode = STAGE_FAILED

    init {
        if (uninstallNotification != null && uninstallNotificationId == null) {
            throw IllegalArgumentException(
                "uninstallNotification cannot be set without uninstallNotificationId"
            )
        }
    }
}
+0 −21
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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
 *
 *      https://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.packageinstaller.v2.model.uninstallstagedata

class UninstallReady : UninstallStage() {

    override val stageCode = STAGE_READY
}
+0 −31
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.packageinstaller.v2.model.uninstallstagedata

abstract class UninstallStage {

    abstract val stageCode: Int

    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
    }
}
Loading