1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 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 */ 16 package com.android.car.assist.client; 17 18 import static com.android.car.assist.CarVoiceInteractionSession.KEY_ACTION; 19 import static com.android.car.assist.CarVoiceInteractionSession.KEY_EXCEPTION; 20 import static com.android.car.assist.CarVoiceInteractionSession.KEY_FALLBACK_ASSISTANT_ENABLED; 21 import static com.android.car.assist.CarVoiceInteractionSession.KEY_NOTIFICATION; 22 import static com.android.car.assist.CarVoiceInteractionSession.VOICE_ACTION_HANDLE_EXCEPTION; 23 import static com.android.car.assist.CarVoiceInteractionSession.VOICE_ACTION_READ_NOTIFICATION; 24 import static com.android.car.assist.CarVoiceInteractionSession.VOICE_ACTION_REPLY_NOTIFICATION; 25 26 import android.os.Bundle; 27 import android.service.notification.StatusBarNotification; 28 29 import com.android.car.assist.CarVoiceInteractionSession.ExceptionValue; 30 31 /** 32 * Helper class for building Bundle arguments. Used by {@link CarAssistUtils}. 33 */ 34 class BundleBuilder { 35 /** 36 * Returns a {@link Bundle} to be delivered to Assistant to indicate that the notification 37 * should be read out. 38 * 39 * @param notification The notification that will be added to the bundle. 40 * @return The bundle that can be sent to Assistant. 41 */ buildAssistantReadBundle(StatusBarNotification notification)42 static Bundle buildAssistantReadBundle(StatusBarNotification notification) { 43 Bundle args = new Bundle(); 44 args.putString(KEY_ACTION, VOICE_ACTION_READ_NOTIFICATION); 45 args.putParcelable(KEY_NOTIFICATION, notification); 46 return args; 47 } 48 49 /** 50 * Returns a {@link Bundle} to be delivered to Assistant to indicate that the notification 51 * should be replied to. 52 * 53 * @param notification The notification that will be added to the bundle. 54 * @return The bundle that can be sent to Assistant. 55 */ buildAssistantReplyBundle(StatusBarNotification notification)56 static Bundle buildAssistantReplyBundle(StatusBarNotification notification) { 57 Bundle args = new Bundle(); 58 args.putString(KEY_ACTION, VOICE_ACTION_REPLY_NOTIFICATION); 59 args.putParcelable(KEY_NOTIFICATION, notification); 60 return args; 61 } 62 63 /** 64 * Returns a {@link Bundle} to be delivered to Assistant to indicate that it should handle 65 * the specified {@input exception}. 66 * 67 * @return The bundle that can be sent to Assistant. 68 */ buildAssistantHandleExceptionBundle( @xceptionValue String exception, boolean fallbackAssistantEnabled)69 static Bundle buildAssistantHandleExceptionBundle( 70 @ExceptionValue String exception, 71 boolean fallbackAssistantEnabled) { 72 Bundle args = new Bundle(); 73 args.putString(KEY_ACTION, VOICE_ACTION_HANDLE_EXCEPTION); 74 args.putString(KEY_EXCEPTION, exception); 75 args.putBoolean(KEY_FALLBACK_ASSISTANT_ENABLED, fallbackAssistantEnabled); 76 return args; 77 } 78 } 79