Search in sources :

Example 46 with SensorManager

use of android.hardware.SensorManager in project android_frameworks_base by AOSPA.

the class GestureLauncherService method registerCameraLaunchGesture.

/**
     * Registers for the camera launch gesture.
     */
private void registerCameraLaunchGesture(Resources resources) {
    if (mRegistered) {
        return;
    }
    mCameraGestureOnTimeMs = SystemClock.elapsedRealtime();
    mCameraGestureLastEventTime = mCameraGestureOnTimeMs;
    SensorManager sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    int cameraLaunchGestureId = resources.getInteger(com.android.internal.R.integer.config_cameraLaunchGestureSensorType);
    if (cameraLaunchGestureId != -1) {
        mRegistered = false;
        String sensorName = resources.getString(com.android.internal.R.string.config_cameraLaunchGestureSensorStringType);
        mCameraLaunchSensor = sensorManager.getDefaultSensor(cameraLaunchGestureId, true);
        // makes the code more robust.
        if (mCameraLaunchSensor != null) {
            if (sensorName.equals(mCameraLaunchSensor.getStringType())) {
                mRegistered = sensorManager.registerListener(mGestureListener, mCameraLaunchSensor, 0);
            } else {
                String message = String.format("Wrong configuration. Sensor type and sensor " + "string type don't match: %s in resources, %s in the sensor.", sensorName, mCameraLaunchSensor.getStringType());
                throw new RuntimeException(message);
            }
        }
        if (DBG)
            Slog.d(TAG, "Camera launch sensor registered: " + mRegistered);
    } else {
        if (DBG)
            Slog.d(TAG, "Camera launch sensor is not specified.");
    }
}
Also used : SensorManager(android.hardware.SensorManager)

Example 47 with SensorManager

use of android.hardware.SensorManager in project android_frameworks_base by ResurrectionRemix.

the class PowerManagerService method systemReady.

public void systemReady(IAppOpsService appOps) {
    synchronized (mLock) {
        mSystemReady = true;
        mAppOps = appOps;
        mDreamManager = getLocalService(DreamManagerInternal.class);
        mDisplayManagerInternal = getLocalService(DisplayManagerInternal.class);
        mPolicy = getLocalService(WindowManagerPolicy.class);
        mBatteryManagerInternal = getLocalService(BatteryManagerInternal.class);
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting();
        mScreenBrightnessSettingMaximum = pm.getMaximumScreenBrightnessSetting();
        mScreenBrightnessSettingDefault = pm.getDefaultScreenBrightnessSetting();
        mScreenBrightnessForVrSettingDefault = pm.getDefaultScreenBrightnessForVrSetting();
        mButtonBrightnessSettingDefault = pm.getDefaultButtonBrightness();
        mKeyboardBrightnessSettingDefault = pm.getDefaultKeyboardBrightness();
        SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper());
        // The notifier runs on the system server's main looper so as not to interfere
        // with the animations and other critical functions of the power manager.
        mBatteryStats = BatteryStatsService.getService();
        mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats, mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"), mPolicy);
        mWirelessChargerDetector = new WirelessChargerDetector(sensorManager, createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"), mHandler);
        mSettingsObserver = new SettingsObserver(mHandler);
        mLightsManager = getLocalService(LightsManager.class);
        mAttentionLight = mLightsManager.getLight(LightsManager.LIGHT_ID_ATTENTION);
        mButtonsLight = mLightsManager.getLight(LightsManager.LIGHT_ID_BUTTONS);
        mKeyboardLight = mLightsManager.getLight(LightsManager.LIGHT_ID_KEYBOARD);
        mCapsLight = mLightsManager.getLight(LightsManager.LIGHT_ID_CAPS);
        mFnLight = mLightsManager.getLight(LightsManager.LIGHT_ID_FUNC);
        // Initialize display power management.
        mDisplayManagerInternal.initPowerManagement(mDisplayPowerCallbacks, mHandler, sensorManager);
        // Initialize proximity sensor
        mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
        mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        // Register for settings changes.
        final ContentResolver resolver = mContext.getContentResolver();
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ENABLED), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_OFF_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.SLEEP_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.STAY_ON_WHILE_PLUGGED_IN), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_FOR_VR), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.THEATER_MODE_ON), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.DOUBLE_TAP_TO_WAKE), false, mSettingsObserver, UserHandle.USER_ALL);
        IVrManager vrManager = (IVrManager) getBinderService(VrManagerService.VR_MANAGER_BINDER_SERVICE);
        if (vrManager != null) {
            try {
                vrManager.registerListener(mVrStateCallbacks);
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to register VR mode state listener: " + e);
            }
        }
        resolver.registerContentObserver(CMSettings.Secure.getUriFor(CMSettings.Secure.BUTTON_BRIGHTNESS), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(CMSettings.Secure.getUriFor(CMSettings.Secure.KEYBOARD_BRIGHTNESS), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(CMSettings.Secure.getUriFor(CMSettings.Secure.BUTTON_BACKLIGHT_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(CMSettings.Global.getUriFor(CMSettings.Global.WAKE_WHEN_PLUGGED_OR_UNPLUGGED), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(CMSettings.Global.getUriFor(CMSettings.Global.DEV_FORCE_SHOW_NAVBAR), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(CMSettings.System.getUriFor(CMSettings.System.PROXIMITY_ON_WAKE), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.WAKELOCK_BLOCKING_ENABLED), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.WAKELOCK_BLOCKING_LIST), false, mSettingsObserver, UserHandle.USER_ALL);
        // Go.
        readConfigurationLocked();
        updateSettingsLocked();
        mDirty |= DIRTY_BATTERY_STATE;
        updatePowerStateLocked();
    }
    // Register for broadcasts from other components of the system.
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_BATTERY_CHANGED);
    filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler);
    filter = new IntentFilter();
    filter.addAction(Intent.ACTION_DREAMING_STARTED);
    filter.addAction(Intent.ACTION_DREAMING_STOPPED);
    mContext.registerReceiver(new DreamReceiver(), filter, null, mHandler);
    filter = new IntentFilter();
    filter.addAction(Intent.ACTION_USER_SWITCHED);
    mContext.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);
    filter = new IntentFilter();
    filter.addAction(Intent.ACTION_DOCK_EVENT);
    mContext.registerReceiver(new DockReceiver(), filter, null, mHandler);
}
Also used : IntentFilter(android.content.IntentFilter) SystemSensorManager(android.hardware.SystemSensorManager) BatteryManagerInternal(android.os.BatteryManagerInternal) ContentResolver(android.content.ContentResolver) PowerManager(android.os.PowerManager) IPowerManager(android.os.IPowerManager) SensorManager(android.hardware.SensorManager) SystemSensorManager(android.hardware.SystemSensorManager) WindowManagerPolicy(android.view.WindowManagerPolicy) LightsManager(com.android.server.lights.LightsManager) DisplayManagerInternal(android.hardware.display.DisplayManagerInternal) RemoteException(android.os.RemoteException) DreamManagerInternal(android.service.dreams.DreamManagerInternal) IVrManager(android.service.vr.IVrManager)

Example 48 with SensorManager

use of android.hardware.SensorManager in project weex-example by KalicyZhou.

the class AmbientLightManager method start.

void start(CameraManager cameraManager) {
    this.cameraManager = cameraManager;
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        if (lightSensor != null) {
            sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
        }
    }
}
Also used : SensorManager(android.hardware.SensorManager) SharedPreferences(android.content.SharedPreferences)

Example 49 with SensorManager

use of android.hardware.SensorManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class GestureSettings method hasSensor.

private static boolean hasSensor(Context context, int nameResId, int vendorResId) {
    Resources resources = context.getResources();
    String name = resources.getString(nameResId);
    String vendor = resources.getString(vendorResId);
    if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
            if (name.equals(s.getName()) && vendor.equals(s.getVendor())) {
                return true;
            }
        }
    }
    return false;
}
Also used : SensorManager(android.hardware.SensorManager) Resources(android.content.res.Resources) Sensor(android.hardware.Sensor)

Example 50 with SensorManager

use of android.hardware.SensorManager in project android_packages_apps_Settings by LineageOS.

the class DoubleTwistPreferenceController method isGestureAvailable.

public static boolean isGestureAvailable(Context context) {
    final Resources resources = context.getResources();
    final String name = resources.getString(R.string.gesture_double_twist_sensor_name);
    final String vendor = resources.getString(R.string.gesture_double_twist_sensor_vendor);
    if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
        final SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
            if (name.equals(s.getName()) && vendor.equals(s.getVendor())) {
                return true;
            }
        }
    }
    return false;
}
Also used : SensorManager(android.hardware.SensorManager) Resources(android.content.res.Resources) Sensor(android.hardware.Sensor)

Aggregations

SensorManager (android.hardware.SensorManager)89 Sensor (android.hardware.Sensor)29 SharedPreferences (android.content.SharedPreferences)12 Resources (android.content.res.Resources)8 PowerManager (android.os.PowerManager)6 ContentResolver (android.content.ContentResolver)5 IntentFilter (android.content.IntentFilter)5 SystemSensorManager (android.hardware.SystemSensorManager)5 IPowerManager (android.os.IPowerManager)5 RemoteException (android.os.RemoteException)5 WindowManager (android.view.WindowManager)5 DisplayManagerInternal (android.hardware.display.DisplayManagerInternal)4 BatteryManagerInternal (android.os.BatteryManagerInternal)4 DreamManagerInternal (android.service.dreams.DreamManagerInternal)4 IVrManager (android.service.vr.IVrManager)4 Display (android.view.Display)4 WindowManagerPolicy (android.view.WindowManagerPolicy)4 LightsManager (com.android.server.lights.LightsManager)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3