取消双击按键启动相机

1

在项目开发过程中,测试报了一个有关相机的bug,在双击按键时会去打开相机,但是板子上没有摄像头,所以打开时就会报错,于是乎我拿着板子抓了一个双击power键的日志:

04-03 00:46:44.252   615   615 D KeyguardViewMediator: handleNotifyStartedGoingToSleep
04-03 00:46:44.285   453   523 I GestureLauncherService: Power button double tap gesture detected, launching camera. Interval=210ms
04-03 00:46:44.286   453   523 I PowerManagerService: Waking up from Asleep (uid=1000, reason=WAKE_REASON_POWER_BUTTON, details=android.policy:POWER)...
04-03 00:46:44.288   239   983 D gralloc4: [File] : hardware/rockchip/libgralloc/bifrost/src/hidl_common/Allocator.cpp; [Line] : 149; [Func] : allocate;
04-03 00:46:44.288   239   983 D gralloc4: got new private_handle_t instance @0xb4000075c08cafd0 for buffer 'ColorFade#0'. share_fd : 8, share_attr_fd : 9, flags : 0x4, width : 800, height : 1280, req_format : 0x1, producer_usage : 0x40000000000b00, consumer_usage : 0x40000000000b00, internal_format : 0x0, stride : 0, byte_stride : 0, internalWidth : 0, internalHeight : 0, alloc_format : 0x100000001, size : 4160512, layer_count : 1, backing_store_size : 4160512, backing_store_id : 1026497183873, allocating_pid : 239, ref_count : 1, yuv_info : 0
04-03 00:46:44.288   239   983 D gralloc4: plane_info[0]: offset : 0, byte_stride : 3200, alloc_width : 800, alloc_height : 1280
04-03 00:46:44.288   239   983 D gralloc4: plane_info[1]: offset : 0, byte_stride : 0, alloc_width : 0, alloc_height : 0
04-03 00:46:44.292   615   634 D KeyguardViewMediator: onFinishedGoingToSleep(2)
04-03 00:46:44.292   615   634 D KeyguardViewMediator: notifyFinishedGoingToSleep
04-03 00:46:44.292   615   634 I KeyguardViewMediator: Camera gesture was triggered, preventing Keyguard locking.
04-03 00:46:44.294   615   634 D KeyguardViewMediator: onStartedWakingUp, seq = 3
04-03 00:46:44.294   615   634 D KeyguardViewMediator: notifyStartedWakingUp
04-03 00:46:44.295   615   615 D KeyguardViewMediator: handleNotifyFinishedGoingToSleep
04-03 00:46:44.298   239   983 D gralloc4: [File] : hardware/rockchip/libgralloc/bifrost/src/hidl_common/Allocator.cpp; [Line] : 149; [Func] : allocate;
04-03 00:46:44.298   239   983 D gralloc4: got new private_handle_t instance @0xb4000075c08caa30 for buffer 'ColorFade#0'. share_fd : 8, share_attr_fd : 9, flags : 0x4, width : 800, height : 1280, req_format : 0x1, producer_usage : 0x40000000000b00, consumer_usage : 0x40000000000b00, internal_format : 0x0, stride : 0, byte_stride : 0, internalWidth : 0, internalHeight : 0, alloc_format : 0x100000001, size : 4160512, layer_count : 1, backing_store_size : 4160512, backing_store_id : 1026497183874, allocating_pid : 239, ref_count : 1, yuv_info : 0
04-03 00:46:44.298   239   983 D gralloc4: plane_info[0]: offset : 0, byte_stride : 3200, alloc_width : 800, alloc_height : 1280
04-03 00:46:44.298   239   983 D gralloc4: plane_info[1]: offset : 0, byte_stride : 0, alloc_width : 0, alloc_height : 0
04-03 00:46:44.301   453   453 D WifiSleepController: onReceive, action=android.intent.action.SCREEN_OFF
04-03 00:46:44.302   453   453 D WifiSleepController: isScanAlwaysAvailable = false
04-03 00:46:44.302   453   453 D WifiSleepController: shouldStartWifiSleep: isWifiOpen = true
04-03 00:46:44.302   453   453 D WifiSleepController: shouldStartBtSleep: isBtOpen = true
04-03 00:46:44.307   239   983 D gralloc4: [File] : hardware/rockchip/libgralloc/bifrost/src/hidl_common/Allocator.cpp; [Line] : 149; [Func] : allocate;
04-03 00:46:44.307   239   983 D gralloc4: got new private_handle_t instance @0xb4000075c08cafd0 for buffer 'ColorFade#0'. share_fd : 8, share_attr_fd : 9, flags : 0x4, width : 800, height : 1280, req_format : 0x1, producer_usage : 0x40000000000b00, consumer_usage : 0x40000000000b00, internal_format : 0x0, stride : 0, byte_stride : 0, internalWidth : 0, internalHeight : 0, alloc_format : 0x100000001, size : 4160512, layer_count : 1, backing_store_size : 4160512, backing_store_id : 1026497183875, allocating_pid : 239, ref_count : 1, yuv_info : 0
04-03 00:46:44.307   268  1055 D AudioHardwareTiny: adev_set_parameters: kvpairs = screen_state=off
04-03 00:46:44.307   239   983 D gralloc4: plane_info[0]: offset : 0, byte_stride : 3200, alloc_width : 800, alloc_height : 1280
04-03 00:46:44.307   239   983 D gralloc4: plane_info[1]: offset : 0, byte_stride : 0, alloc_width : 0, alloc_height : 0
04-03 00:46:44.325   615   615 D KeyguardViewMediator: handleNotifyWakingUp
04-03 00:46:44.329     0     0 W dhd_set_suspend: force extra suspend setting
04-03 00:46:44.329     0     0 W dhd_enable_packet_filter: enter, value = 1
04-03 00:46:44.341   453   826 E VibratorService: vibratorOff command failed (1).
04-03 00:46:44.342   615   615 V StatusBar: Camera launch 

从日志中我们可以提取到"GestureLauncherService: Power button double tap gesture detected, launching camera. Interval=210ms"这样一条信息,然后我们可以去framework中找到这个"Power button double tap"打印的位置,


    public boolean interceptPowerKeyDown(KeyEvent event, boolean interactive,
            MutableBoolean outLaunched) {
        if (event.isLongPress()) {
            // Long presses are sent as a second key down. If the long press threshold is set lower
            // than the double tap of sequence interval thresholds, this could cause false double
            // taps or consecutive taps, so we want to ignore the long press event.
            return false;
        }
        boolean launched = false;
        boolean intercept = false;
        long powerTapInterval;
        synchronized (this) {
            powerTapInterval = event.getEventTime() - mLastPowerDown;
            if (mCameraDoubleTapPowerEnabled
                    && powerTapInterval < CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS) {
                launched = true;
                intercept = interactive;
                mPowerButtonConsecutiveTaps++;
            } else if (powerTapInterval < POWER_SHORT_TAP_SEQUENCE_MAX_INTERVAL_MS) {
                mPowerButtonConsecutiveTaps++;
            } else {
                mPowerButtonConsecutiveTaps = 1;
            }
            mLastPowerDown = event.getEventTime();
        }
        if (DBG && mPowerButtonConsecutiveTaps > 1) {
            Slog.i(TAG, Long.valueOf(mPowerButtonConsecutiveTaps) +
                    " consecutive power button taps detected");
        }
        /*
        if (launched) {
            Slog.i(TAG, "Power button double tap gesture detected, launching camera. Interval="
                    + powerTapInterval + "ms");
            launched = handleCameraGesture(false // useWakelock,
                    StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
            if (launched) {
                mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
                        (int) powerTapInterval);
                mUiEventLogger.log(GestureLauncherEvent.GESTURE_CAMERA_DOUBLE_TAP_POWER);
            }
        }
    */
        mMetricsLogger.histogram("power_consecutive_short_tap_count", mPowerButtonConsecutiveTaps);
        mMetricsLogger.histogram("power_double_tap_interval", (int) powerTapInterval);
        outLaunched.value = launched;
        return intercept && launched;
    }

你可能感兴趣的:(android驱动,android)