android 7.1 屏蔽按压两次电源键(KEYCODE_POWER)打开相机

简介: android 7.1 屏蔽按压两次电源键(KEYCODE_POWER)打开相机

平台


RK3288 + Android7.1


需求


Android 支持通过快速按下电源键两次启动摄像头, 在新的需求中, 需要屏蔽此功能.


修改


frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
        // Hold a wake lock until the power key is released.
        /**省略**/
        GestureLauncherService gestureService = LocalServices.getService(
                GestureLauncherService.class);
        boolean gesturedServiceIntercepted = false;
        if (gestureService != null) {
          //注释下面两行代码.
            //gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive,
            //        mTmpBoolean);
            if (mTmpBoolean.value && mGoingToSleep) {
                mCameraGestureTriggeredDuringGoingToSleep = true;
            }
        }
        /**省略**/


流程


LOG

system_process D/WindowManager: ALog interceptKeyBeforeQueueing KEYCODE_POWER
system_process D/WindowManager: ALog interceptKeyBeforeQueueing KEYCODE_POWER
system_process I/PowerManagerService: Going to sleep due to power button (uid 1000)...
system_process I/PowerManagerService: Sleeping (uid 1000)...
system_process I/VrManagerService: VR mode is disallowed
system_process D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000
? D/PermissionCache: checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (732 us)
com.android.systemui W/FingerprintManager: isFingerprintHardwareDetected(): Service not connected!
system_process D/WindowManager: ALog interceptKeyBeforeQueueing KEYCODE_POWER
system_process I/GestureLauncherService: Power button double tap gesture detected, launching camera. Interval=220ms
system_process I/PowerManagerService: Waking up from sleep (uid 1000)...
system_process I/VrManagerService: VR mode is allowed
com.android.systemui I/KeyguardViewMediator: Camera gesture was triggered, preventing Keyguard locking.
system_process I/SensorsHal: set batch: handle = 0, period_ns = 20000000ns, timeout = 0ns
system_process D/SensorsHal: Couldn't open /dev/mma8452_daemon (No such file or directory)
system_process I/SensorsHal: MmaSensor update delay: 20ms
system_process E/SensorsHal: fail to perform GSENSOR_IOCTL_APP_SET_RATE, result = -1, error is 'Bad file descriptor'
system_process E/SensorService: sensor batch failed 0xa98df420 0 0 20000000 100000000 err=Operation not permitted
system_process I/SensorsHal: set batch: handle = 0, period_ns = 20000000ns, timeout = 0ns
system_process D/SensorsHal: Couldn't open /dev/mma8452_daemon (No such file or directory)
system_process I/SensorsHal: MmaSensor update delay: 20ms
system_process E/SensorsHal: fail to perform GSENSOR_IOCTL_APP_SET_RATE, result = -1, error is 'Bad file descriptor'
system_process E/SensorService: sensor batch failed 0xa98df420 0 0 20000000 0 err=Operation not permitted
system_process V/KeyguardServiceDelegate: onStartedWakingUp()
system_process W/VibratorService: Tried to stop vibrating but there is no vibrator device.
? D/AudioHardwareTiny: adev_set_parameters: kvpairs = screen_state=on
system_process W/VibratorService: Tried to vibrate but there is no vibrator device.
system_process D/WindowManager: ALog interceptKeyBeforeQueueing KEYCODE_POWER
system_process I/ActivityManager: START u0 {act=android.media.action.STILL_IMAGE_CAMERA flg=0x14000000 cmp=com.android.camera2/com.android.camera.CameraActivity} from uid 10018 on display 0
system_process E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
system_process E/ActivityManager: applyOptionsLocked: Unknown animationType=0
system_process I/ActivityManager: Start proc 1467:com.android.camera2/u0a25 for activity com.android.camera2/com.android.camera.CameraActivity


加了LOG interceptKeyBeforeQueueing KEYCODE_POWER

在触发后有输出关键LOG Power button double tap gesture detected, launching camera. Interval=220ms

之后启动了相机 ActivityManager: START u0 {act=android.media.action.STILL_IMAGE_CAMERA flg=0x14000000 cmp=com.android.camera2/com.android.camera.CameraActivity} from uid 10018 on display 0

frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java


/** {@inheritDoc} */
    @Override
    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
        /**省略**/
        // Handle special keys.
        switch (keyCode) {
            /**省略**/
            case KeyEvent.KEYCODE_POWER: {
                android.util.Log.d(TAG, "ALog interceptKeyBeforeQueueing KEYCODE_POWER");
                try {
                    if (mWindowManager.getDualScreenFlag()) {
                        if (mWindowManager.getSecondDisplayTaskId() != -1) {
                            break;
                        }
                    }
                } catch (RemoteException e) {
                }
                result &= ~ACTION_PASS_TO_USER;
                isWakeKey = false; // wake-up will be handled separately
                if (down) {
                    interceptPowerKeyDown(event, interactive);
                } else {
                    interceptPowerKeyUp(event, interactive, canceled);
                }
                break;
            }
        /**省略**/
    }
    private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
        // Hold a wake lock until the power key is released.
        /**省略**/
        GestureLauncherService gestureService = LocalServices.getService(
                GestureLauncherService.class);
        boolean gesturedServiceIntercepted = false;
        if (gestureService != null) {
            gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive,
                    mTmpBoolean);
            if (mTmpBoolean.value && mGoingToSleep) {
                mCameraGestureTriggeredDuringGoingToSleep = true;
            }
        }
        /**省略**/


frameworks/base/services/core/java/com/android/server/GestureLauncherService.java


public boolean interceptPowerKeyDown(KeyEvent event, boolean interactive,
            MutableBoolean outLaunched) {
        boolean launched = false;
        boolean intercept = false;
        long doubleTapInterval;
        synchronized (this) {
            doubleTapInterval = event.getEventTime() - mLastPowerDown;
            if (mCameraDoubleTapPowerEnabled
                    && doubleTapInterval < CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS) {
                launched = true;
                intercept = interactive;
            }
            mLastPowerDown = event.getEventTime();
        }
        if (launched) {
            Slog.i(TAG, "Power button double tap gesture detected, launching camera. Interval="
                    + doubleTapInterval + "ms");
            launched = handleCameraLaunchGesture(false /* useWakelock */,
                    StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
            if (launched) {
                MetricsLogger.action(mContext, MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
                        (int) doubleTapInterval);
            }
        }
        MetricsLogger.histogram(mContext, "power_double_tap_interval", (int) doubleTapInterval);
        outLaunched.value = launched;
        return intercept && launched;
    }
    /**
     * @return true if camera was launched, false otherwise.
     */
    private boolean handleCameraLaunchGesture(boolean useWakelock, int source) {
        boolean userSetupComplete = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
        if (!userSetupComplete) {
            if (DBG) Slog.d(TAG, String.format(
                    "userSetupComplete = %s, ignoring camera launch gesture.",
                    userSetupComplete));
            return false;
        }
        if (DBG) Slog.d(TAG, String.format(
                "userSetupComplete = %s, performing camera launch gesture.",
                userSetupComplete));
        if (useWakelock) {
            // Make sure we don't sleep too early
            mWakeLock.acquire(500L);
        }
        StatusBarManagerInternal service = LocalServices.getService(
                StatusBarManagerInternal.class);
        service.onCameraLaunchGestureDetected(source);
        return true;
    }


frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java


@Override
    public void onCameraLaunchGestureDetected(int source) {
        mLastCameraLaunchSource = source;
        if (mStartedGoingToSleep) {
            mLaunchCameraOnFinishedGoingToSleep = true;
            return;
        }
        if (!mNotificationPanel.canCameraGestureBeLaunched(
                mStatusBarKeyguardViewManager.isShowing() && mExpandedVisible)) {
            return;
        }
        if (!mDeviceInteractive) {
            PowerManager pm = mContext.getSystemService(PowerManager.class);
            pm.wakeUp(SystemClock.uptimeMillis(), "com.android.systemui:CAMERA_GESTURE");
            mStatusBarKeyguardViewManager.notifyDeviceWakeUpRequested();
        }
        vibrateForCameraGesture();
        if (!mStatusBarKeyguardViewManager.isShowing()) {
          //启动摄像头
            startActivity(KeyguardBottomAreaView.INSECURE_CAMERA_INTENT,
                    true /* dismissShade */);
        } else {
            if (!mDeviceInteractive) {
                // Avoid flickering of the scrim when we instant launch the camera and the bouncer
                // comes on.
                mScrimController.dontAnimateBouncerChangesUntilNextFrame();
                mGestureWakeLock.acquire(LAUNCH_TRANSITION_TIMEOUT_MS + 1000L);
            }
            if (mScreenTurningOn || mStatusBarKeyguardViewManager.isScreenTurnedOn()) {
                mNotificationPanel.launchCamera(mDeviceInteractive /* animate */, source);
            } else {
                // We need to defer the camera launch until the screen comes on, since otherwise
                // we will dismiss us too early since we are waiting on an activity to be drawn and
                // incorrectly get notified because of the screen on event (which resumes and pauses
                // some activities)
                mLaunchCameraOnScreenTurningOn = true;
            }
        }
    }


frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java


public static final Intent INSECURE_CAMERA_INTENT =
            new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
相关文章
|
Android开发
Android调用相机与相册的方法1
Android调用相机与相册的方法
444 0
|
XML Java Android开发
Android Studio App开发之使用相机拍摄照片和从相册中选取图片(附源码 超详细必看)
Android Studio App开发之使用相机拍摄照片和从相册中选取图片(附源码 超详细必看)
2478 2
|
11月前
|
XML Java Android开发
微信虚拟视频插件安卓,微信虚拟相机替换拍照,java源码分享
完整的相机应用项目包含三个主要文件:主活动实现、布局文件和清单文件。代码实现了相机预览、
|
11月前
|
Java Android开发
安卓虚拟摄像头过人脸,免root虚拟hook相机,虚拟相机hook版【jar】
两种Hook Android相机的方法:Xposed模块和Frida脚本。Xposed模块需要安装在已root的设备
|
Java Android开发
Android12 双击power键启动相机源码解析
Android12 双击power键启动相机源码解析
489 0
|
测试技术 API Android开发
Android经典实战之简化 Android 相机开发:CameraX 库的全面解析
CameraX是Android Jetpack的一个组件,旨在简化相机应用开发,提供了易于使用的API并支持从Android 5.0(API级别21)起的设备。其主要特性包括广泛的设备兼容性、简洁的API、生命周期感知、简化实现及方便的集成与测试。通过简单的几个步骤即可实现如拍照、视频录制等功能。此外,还提供了最佳实践指导以确保应用的稳定性和性能。
762 0
|
Java Android开发
Android 长按电源键弹出的GlobalActions菜单
Android 长按电源键弹出的GlobalActions菜单
655 1
|
API Android开发
57. 【Android教程】相机:Camera
57. 【Android教程】相机:Camera
575 0
|
Android开发
Android调用相机与相册的方法2
Android调用相机与相册的方法
238 0
|
Android开发
[笔记]Android开发之相机开发 Camera1、2、X
[笔记]Android开发之相机开发 Camera1、2、X
202 0

热门文章

最新文章