导航菜单

页面标题

页面副标题

Petal Maps v4.7.0.310001 - SystemActionGroup.java 源代码

正在查看: Petal Maps v4.7.0.310001 应用的 SystemActionGroup.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.huawei.hiassistant.platform.commonaction.abilityaction;

import android.content.Intent;
import android.text.TextUtils;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.huawei.hiassistant.platform.base.VoiceKitSdkContext;
import com.huawei.hiassistant.platform.base.action.Action;
import com.huawei.hiassistant.platform.base.action.BaseActionGroup;
import com.huawei.hiassistant.platform.base.adapter.businessadapter.HmsProxyFactory;
import com.huawei.hiassistant.platform.base.bean.InteractionIdInfo;
import com.huawei.hiassistant.platform.base.bean.llmstatus.StreamingStatusManager;
import com.huawei.hiassistant.platform.base.bean.recognize.HeaderPayload;
import com.huawei.hiassistant.platform.base.bean.recognize.RecognizeContext;
import com.huawei.hiassistant.platform.base.bean.recognize.Session;
import com.huawei.hiassistant.platform.base.bean.recognize.VoiceContext;
import com.huawei.hiassistant.platform.base.bean.recognize.payload.Header;
import com.huawei.hiassistant.platform.base.bean.recognize.payload.Payload;
import com.huawei.hiassistant.platform.base.bean.util.GsonUtils;
import com.huawei.hiassistant.platform.base.fullduplex.FullDuplex;
import com.huawei.hiassistant.platform.base.interrupt.InterruptInfo;
import com.huawei.hiassistant.platform.base.interrupt.InterruptTtsInfo;
import com.huawei.hiassistant.platform.base.module.IntentionExecutorInterface;
import com.huawei.hiassistant.platform.base.module.ModuleInstanceFactory;
import com.huawei.hiassistant.platform.base.module.RecordStartType;
import com.huawei.hiassistant.platform.base.msg.AssistantMessage;
import com.huawei.hiassistant.platform.base.msg.PlatformMsg;
import com.huawei.hiassistant.platform.base.northinterface.recognize.RecognizerIntent;
import com.huawei.hiassistant.platform.base.report.OperationReportUtils;
import com.huawei.hiassistant.platform.base.util.BusinessFlowId;
import com.huawei.hiassistant.platform.base.util.DeviceUtil;
import com.huawei.hiassistant.platform.base.util.IAssistantConfig;
import com.huawei.hiassistant.platform.base.util.KitLog;
import com.huawei.hiassistant.platform.commonaction.abilityaction.SystemActionGroup;
import com.huawei.hiassistant.platform.commonaction.payload.system.AutoModeRetry;
import com.huawei.hiassistant.platform.commonaction.payload.system.CleanInterruptStatus;
import com.huawei.hiassistant.platform.commonaction.payload.system.HmsLoginPayload;
import com.huawei.hiassistant.platform.commonaction.payload.system.StartNewFullDuplexDialog;
import com.huawei.hiassistant.platform.commonaction.payload.system.SystemPayload;
import com.huawei.hiassistant.platform.commonaction.util.CommonUtil;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

public class SystemActionGroup extends BaseActionGroup {
    private static final int DEFAULT_SCENE_CODE = -1;
    private static final String PACKAGE_NAME = "packageName";
    private static final String SCENE_CODE = "sceneCode";
    private static final String SUPER_POWER_SAVING_BROADCAST_PERMISSION = "huawei.android.permission.HW_SIGNATURE_OR_SYSTEM";
    private static final String TAG = "SystemActionGroup";

    public static boolean lambda$handleFirstRoundDeny$1(JsonObject jsonObject) {
        return jsonObject.get(SCENE_CODE) != null;
    }

    public static Integer lambda$handleFirstRoundDeny$2(JsonObject jsonObject) {
        return Integer.valueOf(jsonObject.get(SCENE_CODE).getAsInt());
    }

    @Action(name = "ASREnded", nameSpace = "System")
    public int handleAsrEnded(Payload payload) {
        KitLog.debug(TAG, "handleAsrEnded", new Object[0]);
        InterruptInfo interruptInfo = ModuleInstanceFactory.State.platformState().getInterruptInfo(InteractionIdInfo.build(BusinessFlowId.getInstance().getSessionId(), BusinessFlowId.getInstance().getInteractionId()));
        if (interruptInfo == null) {
            KitLog.debug(TAG, "handleAsrEnded interruptTtsInfo is null", new Object[0]);
            return 0;
        }
        InterruptTtsInfo interruptTtsInfo = interruptInfo.getInterruptTtsInfo();
        if (interruptTtsInfo == null) {
            KitLog.debug(TAG, "handleAsrEnded interruptTtsInfo is null", new Object[0]);
            return 0;
        }
        if (ModuleInstanceFactory.Ability.tts().isSpeaking()) {
            KitLog.info(TAG, "handleAsrEnded tts not finished");
            return 0;
        }
        if (interruptInfo.getInterruptStatus() == 2) {
            KitLog.info(TAG, "handleAsrEnded not normal");
            return 0;
        }
        KitLog.info(TAG, "handleAsrEnded fire timeout message");
        removeTimer(PlatformMsg.CtlExt.INTENTION_EXECUTOR_INTERRUPT_TIMER_EXPIRED);
        startTimer(interruptTtsInfo.getInterruptWaitTime(), PlatformMsg.CtlExt.INTENTION_EXECUTOR_INTERRUPT_TIMER_EXPIRED);
        return 0;
    }

    @Action(name = "AutoModeRetry", nameSpace = "System")
    public int handleAutoModeRetry(AutoModeRetry autoModeRetry) {
        String text = autoModeRetry.getText();
        KitLog.debug(TAG, "handleAutoModeRetry text ={}", text);
        if (TextUtils.isEmpty(text)) {
            return 0;
        }
        final Intent intent = new Intent();
        intent.putExtra("text", text);
        intent.putExtra(RecognizerIntent.EXT_RECOGNIZE_MODE, RecognizerIntent.HW_CLOUD_RECOGNIZER);
        intent.putExtra(RecognizerIntent.AUTO_MODE_RETRY, true);
        VoiceKitSdkContext.getInstance().get(RecognizerIntent.EXT_VOICE_CONTEXT, String.class).ifPresent(new Consumer() {
            @Override
            public final void accept(Object obj) {
                intent.putExtra(RecognizerIntent.EXT_VOICE_CONTEXT, (String) obj);
            }
        });
        sendTextToRecognize(intent);
        return 0;
    }

    @Action(name = "SendBroadcast", nameSpace = "System")
    public int handleFirstRoundDeny(SystemPayload systemPayload) {
        KitLog.debug(TAG, "handleFirstRoundDeny", new Object[0]);
        if (systemPayload == null) {
            KitLog.error(TAG, "handleFirstRoundDeny ProviderPayload is null.");
            return 0;
        }
        if (KitLog.isDebugOn()) {
            KitLog.debug(TAG, "handleFirstRoundDeny payload:{}", GsonUtils.toJson(systemPayload));
        }
        String action = systemPayload.getAction();
        String packageName = systemPayload.getPackageName();
        Integer num = (Integer) Optional.ofNullable(systemPayload.getCallParams()).filter(new Predicate() {
            @Override
            public final boolean test(Object obj) {
                boolean lambda$handleFirstRoundDeny$1;
                lambda$handleFirstRoundDeny$1 = SystemActionGroup.lambda$handleFirstRoundDeny$1((JsonObject) obj);
                return lambda$handleFirstRoundDeny$1;
            }
        }).map(new Function() {
            @Override
            public final Object apply(Object obj) {
                Integer lambda$handleFirstRoundDeny$2;
                lambda$handleFirstRoundDeny$2 = SystemActionGroup.lambda$handleFirstRoundDeny$2((JsonObject) obj);
                return lambda$handleFirstRoundDeny$2;
            }
        }).orElse(-1);
        int intValue = num.intValue();
        KitLog.debug(TAG, "params not null action={}, packageName={}, sceneCode={}", action, packageName, num);
        if (TextUtils.isEmpty(action) || TextUtils.isEmpty(packageName) || intValue == -1) {
            KitLog.warn(TAG, "params action or packageName or sceneCode is null");
            return 0;
        }
        Intent intent = new Intent();
        intent.setAction(action);
        intent.setPackage(packageName);
        intent.putExtra("packageName", packageName);
        intent.putExtra(SCENE_CODE, intValue);
        IAssistantConfig.getInstance().getAppContext().sendBroadcast(intent, SUPER_POWER_SAVING_BROADCAST_PERMISSION);
        return 0;
    }

    @Action(name = "CleanInterruptStatus", nameSpace = "System")
    public int handleInterruptFail(CleanInterruptStatus cleanInterruptStatus) {
        InterruptTtsInfo interruptTtsInfo;
        KitLog.debug(TAG, "handleInterruptFail", new Object[0]);
        if (!ModuleInstanceFactory.Ability.tts().isSpeaking()) {
            KitLog.info(TAG, "handleInterruptFail tts completed");
            removeTimer(PlatformMsg.CtlExt.INTENTION_EXECUTOR_INTERRUPT_TIMER_EXPIRED);
            this.intentionExecutorCallBack.onExecutorResult(IntentionExecutorInterface.ExecutorCode.CALLBACK_RESULT, Boolean.TRUE);
            return 0;
        }
        if (!cleanInterruptStatus.isInterruptRecord()) {
            KitLog.info(TAG, "handleInterruptFail no need interrupt again");
            return 0;
        }
        InterruptInfo interruptInfo = ModuleInstanceFactory.State.platformState().getInterruptInfo(InteractionIdInfo.build(BusinessFlowId.getInstance().getSessionId(), BusinessFlowId.getInstance().getInteractionId()));
        if (interruptInfo == null || (interruptTtsInfo = interruptInfo.getInterruptTtsInfo()) == null || !IAssistantConfig.getInstance().sdkConfig().isSupportInterrupt()) {
            return 0;
        }
        KitLog.info(TAG, "handleInterruptFail tts not completed");
        Intent intent = new Intent();
        intent.putExtra(RecognizerIntent.EXT_INTERRUPT_INFO, interruptTtsInfo);
        sendControlMessage("START_RECORD", intent);
        return 1;
    }

    @Action(name = "StartNewFullDuplexDialog", nameSpace = "System")
    public int handleRejectRecognize(StartNewFullDuplexDialog startNewFullDuplexDialog) {
        KitLog.debug(TAG, "handleRejectRecognize startNewFullDuplexDialog={}", startNewFullDuplexDialog);
        if (this.intentionExecutorCallBack == null) {
            KitLog.error(TAG, "intentionExecutorCallBack is null.");
            return 0;
        }
        if (!startNewFullDuplexDialog.isContinuousListening()) {
            Session currentSession = getCurrentSession();
            StreamingStatusManager.StreamingState currentStreamingState = StreamingStatusManager.getInstance().getCurrentStreamingState(InteractionIdInfo.build(currentSession.getSessionId(), currentSession.getInteractionId()));
            if (currentStreamingState != null && currentSession.isFullDuplexMode() && (currentStreamingState.equals(StreamingStatusManager.StreamingState.STREAMING_START) || currentStreamingState.equals(StreamingStatusManager.StreamingState.STREAMING_ON))) {
                return 0;
            }
            KitLog.info(TAG, "handleRejectRecognize isContinuousListening = false");
            this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.CANCEL_FULLDUPLEX_RECOGNIZE, null);
            return 0;
        }
        String rejection = startNewFullDuplexDialog.getRejection();
        KitLog.info(TAG, "handleRejectRecognize rejection = " + rejection);
        Intent intent = new Intent();
        intent.putExtra(RecognizerIntent.EXT_VOICE_CONTEXT, GsonUtils.toJson(CommonUtil.setContextProperty(new RecognizeContext(), "System", "ClientContext", "continuousListening", new JsonPrimitive(Boolean.TRUE))));
        if (TextUtils.equals(rejection, FullDuplex.Constants.FULLDUPLEX_REJECT)) {
            intent.putExtra(RecognizerIntent.EXT_FULLDUPLEX_REJECT_INFO, true);
            if (OperationReportUtils.getInstance().getIntentionExecuteRecord().isDialogFinishedFlag()) {
                OperationReportUtils.getInstance().getIntentionExecuteRecord().setEndTime(String.valueOf(System.currentTimeMillis()));
                OperationReportUtils.getInstance().reportIntentionExecuteRecord();
            }
        }
        intent.putExtra(RecognizerIntent.RECORD_TYPE, (TextUtils.equals(rejection, FullDuplex.Constants.FULLDUPLEX_ACCEPT) ? RecordStartType.CONTINUE : RecordStartType.OTHER).getType());
        this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.SEND_APP_CONTINUE_DIALOG, intent);
        return 0;
    }

    @Action(name = "RequestHuaweiAT", nameSpace = "Common")
    public void requestHuaweiAt(Payload payload) {
        Session session;
        KitLog.info(TAG, "requestHuaweiAt");
        JsonObject requestAccessInfoSynchronize = HmsProxyFactory.getHmsDelegateProxy().requestAccessInfoSynchronize(IAssistantConfig.getInstance().getAppContext());
        Header header = new Header("HuaweiAT", "System");
        Payload payload2 = new Payload();
        payload2.setJsonObject(requestAccessInfoSynchronize);
        HeaderPayload headerPayload = new HeaderPayload();
        headerPayload.setHeader(header);
        headerPayload.setPayload(payload2);
        VoiceContext voiceContext = new VoiceContext();
        voiceContext.setNeedTimeoutCheck(true);
        if (DeviceUtil.isHomePanel()) {
            voiceContext.setNeedWebsocket(true);
        }
        voiceContext.getVoiceContexts().add(headerPayload);
        Map<String, Object> map = this.sharedDataMap;
        if (map != null && map.containsKey(RecognizerIntent.EXT_RECOGNIZE_SESSION)) {
            Object obj = this.sharedDataMap.get(RecognizerIntent.EXT_RECOGNIZE_SESSION);
            if (obj instanceof Session) {
                session = (Session) obj;
                this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.UPDATE_VOICE_CONTEXT, AssistantMessage.builder(GsonUtils.toJson(voiceContext), session).build());
            }
        }
        session = null;
        this.intentionExecutorCallBack.onCommanderProcess(IntentionExecutorInterface.CommanderCode.UPDATE_VOICE_CONTEXT, AssistantMessage.builder(GsonUtils.toJson(voiceContext), session).build());
    }

    @Action(name = "RequestHuaweiLogin", nameSpace = "Common")
    public int requestHuaweiLogin(HmsLoginPayload hmsLoginPayload) {
        KitLog.info(TAG, "requestHuaweiLogin");
        Intent intent = new Intent();
        intent.putExtra("utterance", hmsLoginPayload.getUtterance());
        sendControlMessage("HMS_LOGIN", intent);
        return 0;
    }
}