- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
269 lines
8.7 KiB
Java
269 lines
8.7 KiB
Java
package com.bda.controller;
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.os.RemoteException;
|
|
import com.bda.controller.IControllerListener;
|
|
import com.bda.controller.IControllerMonitor;
|
|
import com.bda.controller.IControllerService;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class Controller {
|
|
public final Context mContext;
|
|
public boolean mIsBound = false;
|
|
public IControllerService mService = null;
|
|
public final IControllerListener.Stub mListenerStub = new IControllerListenerStub();
|
|
public final IControllerMonitor.Stub mMonitorStub = new IControllerMonitorStub();
|
|
public final ServiceConnection mServiceConnection = new ServiceConnection();
|
|
public int mActivityEvent = 6;
|
|
public Handler mHandler = null;
|
|
public ControllerListener mListener = null;
|
|
|
|
public void registerMonitor() {
|
|
}
|
|
|
|
public static final Controller getInstance(Context context) {
|
|
return new Controller(context);
|
|
}
|
|
|
|
public Controller(Context context) {
|
|
this.mContext = context;
|
|
}
|
|
|
|
public final void exit() {
|
|
setListener(null, null);
|
|
setMonitor(null);
|
|
if (this.mIsBound) {
|
|
this.mContext.unbindService(this.mServiceConnection);
|
|
this.mIsBound = false;
|
|
}
|
|
}
|
|
|
|
public final int getState(int i) {
|
|
IControllerService iControllerService = this.mService;
|
|
if (iControllerService == null) {
|
|
return 0;
|
|
}
|
|
try {
|
|
return iControllerService.getState(1, i);
|
|
} catch (RemoteException unused) {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public final boolean init() {
|
|
if (!this.mIsBound) {
|
|
Intent intent = new Intent(IControllerService.class.getName());
|
|
this.mContext.startService(intent);
|
|
this.mContext.bindService(intent, this.mServiceConnection, 1);
|
|
this.mIsBound = true;
|
|
}
|
|
return this.mIsBound;
|
|
}
|
|
|
|
public final void onPause() {
|
|
this.mActivityEvent = 6;
|
|
sendMessage(1, 6);
|
|
registerListener();
|
|
}
|
|
|
|
public final void onResume() {
|
|
this.mActivityEvent = 5;
|
|
sendMessage(1, 5);
|
|
registerListener();
|
|
}
|
|
|
|
public void registerListener() {
|
|
IControllerService iControllerService;
|
|
if (this.mListener == null || (iControllerService = this.mService) == null) {
|
|
return;
|
|
}
|
|
try {
|
|
try {
|
|
iControllerService.registerListener2(this.mListenerStub, this.mActivityEvent);
|
|
} catch (RemoteException unused) {
|
|
this.mService.registerListener(this.mListenerStub, this.mActivityEvent);
|
|
}
|
|
} catch (RemoteException unused2) {
|
|
}
|
|
}
|
|
|
|
public void sendMessage(int i, int i2) {
|
|
IControllerService iControllerService = this.mService;
|
|
if (iControllerService != null) {
|
|
try {
|
|
iControllerService.sendMessage(i, i2);
|
|
} catch (RemoteException unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void setListener(ControllerListener controllerListener, Handler handler) {
|
|
unregisterListener();
|
|
this.mListener = controllerListener;
|
|
this.mHandler = handler;
|
|
registerListener();
|
|
}
|
|
|
|
public final void setMonitor(ControllerMonitor controllerMonitor) {
|
|
unregisterMonitor();
|
|
registerMonitor();
|
|
}
|
|
|
|
public void unregisterListener() {
|
|
IControllerService iControllerService = this.mService;
|
|
if (iControllerService != null) {
|
|
try {
|
|
iControllerService.unregisterListener(this.mListenerStub, this.mActivityEvent);
|
|
} catch (RemoteException unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public void unregisterMonitor() {
|
|
IControllerService iControllerService = this.mService;
|
|
if (iControllerService != null) {
|
|
try {
|
|
iControllerService.unregisterMonitor(this.mMonitorStub, this.mActivityEvent);
|
|
} catch (RemoteException unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public class IControllerListenerStub extends IControllerListener.Stub {
|
|
public IControllerListenerStub() {
|
|
}
|
|
|
|
@Override // com.bda.controller.IControllerListener
|
|
public void onKeyEvent(KeyEvent keyEvent) {
|
|
if (keyEvent.getControllerId() == 1) {
|
|
Controller controller = Controller.this;
|
|
if (controller.mListener != null) {
|
|
KeyRunnable keyRunnable = controller.new KeyRunnable(keyEvent);
|
|
Handler handler = Controller.this.mHandler;
|
|
if (handler != null) {
|
|
handler.post(keyRunnable);
|
|
} else {
|
|
keyRunnable.run();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.bda.controller.IControllerListener
|
|
public void onMotionEvent(MotionEvent motionEvent) {
|
|
if (motionEvent.getControllerId() == 1) {
|
|
Controller controller = Controller.this;
|
|
if (controller.mListener != null) {
|
|
MotionRunnable motionRunnable = controller.new MotionRunnable(motionEvent);
|
|
Handler handler = Controller.this.mHandler;
|
|
if (handler != null) {
|
|
handler.post(motionRunnable);
|
|
} else {
|
|
motionRunnable.run();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.bda.controller.IControllerListener
|
|
public void onStateEvent(StateEvent stateEvent) {
|
|
if (stateEvent.getControllerId() == 1) {
|
|
Controller controller = Controller.this;
|
|
if (controller.mListener != null) {
|
|
StateRunnable stateRunnable = controller.new StateRunnable(stateEvent);
|
|
Handler handler = Controller.this.mHandler;
|
|
if (handler != null) {
|
|
handler.post(stateRunnable);
|
|
} else {
|
|
stateRunnable.run();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class IControllerMonitorStub extends IControllerMonitor.Stub {
|
|
public IControllerMonitorStub() {
|
|
}
|
|
|
|
@Override // com.bda.controller.IControllerMonitor
|
|
public void onLog(int i, int i2, String str) {
|
|
Controller.this.getClass();
|
|
}
|
|
}
|
|
|
|
public class KeyRunnable implements Runnable {
|
|
public final KeyEvent mEvent;
|
|
|
|
public KeyRunnable(KeyEvent keyEvent) {
|
|
this.mEvent = keyEvent;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ControllerListener controllerListener = Controller.this.mListener;
|
|
if (controllerListener != null) {
|
|
controllerListener.onKeyEvent(this.mEvent);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class MotionRunnable implements Runnable {
|
|
public final MotionEvent mEvent;
|
|
|
|
public MotionRunnable(MotionEvent motionEvent) {
|
|
this.mEvent = motionEvent;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ControllerListener controllerListener = Controller.this.mListener;
|
|
if (controllerListener != null) {
|
|
controllerListener.onMotionEvent(this.mEvent);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ServiceConnection implements android.content.ServiceConnection {
|
|
public ServiceConnection() {
|
|
}
|
|
|
|
@Override // android.content.ServiceConnection
|
|
public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
|
Controller.this.mService = IControllerService.Stub.asInterface(iBinder);
|
|
Controller.this.registerListener();
|
|
Controller.this.registerMonitor();
|
|
Controller controller = Controller.this;
|
|
if (controller.mActivityEvent == 5) {
|
|
controller.sendMessage(1, 5);
|
|
Controller.this.sendMessage(1, 7);
|
|
}
|
|
}
|
|
|
|
@Override // android.content.ServiceConnection
|
|
public final void onServiceDisconnected(ComponentName componentName) {
|
|
Controller.this.mService = null;
|
|
}
|
|
}
|
|
|
|
public class StateRunnable implements Runnable {
|
|
public final StateEvent mEvent;
|
|
|
|
public StateRunnable(StateEvent stateEvent) {
|
|
this.mEvent = stateEvent;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ControllerListener controllerListener = Controller.this.mListener;
|
|
if (controllerListener != null) {
|
|
controllerListener.onStateEvent(this.mEvent);
|
|
}
|
|
}
|
|
}
|
|
}
|