导航菜单

页面标题

页面副标题

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

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

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


package com.huawei.hiassistant.voice.abilityconnector.operation;

import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.ArrayMap;
import com.huawei.hiassistant.platform.base.bean.VoicekitCallbackInfo;
import com.huawei.hiassistant.platform.base.bean.recognize.MessageConstants;
import com.huawei.hiassistant.platform.base.bean.recognize.VoiceEvent;
import com.huawei.hiassistant.platform.base.bean.util.GsonUtils;
import com.huawei.hiassistant.platform.base.grs.GrsHelper;
import com.huawei.hiassistant.platform.base.module.ModuleInstanceFactory;
import com.huawei.hiassistant.platform.base.module.ability.DecisionCallbackAdapter;
import com.huawei.hiassistant.platform.base.module.ability.OperationAbilityInterface;
import com.huawei.hiassistant.platform.base.northinterface.postoperation.VoicekitCallback;
import com.huawei.hiassistant.platform.base.policy.RealMachineStatusManager;
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.base.util.SecureIntentUtil;
import com.huawei.hiassistant.voice.abilityconnector.recognizer.cloud.api.AuthRequest;
import com.huawei.hiassistant.voice.abilityconnector.recognizer.cloud.common.HiVoiceConstants;
import com.huawei.hiassistant.voice.common.bean.DialogRequestParam;
import com.huawei.hiassistant.voice.common.util.CommonDataUtil;
import defpackage.yab;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;

public class OperationAbilityProxy implements OperationAbilityInterface {
    private static final String DS_FEEDBACK_EVENT_NAME = "huawei.intent.action.feedBack";
    private static final String ERROR_CONTENT = "{\"errorCode\":\"%s\",\"errorMsg\":\"%s\"}";
    private static final String PROPERTY_NAME_HW_AT = "huaweiAT";
    private static final String PROPERTY_NAME_UID = "uid";
    private static final int REPORT_DS_FAILED = -1;
    private static final long REPORT_DS_TIMEOUT = 1000;
    private static final String TAG = "OperationAbilityProxy";
    private DecisionCallBackImpl decisionCallbackImpl = new DecisionCallBackImpl();

    public static class DecisionCallBackImpl implements DecisionCallbackAdapter {
        private VoicekitCallback callBack;

        private DecisionCallBackImpl() {
        }

        public VoicekitCallback getCallBack() {
            return this.callBack;
        }

        @Override
        public void onResult(Map map) throws RemoteException {
            KitLog.info(OperationAbilityProxy.TAG, "onResult.");
            KitLog.debug(OperationAbilityProxy.TAG, "ds post result: {}", GsonUtils.toJson(map));
            Object orElse = Optional.ofNullable(map.get("errorCode")).orElse("-1");
            Object orElse2 = Optional.ofNullable(map.get("content")).orElse("");
            int i = -1;
            if (orElse instanceof String) {
                try {
                    i = Integer.parseInt((String) orElse);
                } catch (NumberFormatException unused) {
                    KitLog.error(OperationAbilityProxy.TAG, "isResultValid NumberFormatException");
                }
            }
            Bundle bundle = new Bundle();
            bundle.putString("operationResponse", GsonUtils.toJson(orElse2));
            final VoicekitCallbackInfo voicekitCallbackInfo = new VoicekitCallbackInfo(i, bundle);
            Optional.ofNullable(this.callBack).ifPresent(new Consumer() {
                @Override
                public final void accept(Object obj) {
                    ((VoicekitCallback) obj).onCallback(VoicekitCallbackInfo.this);
                }
            });
        }

        @Override
        public void onTimeout() {
            KitLog.error(OperationAbilityProxy.TAG, "onTimeout.");
            final VoicekitCallbackInfo voicekitCallbackInfo = new VoicekitCallbackInfo(-1, new Bundle());
            Optional.ofNullable(this.callBack).ifPresent(new Consumer() {
                @Override
                public final void accept(Object obj) {
                    ((VoicekitCallback) obj).onCallback(VoicekitCallbackInfo.this);
                }
            });
        }

        public void setCallBack(VoicekitCallback voicekitCallback) {
            this.callBack = voicekitCallback;
        }
    }

    private AuthRequest buildAuthRequest(Bundle bundle, Intent intent) {
        String str = IAssistantConfig.getInstance().sdkConfig().isSupportAuthCode() ? AuthRequest.TYPE_AUTH_CODE : AuthRequest.TYPE_COMMON;
        String secureIntentString = SecureIntentUtil.getSecureIntentString(intent, "huaweiAT");
        String secureIntentString2 = SecureIntentUtil.getSecureIntentString(intent, "uid");
        AuthRequest createAuthRequest = CommonDataUtil.createAuthRequest(str, secureIntentString2);
        if (TextUtils.equals(str, AuthRequest.TYPE_COMMON)) {
            if (TextUtils.isEmpty(secureIntentString) || TextUtils.isEmpty(secureIntentString2)) {
                KitLog.info(TAG, "invalid hwAT");
            } else {
                KitLog.info(TAG, "valid hwAT");
                createAuthRequest.setHwAt(secureIntentString);
                createAuthRequest.setUid(secureIntentString2);
            }
        }
        createAuthRequest.setConnectAddress(SecureIntentUtil.getSecureBundleString(bundle, "recognizeUrl", ""));
        return createAuthRequest;
    }

    private Bundle getRequestBundle(String str, String str2, String str3, String str4, Intent intent) {
        Bundle bundle = new Bundle();
        bundle.putString("requestBody", str);
        String secureIntentString = SecureIntentUtil.getSecureIntentString(intent, "event");
        if (TextUtils.isEmpty(secureIntentString)) {
            bundle.putString("requestEvent", HiVoiceConstants.EventName.EVENT_POST_OPERATION_MESSAGE);
        } else {
            bundle.putString("requestEvent", secureIntentString);
        }
        bundle.putString("messageName", str2);
        bundle.putString("sender", str3);
        bundle.putString("receiver", str4);
        bundle.putString("sessionId", BusinessFlowId.getInstance().getSessionId());
        bundle.putString("interactionId", String.valueOf((int) BusinessFlowId.getInstance().getInteractionId()));
        bundle.putString("recognizeUrl", GrsHelper.getInstance().getTrsAddress(IAssistantConfig.getInstance().getAppContext(), RealMachineStatusManager.getInstance().isRealMachineStatus(), DeviceUtil.getDeviceName()));
        return bundle;
    }

    private void handleOperationRequest(Intent intent, VoicekitCallback voicekitCallback) {
        KitLog.info(TAG, "handleOperationRequest");
        String secureIntentString = SecureIntentUtil.getSecureIntentString(intent, "sender");
        String secureIntentString2 = SecureIntentUtil.getSecureIntentString(intent, "receiver");
        String secureIntentString3 = SecureIntentUtil.getSecureIntentString(intent, "messageName");
        String secureIntentString4 = SecureIntentUtil.getSecureIntentString(intent, "OperationMsg");
        if (TextUtils.isEmpty(secureIntentString3) || TextUtils.isEmpty(secureIntentString4) || TextUtils.isEmpty(secureIntentString) || TextUtils.isEmpty(secureIntentString2)) {
            KitLog.error(TAG, "postOperationMessage params error");
            return;
        }
        KitLog.debug(TAG, "handleOperationRequest {}", secureIntentString4);
        Bundle requestBundle = getRequestBundle(secureIntentString4, secureIntentString3, secureIntentString, secureIntentString2, intent);
        AuthRequest buildAuthRequest = buildAuthRequest(requestBundle, intent);
        requestBundle.putString("authRequestBody", GsonUtils.toJson(buildAuthRequest));
        requestBundle.putString("huaweiAT", buildAuthRequest.getHwAt());
        requestBundle.putString("hwUid", buildAuthRequest.getUid());
        new yab(voicekitCallback, buildAuthRequest, IAssistantConfig.getInstance().getAppContext(), requestBundle, -1L).c();
    }

    private void handleVisionRequest(Intent intent, VoicekitCallback voicekitCallback) {
        KitLog.debug(TAG, "handleVisionRequest", new Object[0]);
        String secureIntentString = SecureIntentUtil.getSecureIntentString(intent, "voiceEvent");
        long secureIntentLong = SecureIntentUtil.getSecureIntentLong(intent, "timeout", -1L);
        VoiceEvent voiceEvent = (VoiceEvent) GsonUtils.toBean(secureIntentString, VoiceEvent.class);
        if (voiceEvent == null || voiceEvent.getEvents().isEmpty()) {
            KitLog.warn(TAG, "invalid input.");
            return;
        }
        DialogRequestParam dialogRequestParam = new DialogRequestParam(null);
        dialogRequestParam.getSession().setReceiver(MessageConstants.Receiver.MSG_RECEIVER_CLOUD_DM).setMessageName(MessageConstants.MessageName.MSG_NAME_UPDATE_VOICE_EVENT);
        dialogRequestParam.addContexts(voiceEvent.getContexts());
        dialogRequestParam.addEvents(voiceEvent.getEvents());
        Bundle requestBundle = getRequestBundle(GsonUtils.toJson(dialogRequestParam), "", "APP", MessageConstants.Receiver.MSG_RECEIVER_CLOUD_DM, intent);
        AuthRequest buildAuthRequest = buildAuthRequest(requestBundle, intent);
        requestBundle.putString("authRequestBody", GsonUtils.toJson(buildAuthRequest));
        requestBundle.putString("huaweiAT", buildAuthRequest.getHwAt());
        requestBundle.putString("hwUid", buildAuthRequest.getUid());
        new yab(voicekitCallback, buildAuthRequest, IAssistantConfig.getInstance().getAppContext(), requestBundle, secureIntentLong).c();
    }

    @Override
    public boolean isInitEngineFinished() {
        return true;
    }

    @Override
    public void postMessage(Intent intent, VoicekitCallback voicekitCallback) {
        KitLog.info(TAG, "postMessage");
        if (intent == null || voicekitCallback == null) {
            KitLog.error(TAG, "postOperationMessage operationInfo or callBack is Null");
            return;
        }
        String secureIntentString = SecureIntentUtil.getSecureIntentString(intent, "sender");
        String secureIntentString2 = SecureIntentUtil.getSecureIntentString(intent, "receiver");
        if (TextUtils.isEmpty(secureIntentString) || TextUtils.isEmpty(secureIntentString2)) {
            KitLog.error(TAG, "post message params error: sender or receiver is empty.");
            return;
        }
        if ("VoiceKit".equals(secureIntentString2)) {
            return;
        }
        if (!MessageConstants.Receiver.MSG_RECEIVER_NATIVE_DS.equals(secureIntentString2)) {
            if (TextUtils.equals(secureIntentString2, "Vision")) {
                handleVisionRequest(intent, voicekitCallback);
                return;
            } else {
                handleOperationRequest(intent, voicekitCallback);
                return;
            }
        }
        String str = (String) Optional.ofNullable(SecureIntentUtil.getSecureIntentString(intent, "eventName")).orElse("");
        String str2 = (String) Optional.ofNullable(SecureIntentUtil.getSecureIntentString(intent, "dataId")).orElse("");
        String str3 = (String) Optional.ofNullable(SecureIntentUtil.getSecureIntentString(intent, "postInfo")).orElse("");
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || TextUtils.isEmpty(str3)) {
            KitLog.warn(TAG, "eventName or dataId or postInfo is empty.");
            return;
        }
        ArrayMap arrayMap = new ArrayMap();
        arrayMap.put("content", str3);
        if (DS_FEEDBACK_EVENT_NAME.equals(str)) {
            ModuleInstanceFactory.Ability.decisionService().executeEvent(str, str2, arrayMap, false);
        } else {
            this.decisionCallbackImpl.setCallBack(voicekitCallback);
            ModuleInstanceFactory.Ability.decisionService().executeEvent(str, str2, arrayMap, this.decisionCallbackImpl, 1000L);
        }
    }

    @Override
    public void destroy() {
    }

    @Override
    public void initConnector() {
    }
}