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);
相關文章
- 啟動按ctrl鍵 遮蔽自動隱藏功能
- RK3399 android7.1 DTS 電壓域的配置Android
- 直播原始碼開發,Android 遮蔽返回鍵(後退鍵)原始碼Android
- RK3399 android7.1 DTS 頻率電壓表配置Android
- 按下電源鍵後竟然發生了這一幕 —— Android 系統啟動流程分析Android
- 電腦睡眠模式按什麼鍵開機 電腦睡眠模式怎麼喚醒啟動模式
- win10系統遮蔽機箱電源鍵關機功能使其不關機的方法Win10
- 遮蔽iframe子頁面F12按鍵
- 開關電源——壓敏電阻
- android--相機開發----我的相機我做主Android
- android短視訊開發,呼叫相機、相簿,壓縮圖片後上傳Android
- win7軟鍵盤怎麼開啟?WIN7電腦中開啟“軟鍵盤”使用的兩種方法Win7
- Android開發在Activity外申請許可權呼叫相機開啟相簿Android
- Win10系統取消按電源鍵喚醒的方法Win10
- 直流穩壓電源
- win10怎麼重啟電腦_win10電腦按什麼鍵重啟Win10
- CameraX:Android 相機庫開發實踐Android
- 遮蔽電感廠家科普遮蔽電感和非遮蔽電感的區別
- 電腦開機白屏但是有滑鼠怎麼解決 電腦白屏按哪三個鍵
- 電腦白屏了按哪個鍵可以修復 電腦開機後白屏怎麼解決
- Android開機自啟動程式Android
- win10系統下不能連續按兩下鍵盤按鍵如何解決Win10
- 技嘉主機板進入bios按哪個鍵 技嘉主機板u盤啟動按f幾iOS
- win10如何遮蔽 win鍵_win10怎麼遮蔽win鍵Win10
- 遮蔽電感和非遮蔽電感的區別
- DM 關鍵字、遮蔽關鍵字
- 二、zigbee裸機程式--按鍵
- RK3288 Android7.1 軟體開發指南Android
- Android開發筆記——透明狀態列與透明虛擬按鍵Android筆記
- 清華機試oj——手機按鍵
- android開啟軟鍵盤部分內容上移Android
- 感應電動機的啟動壓降計算
- 在全志T507開發板上新增兩個GPIO按鍵
- Android使用者請注意,你的相機正在偷偷開啟並拍照攝像Android
- Oracle Linux 7.1 透過systemctl將Weblogic設定為開機自啟動OracleLinuxWeb
- Android設定app開機自啟AndroidAPP
- Android 實現開機自啟APPAndroidAPP
- 遠端控制你的智慧電視,按鍵|輸入|安裝App等都已實現,已開源!APP