diff --git a/core/java/android/service/controls/Control.java b/core/java/android/service/controls/Control.java index d01bc2524332b..8383072a48e32 100644 --- a/core/java/android/service/controls/Control.java +++ b/core/java/android/service/controls/Control.java @@ -73,25 +73,37 @@ public final class Control implements Parcelable { }) public @interface Status {}; + /** + * Reserved for use with the {@link StatelessBuilder}, and while loading. When state is + * requested via {@link ControlsProviderService#createPublisherFor}, use other status codes + * to indicate the proper device state. + */ public static final int STATUS_UNKNOWN = 0; /** - * The device corresponding to the {@link Control} is responding correctly. + * Used to indicate that the state of the device was successfully retrieved. This includes + * all scenarios where the device may have a warning for the user, such as "Lock jammed", + * or "Vacuum stuck". Any information for the user should be set through + * {@link StatefulBuilder#setStatusText}. */ public static final int STATUS_OK = 1; /** - * The device corresponding to the {@link Control} cannot be found or was removed. + * The device corresponding to the {@link Control} cannot be found or was removed. The user + * will be alerted and directed to the application to resolve. */ public static final int STATUS_NOT_FOUND = 2; /** - * The device corresponding to the {@link Control} is in an error state. + * Used to indicate that there was a temporary error while loading the device state. A default + * error message will be displayed in place of any custom text that was set through + * {@link StatefulBuilder#setStatusText}. */ public static final int STATUS_ERROR = 3; /** - * The {@link Control} is currently disabled. + * The {@link Control} is currently disabled. A default error message will be displayed in + * place of any custom text that was set through {@link StatefulBuilder#setStatusText}. */ public static final int STATUS_DISABLED = 4; diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 0a6498b9f0c11..0314fc89d33a7 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2790,7 +2790,13 @@ a retry will be attempted [CHAR LIMIT=30] --> Error, retrying\u2026 - Device removed + Not found + + Control is unavailable + + Couldn\u2019t access %1$s. Check the %2$s app to make sure the control is still available and that the app settings haven\u2019t changed. + + Open app Can\u2019t load status diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt index f07f3168d2460..994557cf696b8 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt @@ -118,6 +118,7 @@ class ControlViewHolder( var behavior: Behavior? = null var lastAction: ControlAction? = null var isLoading = false + var visibleDialog: Dialog? = null private var lastChallengeDialog: Dialog? = null private val onDialogCancel: () -> Unit = { lastChallengeDialog = null } @@ -197,18 +198,24 @@ class ControlViewHolder( fun dismiss() { lastChallengeDialog?.dismiss() lastChallengeDialog = null + visibleDialog?.dismiss() + visibleDialog = null } fun setTransientStatus(tempStatus: String) { val previousText = status.getText() cancelUpdate = uiExecutor.executeDelayed({ - setStatusText(previousText) - updateContentDescription() + animateStatusChange(/* animated */ true, { + setStatusText(previousText, /* immediately */ true) + updateContentDescription() + }) }, UPDATE_DELAY_IN_MILLIS) - setStatusText(tempStatus) - updateContentDescription() + animateStatusChange(/* animated */ true, { + setStatusText(tempStatus, /* immediately */ true) + updateContentDescription() + }) } private fun updateContentDescription() = diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt index bf3835dba4fd8..6bf1897440337 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt @@ -16,7 +16,13 @@ package com.android.systemui.controls.ui +import android.app.AlertDialog +import android.app.PendingIntent +import android.content.DialogInterface +import android.content.pm.PackageManager import android.service.controls.Control +import android.view.View +import android.view.WindowManager import com.android.systemui.R @@ -31,7 +37,17 @@ class StatusBehavior : Behavior { val status = cws.control?.status ?: Control.STATUS_UNKNOWN val msg = when (status) { Control.STATUS_ERROR -> R.string.controls_error_generic - Control.STATUS_NOT_FOUND -> R.string.controls_error_removed + Control.STATUS_DISABLED -> R.string.controls_error_timeout + Control.STATUS_NOT_FOUND -> { + cvh.layout.setOnClickListener(View.OnClickListener() { + showNotFoundDialog(cvh, cws) + }) + cvh.layout.setOnLongClickListener(View.OnLongClickListener() { + showNotFoundDialog(cvh, cws) + true + }) + R.string.controls_error_removed + } else -> { cvh.isLoading = true com.android.internal.R.string.loading @@ -40,4 +56,42 @@ class StatusBehavior : Behavior { cvh.setStatusText(cvh.context.getString(msg)) cvh.applyRenderInfo(false, colorOffset) } + + private fun showNotFoundDialog(cvh: ControlViewHolder, cws: ControlWithState) { + val pm = cvh.context.getPackageManager() + val ai = pm.getApplicationInfo(cws.componentName.packageName, PackageManager.GET_META_DATA) + val appLabel = pm.getApplicationLabel(ai) + val builder = AlertDialog.Builder( + cvh.context, + android.R.style.Theme_DeviceDefault_Dialog_Alert + ).apply { + val res = cvh.context.resources + setTitle(res.getString(R.string.controls_error_removed_title)) + setMessage(res.getString( + R.string.controls_error_removed_message, cvh.title.getText(), appLabel)) + setPositiveButton( + R.string.controls_open_app, + DialogInterface.OnClickListener { dialog, _ -> + try { + cws.control?.getAppIntent()?.send() + } catch (e: PendingIntent.CanceledException) { + cvh.setTransientStatus( + cvh.context.resources.getString(R.string.controls_error_failed)) + } + dialog.dismiss() + }) + setNegativeButton( + android.R.string.cancel, + DialogInterface.OnClickListener { dialog, _ -> + dialog.cancel() + } + ) + } + cvh.visibleDialog = builder.create().apply { + getWindow().apply { + setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY) + show() + } + } + } }