Loading core/java/android/provider/Settings.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -5711,6 +5711,13 @@ public final class Settings { */ */ public static final String ASSISTANT = "assistant"; public static final String ASSISTANT = "assistant"; /** * Whether the camera launch gesture should be disabled. * * @hide */ public static final String CAMERA_GESTURE_DISABLED = "camera_gesture_disabled"; /** /** * This are the settings to be backed up. * This are the settings to be backed up. * * Loading Loading @@ -5767,6 +5774,7 @@ public final class Settings { MOUNT_UMS_NOTIFY_ENABLED, MOUNT_UMS_NOTIFY_ENABLED, SLEEP_TIMEOUT, SLEEP_TIMEOUT, DOUBLE_TAP_TO_WAKE, DOUBLE_TAP_TO_WAKE, CAMERA_GESTURE_DISABLED, }; }; /** /** Loading services/core/java/com/android/server/GestureLauncherService.java +69 −7 Original line number Original line Diff line number Diff line Loading @@ -16,21 +16,26 @@ package com.android.server; package com.android.server; import android.app.ActivityManager; import android.app.KeyguardManager; import android.app.KeyguardManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.content.res.Resources; import android.database.ContentObserver; import android.hardware.Sensor; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.hardware.SensorManager; import android.os.Handler; import android.os.PowerManager; import android.os.PowerManager; import android.os.Vibrator; import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock; import android.os.SystemProperties; import android.os.SystemProperties; import android.os.Vibrator; import android.provider.MediaStore; import android.provider.MediaStore; import android.provider.Settings; import android.provider.Settings; import android.util.Slog; import android.util.Slog; Loading @@ -56,6 +61,8 @@ class GestureLauncherService extends SystemService { /** The wake lock held when a gesture is detected. */ /** The wake lock held when a gesture is detected. */ private WakeLock mWakeLock; private WakeLock mWakeLock; private boolean mRegistered; private int mUserId; public GestureLauncherService(Context context) { public GestureLauncherService(Context context) { super(context); super(context); Loading @@ -81,22 +88,51 @@ class GestureLauncherService extends SystemService { mWakeLock = powerManager.newWakeLock( mWakeLock = powerManager.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GestureLauncherService"); "GestureLauncherService"); if (isCameraLaunchEnabled(resources)) { updateCameraRegistered(); mUserId = ActivityManager.getCurrentUser(); mContext.registerReceiver(mUserReceiver, new IntentFilter(Intent.ACTION_USER_SWITCHED)); registerContentObserver(); } } private void registerContentObserver() { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.CAMERA_GESTURE_DISABLED), false, mSettingObserver, mUserId); } private void updateCameraRegistered() { Resources resources = mContext.getResources(); if (isCameraLaunchSettingEnabled(mContext, mUserId)) { registerCameraLaunchGesture(resources); registerCameraLaunchGesture(resources); } else { unregisterCameraLaunchGesture(); } } } } private void unregisterCameraLaunchGesture() { if (mRegistered) { mRegistered = false; SensorManager sensorManager = (SensorManager) mContext.getSystemService( Context.SENSOR_SERVICE); sensorManager.unregisterListener(mGestureListener); } } } /** /** * Registers for the camera launch gesture. * Registers for the camera launch gesture. */ */ private void registerCameraLaunchGesture(Resources resources) { private void registerCameraLaunchGesture(Resources resources) { if (mRegistered) { return; } SensorManager sensorManager = (SensorManager) mContext.getSystemService( SensorManager sensorManager = (SensorManager) mContext.getSystemService( Context.SENSOR_SERVICE); Context.SENSOR_SERVICE); int cameraLaunchGestureId = resources.getInteger( int cameraLaunchGestureId = resources.getInteger( com.android.internal.R.integer.config_cameraLaunchGestureSensorType); com.android.internal.R.integer.config_cameraLaunchGestureSensorType); if (cameraLaunchGestureId != -1) { if (cameraLaunchGestureId != -1) { boolean registered = false; mRegistered = false; String sensorName = resources.getString( String sensorName = resources.getString( com.android.internal.R.string.config_cameraLaunchGestureSensorStringType); com.android.internal.R.string.config_cameraLaunchGestureSensorStringType); mCameraLaunchSensor = sensorManager.getDefaultSensor( mCameraLaunchSensor = sensorManager.getDefaultSensor( Loading @@ -108,7 +144,7 @@ class GestureLauncherService extends SystemService { // makes the code more robust. // makes the code more robust. if (mCameraLaunchSensor != null) { if (mCameraLaunchSensor != null) { if (sensorName.equals(mCameraLaunchSensor.getStringType())) { if (sensorName.equals(mCameraLaunchSensor.getStringType())) { registered = sensorManager.registerListener(mGestureListener, mRegistered = sensorManager.registerListener(mGestureListener, mCameraLaunchSensor, 0); mCameraLaunchSensor, 0); } else { } else { String message = String.format("Wrong configuration. Sensor type and sensor " String message = String.format("Wrong configuration. Sensor type and sensor " Loading @@ -117,12 +153,18 @@ class GestureLauncherService extends SystemService { throw new RuntimeException(message); throw new RuntimeException(message); } } } } if (DBG) Slog.d(TAG, "Camera launch sensor registered: " + registered); if (DBG) Slog.d(TAG, "Camera launch sensor registered: " + mRegistered); } else { } else { if (DBG) Slog.d(TAG, "Camera launch sensor is not specified."); if (DBG) Slog.d(TAG, "Camera launch sensor is not specified."); } } } } public static boolean isCameraLaunchSettingEnabled(Context context, int userId) { return isCameraLaunchEnabled(context.getResources()) && (Settings.Secure.getIntForUser(context.getContentResolver(), Settings.Secure.CAMERA_GESTURE_DISABLED, 0, userId) == 0); } /** /** * Whether to enable the camera launch gesture. * Whether to enable the camera launch gesture. */ */ Loading @@ -142,6 +184,26 @@ class GestureLauncherService extends SystemService { return isCameraLaunchEnabled(resources); return isCameraLaunchEnabled(resources); } } private final BroadcastReceiver mUserReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { mUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); mContext.getContentResolver().unregisterContentObserver(mSettingObserver); registerContentObserver(); updateCameraRegistered(); } } }; private final ContentObserver mSettingObserver = new ContentObserver(new Handler()) { public void onChange(boolean selfChange, android.net.Uri uri, int userId) { if (userId == mUserId) { updateCameraRegistered(); } } }; private final class GestureEventListener implements SensorEventListener { private final class GestureEventListener implements SensorEventListener { @Override @Override public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) { Loading Loading
core/java/android/provider/Settings.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -5711,6 +5711,13 @@ public final class Settings { */ */ public static final String ASSISTANT = "assistant"; public static final String ASSISTANT = "assistant"; /** * Whether the camera launch gesture should be disabled. * * @hide */ public static final String CAMERA_GESTURE_DISABLED = "camera_gesture_disabled"; /** /** * This are the settings to be backed up. * This are the settings to be backed up. * * Loading Loading @@ -5767,6 +5774,7 @@ public final class Settings { MOUNT_UMS_NOTIFY_ENABLED, MOUNT_UMS_NOTIFY_ENABLED, SLEEP_TIMEOUT, SLEEP_TIMEOUT, DOUBLE_TAP_TO_WAKE, DOUBLE_TAP_TO_WAKE, CAMERA_GESTURE_DISABLED, }; }; /** /** Loading
services/core/java/com/android/server/GestureLauncherService.java +69 −7 Original line number Original line Diff line number Diff line Loading @@ -16,21 +16,26 @@ package com.android.server; package com.android.server; import android.app.ActivityManager; import android.app.KeyguardManager; import android.app.KeyguardManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.content.res.Resources; import android.database.ContentObserver; import android.hardware.Sensor; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.hardware.SensorManager; import android.os.Handler; import android.os.PowerManager; import android.os.PowerManager; import android.os.Vibrator; import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock; import android.os.SystemProperties; import android.os.SystemProperties; import android.os.Vibrator; import android.provider.MediaStore; import android.provider.MediaStore; import android.provider.Settings; import android.provider.Settings; import android.util.Slog; import android.util.Slog; Loading @@ -56,6 +61,8 @@ class GestureLauncherService extends SystemService { /** The wake lock held when a gesture is detected. */ /** The wake lock held when a gesture is detected. */ private WakeLock mWakeLock; private WakeLock mWakeLock; private boolean mRegistered; private int mUserId; public GestureLauncherService(Context context) { public GestureLauncherService(Context context) { super(context); super(context); Loading @@ -81,22 +88,51 @@ class GestureLauncherService extends SystemService { mWakeLock = powerManager.newWakeLock( mWakeLock = powerManager.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GestureLauncherService"); "GestureLauncherService"); if (isCameraLaunchEnabled(resources)) { updateCameraRegistered(); mUserId = ActivityManager.getCurrentUser(); mContext.registerReceiver(mUserReceiver, new IntentFilter(Intent.ACTION_USER_SWITCHED)); registerContentObserver(); } } private void registerContentObserver() { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.CAMERA_GESTURE_DISABLED), false, mSettingObserver, mUserId); } private void updateCameraRegistered() { Resources resources = mContext.getResources(); if (isCameraLaunchSettingEnabled(mContext, mUserId)) { registerCameraLaunchGesture(resources); registerCameraLaunchGesture(resources); } else { unregisterCameraLaunchGesture(); } } } } private void unregisterCameraLaunchGesture() { if (mRegistered) { mRegistered = false; SensorManager sensorManager = (SensorManager) mContext.getSystemService( Context.SENSOR_SERVICE); sensorManager.unregisterListener(mGestureListener); } } } /** /** * Registers for the camera launch gesture. * Registers for the camera launch gesture. */ */ private void registerCameraLaunchGesture(Resources resources) { private void registerCameraLaunchGesture(Resources resources) { if (mRegistered) { return; } SensorManager sensorManager = (SensorManager) mContext.getSystemService( SensorManager sensorManager = (SensorManager) mContext.getSystemService( Context.SENSOR_SERVICE); Context.SENSOR_SERVICE); int cameraLaunchGestureId = resources.getInteger( int cameraLaunchGestureId = resources.getInteger( com.android.internal.R.integer.config_cameraLaunchGestureSensorType); com.android.internal.R.integer.config_cameraLaunchGestureSensorType); if (cameraLaunchGestureId != -1) { if (cameraLaunchGestureId != -1) { boolean registered = false; mRegistered = false; String sensorName = resources.getString( String sensorName = resources.getString( com.android.internal.R.string.config_cameraLaunchGestureSensorStringType); com.android.internal.R.string.config_cameraLaunchGestureSensorStringType); mCameraLaunchSensor = sensorManager.getDefaultSensor( mCameraLaunchSensor = sensorManager.getDefaultSensor( Loading @@ -108,7 +144,7 @@ class GestureLauncherService extends SystemService { // makes the code more robust. // makes the code more robust. if (mCameraLaunchSensor != null) { if (mCameraLaunchSensor != null) { if (sensorName.equals(mCameraLaunchSensor.getStringType())) { if (sensorName.equals(mCameraLaunchSensor.getStringType())) { registered = sensorManager.registerListener(mGestureListener, mRegistered = sensorManager.registerListener(mGestureListener, mCameraLaunchSensor, 0); mCameraLaunchSensor, 0); } else { } else { String message = String.format("Wrong configuration. Sensor type and sensor " String message = String.format("Wrong configuration. Sensor type and sensor " Loading @@ -117,12 +153,18 @@ class GestureLauncherService extends SystemService { throw new RuntimeException(message); throw new RuntimeException(message); } } } } if (DBG) Slog.d(TAG, "Camera launch sensor registered: " + registered); if (DBG) Slog.d(TAG, "Camera launch sensor registered: " + mRegistered); } else { } else { if (DBG) Slog.d(TAG, "Camera launch sensor is not specified."); if (DBG) Slog.d(TAG, "Camera launch sensor is not specified."); } } } } public static boolean isCameraLaunchSettingEnabled(Context context, int userId) { return isCameraLaunchEnabled(context.getResources()) && (Settings.Secure.getIntForUser(context.getContentResolver(), Settings.Secure.CAMERA_GESTURE_DISABLED, 0, userId) == 0); } /** /** * Whether to enable the camera launch gesture. * Whether to enable the camera launch gesture. */ */ Loading @@ -142,6 +184,26 @@ class GestureLauncherService extends SystemService { return isCameraLaunchEnabled(resources); return isCameraLaunchEnabled(resources); } } private final BroadcastReceiver mUserReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { mUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); mContext.getContentResolver().unregisterContentObserver(mSettingObserver); registerContentObserver(); updateCameraRegistered(); } } }; private final ContentObserver mSettingObserver = new ContentObserver(new Handler()) { public void onChange(boolean selfChange, android.net.Uri uri, int userId) { if (userId == mUserId) { updateCameraRegistered(); } } }; private final class GestureEventListener implements SensorEventListener { private final class GestureEventListener implements SensorEventListener { @Override @Override public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) { Loading