android.view.IWindowManager#android.hardware.input.InputManager源码实例Demo

下面列出了android.view.IWindowManager#android.hardware.input.InputManager 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * Send a key event to the currently focused window/view and wait for it to
 * be processed.  Finished at some point after the recipient has returned
 * from its event processing, though it may <em>not</em> have completely
 * finished reacting from the event -- for example, if it needs to update
 * its display as a result, it may still be in the process of doing that.
 *
 * @param event The event to send to the current focus.
 */
public void sendKeySync(KeyEvent event) {
    validateNotAppThread();

    long downTime = event.getDownTime();
    long eventTime = event.getEventTime();
    int source = event.getSource();
    if (source == InputDevice.SOURCE_UNKNOWN) {
        source = InputDevice.SOURCE_KEYBOARD;
    }
    if (eventTime == 0) {
        eventTime = SystemClock.uptimeMillis();
    }
    if (downTime == 0) {
        downTime = eventTime;
    }
    KeyEvent newEvent = new KeyEvent(event);
    newEvent.setTime(downTime, eventTime);
    newEvent.setSource(source);
    newEvent.setFlags(event.getFlags() | KeyEvent.FLAG_FROM_SYSTEM);
    InputManager.getInstance().injectInputEvent(newEvent,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
@Override
public boolean injectInputEvent(InputEvent event, boolean sync) {
    synchronized (mLock) {
        throwIfCalledByNotTrustedUidLocked();
        throwIfShutdownLocked();
        throwIfNotConnectedLocked();
    }
    final int mode = (sync) ? InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH
            : InputManager.INJECT_INPUT_EVENT_MODE_ASYNC;
    final long identity = Binder.clearCallingIdentity();
    try {
        return InputManager.getInstance().injectInputEvent(event, mode);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
源代码3 项目: GravityBox   文件: PieController.java
public void handleMessage(Message m) {
    switch (m.what) {
        case MSG_INJECT_KEY:
            final long eventTime = SystemClock.uptimeMillis();
            final InputManager inputManager = (InputManager)
                    XposedHelpers.callStaticMethod(InputManager.class, "getInstance");

            int flags = KeyEvent.FLAG_FROM_SYSTEM;
            XposedHelpers.callMethod(inputManager, "injectInputEvent",
                    new KeyEvent(eventTime - 50, eventTime - 50, KeyEvent.ACTION_DOWN, m.arg1, 0,
                            0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0);
            XposedHelpers.callMethod(inputManager, "injectInputEvent",
                    new KeyEvent(eventTime - 50, eventTime - 25, KeyEvent.ACTION_UP, m.arg1, 0,
                            0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0);

            break;
    }
}
 
源代码4 项目: GravityBox   文件: ModHwKeys.java
public static void injectKey(final int keyCode) {
    Handler handler = (Handler) XposedHelpers.getObjectField(mPhoneWindowManager, "mHandler");
    if (handler == null) return;

    handler.post(new Runnable() {
        @Override
        public void run() {
            try {
                final long eventTime = SystemClock.uptimeMillis();
                final InputManager inputManager = (InputManager)
                        mContext.getSystemService(Context.INPUT_SERVICE);
                int flags = KeyEvent.FLAG_FROM_SYSTEM;
                XposedHelpers.callMethod(inputManager, "injectInputEvent",
                        new KeyEvent(eventTime - 50, eventTime - 50, KeyEvent.ACTION_DOWN,
                                keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags,
                                InputDevice.SOURCE_UNKNOWN), 0);
                XposedHelpers.callMethod(inputManager, "injectInputEvent",
                        new KeyEvent(eventTime - 50, eventTime - 25, KeyEvent.ACTION_UP,
                                keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags,
                                InputDevice.SOURCE_UNKNOWN), 0);
            } catch (Throwable t) {
                XposedBridge.log(t);
            }
        }
    });
}
 
源代码5 项目: TvRemoteControl   文件: NetUtils.java
@Override
public void run() {
    isFlag = true;/*线程开始运行,设置标志位进入轮询*/
    while (isFlag) {
        try {
            long now = System.currentTimeMillis();
            KeyEvent down = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 0);
            KeyEvent up = new KeyEvent(now, now, KeyEvent.ACTION_UP, keyCode, 0);
            InputManager.getInstance().injectInputEvent(down, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
            InputManager.getInstance().injectInputEvent(up, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
            Log.i("gky", "--------->injectKeyEvent " + keyCode);
            Thread.sleep(30);
        } catch (InterruptedException e) {
            e.printStackTrace();
            isFlag = false;/*异常结束线程运行*/
        }
    }
    Log.i("gky", "---------->stop LongKeyRunnale");
}
 
源代码6 项目: AndroidDemoProjects   文件: GameView.java
public GameView(Context context) {
    super( context );

    setEGLContextClientVersion( 2 );
    this.setRenderer( this );
    this.requestFocus();

    mInstance = this;

    mLastUpdateTimeMillis = System.currentTimeMillis();

    mShip = new Ship();

    InputManager inputManager = (InputManager) context.getSystemService( Context.INPUT_SERVICE );
    inputManager.registerInputDeviceListener( this, null );
    mAsteroids = new ArrayList<Asteroid>();
    mBullets = new ArrayList<Bullet>();
    initLevel();
}
 
源代码7 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * Send a key event to the currently focused window/view and wait for it to
 * be processed.  Finished at some point after the recipient has returned
 * from its event processing, though it may <em>not</em> have completely
 * finished reacting from the event -- for example, if it needs to update
 * its display as a result, it may still be in the process of doing that.
 * 
 * @param event The event to send to the current focus.
 */
public void sendKeySync(KeyEvent event) {
    validateNotAppThread();

    long downTime = event.getDownTime();
    long eventTime = event.getEventTime();
    int action = event.getAction();
    int code = event.getKeyCode();
    int repeatCount = event.getRepeatCount();
    int metaState = event.getMetaState();
    int deviceId = event.getDeviceId();
    int scancode = event.getScanCode();
    int source = event.getSource();
    int flags = event.getFlags();
    if (source == InputDevice.SOURCE_UNKNOWN) {
        source = InputDevice.SOURCE_KEYBOARD;
    }
    if (eventTime == 0) {
        eventTime = SystemClock.uptimeMillis();
    }
    if (downTime == 0) {
        downTime = eventTime;
    }
    KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
            deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
    InputManager.getInstance().injectInputEvent(newEvent,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
源代码8 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * Send a key event to the currently focused window/view and wait for it to
 * be processed.  Finished at some point after the recipient has returned
 * from its event processing, though it may <em>not</em> have completely
 * finished reacting from the event -- for example, if it needs to update
 * its display as a result, it may still be in the process of doing that.
 * 
 * @param event The event to send to the current focus.
 */
public void sendKeySync(KeyEvent event) {
    validateNotAppThread();

    long downTime = event.getDownTime();
    long eventTime = event.getEventTime();
    int action = event.getAction();
    int code = event.getKeyCode();
    int repeatCount = event.getRepeatCount();
    int metaState = event.getMetaState();
    int deviceId = event.getDeviceId();
    int scancode = event.getScanCode();
    int source = event.getSource();
    int flags = event.getFlags();
    if (source == InputDevice.SOURCE_UNKNOWN) {
        source = InputDevice.SOURCE_KEYBOARD;
    }
    if (eventTime == 0) {
        eventTime = SystemClock.uptimeMillis();
    }
    if (downTime == 0) {
        downTime = eventTime;
    }
    KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
            deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
    InputManager.getInstance().injectInputEvent(newEvent,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
源代码9 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * Dispatch a pointer event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    try {
        WindowManagerGlobal.getWindowManagerService().injectInputAfterTransactionsApplied(event,
                InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
    } catch (RemoteException e) {
    }
}
 
源代码10 项目: android_9.0.0_r45   文件: HdmiCecLocalDevice.java
static void injectKeyEvent(long time, int action, int keycode, int repeat) {
     KeyEvent keyEvent = KeyEvent.obtain(time, time, action, keycode,
             repeat, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM,
             InputDevice.SOURCE_HDMI, null);
     InputManager.getInstance().injectInputEvent(keyEvent,
             InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
     keyEvent.recycle();
}
 
源代码11 项目: android_9.0.0_r45   文件: InputManagerService.java
private boolean injectInputEventInternal(InputEvent event, int displayId, int mode) {
    if (event == null) {
        throw new IllegalArgumentException("event must not be null");
    }
    if (mode != InputManager.INJECT_INPUT_EVENT_MODE_ASYNC
            && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH
            && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT) {
        throw new IllegalArgumentException("mode is invalid");
    }

    final int pid = Binder.getCallingPid();
    final int uid = Binder.getCallingUid();
    final long ident = Binder.clearCallingIdentity();
    final int result;
    try {
        result = nativeInjectInputEvent(mPtr, event, displayId, pid, uid, mode,
                INJECTION_TIMEOUT_MILLIS, WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    switch (result) {
        case INPUT_EVENT_INJECTION_PERMISSION_DENIED:
            Slog.w(TAG, "Input event injection from pid " + pid + " permission denied.");
            throw new SecurityException(
                    "Injecting to another application requires INJECT_EVENTS permission");
        case INPUT_EVENT_INJECTION_SUCCEEDED:
            return true;
        case INPUT_EVENT_INJECTION_TIMED_OUT:
            Slog.w(TAG, "Input event injection from pid " + pid + " timed out.");
            return false;
        case INPUT_EVENT_INJECTION_FAILED:
        default:
            Slog.w(TAG, "Input event injection from pid " + pid + " failed.");
            return false;
    }
}
 
源代码12 项目: android_9.0.0_r45   文件: InputManagerService.java
private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) {
    final PackageManager pm = mContext.getPackageManager();
    Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);
    for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent,
            PackageManager.GET_META_DATA | PackageManager.MATCH_DIRECT_BOOT_AWARE
                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE)) {
        final ActivityInfo activityInfo = resolveInfo.activityInfo;
        final int priority = resolveInfo.priority;
        visitKeyboardLayoutsInPackage(pm, activityInfo, null, priority, visitor);
    }
}
 
源代码13 项目: android_9.0.0_r45   文件: InputManagerService.java
@Override // Binder call
public void tryPointerSpeed(int speed) {
    if (!checkCallingPermission(android.Manifest.permission.SET_POINTER_SPEED,
            "tryPointerSpeed()")) {
        throw new SecurityException("Requires SET_POINTER_SPEED permission");
    }

    if (speed < InputManager.MIN_POINTER_SPEED || speed > InputManager.MAX_POINTER_SPEED) {
        throw new IllegalArgumentException("speed out of range");
    }

    setPointerSpeedUnchecked(speed);
}
 
源代码14 项目: android_9.0.0_r45   文件: InputManagerService.java
private int getPointerSpeedSetting() {
    int speed = InputManager.DEFAULT_POINTER_SPEED;
    try {
        speed = Settings.System.getIntForUser(mContext.getContentResolver(),
                Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT);
    } catch (SettingNotFoundException snfe) {
    }
    return speed;
}
 
源代码15 项目: android_9.0.0_r45   文件: InputManagerService.java
@Override
public void sendInputEvent(InputEvent event, int policyFlags) {
    if (event == null) {
        throw new IllegalArgumentException("event must not be null");
    }

    synchronized (mInputFilterLock) {
        if (!mDisconnected) {
            nativeInjectInputEvent(mPtr, event, Display.DEFAULT_DISPLAY, 0, 0,
                    InputManager.INJECT_INPUT_EVENT_MODE_ASYNC, 0,
                    policyFlags | WindowManagerPolicy.FLAG_FILTERED);
        }
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: KeyCharacterMap.java
/**
 * Loads the key character maps for the keyboard with the specified device id.
 *
 * @param deviceId The device id of the keyboard.
 * @return The associated key character map.
 * @throws {@link UnavailableException} if the key character map
 * could not be loaded because it was malformed or the default key character map
 * is missing from the system.
 */
public static KeyCharacterMap load(int deviceId) {
    final InputManager im = InputManager.getInstance();
    InputDevice inputDevice = im.getInputDevice(deviceId);
    if (inputDevice == null) {
        inputDevice = im.getInputDevice(VIRTUAL_KEYBOARD);
        if (inputDevice == null) {
            throw new UnavailableException(
                    "Could not load key character map for device " + deviceId);
        }
    }
    return inputDevice.getKeyCharacterMap();
}
 
源代码17 项目: android_9.0.0_r45   文件: InputDevice.java
/**
 * Gets the vibrator service associated with the device, if there is one.
 * Even if the device does not have a vibrator, the result is never null.
 * Use {@link Vibrator#hasVibrator} to determine whether a vibrator is
 * present.
 *
 * Note that the vibrator associated with the device may be different from
 * the system vibrator.  To obtain an instance of the system vibrator instead, call
 * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument.
 *
 * @return The vibrator service associated with the device, never null.
 */
public Vibrator getVibrator() {
    synchronized (mMotionRanges) {
        if (mVibrator == null) {
            if (mHasVibrator) {
                mVibrator = InputManager.getInstance().getInputDeviceVibrator(mId);
            } else {
                mVibrator = NullVibrator.getInstance();
            }
        }
        return mVibrator;
    }
}
 
源代码18 项目: android_9.0.0_r45   文件: Instrumentation.java
/**
 * Send a key event to the currently focused window/view and wait for it to
 * be processed.  Finished at some point after the recipient has returned
 * from its event processing, though it may <em>not</em> have completely
 * finished reacting from the event -- for example, if it needs to update
 * its display as a result, it may still be in the process of doing that.
 * 
 * @param event The event to send to the current focus.
 */
public void sendKeySync(KeyEvent event) {
    validateNotAppThread();

    long downTime = event.getDownTime();
    long eventTime = event.getEventTime();
    int action = event.getAction();
    int code = event.getKeyCode();
    int repeatCount = event.getRepeatCount();
    int metaState = event.getMetaState();
    int deviceId = event.getDeviceId();
    int scancode = event.getScanCode();
    int source = event.getSource();
    int flags = event.getFlags();
    if (source == InputDevice.SOURCE_UNKNOWN) {
        source = InputDevice.SOURCE_KEYBOARD;
    }
    if (eventTime == 0) {
        eventTime = SystemClock.uptimeMillis();
    }
    if (downTime == 0) {
        downTime = eventTime;
    }
    KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
            deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
    InputManager.getInstance().injectInputEvent(newEvent,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
源代码19 项目: FunnyDraw   文件: SampleManager.java
private MotionInjector() throws MotionDrawException {
    try {
        mInputManager = (InputManager)
                InputManager.class.getDeclaredMethod("getInstance").invoke(null);
        mInjectInputEvent =
                InputManager.class.getDeclaredMethod("injectInputEvent",
                        InputEvent.class, Integer.TYPE);
        mInjectInputEvent.setAccessible(true);
    } catch (Exception e) {
        throw new MotionDrawException(e.getMessage());
    }
}
 
源代码20 项目: HJMirror   文件: HJInput.java
@SuppressLint("PrivateApi")
public HJInput() {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mInputManager = (InputManager) InputManager.class.getDeclaredMethod("getInstance").invoke(null);
            mInjectInputEventMethod = InputManager.class.getMethod("injectInputEvent", InputEvent.class, Integer.TYPE);
        }
    } catch (Exception e) {
        HJLog.e(e);
    }
}
 
源代码21 项目: XposedSmsCode   文件: InputHelper.java
/**
 * refer com.android.commands.input.Input#injectKeyEvent()
 */
@SuppressLint("PrivateApi")
private static void injectKeyEvent(KeyEvent keyEvent) throws Throwable {
    InputManager inputManager = (InputManager) XposedHelpers.callStaticMethod(InputManager.class, "getInstance");

    int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH =
            XposedHelpers.getStaticIntField(InputManager.class, "INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH");

    Class<?>[] paramTypes = {KeyEvent.class, int.class,};
    Object[] args = {keyEvent, INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH,};

    XposedHelpers.callMethod(inputManager, "injectInputEvent", paramTypes, args);
}
 
源代码22 项目: GravityBox   文件: KeyButtonView.java
void sendEvent(int action, int flags, long when, boolean applyDefaultFlags) {
    try {
        final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0;
        if (applyDefaultFlags) {
            flags |= KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY;
        }
        final KeyEvent ev = new KeyEvent(mDownTime, when, action, mCode, repeatCount,
                0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags,
                InputDevice.SOURCE_KEYBOARD);
        final Object inputManager = XposedHelpers.callStaticMethod(InputManager.class, "getInstance");
        XposedHelpers.callMethod(inputManager, "injectInputEvent", ev, 0);
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
源代码23 项目: 365browser   文件: GamepadList.java
private void attachedToWindow(Context context) {
    if (mAttachedToWindowCounter++ == 0) {
        mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
        synchronized (mLock) {
            initializeDevices();
        }
        // Register an input device listener.
        mInputManager.registerInputDeviceListener(mInputDeviceListener, null);
    }
}
 
源代码24 项目: droidel   文件: Instrumentation.java
/**
 * Send a key event to the currently focused window/view and wait for it to
 * be processed.  Finished at some point after the recipient has returned
 * from its event processing, though it may <em>not</em> have completely
 * finished reacting from the event -- for example, if it needs to update
 * its display as a result, it may still be in the process of doing that.
 * 
 * @param event The event to send to the current focus.
 */
public void sendKeySync(KeyEvent event) {
    validateNotAppThread();

    long downTime = event.getDownTime();
    long eventTime = event.getEventTime();
    int action = event.getAction();
    int code = event.getKeyCode();
    int repeatCount = event.getRepeatCount();
    int metaState = event.getMetaState();
    int deviceId = event.getDeviceId();
    int scancode = event.getScanCode();
    int source = event.getSource();
    int flags = event.getFlags();
    if (source == InputDevice.SOURCE_UNKNOWN) {
        source = InputDevice.SOURCE_KEYBOARD;
    }
    if (eventTime == 0) {
        eventTime = SystemClock.uptimeMillis();
    }
    if (downTime == 0) {
        downTime = eventTime;
    }
    KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
            deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
    InputManager.getInstance().injectInputEvent(newEvent,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
源代码25 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createStaticService() {
    return InputManager.getInstance();
}
 
源代码26 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createStaticService() {
    return InputManager.getInstance();
}
 
源代码27 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createStaticService() {
    return InputManager.getInstance();
}
 
源代码28 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createStaticService() {
    return InputManager.getInstance();
}
 
源代码29 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createStaticService() {
    return InputManager.getInstance();
}
 
源代码30 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createStaticService() {
    return InputManager.getInstance();
}