本人菜鸟一枚,如有什么错误的地方请指正。
最近拿到一个zedboard板卡,在板卡上移植了一个xilinx提供的android2.3.3系统。使用HDMI显示到屏幕上,但是这样不能与android进行交互,所以想在其源码中添加鼠标支持,通过借鉴mips和x86的android鼠标实现方式,在xilinx提供的源码之上进行改动。下面提供修改的步骤。
参考资料:
1、http://elinux.org/Zedboard_Android
3、http://blog.csdn.net/luoshengyang/article/details/6882903 //Android应用程序键盘(Keyboard)消息处理机制分析
4、http://www.hovercool.com/en/Input%E4%BA%8B%E4%BB%B6%E6%B5%81%E7%A8%8B
5、http://blog.sina.com.cn/s/blog_89f592f50101394l.html
移植步骤:
1、添加鼠标图片
在framework/base/core/res/res/drawable-nodpi/中添加一张鼠标png图片 pointer.png
2、添加鼠标设备定义
源代码路径:framework/base/include/ui/EventHub.h
/*
96 * Input device classes.
97 */
98 enum {
99 /* The input device is a keyboard. */
100 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001,
101
102 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
103 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002,
104
105 /* The input device is a touchscreen (either single-touch or multi-touch). */
106 INPUT_DEVICE_CLASS_TOUCHSCREEN = 0x00000004,
107
108 /* The input device is a trackball. */
109 INPUT_DEVICE_CLASS_TRACKBALL = 0x00000008,
110
111 /* The input device is a multi-touch touchscreen. */
112 INPUT_DEVICE_CLASS_TOUCHSCREEN_MT= 0x00000010,
113
114 /* The input device is a directional pad (implies keyboard, has DPAD keys). */
115 INPUT_DEVICE_CLASS_DPAD = 0x00000020,
116
117 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
118 INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040,
119
120 /* The input device has switches. */
121 INPUT_DEVICE_CLASS_SWITCH = 0x00000080,
122
123 /* The input device is a mouse. */
124 INPUT_DEVICE_CLASS_MOUSE = 0x00000100,//添加鼠标设备
125 };
3、定义鼠标事件接口
源代码路径:framework/base/include/ui/InputReader.h
class MouseInputMapper : public InputMapper {
508 public:
509 MouseInputMapper(InputDevice* device, int32_t associatedDisplayId);
510
511 virtual uint32_t getSources();
512 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
513 virtual void dump(String8& dump);
514 virtual void reset();
515 virtual void process(const RawEvent* rawEvent);
516
517 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
518
519 private:
520 Mutex mLock;
521
522 int32_t mAssociatedDisplayId;
523
524 struct Accumulator {
525 enum {
526 FIELD_BTN_LEFT = 1,
527 FIELD_REL_X = 2,
528 FIELD_REL_Y = 4,
529 FIELD_BTN_RIGHT = 8,
530 FIELD_BTN_MIDDLE = 16,
531 FIELD_BTN_SIDE = 32,
532 FIELD_BTN_EXTRA = 64,
533 FIELD_BTN_FORWARD = 128,
534 FIELD_BTN_BACK = 256,
535 FIELD_REL_WHEEL = 512,
536 };
537
538 uint32_t fields;
539
540 bool btnLeft;
541 bool btnRight;
542 bool btnMiddle;
543 bool btnSide;
544 bool btnExtra;
545 bool btnForward;
546 bool btnBack;
547 bool btnScrollUp;
548 bool btnScrollDown;
549 int32_t relX;
550 int32_t relY;
551 int32_t absX;
552 int32_t absY;
553
554 inline void clear() {
555 fields = 0;
556 }
557 } mAccumulator;
558
559 struct LockedState {
560 bool down;
561 nsecs_t downTime;
562 } mLocked;
563
564 struct Keyevent {
565 bool down;
566 int keycode;
567 };
568
569 void initializeLocked();
570
571 void sync(nsecs_t when);
572 void sendKey();
573 };
4、实现鼠标接口
源代码路径:framework/base/libs/ui/InputReader.cpp
3185 // --- MouseInputMapper ---
3186
3187 MouseInputMapper::MouseInputMapper(InputDevice* device, int32_t associatedDisplayId) :
3188 InputMapper(device), mAssociatedDisplayId(associatedDisplayId) {
3189 initializeLocked();
3190 }
3191
3192 uint32_t MouseInputMapper::getSources() {
3193 return AINPUT_SOURCE_MOUSE;
3194 }
3195
3196 void MouseInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
3197 InputMapper::populateDeviceInfo(info);
3198 }
3199
3200 void MouseInputMapper::dump(String8& dump) {
3201 AutoMutex _l(mLock);
3202 dump.append(INDENT2 "Mouse Input Mapper:\n");
3203 dump.appendFormat(INDENT3 "AssociatedDisplayId: %d\n", mAssociatedDisplayId);
3204 dump.appendFormat(INDENT3 "Down: %s\n", toString(mLocked.down));
3205 dump.appendFormat(INDENT3 "DownTime: %lld\n", mLocked.downTime);
3206 }
3207
3208 void MouseInputMapper::reset() {
3209 for (;;) {
3210 { // acquire lock
3211 AutoMutex _l(mLock);
3212
3213 if (! mLocked.down) {
3214 initializeLocked();
3215 break; // done
3216 }
3217 } // release lock
3218
3219 // Synthesize trackball button up event on reset.
3220 nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC);
3221 mAccumulator.fields = Accumulator::FIELD_BTN_LEFT;
3222 mAccumulator.btnLeft = false;
3223 mAccumulator.btnScrollUp = false;
3224 mAccumulator.btnScrollDown = false;
3225 sync(when);
3226 }
3227
3228 InputMapper::reset();
3229 }
3230
3231 void MouseInputMapper::process(const RawEvent* rawEvent) {
3232 switch (rawEvent->type) {
3233 case EV_KEY:
3234 switch (rawEvent->scanCode) {
3235 case BTN_LEFT:
3236 mAccumulator.fields |= Accumulator::FIELD_BTN_LEFT;
3237 mAccumulator.btnLeft = rawEvent->value;
3238 break;
3239 case BTN_RIGHT:
3240 mAccumulator.fields |= Accumulator::FIELD_BTN_RIGHT;
3241 mAccumulator.btnRight = rawEvent->value;
3242 break;
3243 case BTN_MIDDLE:
3244 mAccumulator.fields |= Accumulator::FIELD_BTN_MIDDLE;
3245 mAccumulator.btnMiddle = rawEvent->value;
3246 break;
3247 case BTN_SIDE:
3248 mAccumulator.fields |= Accumulator::FIELD_BTN_SIDE;
3249 mAccumulator.btnSide = rawEvent->value;
3250 break;
3251 case BTN_EXTRA:
3252 mAccumulator.fields |= Accumulator::FIELD_BTN_EXTRA;
3253 mAccumulator.btnExtra = rawEvent->value;
3254 break;
3255 case BTN_FORWARD:
3256 mAccumulator.fields |= Accumulator::FIELD_BTN_FORWARD;
3257 mAccumulator.btnForward = rawEvent->value;
3258 break;
3259 case BTN_BACK:
3260 mAccumulator.fields |= Accumulator::FIELD_BTN_BACK;
3261 mAccumulator.btnBack = rawEvent->value;
3262 break;
3263 }
3264 sync(rawEvent->when);
3265 break;
3266
3267 case EV_REL:
3268 switch (rawEvent->scanCode) {
3269 case REL_X:
3270 mAccumulator.fields |= Accumulator::FIELD_REL_X;
3271 mAccumulator.relX = rawEvent->value;
3272 break;
3273 case REL_Y:
3274 mAccumulator.fields |= Accumulator::FIELD_REL_Y;
3275 mAccumulator.relY = rawEvent->value;
3276 break;
3277 case REL_WHEEL:
3278 mAccumulator.fields |= Accumulator::FIELD_REL_WHEEL;
3279 mAccumulator.btnScrollUp = (rawEvent->value == 1);
3280 mAccumulator.btnScrollDown = (rawEvent->value == -1);
3281 break;
3282 }
3283 break;
3284
3285 case EV_SYN:
3286 switch (rawEvent->scanCode) {
3287 case SYN_REPORT:
3288 sync(rawEvent->when);
3289 break;
3290 }
3291 break;
3292 }
3293 }
3294
3295 int32_t MouseInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
3296 return (scanCode >= BTN_LEFT && scanCode < BTN_JOYSTICK) ?
3297 getEventHub()->getScanCodeState(getDeviceId(), scanCode) : AKEY_STATE_UNKNOWN;
3298 }
3299
3300 void MouseInputMapper::initializeLocked() {
3301 mAccumulator.clear();
3302
3303 mLocked.down = false;
3304 mLocked.downTime = 0;
3305
3306 int32_t screenWidth;
3307 int32_t screenHeight;
3308 if (mAssociatedDisplayId < 0 || ! getPolicy()->getDisplayInfo(mAssociatedDisplayId, &screenWidth, &screenHeight, NULL)) {
3309 mAccumulator.absX = 0;
3310 mAccumulator.absY = 0;
3311 } else {
3312 mAccumulator.absX = screenWidth / 2;
3313 mAccumulator.absY = screenHeight / 2;
3314 }
3315 }
3316
3317 void MouseInputMapper::sync(nsecs_t when) {
3318 uint32_t fields = mAccumulator.fields;
3319 if (fields == 0) {
3320 return; // no new state changes, so nothing to do
3321 }
3322
3323 int motionEventAction;
3324 PointerCoords pointerCoords;
3325 Vector<Keyevent> events;
3326 nsecs_t downTime;
3327 { // acquire lock
3328 AutoMutex _l(mLock);
3329
3330 if (fields & Accumulator::FIELD_BTN_LEFT) {
3331 if ((mLocked.down = mAccumulator.btnLeft)) {
3332 mLocked.downTime = when;
3333 motionEventAction = AMOTION_EVENT_ACTION_DOWN;
3334 } else {
3335 motionEventAction = AMOTION_EVENT_ACTION_UP;
3336 }
3337 } else {
3338 motionEventAction = AMOTION_EVENT_ACTION_MOVE;
3339 }
3340
3341 Keyevent kevent;
3342 if (fields & Accumulator::FIELD_BTN_RIGHT) {
3343 kevent.down = mAccumulator.btnRight;
3344 kevent.keycode = mLocked.down ? AKEYCODE_HOME : AKEYCODE_BACK;
3345 events.push(kevent);
3346 }
3347 if (fields & Accumulator::FIELD_BTN_MIDDLE) {
3348 kevent.down = mAccumulator.btnMiddle;
3349 kevent.keycode = mLocked.down ? AKEYCODE_ENTER : AKEYCODE_MENU;
3350 events.push(kevent);
3351 }
3352 if (fields & Accumulator::FIELD_BTN_SIDE) {
3353 kevent.down = mAccumulator.btnSide;
3354 kevent.keycode = mLocked.down ? AKEYCODE_DPAD_RIGHT : AKEYCODE_HOME;
3355 events.push(kevent);
3356 }
3357 if (fields & Accumulator::FIELD_BTN_EXTRA) {
3358 kevent.down = mAccumulator.btnExtra;
3359 kevent.keycode = mLocked.down ? AKEYCODE_DPAD_LEFT : AKEYCODE_ENTER;
3360 events.push(kevent);
3361 }
3362 if (fields & Accumulator::FIELD_BTN_FORWARD) {
3363 kevent.down = mAccumulator.btnForward;
3364 kevent.keycode = AKEYCODE_DPAD_RIGHT;
3365 events.push(kevent);
3366 }
3367 if (fields & Accumulator::FIELD_BTN_BACK) {
3368 kevent.down = mAccumulator.btnBack;
3369 kevent.keycode = AKEYCODE_DPAD_LEFT;
3370 events.push(kevent);
3371 }
3372 if (fields & Accumulator::FIELD_REL_WHEEL) {
3373 if (mAccumulator.btnScrollUp) {
3374 kevent.keycode = mLocked.down ? AKEYCODE_MEDIA_NEXT : AKEYCODE_DPAD_UP;
3375 kevent.down = true;
3376 events.push(kevent);
3377 kevent.down = false;
3378 events.push(kevent);
3379 } else if (mAccumulator.btnScrollDown) {
3380 kevent.keycode = mLocked.down ? AKEYCODE_MEDIA_PREVIOUS : AKEYCODE_DPAD_DOWN;
3381 kevent.down = true;
3382 events.push(kevent);
3383 kevent.down = false;
3384 events.push(kevent);
3385 }
3386 }
3387
3388 downTime = mLocked.downTime;
3389
3390 float x = fields & Accumulator::FIELD_REL_X ? mAccumulator.relX : 0.0f;
3391 float y = fields & Accumulator::FIELD_REL_Y ? mAccumulator.relY : 0.0f;
3392
3393 int32_t screenWidth;
3394 int32_t screenHeight;
3395 int32_t orientation;
3396
3397 if (mAssociatedDisplayId < 0 || ! getPolicy()->getDisplayInfo(mAssociatedDisplayId, &screenWidth, &screenHeight, &orientation)) {
3398 return;
3399 }
3400
3401 mAccumulator.absX = (mAccumulator.absX + x) > screenWidth ? screenWidth - 1 : ((mAccumulator.absX + x) < 0 ? 0 : mAccumulator.absX + x);
3402 mAccumulator.absY = (mAccumulator.absY + y) > screenHeight ? screenHeight - 1 : ((mAccumulator.absY + y) < 0 ? 0 : mAccumulator.absY + y);
3403 pointerCoords.x = mAccumulator.absX;
3404 pointerCoords.y = mAccumulator.absY;
3405 pointerCoords.pressure = mLocked.down ? 1.0f : 0.0f;
3406 pointerCoords.size = 0;
3407 pointerCoords.touchMajor = 0;
3408 pointerCoords.touchMinor = 0;
3409 pointerCoords.toolMajor = 0;
3410 pointerCoords.toolMinor = 0;
3411 pointerCoords.orientation = 0;
3412
3413 float temp;
3414 switch (orientation) {
3415 case InputReaderPolicyInterface::ROTATION_90:
3416 temp = x;
3417 x = y;
3418 y = - temp;
3419 temp = screenHeight;
3420 screenHeight = screenWidth;
3421 screenWidth = temp;
3422 break;
3423
3424 case InputReaderPolicyInterface::ROTATION_180:
3425 x = - x;
3426 y = - y;
3427 break;
3428
3429 case InputReaderPolicyInterface::ROTATION_270:
3430 temp = x;
3431 x = - y;
3432 y = temp;
3433 temp = screenHeight;
3434 screenHeight = screenWidth;
3435 screenWidth = temp;
3436 break;
3437 }
3438
3439 } // release lock
3440
3441 int32_t metaState = mContext->getGlobalMetaState();
3442 for (size_t i = 0; i < events.size(); ++i) {
3443 getDispatcher()->notifyKey(when, getDeviceId(), AINPUT_SOURCE_DPAD, 0,
3444 events[i].down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
3445 AKEY_EVENT_FLAG_FROM_SYSTEM, events[i].keycode, 0,
3446 metaState, when);
3447 }
3448
3449 int32_t pointerId = 0;
3450 getDispatcher()->notifyMotion(when, getDeviceId(), AINPUT_SOURCE_MOUSE, 0,
3451 motionEventAction, 0, metaState, AMOTION_EVENT_EDGE_FLAG_NONE,
3452 1, &pointerId, &pointerCoords, 1, 1, downTime);
3453 mAccumulator.clear();
3454 }
3455
5、在openDevice(const char *deviceName)处增加鼠标类型
源代码路径:framework/base/libs/ui/EventHub.cpp
731 // See if this is a trackball (or mouse).
732 if (test_bit(BTN_MOUSE, key_bitmask)) {
733 uint8_t rel_bitmask[sizeof_bit_array(REL_MAX + 1)];
734 memset(rel_bitmask, 0, sizeof(rel_bitmask));
735 LOGV("Getting relative controllers...");
736 if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) >= 0) {
737 if (test_bit(REL_X, rel_bitmask) && test_bit(REL_Y, rel_bitmask)) {
738 device->classes |= (test_bit(BTN_LEFT, key_bitmask) && test_bit(BTN_RIGHT, key_bitmask)) ?
739 INPUT_DEVICE_CLASS_MOUSE : INPUT_DEVICE_CLASS_TRACKBALL;
740 }
741 }
742 }
743
6、修改鼠标事件分发响应
源代码路径:framework/base/libs/ui/InputDispatcher.cpp
718 bool InputDispatcher::dispatchMotionLocked(
719 nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime) {
720 // Preprocessing.
721 if (! entry->dispatchInProgress) {
722 entry->dispatchInProgress = true;
723 resetTargetsLocked();
724
725 logOutboundMotionDetailsLocked("dispatchMotion - ", entry);
726 }
727
728 // Clean up if dropping the event.
729 if (*dropReason != DROP_REASON_NOT_DROPPED) {
730 resetTargetsLocked();
731 setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
732 ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
733 return true;
734 }
735
736 bool isTouchEvent = ! ((entry->source & AINPUT_SOURCE_TOUCHSCREEN) ^ AINPUT_SOURCE_TOUCHSCREEN);
737 bool isMouseEvent = ! ((entry->source & AINPUT_SOURCE_MOUSE) ^ AINPUT_SOURCE_MOUSE);
738 bool isDownEvent = (entry->action & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_DOWN;
739
740 // Identify targets.
741 if (! mCurrentInputTargetsValid) {
742 int32_t injectionResult;
743 if (isTouchEvent || (isMouseEvent && (isDownEvent || mTouchState.down))) {
744 // Touch-like event. (eg. touchscreen or mouse drag-n-drop )
745 injectionResult = findTouchedWindowTargetsLocked(currentTime,
746 entry, nextWakeupTime);
747 } else {
748 // Non touch event. (eg. trackball or mouse simple move)
749 injectionResult = findFocusedWindowTargetsLocked(currentTime,
750 entry, nextWakeupTime);
751 }
752 if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
753 return false;
754 }
755
756 setInjectionResultLocked(entry, injectionResult);
757 if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
758 return true;
759 }
760
761 addMonitoringTargetsLocked();
762 commitTargetsLocked();
763 }
764
765 // Dispatch the motion.
766 dispatchEventToCurrentInputTargetsLocked(currentTime, entry, false);
767 return true;
768 }
769
源代码路径:framework/base/libs/ui/InputReader.cpp
310 InputDevice* InputReader::createDevice(int32_t deviceId, const String8& name, uint32_t classes) {
311 InputDevice* device = new InputDevice(this, deviceId, name);
312
313 const int32_t associatedDisplayId = 0; // FIXME: hardcoded for current single-display devices
314
315 // Switch-like devices.
316 if (classes & INPUT_DEVICE_CLASS_SWITCH) {
317 device->addMapper(new SwitchInputMapper(device));
318 }
319
320 // Keyboard-like devices.
321 uint32_t keyboardSources = 0;
322 int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC;
323 if (classes & INPUT_DEVICE_CLASS_KEYBOARD) {
324 keyboardSources |= AINPUT_SOURCE_KEYBOARD;
325 }
326 if (classes & INPUT_DEVICE_CLASS_ALPHAKEY) {
327 keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC;
328 }
329 if (classes & INPUT_DEVICE_CLASS_DPAD) {
330 keyboardSources |= AINPUT_SOURCE_DPAD;
331 }
332
333 if (keyboardSources != 0) {
334 device->addMapper(new KeyboardInputMapper(device,
335 associatedDisplayId, keyboardSources, keyboardType));
336 }
337
338 // Trackball-like devices.
339 if (classes & INPUT_DEVICE_CLASS_TRACKBALL) {
340 device->addMapper(new TrackballInputMapper(device, associatedDisplayId));
341 }
342
343 // Touchscreen-like devices.
344 if (classes & INPUT_DEVICE_CLASS_TOUCHSCREEN_MT) {
345 device->addMapper(new MultiTouchInputMapper(device, associatedDisplayId));
346 } else if (classes & INPUT_DEVICE_CLASS_TOUCHSCREEN) {
347 device->addMapper(new SingleTouchInputMapper(device, associatedDisplayId));
348 }
349
350 // Mouse-like devices.
351 if (classes & INPUT_DEVICE_CLASS_MOUSE) {
352 device->addMapper(new MouseInputMapper(device, associatedDisplayId));
353 }
354
355 return device;
356 }
8、鼠标绘制及响应
8-1、导入相应的包文件
源代码路径:framework/base/services/com/android/server/WindowsManagerService.java
import com.android.internal.view.BaseInputHandler;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.InputHandler;
import android.view.InputQueue;
8-2、添加鼠标显示函数
4977 private void showPointer() {
4978 if (mPointerSurface == null) {
4979 Bitmap pointer = BitmapFactory.decodeResource(mContext.getResources(),
4980 com.android.internal.R.drawable.pointer);
4981
4982 try {
4983 mPointerSurface = new Surface(mFxSession, 0, -1,
4984 pointer.getWidth(),
4985 pointer.getHeight(),
4986 PixelFormat.TRANSPARENT,
4987 Surface.FX_SURFACE_NORMAL);
4988
4989 Canvas canvas = mPointerSurface.lockCanvas(null);
4990 canvas.drawBitmap(pointer, 0, 0, new Paint());
4991 mPointerSurface.unlockCanvasAndPost(canvas);
4992 } catch (Surface.OutOfResourcesException e) {
4993 Log.e(TAG, "Failed to create mouse surface", e);
4994 }
4995 }
4996
4997 mPointerVisible = true;
4998 requestAnimationLocked(0);
4999 }
5000
5001 private void hidePointer() {
5002 mPointerVisible = false;
5003 requestAnimationLocked(0);
5004 }
5005
5006 private void startMouseMonitor() {
5007 mPointerInputChannel = monitorInput("MousePointer");
5008 InputQueue.registerInputChannel(mPointerInputChannel,
5009 mPointerInputHandler, mHandler.getLooper().getQueue());
5010 }
5011
8-3、定义一个inputHandler传递指标值
518 // Mouse pointer handling
519 Handler mHandler = new Handler();
520 Surface mPointerSurface;
521 boolean mPointerVisible;
522 int mPointerX;
523 int mPointerY;
524 InputChannel mPointerInputChannel;
525 final InputHandler mPointerInputHandler = new BaseInputHandler() {
526 @Override
527 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
528 finishedCallback.run();
529
530 boolean isMouse = ((event.getSource() & InputDevice.SOURCE_MOUSE) ^ InputDevice.SOURCE_MOUSE) == 0;
531 if (isMouse) {
532 mPointerX = (int) event.getRawX();
533 mPointerY = (int) event.getRawY();
534 showPointer();
535 } else if (mPointerVisible) {
536 hidePointer();
537 }
538 }
539 };
8-4、在 performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMemory)函数中绘制鼠标
9589 // Draw the mouse cursor, if necessary
9590 if (mPointerSurface != null) {
9591 if (mPointerVisible) {
9592 WindowState top = (WindowState)mWindows.get(mWindows.size() - 1);
9593 mPointerSurface.setPosition(mPointerX, mPointerY);
9594 mPointerSurface.setLayer(top.mAnimLayer + 1);
9595 mPointerSurface.show();
9596 } else {
9597 mPointerSurface.hide();
9598 }
9599 }
8-5、在WindowManagerService(Context context, PowerManagerService pm,boolean haveInputMethods) 函数中启动鼠标
672
673 mInputManager.start();
674 startMouseMonitor();
675
676 // Add ourself to the Watchdog monitors.
677 Watchdog.getInstance().addMonitor(this);
9、使能OTG USB设备
在xilinx via提供的android源码中有一个bug,鼠标或键盘通过OTG链接到zedboard板卡上,鼠标或键盘是不能工作的,如果希望鼠标或键盘工作则需要做一些修改
(1)修改PhoneWindowManager.java文件
源代码路径:framework/base/policy/src/com/android/internal/policy/im[l/PhoneWindowManager.java
修改处大约在1770行
将 if( isScroonOn || isInjected ) 改为if( isScroonOn || isInjected || true )
(2)修改com_android_server_InputManager.cpp文件
源代码路径:framework/base/services/jni/com_android_server_InputManager.cpp
913 void NativeInputManager::interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
914 #if DEBUG_INPUT_DISPATCHER_POLICY
915 LOGD("interceptGenericBeforeQueueing - when=%lld, policyFlags=0x%x", when, policyFlags);
916 #endif
917
918 // Policy:
919 // - Ignore untrusted events and pass them along.
920 // - No special filtering for injected events required at this time.
921 // - Filter normal events based on screen state.
922 // - For normal events brighten (but do not wake) the screen if currently dim.
923 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
924 if (isScreenOn()||true) {
925 policyFlags |= POLICY_FLAG_PASS_TO_USER;
926
927 if (!isScreenBright()) {
928 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
929 }
930 }
931 } else {
932 policyFlags |= POLICY_FLAG_PASS_TO_USER;
933 }
934 }
至此,zedboard上android移植鼠标步骤完成。