blob: 84f4408ce3c74c4a199d9a339635d730326e3593 [file] [log] [blame]
Uriel Sade298f6c02018-12-19 20:34:43 -08001/*
Uriel Saded81ddc92018-12-21 15:16:56 -08002 * Copyright (C) 2019 The Android Open Source Project
Uriel Sade298f6c02018-12-19 20:34:43 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.car.assist.client;
17
Uriel Saded81ddc92018-12-21 15:16:56 -080018import static android.app.Notification.Action.SEMANTIC_ACTION_MARK_AS_READ;
19import static android.app.Notification.Action.SEMANTIC_ACTION_REPLY;
Uriel Sade3703dbd2019-01-16 12:55:19 -080020import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_NOTIFICATION;
Uriel Saded81ddc92018-12-21 15:16:56 -080021
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -070022import static com.android.car.assist.CarVoiceInteractionSession.EXCEPTION_NOTIFICATION_LISTENER_PERMISSIONS_MISSING;
23
Ritwika Mitra146ed852019-05-01 10:33:06 -070024import android.annotation.Nullable;
Ritwika Mitra3eb68932019-04-29 16:40:04 -070025import android.app.ActivityManager;
Uriel Sade298f6c02018-12-19 20:34:43 -080026import android.app.Notification;
Uriel Saded81ddc92018-12-21 15:16:56 -080027import android.app.RemoteInput;
Uriel Sade298f6c02018-12-19 20:34:43 -080028import android.content.Context;
29import android.os.Bundle;
30import android.provider.Settings;
31import android.service.notification.StatusBarNotification;
32import android.util.Log;
33
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -070034import androidx.annotation.StringDef;
Uriel Sade298f6c02018-12-19 20:34:43 -080035import androidx.core.app.NotificationCompat;
36
37import com.android.car.assist.CarVoiceInteractionSession;
38import com.android.internal.app.AssistUtils;
Uriel Sade3703dbd2019-01-16 12:55:19 -080039import com.android.internal.app.IVoiceActionCheckCallback;
Uriel Sade298f6c02018-12-19 20:34:43 -080040
Priyank Singh128ff292019-04-29 20:07:36 -070041import java.util.ArrayList;
Uriel Sade298f6c02018-12-19 20:34:43 -080042import java.util.Arrays;
43import java.util.Collections;
44import java.util.HashSet;
45import java.util.List;
46import java.util.Objects;
47import java.util.Set;
48import java.util.stream.Collectors;
49import java.util.stream.IntStream;
50
51/**
52 * Util class providing helper methods to interact with the current active voice service,
53 * while ensuring that the active voice service has the required permissions.
54 */
55public class CarAssistUtils {
56 public static final String TAG = "CarAssistUtils";
Uriel Saded81ddc92018-12-21 15:16:56 -080057 private static final List<Integer> REQUIRED_SEMANTIC_ACTIONS = Collections.unmodifiableList(
Uriel Sade298f6c02018-12-19 20:34:43 -080058 Arrays.asList(
Uriel Saded81ddc92018-12-21 15:16:56 -080059 SEMANTIC_ACTION_MARK_AS_READ
Uriel Sade298f6c02018-12-19 20:34:43 -080060 )
61 );
62
Ritwika Mitraaaf0c172019-01-30 08:25:03 -080063 private static final List<Integer> SUPPORTED_SEMANTIC_ACTIONS = Collections.unmodifiableList(
64 Arrays.asList(
65 SEMANTIC_ACTION_MARK_AS_READ,
66 SEMANTIC_ACTION_REPLY
67 )
68 );
Uriel Saded81ddc92018-12-21 15:16:56 -080069
Uriel Sade298f6c02018-12-19 20:34:43 -080070 private final Context mContext;
71 private final AssistUtils mAssistUtils;
Uriel Saded81ddc92018-12-21 15:16:56 -080072 private final FallbackAssistant mFallbackAssistant;
73 private final String mErrorMessage;
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -070074 private final boolean mIsFallbackAssistantEnabled;
Uriel Sade298f6c02018-12-19 20:34:43 -080075
Uriel Sade3703dbd2019-01-16 12:55:19 -080076 /** Interface used to receive callbacks from voice action requests. */
77 public interface ActionRequestCallback {
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -070078 /**
79 * The action was successfully completed either by the active or fallback assistant.
80 **/
81 String RESULT_SUCCESS = "SUCCESS";
82
83 /**
84 * The action was not successfully completed, but the active assistant has been prompted to
85 * alert the user of this error and handle it. The caller of this callback is recommended
86 * to NOT alert the user of this error again.
87 */
88 String RESULT_FAILED_WITH_ERROR_HANDLED = "FAILED_WITH_ERROR_HANDLED";
89
90 /**
91 * The action has not been successfully completed, and the error has not been handled.
92 **/
93 String RESULT_FAILED = "FAILED";
94
95 /**
96 * The list of result states.
97 */
98 @StringDef({RESULT_FAILED, RESULT_FAILED_WITH_ERROR_HANDLED, RESULT_SUCCESS})
99 @interface ResultState {
100 }
101
102 /** Callback containing the result of completing the voice action request. */
103 void onResult(@ResultState String state);
Uriel Sade3703dbd2019-01-16 12:55:19 -0800104 }
105
Uriel Sade298f6c02018-12-19 20:34:43 -0800106 public CarAssistUtils(Context context) {
Uriel Sade298f6c02018-12-19 20:34:43 -0800107 mContext = context;
Uriel Saded81ddc92018-12-21 15:16:56 -0800108 mAssistUtils = new AssistUtils(context);
Ritwika Mitra146ed852019-05-01 10:33:06 -0700109 mFallbackAssistant = new FallbackAssistant(context);
Uriel Saded81ddc92018-12-21 15:16:56 -0800110 mErrorMessage = context.getString(R.string.assist_action_failed_toast);
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700111 mIsFallbackAssistantEnabled =
112 context.getResources().getBoolean(R.bool.config_enableFallbackAssistant);
113 }
114
115 /**
116 * @return {@code true} if there is an active assistant.
117 */
118 public boolean hasActiveAssistant() {
119 return mAssistUtils.getActiveServiceComponentName() != null;
Uriel Sade298f6c02018-12-19 20:34:43 -0800120 }
121
122 /**
123 * Returns true if the current active assistant has notification listener permissions.
124 */
125 public boolean assistantIsNotificationListener() {
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700126 if (!hasActiveAssistant()) {
127 if (Log.isLoggable(TAG, Log.DEBUG)) {
128 Log.d(TAG, "No active assistant was found.");
129 }
130 return false;
131 }
Uriel Sade298f6c02018-12-19 20:34:43 -0800132 final String activeComponent = mAssistUtils.getActiveServiceComponentName()
133 .flattenToString();
Ritwika Mitraac5f1512019-02-04 10:21:14 -0800134 int slashIndex = activeComponent.indexOf("/");
135 final String activePackage = activeComponent.substring(0, slashIndex);
136
Ritwika Mitra3eb68932019-04-29 16:40:04 -0700137 final String listeners = Settings.Secure.getStringForUser(mContext.getContentResolver(),
138 Settings.Secure.ENABLED_NOTIFICATION_LISTENERS, ActivityManager.getCurrentUser());
Uriel Sade298f6c02018-12-19 20:34:43 -0800139
Ritwika Mitraf89855b2019-05-21 11:56:20 -0700140 if (Log.isLoggable(TAG, Log.DEBUG)) {
141 Log.d(TAG, "Current user: " + ActivityManager.getCurrentUser()
142 + " has active voice service: " + activePackage + " and enabled notification "
143 + " listeners: " + listeners);
144 }
145
Ritwika Mitraac5f1512019-02-04 10:21:14 -0800146 if (listeners != null) {
147 for (String listener : Arrays.asList(listeners.split(":"))) {
148 if (listener.contains(activePackage)) {
149 return true;
150 }
151 }
152 }
Ritwika Mitra295d91a2019-04-26 09:55:11 -0700153 Log.w(TAG, "No notification listeners found for assistant: " + activeComponent);
Ritwika Mitraac5f1512019-02-04 10:21:14 -0800154 return false;
Uriel Sade298f6c02018-12-19 20:34:43 -0800155 }
156
157 /**
158 * Checks whether the notification is a car-compatible messaging notification.
159 *
160 * @param sbn The notification being checked.
161 * @return true if the notification is a car-compatible messaging notification.
162 */
163 public static boolean isCarCompatibleMessagingNotification(StatusBarNotification sbn) {
164 return hasMessagingStyle(sbn)
165 && hasRequiredAssistantCallbacks(sbn)
166 && replyCallbackHasRemoteInput(sbn)
167 && assistantCallbacksShowNoUi(sbn);
168 }
169
170 /** Returns true if the semantic action provided can be supported. */
171 public static boolean isSupportedSemanticAction(int semanticAction) {
Uriel Saded81ddc92018-12-21 15:16:56 -0800172 return SUPPORTED_SEMANTIC_ACTIONS.contains(semanticAction);
Uriel Sade298f6c02018-12-19 20:34:43 -0800173 }
174
175 /**
176 * Returns true if the notification has a messaging style.
177 * <p/>
178 * This is the case if the notification in question was provided an instance of
179 * {@link Notification.MessagingStyle} (or an instance of
180 * {@link NotificationCompat.MessagingStyle} if {@link NotificationCompat} was used).
181 */
182 private static boolean hasMessagingStyle(StatusBarNotification sbn) {
183 return NotificationCompat.MessagingStyle
184 .extractMessagingStyleFromNotification(sbn.getNotification()) != null;
185 }
186
187 /**
188 * Returns true if the notification has the required Assistant callbacks to be considered
189 * a car-compatible messaging notification. The callbacks must be unambiguous, therefore false
190 * is returned if multiple callbacks exist for any semantic action that is supported.
191 */
192 private static boolean hasRequiredAssistantCallbacks(StatusBarNotification sbn) {
Priyank Singh128ff292019-04-29 20:07:36 -0700193 List<Integer> semanticActionList = getAllActions(sbn.getNotification())
194 .stream()
195 .map(NotificationCompat.Action::getSemanticAction)
Uriel Saded81ddc92018-12-21 15:16:56 -0800196 .filter(REQUIRED_SEMANTIC_ACTIONS::contains)
Uriel Sade298f6c02018-12-19 20:34:43 -0800197 .collect(Collectors.toList());
198 Set<Integer> semanticActionSet = new HashSet<>(semanticActionList);
Uriel Sade298f6c02018-12-19 20:34:43 -0800199 return semanticActionList.size() == semanticActionSet.size()
Uriel Saded81ddc92018-12-21 15:16:56 -0800200 && semanticActionSet.containsAll(REQUIRED_SEMANTIC_ACTIONS);
Uriel Sade298f6c02018-12-19 20:34:43 -0800201 }
202
Priyank Singh128ff292019-04-29 20:07:36 -0700203 /** Retrieves all visible and invisible {@link Action}s from the {@link #notification}. */
Ritwika Mitra146ed852019-05-01 10:33:06 -0700204 public static List<NotificationCompat.Action> getAllActions(Notification notification) {
Priyank Singh128ff292019-04-29 20:07:36 -0700205 List<NotificationCompat.Action> actions = new ArrayList<>();
206 actions.addAll(NotificationCompat.getInvisibleActions(notification));
207 for (int i = 0; i < NotificationCompat.getActionCount(notification); i++) {
208 actions.add(NotificationCompat.getAction(notification, i));
209 }
210 return actions;
211 }
212
Uriel Sade298f6c02018-12-19 20:34:43 -0800213 /**
Ritwika Mitra146ed852019-05-01 10:33:06 -0700214 * Retrieves the {@link NotificationCompat.Action} containing the
215 * {@link NotificationCompat.Action#SEMANTIC_ACTION_MARK_AS_READ} semantic action.
216 */
217 @Nullable
218 public static NotificationCompat.Action getMarkAsReadAction(Notification notification) {
219 for (NotificationCompat.Action action : getAllActions(notification)) {
220 if (action.getSemanticAction()
221 == NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ) {
222 return action;
223 }
224 }
225 return null;
226 }
227
228 /**
Uriel Saded81ddc92018-12-21 15:16:56 -0800229 * Returns true if the reply callback has at least one {@link RemoteInput}.
Uriel Sade298f6c02018-12-19 20:34:43 -0800230 * <p/>
231 * Precondition: There exists only one reply callback.
232 */
233 private static boolean replyCallbackHasRemoteInput(StatusBarNotification sbn) {
234 return Arrays.stream(sbn.getNotification().actions)
Uriel Saded81ddc92018-12-21 15:16:56 -0800235 .filter(action -> action.getSemanticAction() == SEMANTIC_ACTION_REPLY)
Uriel Sade298f6c02018-12-19 20:34:43 -0800236 .map(Notification.Action::getRemoteInputs)
Uriel Saded81ddc92018-12-21 15:16:56 -0800237 .filter(Objects::nonNull)
238 .anyMatch(remoteInputs -> remoteInputs.length > 0);
Uriel Sade298f6c02018-12-19 20:34:43 -0800239 }
240
241 /** Returns true if all Assistant callbacks indicate that they show no UI, false otherwise. */
242 private static boolean assistantCallbacksShowNoUi(StatusBarNotification sbn) {
243 final Notification notification = sbn.getNotification();
244 return IntStream.range(0, notification.actions.length)
245 .mapToObj(i -> NotificationCompat.getAction(notification, i))
246 .filter(Objects::nonNull)
Uriel Saded81ddc92018-12-21 15:16:56 -0800247 .filter(action -> SUPPORTED_SEMANTIC_ACTIONS.contains(action.getSemanticAction()))
Uriel Sade298f6c02018-12-19 20:34:43 -0800248 .noneMatch(NotificationCompat.Action::getShowsUserInterface);
249 }
250
251 /**
Uriel Saded81ddc92018-12-21 15:16:56 -0800252 * Requests a given action from the current active Assistant.
253 *
Ritwika Mitra146ed852019-05-01 10:33:06 -0700254 * @param sbn the notification payload to deliver to assistant
255 * @param voiceAction must be a valid {@link CarVoiceInteractionSession} VOICE_ACTION
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700256 * @param callback the callback to issue on success/error
Uriel Sade298f6c02018-12-19 20:34:43 -0800257 */
Ritwika Mitra146ed852019-05-01 10:33:06 -0700258 public void requestAssistantVoiceAction(StatusBarNotification sbn, String voiceAction,
Uriel Sade3703dbd2019-01-16 12:55:19 -0800259 ActionRequestCallback callback) {
Uriel Saded81ddc92018-12-21 15:16:56 -0800260 if (!isCarCompatibleMessagingNotification(sbn)) {
261 Log.w(TAG, "Assistant action requested for non-compatible notification.");
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700262 callback.onResult(ActionRequestCallback.RESULT_FAILED);
Uriel Sade3703dbd2019-01-16 12:55:19 -0800263 return;
264 }
265
Ritwika Mitra146ed852019-05-01 10:33:06 -0700266 switch (voiceAction) {
267 case CarVoiceInteractionSession.VOICE_ACTION_READ_NOTIFICATION:
Uriel Sade3703dbd2019-01-16 12:55:19 -0800268 readMessageNotification(sbn, callback);
269 return;
Ritwika Mitra146ed852019-05-01 10:33:06 -0700270 case CarVoiceInteractionSession.VOICE_ACTION_REPLY_NOTIFICATION:
Uriel Sade3703dbd2019-01-16 12:55:19 -0800271 replyMessageNotification(sbn, callback);
272 return;
Uriel Saded81ddc92018-12-21 15:16:56 -0800273 default:
Ritwika Mitra146ed852019-05-01 10:33:06 -0700274 Log.w(TAG, "Requested Assistant action for unsupported semantic action.");
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700275 callback.onResult(ActionRequestCallback.RESULT_FAILED);
Uriel Sade3703dbd2019-01-16 12:55:19 -0800276 return;
Uriel Saded81ddc92018-12-21 15:16:56 -0800277 }
Uriel Sade298f6c02018-12-19 20:34:43 -0800278 }
279
280 /**
281 * Requests a read action for the notification from the current active Assistant.
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700282 * If the Assistant cannot handle the request, a fallback implementation will attempt to
Uriel Saded81ddc92018-12-21 15:16:56 -0800283 * handle it.
Uriel Sade298f6c02018-12-19 20:34:43 -0800284 *
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700285 * @param sbn the notification to deliver as the payload
Uriel Sade3703dbd2019-01-16 12:55:19 -0800286 * @param callback the callback to issue on success/error
Uriel Sade298f6c02018-12-19 20:34:43 -0800287 */
Uriel Sade3703dbd2019-01-16 12:55:19 -0800288 private void readMessageNotification(StatusBarNotification sbn,
289 ActionRequestCallback callback) {
290 Bundle args = BundleBuilder.buildAssistantReadBundle(sbn);
291 String action = CarVoiceInteractionSession.VOICE_ACTION_READ_NOTIFICATION;
292
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700293 requestAction(action, sbn, args, callback);
Uriel Sade298f6c02018-12-19 20:34:43 -0800294 }
295
296 /**
297 * Requests a reply action for the notification from the current active Assistant.
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700298 * If the Assistant cannot handle the request, a fallback implementation will attempt to
Uriel Saded81ddc92018-12-21 15:16:56 -0800299 * handle it.
Uriel Sade298f6c02018-12-19 20:34:43 -0800300 *
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700301 * @param sbn the notification to deliver as the payload
Uriel Sade3703dbd2019-01-16 12:55:19 -0800302 * @param callback the callback to issue on success/error
Uriel Sade298f6c02018-12-19 20:34:43 -0800303 */
Uriel Sade3703dbd2019-01-16 12:55:19 -0800304 private void replyMessageNotification(StatusBarNotification sbn,
305 ActionRequestCallback callback) {
306 Bundle args = BundleBuilder.buildAssistantReplyBundle(sbn);
307 String action = CarVoiceInteractionSession.VOICE_ACTION_REPLY_NOTIFICATION;
308
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700309 requestAction(action, sbn, args, callback);
Uriel Sade298f6c02018-12-19 20:34:43 -0800310 }
311
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700312 private void requestAction(String action, StatusBarNotification sbn, Bundle payloadArguments,
Uriel Sade3703dbd2019-01-16 12:55:19 -0800313 ActionRequestCallback callback) {
314
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700315 if (!hasActiveAssistant()) {
316 if (mIsFallbackAssistantEnabled) {
317 handleFallback(sbn, action, callback);
318 } else {
319 // If there is no active assistant, and fallback assistant is not enabled, then
320 // there is nothing for us to do.
321 callback.onResult(ActionRequestCallback.RESULT_FAILED);
322 }
323 return;
324 }
325
Uriel Sade3703dbd2019-01-16 12:55:19 -0800326 if (!assistantIsNotificationListener()) {
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700327 if (mIsFallbackAssistantEnabled) {
328 handleFallback(sbn, action, callback);
329 } else {
330 // If there is an active assistant, alert them to request permissions.
331 callback.onResult(requestHandleMissingPermissions()
332 ? ActionRequestCallback.RESULT_FAILED_WITH_ERROR_HANDLED
333 : ActionRequestCallback.RESULT_FAILED);
334 }
Uriel Sade3703dbd2019-01-16 12:55:19 -0800335 return;
336 }
337
338 IVoiceActionCheckCallback actionCheckCallback = new IVoiceActionCheckCallback.Stub() {
339 @Override
340 public void onComplete(List<String> supportedActions) {
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700341 String resultState = ActionRequestCallback.RESULT_FAILED;
Uriel Sade3703dbd2019-01-16 12:55:19 -0800342 boolean success;
343 if (supportedActions != null && supportedActions.contains(action)) {
344 if (Log.isLoggable(TAG, Log.DEBUG)) {
345 Log.d(TAG, "Launching active Assistant for action: " + action);
346 }
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700347 if (mAssistUtils.showSessionForActiveService(payloadArguments,
348 SHOW_SOURCE_NOTIFICATION, null, null)) {
349 resultState = ActionRequestCallback.RESULT_SUCCESS;
350 }
Uriel Sade3703dbd2019-01-16 12:55:19 -0800351 } else {
352 Log.w(TAG, "Active Assistant does not support voice action: " + action);
Uriel Sade3703dbd2019-01-16 12:55:19 -0800353 }
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700354 callback.onResult(resultState);
Uriel Sade3703dbd2019-01-16 12:55:19 -0800355 }
356 };
357
358 Set<String> actionSet = new HashSet<>(Collections.singletonList(action));
359 mAssistUtils.getActiveServiceSupportedActions(actionSet, actionCheckCallback);
360 }
361
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700362 private void handleFallback(StatusBarNotification sbn, String action,
363 ActionRequestCallback callback) {
364 FallbackAssistant.Listener listener = new FallbackAssistant.Listener() {
365 @Override
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700366 public void onMessageRead(boolean hasError) {
367 String resultState = hasError ? ActionRequestCallback.RESULT_FAILED
368 : ActionRequestCallback.RESULT_SUCCESS;
369 // Only change the resultState if fallback failed, and assistant successfully
370 // alerted to prompt user for permissions.
371 if (hasActiveAssistant() && requestHandleMissingPermissions()
372 && resultState.equals(ActionRequestCallback.RESULT_FAILED)) {
373 resultState = ActionRequestCallback.RESULT_FAILED_WITH_ERROR_HANDLED;
374 }
375 callback.onResult(resultState);
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700376 }
377 };
378
Uriel Sade3703dbd2019-01-16 12:55:19 -0800379 switch (action) {
380 case CarVoiceInteractionSession.VOICE_ACTION_READ_NOTIFICATION:
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700381 mFallbackAssistant.handleReadAction(sbn, listener);
382 break;
Uriel Sade3703dbd2019-01-16 12:55:19 -0800383 case CarVoiceInteractionSession.VOICE_ACTION_REPLY_NOTIFICATION:
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700384 mFallbackAssistant.handleErrorMessage(mErrorMessage, listener);
385 break;
Uriel Sade3703dbd2019-01-16 12:55:19 -0800386 default:
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700387 Log.w(TAG, "Requested unsupported FallbackAssistant action.");
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700388 callback.onResult(ActionRequestCallback.RESULT_FAILED);
Ritwika Mitraeeb910c2019-05-23 12:32:06 -0700389 return;
Uriel Sade3703dbd2019-01-16 12:55:19 -0800390 }
Uriel Sade298f6c02018-12-19 20:34:43 -0800391 }
Ritwika Mitra2f0ffb22019-05-23 10:10:00 -0700392
393 /**
394 * Requests the active voice service to handle the permissions missing error.
395 *
396 * @return {@code true} if active assistant was successfully alerted.
397 **/
398 private boolean requestHandleMissingPermissions() {
399 Bundle payloadArguments = BundleBuilder
400 .buildAssistantHandleExceptionBundle(
401 EXCEPTION_NOTIFICATION_LISTENER_PERMISSIONS_MISSING);
402 boolean requestedSuccessfully = mAssistUtils.showSessionForActiveService(payloadArguments,
403 SHOW_SOURCE_NOTIFICATION, null, null);
404 if (!requestedSuccessfully) {
405 Log.w(TAG, "Failed to alert assistant to request permissions from user");
406 }
407 return requestedSuccessfully;
408 }
Uriel Sade298f6c02018-12-19 20:34:43 -0800409}