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

Commit 5d7830b5 authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI][52/N] add strings for app update

+ Also add a small refactoring for stage transitions
+ Also change the button style to outlined

BUG: 360129657
FLAG: android.content.pm.verification_service
Test: manual

Change-Id: I048adc32f35e5a2e98d9d88744f1ba9caa640be3
parent 6e011cf4
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -93,10 +93,11 @@
            android:visibility="gone">

            <TextView
                android:id="@+id/more_details_expanded_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="start"
                android:text="@string/install_without_verifying_summary"
                android:text="@string/more_details_expanded_install_summary"
                style="?attr/textAppearanceInstallerCustomMessage"/>

            <TextView
+2 −1
Original line number Diff line number Diff line
@@ -89,10 +89,11 @@
            android:visibility="gone">

            <TextView
                android:id="@+id/more_details_expanded_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="start"
                android:text="@string/install_without_verifying_summary"
                android:text="@string/more_details_expanded_install_summary"
                style="?attr/textAppearanceInstallerCustomMessage"/>

            <TextView
+0 −2
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@
    <!-- [CHAR LIMIT=15] -->
    <string name="cancel">Cancel</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="install_without_verifying">Install without verifying</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="more_details">More details</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="dont_install">Don\'t install</string>
+38 −3
Original line number Diff line number Diff line
@@ -155,23 +155,58 @@
    <string name="cannot_install_app_blocked_summary">&lt;p>This app was blocked. To help keep your
        device and data safe, only apps from verified developers can be installed.&lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;/p></string>
    <!-- Message presented in a dialog box when verification failed due to problems with the network. [CHAR LIMIT=none]-->
    <!-- Message presented in a dialog box when the verifier blocked an app from being updated. [CHAR LIMIT=none]-->
    <string name="cannot_update_app_blocked_summary">&lt;p>This app was not updated. To help keep your
        device and data safe, only updates from verified developers can be installed.&lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;/p>
    </string>
    <!-- Message presented in a dialog box when verification failed due to problems with the network during installation. [CHAR LIMIT=none]-->
    <string name="cannot_install_verification_no_internet_summary">&lt;p>This app was not installed.
        Apps from unverified developers may be unsafe.&lt;/p>
        &lt;p>An internet connection is required to verify the app developer.
            Make sure your device is connected to the internet, then try installing the app again.
        &lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;p></string>
    <!-- Message presented in a dialog box when verification failed due to internal failures. [CHAR LIMIT=none]-->
    <!-- Message presented in a dialog box when verification failed due to problems with the network during update. [CHAR LIMIT=none]-->
    <string name="cannot_update_verification_no_internet_summary">&lt;p>This app was not updated.
        Updates from unverified developers may be unsafe.&lt;/p>
        &lt;p>An internet connection is required to verify the app developer.
            Make sure your device is connected to the internet, then try updating the app again.
        &lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;p></string>

    <!-- Message presented in a dialog box when verification failed due to internal failures during installation. [CHAR LIMIT=none]-->
    <string name="cannot_install_verification_unavailable_summary">&lt;p>There was a problem verifying
        this app\'s developer. Apps from unverified developers may be unsafe,
        so the app was not installed.&lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;/p></string>
    <string name="install_without_verifying_summary">If you install without verifying, keep in
    <!-- Message presented in a dialog box when verification failed due to problems with the network during update. [CHAR LIMIT=none]-->
    <string name="cannot_update_verification_unavailable_summary">&lt;p>There was a problem verifying
        this app\'s developer. Updates from unverified developers may be unsafe,
        so the app was not updated.&lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;/p></string>
    <!-- Message presented in a dialog box when verification failed due to internal failures during installation for fail closed policy. [CHAR LIMIT=none]-->
    <string name="cannot_install_verification_unavailable_fail_closed_summary">&lt;p>This app was blocked
        because there was a problem verifying the developer. To help keep your device and data safe,
        only apps from verified developers can be installed.&lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;/p></string>
    <!-- Message presented in a dialog box when verification failed due to internal failures during update for fail closed policy. [CHAR LIMIT=none]-->
    <string name="cannot_update_verification_unavailable_fail_closed_summary">&lt;p>This app was not updated
        because there was a problem verifying the developer. To help keep your device and data safe,
        only updates from verified developers can be installed.&lt;/p>
        &lt;p>&lt;a href="">Learn more about developer verification&lt;/a>&lt;/p></string>

    <string name="more_details_expanded_install_summary">If you install without verifying, keep in
        mind apps from unverified developers may put your device and data at risk.</string>
    <string name="more_details_expanded_update_summary">If you update without verifying, keep in
        mind updates from unverified developers may put your device and data at risk.</string>
    <string name="cannot_install_app_blocked_title">App developer unverified</string>
    <string name="cannot_install_verification_no_internet_title">No internet, can\'t verify app developer</string>
    <string name="cannot_install_verification_unavailable_title">Can\'t verify app developer</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="install_without_verifying">Install without verifying</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="update_without_verifying">Update without verifying</string>

    <!-- End of placeholder strings -->
    <!-- Dialog Messages end -->
+39 −14
Original line number Diff line number Diff line
@@ -29,10 +29,12 @@ import android.content.pm.ApplicationInfo
import android.content.pm.Flags
import android.content.pm.PackageInfo
import android.content.pm.PackageInstaller
import android.content.pm.PackageInstaller.SessionInfo
import android.content.pm.PackageInstaller.SessionParams
import android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT
import android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_ERROR
import android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_INSTALL_ANYWAY
import android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo
import android.content.pm.PackageInstaller.SessionInfo
import android.content.pm.PackageInstaller.SessionParams
import android.content.pm.PackageManager
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
import android.net.Uri
@@ -844,16 +846,51 @@ class InstallRepository(private val context: Context) {
        confirmationSnippet = confirmationSnippet as InstallUserActionRequired
        val appSnippet = PackageUtil.getAppSnippet(
                context, confirmationSnippet.appLabel, confirmationSnippet.appIcon)
        val sessionInfo = packageInstaller.getSessionInfo(sessionId)
        val stubPackageInfo = generateStubPackageInfo(sessionInfo?.getAppPackageName())
        val isAppUpdating = isAppUpdating(stubPackageInfo)

        // Since InstallUserActionRequired returned by generateConfirmationSnippet is immutable,
        // create a new InstallUserActionRequired with the required data
        return InstallUserActionRequired(
            isAppUpdating = isAppUpdating,
            actionReason = USER_ACTION_REASON_VERIFICATION_CONFIRMATION,
            appSnippet = appSnippet,
            verificationInfo = verificationInfo
        )
    }

    fun setNegativeVerificationUserResponse(): InstallStage {
        if (PackageInstaller.ACTION_CONFIRM_DEVELOPER_VERIFICATION != intent.action) {
            Log.e(LOG_TAG, "Cannot set verification response for this request: $intent")
            return InstallAborted(ABORT_REASON_INTERNAL_ERROR)
        }
        if (localLogv) {
            Log.d(LOG_TAG, "Setting negative verification user response")
        }
        packageInstaller.setDeveloperVerificationUserResponse(
            sessionId, DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT
        )
        return InstallAborted(
            ABORT_REASON_DONE, activityResultCode = Activity.RESULT_OK
        )
    }

    fun setPositiveVerificationUserResponse(): InstallStage {
        if (PackageInstaller.ACTION_CONFIRM_DEVELOPER_VERIFICATION != intent.action) {
            Log.e(LOG_TAG, "Cannot set verification response for this request: $intent")
            return InstallAborted(ABORT_REASON_INTERNAL_ERROR)
        }
        if (localLogv) {
            Log.d(LOG_TAG, "Setting positive verification user response")
        }
        packageInstaller.setDeveloperVerificationUserResponse(
            sessionId, DEVELOPER_VERIFICATION_USER_RESPONSE_INSTALL_ANYWAY
        )
        return InstallAborted(
            ABORT_REASON_DONE, activityResultCode = Activity.RESULT_OK)
    }

    /**
     * Once the user returns from Settings related to installing from unknown sources, reattempt
     * the installation if the source app is granted permission to install other apps. Abort the
@@ -1107,18 +1144,6 @@ class InstallRepository(private val context: Context) {
        cleanupStagingSession()
    }

    fun setUserVerificationResponse(responseCode: Int) {
        if (PackageInstaller.ACTION_CONFIRM_DEVELOPER_VERIFICATION != intent.action) {
            Log.e(LOG_TAG, "Cannot set verification response for this request: $intent")
            _installResult.value = InstallAborted(ABORT_REASON_INTERNAL_ERROR)
            return
        }
        packageInstaller.setDeveloperVerificationUserResponse(sessionId, responseCode)
        _installResult.value = InstallAborted(
            ABORT_REASON_DONE, activityResultCode = Activity.RESULT_OK
        )
    }

    val stagingProgress: LiveData<Int>
        get() = sessionStager?.progress ?: MutableLiveData(0)

Loading