DO NOT MERGE Cleanup: applying comments made in a Q CP CL
Change-Id: Ib94ad45944de6f49e667f8cac0dd933ffccf63f4
Fix: 133861115
Test: manual
diff --git a/car-assist-client-lib/src/com/android/car/assist/client/CarAssistUtils.java b/car-assist-client-lib/src/com/android/car/assist/client/CarAssistUtils.java
index cd0c93f..a4a95a9 100644
--- a/car-assist-client-lib/src/com/android/car/assist/client/CarAssistUtils.java
+++ b/car-assist-client-lib/src/com/android/car/assist/client/CarAssistUtils.java
@@ -121,14 +121,14 @@
* Returns true if the current active assistant has notification listener permissions.
*/
public boolean assistantIsNotificationListener() {
- final String activeComponent = mAssistUtils.getActiveServiceComponentName()
- .flattenToString();
- if (activeComponent == null) {
+ if (!hasActiveAssistant()) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "No active assistant was found.");
}
return false;
}
+ final String activeComponent = mAssistUtils.getActiveServiceComponentName()
+ .flattenToString();
int slashIndex = activeComponent.indexOf("/");
final String activePackage = activeComponent.substring(0, slashIndex);
@@ -309,17 +309,26 @@
private void requestAction(String action, StatusBarNotification sbn, Bundle payloadArguments,
ActionRequestCallback callback) {
- if (!assistantIsNotificationListener()) {
+
+ if (!hasActiveAssistant()) {
if (mIsFallbackAssistantEnabled) {
handleFallback(sbn, action, callback);
} else {
// If there is no active assistant, and fallback assistant is not enabled, then
- // there is nothing for us to do. If there is an active assistant, alert them
- // to request permissions.
- String resultState = ActionRequestCallback.RESULT_FAILED;
- if (hasActiveAssistant() && requestedHandlePermissionsActionSuccessfully()) {
- resultState = ActionRequestCallback.RESULT_FAILED_WITH_ERROR_HANDLED;
- }
+ // there is nothing for us to do.
+ callback.onResult(ActionRequestCallback.RESULT_FAILED);
+ }
+ return;
+ }
+
+ if (!assistantIsNotificationListener()) {
+ if (mIsFallbackAssistantEnabled) {
+ handleFallback(sbn, action, callback);
+ } else {
+ // If there is an active assistant, alert them to request permissions.
+ String resultState = requestHandleMissingPermission()
+ ? ActionRequestCallback.RESULT_FAILED_WITH_ERROR_HANDLED
+ : ActionRequestCallback.RESULT_FAILED;
callback.onResult(resultState);
}
return;
@@ -348,7 +357,7 @@
: ActionRequestCallback.RESULT_SUCCESS;
// Only change the resultState if fallback failed, and assistant successfully
// alerted to prompt user for permissions.
- if (hasActiveAssistant() && requestedHandlePermissionsActionSuccessfully()
+ if (hasActiveAssistant() && requestHandleMissingPermission()
&& resultState.equals(ActionRequestCallback.RESULT_FAILED)) {
resultState = ActionRequestCallback.RESULT_FAILED_WITH_ERROR_HANDLED;
}
@@ -375,7 +384,7 @@
*
* @return {@code true} if active assistant was successfully alerted.
**/
- private boolean requestedHandlePermissionsActionSuccessfully() {
+ private boolean requestHandleMissingPermission() {
Bundle payloadArguments = BundleBuilder
.buildAssistantHandleExceptionBundle(
EXCEPTION_NOTIFICATION_LISTENER_PERMISSIONS_MISSING);