正在查看: Petal Maps v4.7.0.310001 应用的 BaseActionGroup.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Petal Maps v4.7.0.310001 应用的 BaseActionGroup.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.huawei.hiassistant.platform.base.action;
import android.content.Intent;
import android.os.Parcelable;
import android.text.TextUtils;
import com.huawei.hiai.tts.constants.BaseConstants;
import com.huawei.hiassistant.platform.base.bean.Indication;
import com.huawei.hiassistant.platform.base.bean.UiConversationCard;
import com.huawei.hiassistant.platform.base.bean.recognize.Session;
import com.huawei.hiassistant.platform.base.bean.recognize.VoiceKitMessage;
import com.huawei.hiassistant.platform.base.bean.ui.DisplayCardPayload;
import com.huawei.hiassistant.platform.base.bean.ui.UiMessageType;
import com.huawei.hiassistant.platform.base.bean.ui.UiPayload;
import com.huawei.hiassistant.platform.base.fullduplex.FullDuplex;
import com.huawei.hiassistant.platform.base.interrupt.InterruptTtsInfo;
import com.huawei.hiassistant.platform.base.module.ActionGroupInterface;
import com.huawei.hiassistant.platform.base.module.IntentionExecutorInterface;
import com.huawei.hiassistant.platform.base.module.TimerInfo;
import com.huawei.hiassistant.platform.base.multipintentions.MultiIntentionManager;
import com.huawei.hiassistant.platform.base.northinterface.recognize.RecognizerIntent;
import com.huawei.hiassistant.platform.base.northinterface.tts.ClientIdConstant;
import com.huawei.hiassistant.platform.base.report.OperationReportUtils;
import com.huawei.hiassistant.platform.base.streamspeak.StreamSpeakManager;
import com.huawei.hiassistant.platform.base.util.BaseUtils;
import com.huawei.hiassistant.platform.base.util.IAssistantConfig;
import com.huawei.hiassistant.platform.base.util.InterruptUtil;
import com.huawei.hiassistant.platform.base.util.KitLog;
import com.huawei.hiassistant.platform.base.util.SecureIntentUtil;
import com.huawei.hiassistant.platform.base.util.StringUtils;
import com.huawei.hiassistant.platform.base.util.Utils;
import com.huawei.hiassistant.platform.base.util.VoiceBusinessFlowCache;
import com.huawei.hiassistant.platform.base.util.common.HeadsetScoManager;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;
public abstract class BaseActionGroup implements ActionGroupInterface {
protected static final String DIRECTIVE_PLACE_HOLDER_KEY_NAME = "placeHolderValues";
public static final String INDICATION_KEY = "UserInteraction_Indication";
private static final String TAG = "BaseActionGroup";
private static final String TTS_SUCCESS_CODE = "0";
protected volatile boolean isStopped = true;
protected IntentionExecutorInterface.CallBack intentionExecutorCallBack = createPseudoExecutorCallBack();
protected Map<String, Object> sharedDataMap = new HashMap();
private IntentionExecutorInterface.CallBack createPseudoExecutorCallBack() {
return new IntentionExecutorInterface.CallBack() {
@Override
public void onCommanderProcess(IntentionExecutorInterface.CommanderCode commanderCode, Object obj) {
KitLog.error(BaseActionGroup.TAG, "unexpected method onCommanderProcess call");
}
@Override
public void onError(IntentionExecutorInterface.ErrorCode errorCode, String str) {
KitLog.error(BaseActionGroup.TAG, "unexpected method onError call");
}
@Override
public void onExecutorResult(IntentionExecutorInterface.ExecutorCode executorCode, Object obj) {
KitLog.error(BaseActionGroup.TAG, "unexpected method onExecutorResult call");
}
@Override
public void onUiProcess(Object obj) {
KitLog.error(BaseActionGroup.TAG, "unexpected method onUiProcess call");
}
};
}
private Intent generateIntent(String str, Intent intent) {
if (intent == null) {
intent = new Intent();
}
intent.putExtra(RecognizerIntent.EXT_CLIENT_ID, ClientIdConstant.INTENTION_EXECUTOR);
return intent;
}
private boolean isInterruptAllowed(String str) {
if (FullDuplex.stateManager().isFullDuplexMode()) {
KitLog.debug(TAG, "isFullDuplexMode ,not support interrupt. ", new Object[0]);
return false;
}
int validLength = StringUtils.getValidLength(str);
if (validLength <= 4) {
KitLog.info(TAG, "isInterruptAllowed tts length = " + validLength);
return false;
}
if (!IAssistantConfig.getInstance().sdkConfig().isSupportInterrupt()) {
KitLog.info(TAG, "isInterruptAllowed InterruptUtil not support");
return false;
}
boolean booleanValue = ((Boolean) getSharedDataInDialog(INDICATION_KEY, Indication.class).map(new Function() {
@Override
public final Object apply(Object obj) {
return Boolean.valueOf(((Indication) obj).isInterrupt());
}
}).orElse(Boolean.FALSE)).booleanValue();
KitLog.info(TAG, "isInterruptAllowed isIndicationAllowed=" + booleanValue);
return booleanValue;
}
private void sendToSpeak(Intent intent, String str) {
if (intent.hasExtra("streamType")) {
KitLog.info(TAG, "use app custom");
} else if (IAssistantConfig.getInstance().sdkConfig().isSupportHeadsetTtsStream()) {
KitLog.info(TAG, "supportSetTts stream, use tts stream");
} else if (HeadsetScoManager.getInstance().isScoConnected()) {
KitLog.info(TAG, "sco is connected, use voice_call");
intent.putExtra("streamType", 0);
} else if (HeadsetScoManager.getInstance().isA2dpConnected()) {
KitLog.info(TAG, "a2dp is connected, use music");
intent.putExtra("streamType", 3);
} else {
KitLog.debug(TAG, "use tts", new Object[0]);
}
intent.putExtra(BaseConstants.INTENT_SPEAK_TEXT_CONTENT, str);
IntentionExecutorInterface.CommanderCode commanderCode = IntentionExecutorInterface.CommanderCode.SEND_SPEAK_DIRECTIVE;
if (intent.hasExtra("streamState")) {
commanderCode = IntentionExecutorInterface.CommanderCode.SEND_STREAM_SPEAK_DIRECTIVE;
}
this.intentionExecutorCallBack.onCommanderProcess(commanderCode, intent);
}
@Override
public void clear() {
stop();
KitLog.debug(TAG, "clear actiongroup", new Object[0]);
}
public void displayAndSpeakRobotContent(String str) {
sendRobotContentToUi(str);
sendTextToSpeak("0", str);
}
public Session getCurrentSession() {
return (Session) BaseUtils.getTargetInstance(this.sharedDataMap.get(RecognizerIntent.EXT_RECOGNIZE_SESSION), Session.class).orElse(null);
}
public IntentionExecutorInterface.CallBack getIntentionExecutorCallBack() {
return this.intentionExecutorCallBack;
}
public <T> Optional<T> getSharedDataInDialog(String str, Class<T> cls) {
Map<String, Object> map = this.sharedDataMap;
return (map == null || !map.containsKey(str)) ? Optional.empty() : BaseUtils.getTargetInstance(this.sharedDataMap.get(str), cls);
}
@Override
public void init(IntentionExecutorInterface.CallBack callBack) {
KitLog.debug(TAG, "init", new Object[0]);
this.isStopped = false;
if (callBack == null) {
KitLog.error(TAG, "IntentionExecutorInterface callBack null");
} else {
this.intentionExecutorCallBack = callBack;
}
}
public void removeTimer(int i) {
this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.REMOVE_TIMER, Integer.valueOf(i));
}
public void sendCacheableMsgToUi(String str, Intent intent) {
UiPayload uiPayload = new UiPayload();
uiPayload.setContent(str);
uiPayload.setIntent(intent);
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.UI_BACKGROUD, uiPayload, getCurrentSession()));
}
public void sendCardMsgToUi(UiConversationCard uiConversationCard) {
DisplayCardPayload displayCardPayload = new DisplayCardPayload();
displayCardPayload.setCard(uiConversationCard);
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.CARD_DISPLAY, displayCardPayload, getCurrentSession()));
}
public void sendChipsMsgToUi(UiPayload uiPayload) {
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.CHIPS_DISPLAY, uiPayload, getCurrentSession()));
}
public void sendControlMessage(String str, Intent intent) {
UiPayload uiPayload = new UiPayload();
uiPayload.setContent(str);
uiPayload.setIntent(intent);
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.CONTROL, uiPayload, getCurrentSession()));
}
public void sendDataMsgToUi(String str) {
UiPayload uiPayload = new UiPayload();
uiPayload.setContent(str);
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.DATA_DISPLAY, uiPayload, getCurrentSession()));
}
public void sendDisplayContentToUi(String str, String str2, boolean z) {
UiConversationCard uiConversationCard = new UiConversationCard();
uiConversationCard.setTemplateName(str);
UiConversationCard.TemplateData templateData = new UiConversationCard.TemplateData();
templateData.setText(str2);
templateData.setCorrectable(z);
templateData.setShowEvaluation(Boolean.parseBoolean(String.valueOf(this.sharedDataMap.get(RecognizerIntent.VISIBLE_OMT))));
uiConversationCard.setTemplateData(templateData);
sendCardMsgToUi(uiConversationCard);
}
public void sendHumanContentToUi(String str, boolean z) {
OperationReportUtils.getInstance().getTtsRecord().setDisplayTextHash(StringUtils.getStringSha256(str));
sendDisplayContentToUi("HumanMsgCard", str, z);
}
public void sendInitEngine() {
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.INIT_ENGINE, new UiPayload(), getCurrentSession()));
}
public void sendMessageToExecutor(VoiceKitMessage voiceKitMessage) {
this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.SEND_ACTION_TO_EXECUTOR, voiceKitMessage);
}
public void sendReleaseEngineMessage(String str) {
UiPayload uiPayload = new UiPayload();
uiPayload.setContent(str);
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.RELEASE_ENGINE, uiPayload, getCurrentSession()));
}
public void sendRobotContentToUi(String str) {
sendDisplayContentToUi("RobotMsgCard", str, false);
}
public void sendStreamTextToSpeak(String str, Intent intent) {
Object valueOf;
String filterString;
StringBuilder sb = new StringBuilder();
sb.append("speaking action start TTS, text = ");
if (IAssistantConfig.getInstance().isLogDebug()) {
valueOf = str;
} else {
valueOf = Integer.valueOf(TextUtils.isEmpty(str) ? 0 : str.length());
}
sb.append(valueOf);
KitLog.info(TAG, sb.toString());
Intent generateIntent = generateIntent(str, intent);
generateIntent.putExtra(RecognizerIntent.EXT_RECOGNIZE_SESSION, (Session) getSharedDataInDialog(RecognizerIntent.EXT_RECOGNIZE_SESSION, Session.class).orElse(null));
int secureIntentInt = SecureIntentUtil.getSecureIntentInt(intent, "streamState", -1);
if (secureIntentInt == 0) {
StreamSpeakManager.setLastStreamUtteranceId(UUID.randomUUID().toString());
}
if (SecureIntentUtil.getSecureIntentBoolean(intent, "isUserPlayback", false) || Utils.isNeedTtsSpeak()) {
filterString = StringUtils.getFilterString(str);
} else {
generateIntent.removeExtra("streamState");
filterString = "";
}
if (TextUtils.isEmpty(StreamSpeakManager.getLastStreamUtteranceId())) {
String uuid = UUID.randomUUID().toString();
generateIntent.putExtra("utteranceId", uuid);
StreamSpeakManager.setLastStreamUtteranceId(uuid);
} else {
generateIntent.putExtra("utteranceId", StreamSpeakManager.getLastStreamUtteranceId());
}
if (!generateIntent.hasExtra("streamState")) {
sendToSpeak(generateIntent, filterString);
return;
}
if (secureIntentInt == 0) {
Intent intent2 = new Intent(generateIntent);
intent2.putExtra("streamState", 0);
sendToSpeak(intent2, "");
}
if (!TextUtils.isEmpty(filterString)) {
Intent intent3 = new Intent(generateIntent);
intent3.putExtra("streamState", 1);
sendToSpeak(intent3, filterString);
}
if (secureIntentInt == 2) {
Intent intent4 = new Intent(generateIntent);
intent4.putExtra("streamState", 2);
sendToSpeak(intent4, "");
}
}
public void sendTextRecognizeMessage(String str, Intent intent) {
UiPayload uiPayload = new UiPayload();
uiPayload.setContent(str);
uiPayload.setIntent(intent);
this.intentionExecutorCallBack.onUiProcess(VoiceKitMessage.buildUiMessage(UiMessageType.START_TEXT_RECOGNIZE, uiPayload, getCurrentSession()));
}
public void sendTextToRecognize(String str) {
Intent intent = new Intent();
intent.putExtra("text", str);
this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.START_INTENT_ACQUISITION, intent);
}
public void sendTextToSpeak(String str) {
sendTextToSpeak("-1", str, null);
}
public void setBusinessSupportInterrupt(boolean z) {
KitLog.info(TAG, "setSupportInterrupt =" + z);
Optional sharedDataInDialog = getSharedDataInDialog(INDICATION_KEY, Indication.class);
if (sharedDataInDialog.isPresent()) {
((Indication) sharedDataInDialog.get()).setInterrupt(z);
return;
}
Indication indication = new Indication();
indication.setInterrupt(z);
indication.setInterruptWaitTime(InterruptUtil.getInterruptTimeOut());
this.sharedDataMap.put(INDICATION_KEY, indication);
}
@Override
public void setSharedDataInDialog(Map<String, Object> map) {
this.sharedDataMap = map;
}
public void startTimer(long j, int i) {
this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.START_TIMER, new TimerInfo(j, i));
}
@Override
public void stop() {
KitLog.debug(TAG, "stop actiongroup", new Object[0]);
this.isStopped = true;
}
public void sendTextToSpeak(String str, Intent intent) {
sendTextToSpeak("-1", str, intent);
}
public void sendTextToSpeak(String str, String str2) {
sendTextToSpeak(str, str2, null);
}
public <T> T getSharedDataInDialog(String str, Class<T> cls, T t) {
Map<String, Object> map = this.sharedDataMap;
return (map == null || !map.containsKey(str)) ? t : (T) BaseUtils.getTargetInstance(this.sharedDataMap.get(str), cls).orElse(t);
}
public void sendTextToRecognize(Intent intent) {
this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.START_INTENT_ACQUISITION, intent);
}
public void sendTextToSpeak(String str, String str2, Intent intent) {
Object valueOf;
StringBuilder sb = new StringBuilder();
sb.append("speaking action start TTS, text = ");
if (IAssistantConfig.getInstance().isLogDebug()) {
valueOf = str2;
} else {
valueOf = Integer.valueOf(TextUtils.isEmpty(str2) ? 0 : str2.length());
}
sb.append(valueOf);
KitLog.info(TAG, sb.toString());
Intent generateIntent = generateIntent(str2, intent);
Session session = (Session) getSharedDataInDialog(RecognizerIntent.EXT_RECOGNIZE_SESSION, Session.class).orElse(null);
generateIntent.putExtra(RecognizerIntent.EXT_RECOGNIZE_SESSION, session);
if (!Utils.isNeedTtsSpeak()) {
str2 = "";
}
VoiceBusinessFlowCache.VoiceFlowInfo orElse = session != null ? VoiceBusinessFlowCache.getInstance().getVoiceFlowInfo(session.getSessionId(), session.getInteractionId()).orElse(null) : null;
VoiceBusinessFlowCache.VoiceFlowInfo currentExecutingInfo = VoiceBusinessFlowCache.getInstance().getCurrentExecutingInfo();
if (IAssistantConfig.getInstance().sdkConfig().isSupportV5() && currentExecutingInfo != null) {
KitLog.info(TAG, "isSupportV5, currentVoiceFlowInfo get from VoiceBusinessFlowCache.");
orElse = currentExecutingInfo;
}
String filter = MultiIntentionManager.filter(orElse, str, str2, session);
MultiIntentionManager.setLastSpeakText(filter);
if (isInterruptAllowed(filter)) {
String secureIntentString = SecureIntentUtil.getSecureIntentString(generateIntent, "utteranceId");
if (TextUtils.isEmpty(secureIntentString)) {
secureIntentString = UUID.randomUUID().toString();
generateIntent.putExtra("utteranceId", secureIntentString);
}
Parcelable interruptTtsInfo = new InterruptTtsInfo(secureIntentString, filter, InterruptUtil.getInterruptTimeOut());
KitLog.debug(TAG, "interruptTtsId: {}", secureIntentString);
Intent intent2 = new Intent();
intent2.putExtra(RecognizerIntent.EXT_INTERRUPT_INFO, interruptTtsInfo);
sendControlMessage("START_RECORD", intent2);
}
sendToSpeak(generateIntent, filter);
}
}