导航菜单

页面标题

页面副标题

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

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

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


package com.huawei.hiai.asr.local;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import com.huawei.hiai.asr.AsrListener;
import com.huawei.hiai.asr.IAsrService;
import com.huawei.hiai.asr.ISdkAsrEngine;
import com.huawei.hiai.asr.Log;
import com.huawei.hiai.asr.local.AsrLocalEngine;
import com.huawei.hiai.asr.local.a;
import com.huawei.hiai.pdk.utils.AppUtil;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Consumer;

public class AsrLocalEngine implements ISdkAsrEngine {
    private static HandlerThread k;
    private c b;
    private final Context c;
    private Handler d;
    private IAsrService e;
    private AsrListener f;
    private com.huawei.hiai.asr.local.a g;
    private static final Object i = new Object();
    private static final Object j = new Object();
    private static final Uri l = Uri.parse("content://com.huawei.hiai.asr.feature");
    private d a = null;
    private final LinkedBlockingQueue<Message> h = new LinkedBlockingQueue<>();

    public class a extends Handler {
        public a(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message message) {
            AsrLocalEngine.this.d(message);
        }
    }

    public class b implements Runnable {
        final Looper a;
        final AsrListener b;

        public b(Looper looper, AsrListener asrListener) {
            this.a = looper;
            this.b = asrListener;
        }

        @Override
        public void run() {
            AsrLocalEngine.this.a = AsrLocalEngine.this.new d(this.a);
            if (AsrLocalEngine.this.g == null) {
                Log.i("AsrLocalEngine", "init, create new mListener");
                AsrLocalEngine.this.g = new com.huawei.hiai.asr.local.a(this.b);
            }
            synchronized (AsrLocalEngine.j) {
                AsrLocalEngine.this.g.a(AsrLocalEngine.this.a);
            }
            AsrLocalEngine.this.c();
        }
    }

    public class c implements ServiceConnection {
        private boolean a;

        public class a implements Runnable {
            final ComponentName a;
            final IBinder b;

            public a(ComponentName componentName, IBinder iBinder) {
                this.a = componentName;
                this.b = iBinder;
            }

            @Override
            public void run() {
                c cVar = c.this;
                AsrLocalEngine.this.a(this.a, this.b, cVar.a);
            }
        }

        public class b implements Runnable {
            final ComponentName a;

            public b(ComponentName componentName) {
                this.a = componentName;
            }

            @Override
            public void run() {
                AsrLocalEngine.this.a(this.a);
            }
        }

        public c() {
        }

        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            boolean post;
            Log.w("AsrLocalEngine", "onServiceConnected");
            synchronized (AsrLocalEngine.j) {
                try {
                    post = AsrLocalEngine.this.d != null ? AsrLocalEngine.this.d.post(new a(componentName, iBinder)) : false;
                } catch (Throwable th) {
                    throw th;
                }
            }
            if (post) {
                return;
            }
            AsrLocalEngine.this.a(componentName, iBinder, this.a);
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            boolean post;
            Log.w("AsrLocalEngine", "onServiceDisconnected");
            synchronized (AsrLocalEngine.j) {
                try {
                    post = AsrLocalEngine.this.d != null ? AsrLocalEngine.this.d.post(new b(componentName)) : false;
                } catch (Throwable th) {
                    throw th;
                }
            }
            if (!post) {
                AsrLocalEngine.this.a(componentName);
            }
            Log.d("AsrLocalEngine", "onServiceDisconnected - Success");
        }

        public void a(boolean z) {
            this.a = z;
        }
    }

    public class d extends Handler {
        public d(Looper looper) {
            super(looper);
        }

        private boolean a(Message message) {
            Object obj = message.obj;
            switch (message.what) {
                case 1:
                    if (!(obj instanceof AsrListener)) {
                        return true;
                    }
                    ((AsrListener) obj).onBeginningOfSpeech();
                    return true;
                case 2:
                    if (!(obj instanceof a.C0018a)) {
                        return true;
                    }
                    a.C0018a c0018a = (a.C0018a) obj;
                    c0018a.b().onBufferReceived(c0018a.a());
                    return true;
                case 3:
                    if (!(obj instanceof AsrListener)) {
                        return true;
                    }
                    ((AsrListener) obj).onEndOfSpeech();
                    return true;
                case 4:
                    if (!(obj instanceof a.b)) {
                        return true;
                    }
                    a.b bVar = (a.b) obj;
                    bVar.c().onError(bVar.b());
                    return true;
                case 5:
                    if (obj instanceof a.b) {
                        a.b bVar2 = (a.b) obj;
                        bVar2.c().onInit(bVar2.a());
                        return true;
                    }
                    if (!(obj instanceof Bundle)) {
                        return true;
                    }
                    AsrLocalEngine.this.f.onInit((Bundle) obj);
                    return true;
                case 6:
                    if (!(obj instanceof a.b)) {
                        return true;
                    }
                    a.b bVar3 = (a.b) obj;
                    bVar3.c().onResults(bVar3.a());
                    return true;
                default:
                    return false;
            }
        }

        private boolean b(Message message) {
            Object obj = message.obj;
            switch (message.what) {
                case 7:
                    if (!(obj instanceof a.b)) {
                        return true;
                    }
                    a.b bVar = (a.b) obj;
                    bVar.c().onPartialResults(bVar.a());
                    return true;
                case 8:
                    if (!(obj instanceof a.c)) {
                        return true;
                    }
                    a.c cVar = (a.c) obj;
                    cVar.a().onRmsChanged(cVar.b());
                    return true;
                case 9:
                    if (!(obj instanceof a.b)) {
                        return true;
                    }
                    a.b bVar2 = (a.b) obj;
                    bVar2.c().onEvent(bVar2.b(), bVar2.a());
                    return true;
                case 10:
                    if (!(obj instanceof AsrListener)) {
                        return true;
                    }
                    ((AsrListener) obj).onEnd();
                    return true;
                case 11:
                    if (!(obj instanceof a.b)) {
                        return true;
                    }
                    a.b bVar3 = (a.b) obj;
                    bVar3.c().onLexiconUpdated(bVar3.d(), bVar3.b());
                    return true;
                case 12:
                    if (!(obj instanceof AsrListener)) {
                        return true;
                    }
                    ((AsrListener) obj).onRecordStart();
                    return true;
                default:
                    return false;
            }
        }

        private boolean c(Message message) {
            Object obj = message.obj;
            switch (message.what) {
                case 13:
                    if (!(obj instanceof AsrListener)) {
                        return true;
                    }
                    ((AsrListener) obj).onRecordEnd();
                    return true;
                case 14:
                    AsrLocalEngine.this.f.onServiceConnected();
                    return true;
                case 15:
                    AsrLocalEngine.this.f.onServiceDisconnected();
                    return true;
                case 16:
                    if (!(obj instanceof a.b)) {
                        return true;
                    }
                    a.b bVar = (a.b) obj;
                    bVar.c().onSubText(bVar.a());
                    return true;
                case 17:
                    if (!(obj instanceof a.b)) {
                        return true;
                    }
                    a.b bVar2 = (a.b) obj;
                    bVar2.c().onUpdateParams(bVar2.a());
                    return true;
                default:
                    return false;
            }
        }

        @Override
        public void handleMessage(Message message) {
            if (message == null) {
                return;
            }
            int i = message.what;
            if (i != 8 && i != 2 && i != 7) {
                Log.i("AsrLocalEngine", "handleMessage engine callBack is: " + message.what);
            }
            if (a(message) || b(message) || c(message)) {
                return;
            }
            Log.d("AsrLocalEngine", "unknown message");
        }
    }

    public static class e {
        private final Intent a;
        private final byte[] b;
        private final int c;

        public e(Intent intent, byte[] bArr, int i) {
            this.a = intent;
            this.b = bArr;
            this.c = i;
        }
    }

    public static class f {
        private final Intent a;
        private final AsrListener b;

        public f(Intent intent, AsrListener asrListener) {
            this.a = intent;
            this.b = asrListener;
        }
    }

    public AsrLocalEngine(Context context) {
        this.d = null;
        this.c = context;
        synchronized (j) {
            this.d = new a(e());
        }
    }

    private void f(Intent intent) {
        IAsrService b2 = b();
        if (b2 == null || this.g == null) {
            return;
        }
        try {
            if (b2.checkServerVersion(2)) {
                b2.updateLexicon(intent, this.g);
                Log.d("AsrLocalEngine", "service update lexicon command succeeded");
            } else {
                this.g.onError(15);
            }
        } catch (RemoteException | SecurityException unused) {
            Log.e("AsrLocalEngine", "updateLexicon() failed");
            this.g.onError(24);
        }
    }

    private void g() {
        Log.i("AsrLocalEngine", "handleDestroy");
        if (this.e != null && this.g != null) {
            try {
                if (!com.huawei.hiai.asr.b.a(this.c)) {
                    Log.i("AsrLocalEngine", "handleDestroy,not oda device");
                    this.e.cancel(this.g);
                }
                this.e.destroy(this.g);
            } catch (RemoteException | SecurityException unused) {
                Log.e("AsrLocalEngine", "destroy() failed");
            }
        }
        j();
        Log.i("AsrLocalEngine", "handleDestroy completed");
    }

    private void h() {
        com.huawei.hiai.asr.local.a aVar;
        IAsrService b2 = b();
        if (b2 == null || (aVar = this.g) == null) {
            return;
        }
        try {
            b2.stopListening(aVar);
            Log.d("AsrLocalEngine", "service stop listening command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "stopListening() failed");
            this.g.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "stopListening() failed");
            this.g.onError(5);
        }
    }

    private boolean i() {
        return this.b == null;
    }

    private void j() {
        Context context;
        Log.i("AsrLocalEngine", "releaseServiceData");
        this.h.clear();
        c cVar = this.b;
        if (cVar != null && (context = this.c) != null) {
            try {
                context.unbindService(cVar);
            } catch (IllegalArgumentException | SecurityException unused) {
                Log.e("AsrLocalEngine", "releaseServiceData unbindService exception");
            }
        }
        this.b = null;
        this.e = null;
        this.g = null;
    }

    private void k() {
        synchronized (j) {
            try {
                Handler handler = this.d;
                if (handler != null) {
                    handler.removeCallbacksAndMessages(null);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override
    public void authenticate(Intent intent) {
        Log.i("AsrLocalEngine", "authenticate");
    }

    @Override
    public void cancel() {
        e(Message.obtain((Handler) null, 3));
    }

    @Override
    public void deleteUserData(Intent intent, AsrListener asrListener) {
        Log.i("AsrLocalEngine", "deleteUserData");
    }

    @Override
    public void destroy() {
        Log.i("AsrLocalEngine", "destroy");
        k();
        this.h.clear();
        e(Message.obtain((Handler) null, 7));
    }

    @Override
    public int getEngineMode() {
        return 0;
    }

    @Override
    public Bundle getRegion() {
        Log.i("AsrLocalEngine", "getRegion");
        return new Bundle();
    }

    @Override
    public void init(Intent intent, AsrListener asrListener) {
        Log.i("AsrLocalEngine", "init");
        this.f = asrListener;
        a(new b(e(), asrListener));
        e(Message.obtain(null, 4, new f(intent, asrListener)));
    }

    @Override
    public java.util.Optional<android.os.Bundle> isFeatureSupport(android.os.Bundle r5) {
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hiai.asr.local.AsrLocalEngine.isFeatureSupport(android.os.Bundle):java.util.Optional");
    }

    @Override
    public void setParameter(Intent intent) {
        Log.i("AsrLocalEngine", "setParameter");
        e(Message.obtain(null, 9, intent));
    }

    @Override
    public void startListening(Intent intent) {
        if (intent == null) {
            throw new IllegalArgumentException("intent must not be null");
        }
        e(Message.obtain(null, 1, intent));
    }

    @Deprecated
    public void startPermissionRequestForEngine() {
        Log.e("AsrLocalEngine", "permission will request by engine self");
    }

    @Override
    public void stopListening() {
        e(Message.obtain((Handler) null, 2));
    }

    @Override
    public void updateLexicon(Intent intent) {
        if (intent == null) {
            throw new IllegalArgumentException("intent must not be null");
        }
        e(Message.obtain(null, 5, intent));
    }

    @Override
    public void updateParams(Intent intent) {
        Log.i("AsrLocalEngine", "updateParams");
        e(Message.obtain(null, 11, intent));
    }

    @Override
    public void writePcm(byte[] bArr, int i2) {
        e(Message.obtain(null, 6, new e(null, bArr, i2)));
    }

    private IAsrService b() {
        IAsrService iAsrService = this.e;
        if (iAsrService != null) {
            return iAsrService;
        }
        if (this.g != null) {
            Log.e("AsrLocalEngine", "checkOpenConnection error!");
            this.g.onError(5);
        }
        Log.e("AsrLocalEngine", "not connected to the recognition service");
        return null;
    }

    public void c() {
        Log.i("AsrLocalEngine", "connectToService mConnection: " + this.b);
        boolean b2 = com.huawei.hiai.asr.b.b(this.c);
        if (this.b == null) {
            this.b = new c();
            if (!AppUtil.isAppExists(this.c, "com.huawei.hiai")) {
                a(36);
                Log.e("AsrLocalEngine", "com.huawei.hiai not found");
            } else {
                if (com.huawei.hiai.asr.b.a(this.c, this.b, b2) || this.g == null) {
                    return;
                }
                Log.i("AsrLocalEngine", "will send error message to client");
                this.g.onError(34);
            }
        }
    }

    private void d() {
        synchronized (j) {
            try {
                if (!this.h.isEmpty() && this.d != null) {
                    Log.d("AsrLocalEngine", "handle pending tasks");
                    while (!this.h.isEmpty()) {
                        Message poll = this.h.poll();
                        if (poll != null) {
                            this.d.sendMessage(poll);
                        }
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    private void e(Intent intent) {
        com.huawei.hiai.asr.local.a aVar;
        IAsrService b2 = b();
        if (b2 == null || (aVar = this.g) == null) {
            return;
        }
        try {
            b2.updateParams(intent, aVar);
            Log.d("AsrLocalEngine", "updateParams command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "updateParams() failed");
            this.g.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "updateParams() failed");
            this.g.onError(5);
        }
    }

    @Override
    public void cancel(Intent intent) {
        e(Message.obtain(null, 3, intent));
    }

    @Override
    public void stopListening(Intent intent) {
        e(Message.obtain(null, 10, intent));
    }

    @Override
    public void writePcm(Intent intent, byte[] bArr, int i2) {
        e(Message.obtain(null, 6, new e(intent, bArr, i2)));
    }

    @Override
    public void startListening(Intent intent, AsrListener asrListener) {
        if (intent != null && asrListener != null) {
            e(Message.obtain(null, 1, new f(intent, asrListener)));
            return;
        }
        throw new IllegalArgumentException("intent or intent must not be null");
    }

    private boolean b(Message message) {
        if (message == null) {
            Log.w("AsrLocalEngine", "handleMessagePart2 handleMessage msg is null");
            return false;
        }
        Object obj = message.obj;
        switch (message.what) {
            case 7:
                g();
                return true;
            case 8:
                c(message);
                return true;
            case 9:
                if (obj instanceof Intent) {
                    b((Intent) obj);
                }
                return true;
            case 10:
                if (obj instanceof Intent) {
                    d((Intent) obj);
                }
                return true;
            case 11:
                if (obj instanceof Intent) {
                    e((Intent) obj);
                }
                return true;
            default:
                return false;
        }
    }

    public void a(ComponentName componentName, IBinder iBinder, boolean z) {
        if (!a(z, iBinder)) {
            Log.e("AsrLocalEngine", "binderServiceNotSdk failed!");
            return;
        }
        if (this.e == null) {
            Log.e("AsrLocalEngine", "mService is null, will send init failed message");
            a(23);
            return;
        }
        Log.d("AsrLocalEngine", "onServiceConnected - Success");
        d dVar = this.a;
        if (dVar != null) {
            Message.obtain(dVar, 14, null).sendToTarget();
        }
        d();
    }

    public void d(Message message) {
        if (a(message) || b(message)) {
            return;
        }
        Log.i("AsrLocalEngine", "unknown message");
    }

    private void f() {
        com.huawei.hiai.asr.local.a aVar;
        IAsrService b2 = b();
        if (b2 == null || (aVar = this.g) == null) {
            return;
        }
        try {
            b2.cancel(aVar);
            Log.d("AsrLocalEngine", "service cancel command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "cancel() failed");
            this.g.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "cancel() failed");
            this.g.onError(5);
        }
    }

    private void e(Message message) {
        f(Message.obtain(null, 8, message));
    }

    private Looper e() {
        Looper looper;
        synchronized (i) {
            try {
                HandlerThread handlerThread = k;
                if (handlerThread != null) {
                    if (!handlerThread.isAlive()) {
                    }
                    looper = k.getLooper();
                }
                Log.i("AsrLocalEngine", "new thread");
                HandlerThread handlerThread2 = new HandlerThread("AsrLocalEngine");
                k = handlerThread2;
                handlerThread2.start();
                looper = k.getLooper();
            } catch (Throwable th) {
                throw th;
            }
        }
        return looper;
    }

    private void d(Intent intent) {
        com.huawei.hiai.asr.local.a aVar;
        IAsrService b2 = b();
        if (b2 == null || (aVar = this.g) == null) {
            return;
        }
        try {
            b2.stopListeningWithIntent(intent, aVar);
            Log.d("AsrLocalEngine", "service stop listening command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "stopListening() failed");
            this.g.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "stopListening() failed");
            this.g.onError(5);
        }
    }

    private void c(Intent intent) {
        com.huawei.hiai.asr.local.a aVar;
        IAsrService b2 = b();
        if (b2 == null || (aVar = this.g) == null) {
            return;
        }
        try {
            b2.startListening(intent, aVar);
            Log.d("AsrLocalEngine", "service start listening command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "startListening() failed");
            this.g.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "startListening() failed");
            this.g.onError(5);
        }
    }

    private void f(Message message) {
        synchronized (j) {
            try {
                Handler handler = this.d;
                if (handler != null) {
                    handler.sendMessage(message);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    private boolean a(boolean z, IBinder iBinder) {
        Log.i("AsrLocalEngine", "enter binderServiceNotSdk");
        if (!z && com.huawei.hiai.asr.b.c(this.c)) {
            try {
                if (com.huawei.hiai.asr.a.b(iBinder) == 0) {
                    a(37);
                    com.huawei.hiai.asr.a.a(iBinder).ifPresent(new Consumer() {
                        @Override
                        public final void accept(Object obj) {
                            AsrLocalEngine.this.a((IBinder) obj);
                        }
                    });
                    return true;
                }
                a(35);
                return false;
            } catch (SecurityException unused) {
                Log.e("AsrLocalEngine", "onHiAiServiceConnected SecurityException");
                return false;
            }
        }
        this.e = IAsrService.a.a(iBinder);
        return true;
    }

    private void b(Intent intent) {
        com.huawei.hiai.asr.local.a aVar;
        IAsrService b2 = b();
        if (b2 == null || (aVar = this.g) == null) {
            return;
        }
        try {
            b2.setParameter(intent, aVar);
            Log.d("AsrLocalEngine", "service set parameter command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "setParameter() failed");
            this.g.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "setParameter() failed");
            this.g.onError(5);
        }
    }

    private void c(Message message) {
        if (message == null) {
            Log.w("AsrLocalEngine", "handlePutMessage wrapperMsg is null");
            return;
        }
        Object obj = message.obj;
        if (!(obj instanceof Message)) {
            Log.w("AsrLocalEngine", "handlePutMessage wrapperMsg.obj is not msg");
            return;
        }
        Message message2 = (Message) obj;
        if (this.e == null) {
            Log.w("AsrLocalEngine", "mService is null");
            if (i() || !this.h.offer(message2)) {
                Log.w("AsrLocalEngine", "offer msg " + message2.what + " to mPendingTasks false");
            }
            if (message2 == null || message2.what != 7) {
                return;
            }
            Log.w("AsrLocalEngine", "handle destroy msg");
            d(message2);
            return;
        }
        d(message2);
    }

    public void a(IBinder iBinder) {
        this.e = IAsrService.a.a(iBinder);
    }

    private void a(int i2) {
        Bundle bundle = new Bundle();
        bundle.putInt("error_code", i2);
        d dVar = this.a;
        if (dVar != null) {
            Message.obtain(dVar, 5, bundle).sendToTarget();
        }
    }

    public void a(ComponentName componentName) {
        Log.d("AsrLocalEngine", "onHiAiServiceDisconnected success");
        j();
        d dVar = this.a;
        if (dVar != null) {
            Message.obtain(dVar, 15, null).sendToTarget();
        }
    }

    private boolean a(Message message) {
        if (message == null) {
            Log.w("AsrLocalEngine", "handleMessagePart1 handleMessage msg is null");
            return false;
        }
        Object obj = message.obj;
        switch (message.what) {
            case 1:
                if (obj instanceof Intent) {
                    Log.i("AsrLocalEngine", "handleMessage msg handleStartListening");
                    c((Intent) obj);
                } else if (obj instanceof f) {
                    Log.i("AsrLocalEngine", "handleMessage msg handleStartListeningSession");
                    f fVar = (f) obj;
                    a(fVar.a, fVar.b);
                }
                return true;
            case 2:
                h();
                return true;
            case 3:
                if (obj instanceof Intent) {
                    a((Intent) obj);
                } else {
                    f();
                }
                return true;
            case 4:
                if (obj instanceof f) {
                    a((f) obj);
                }
                return true;
            case 5:
                if (obj instanceof Intent) {
                    f((Intent) obj);
                }
                return true;
            case 6:
                if (obj instanceof e) {
                    a((e) obj);
                }
                return true;
            default:
                return false;
        }
    }

    private void a(e eVar) {
        IAsrService b2 = b();
        if (b2 == null) {
            return;
        }
        byte[] bArr = eVar.b;
        int i2 = eVar.c;
        Intent intent = eVar.a;
        if (intent == null) {
            try {
                b2.writePcm(bArr, i2, this.g);
                return;
            } catch (RemoteException unused) {
                Log.e("AsrLocalEngine", "writePcm() failed");
                this.g.onError(34);
                return;
            } catch (SecurityException unused2) {
                Log.e("AsrLocalEngine", "writePcm() failed");
                this.g.onError(5);
                return;
            }
        }
        try {
            b2.writePcmWithIntent(intent, bArr, i2);
        } catch (RemoteException | SecurityException unused3) {
            Log.e("AsrLocalEngine", "writePcm() failed exception");
        }
    }

    private void a(Intent intent, AsrListener asrListener) {
        IAsrService b2 = b();
        if (b2 == null || asrListener == null) {
            return;
        }
        com.huawei.hiai.asr.local.a aVar = new com.huawei.hiai.asr.local.a(asrListener);
        aVar.a(this.a);
        try {
            b2.startListening(intent, aVar);
            Log.d("AsrLocalEngine", "service start listening command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "startListening() failed");
            aVar.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "startListening() failed");
            aVar.onError(5);
        }
    }

    private void a(Intent intent) {
        com.huawei.hiai.asr.local.a aVar;
        IAsrService b2 = b();
        if (b2 == null || (aVar = this.g) == null) {
            return;
        }
        try {
            b2.cancelWithIntent(intent, aVar);
            Log.d("AsrLocalEngine", "service cancel with intent command succeeded");
        } catch (RemoteException unused) {
            Log.e("AsrLocalEngine", "cancel() with intent failed");
            this.g.onError(34);
        } catch (SecurityException unused2) {
            Log.e("AsrLocalEngine", "cancel() with intent failed");
            this.g.onError(5);
        }
    }

    private void a(f fVar) {
        IAsrService b2 = b();
        if (b2 == null || fVar.a == null || this.g == null) {
            return;
        }
        try {
            fVar.a.putExtra("com.huawei.hiai.asr.sdk.version", 2);
            b2.init(fVar.a, this.g);
            Log.d("AsrLocalEngine", "service init command succeeded");
        } catch (RemoteException | SecurityException unused) {
            Log.e("AsrLocalEngine", "init() failed");
            this.g.onError(23);
        }
    }

    private void a(Runnable runnable) {
        synchronized (j) {
            if (runnable != null) {
                try {
                    Handler handler = this.d;
                    if (handler != null) {
                        handler.post(runnable);
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }
}