Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52af7e07 authored by Adrian Roos's avatar Adrian Roos Committed by Android (Google) Code Review
Browse files

Merge "Separate ambient display triggers" into nyc-mr1-dev

parents 964874e4 b7e4e106
Loading
Loading
Loading
Loading
+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.internal.hardware;

import com.android.internal.R;

import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;

public class AmbientDisplayConfiguration {

    private final Context mContext;

    public AmbientDisplayConfiguration(Context context) {
        mContext = context;
    }
    
    public boolean enabled(int user) {
        return pulseOnNotificationEnabled(user)
                || pulseOnPickupEnabled(user)
                || pulseOnDoubleTapEnabled(user);
    }
    
    public boolean available() {
        return pulseOnNotificationAvailable() || pulseOnPickupAvailable()
                || pulseOnDoubleTapAvailable();
    }
    
    public boolean pulseOnNotificationEnabled(int user) {
        return boolSetting(Settings.Secure.DOZE_ENABLED, user) && pulseOnNotificationAvailable();
    }

    public boolean pulseOnNotificationAvailable() {
        return ambientDisplayAvailable();
    }

    public boolean pulseOnPickupEnabled(int user) {
        return boolSetting(Settings.Secure.DOZE_PULSE_ON_PICK_UP, user)
                && pulseOnPickupAvailable();
    }
    
    public boolean pulseOnPickupAvailable() {
        return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup)
                && ambientDisplayAvailable();
    }
    
    public boolean pulseOnDoubleTapEnabled(int user) {
        return boolSetting(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, user)
                && pulseOnDoubleTapAvailable();
    }

    public boolean pulseOnDoubleTapAvailable() {
        return !TextUtils.isEmpty(doubleTapSensorType()) && ambientDisplayAvailable();
    }

    public String doubleTapSensorType() {
        return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
    }

    public String ambientDisplayComponent() {
        return mContext.getResources().getString(R.string.config_dozeComponent);
    }

    private boolean ambientDisplayAvailable() {
        return !TextUtils.isEmpty(ambientDisplayComponent());
    }

    private boolean boolSetting(String name, int user) {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, 1, user) != 0;
    }

}
+6 −0
Original line number Diff line number Diff line
@@ -1661,6 +1661,12 @@
         turned off and the screen off animation has been performed. -->
    <bool name="config_dozeAfterScreenOff">false</bool>

    <!-- Doze: should the TYPE_PICK_UP_GESTURE sensor be used as a pulse signal. -->
    <bool name="config_dozePulsePickup">false</bool>

    <!-- Type of the double tap sensor. Empty if double tap is not supported. -->
    <string name="config_dozeDoubleTapSensorType" translatable="false"></string>

    <!-- Power Management: Specifies whether to decouple the auto-suspend state of the
         device from the display on/off state.

+3 −0
Original line number Diff line number Diff line
@@ -2668,6 +2668,9 @@
  <java-symbol type="string" name="config_emergency_call_number" />
  <java-symbol type="array" name="config_emergency_mcc_codes" />

  <java-symbol type="string" name="config_dozeDoubleTapSensorType" />
  <java-symbol type="bool" name="config_dozePulsePickup" />

  <!-- Used for MimeIconUtils. -->
  <java-symbol type="drawable" name="ic_doc_apk" />
  <java-symbol type="drawable" name="ic_doc_audio" />
+0 −6
Original line number Diff line number Diff line
@@ -209,9 +209,6 @@
    <!-- Doze: should the significant motion sensor be used as a pulse signal? -->
    <bool name="doze_pulse_on_significant_motion">false</bool>

    <!-- Doze: should the pickup sensor be used as a pulse signal? -->
    <bool name="doze_pulse_on_pick_up">false</bool>

    <!-- Doze: check proximity sensor before pulsing? -->
    <bool name="doze_proximity_check_before_pulse">true</bool>

@@ -240,9 +237,6 @@
    -->
    <string name="doze_pickup_subtype_performs_proximity_check"></string>

    <!-- Type of the double tap sensor. Empty if double tap is not supported. -->
    <string name="doze_double_tap_sensor_type" translatable="false"></string>

    <!-- Doze: pulse parameter - how long does it take to fade in? -->
    <integer name="doze_pulse_duration_in">900</integer>

+9 −5
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.Display;

import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.systemui.SystemUIApplication;
@@ -85,6 +86,8 @@ public class DozeService extends DreamService {
    private boolean mCarMode;
    private long mNotificationPulseTime;

    private AmbientDisplayConfiguration mConfig;

    public DozeService() {
        if (DEBUG) Log.d(mTag, "new DozeService()");
        setDebug(DEBUG);
@@ -125,6 +128,7 @@ public class DozeService extends DreamService {
        setWindowless(true);

        mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
        mConfig = new AmbientDisplayConfiguration(mContext);
        mSensors = new TriggerSensor[] {
                new TriggerSensor(
                        mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION),
@@ -135,12 +139,12 @@ public class DozeService extends DreamService {
                mPickupSensor = new TriggerSensor(
                        mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE),
                        Settings.Secure.DOZE_PULSE_ON_PICK_UP,
                        mDozeParameters.getPulseOnPickup(), mDozeParameters.getVibrateOnPickup(),
                        mConfig.pulseOnPickupAvailable(), mDozeParameters.getVibrateOnPickup(),
                        DozeLog.PULSE_REASON_SENSOR_PICKUP),
                new TriggerSensor(
                        findSensorWithType(mDozeParameters.getDoubleTapSensorType()),
                        Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP,
                        mDozeParameters.getPulseOnPickup(), mDozeParameters.getVibrateOnPickup(),
                        findSensorWithType(mConfig.doubleTapSensorType()),
                        Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, true,
                        mDozeParameters.getVibrateOnPickup(),
                        DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP)
        };
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
@@ -359,7 +363,7 @@ public class DozeService extends DreamService {

    private void requestNotificationPulse() {
        if (DEBUG) Log.d(mTag, "requestNotificationPulse");
        if (!mDozeParameters.getPulseOnNotifications()) return;
        if (!mConfig.pulseOnNotificationEnabled(UserHandle.USER_CURRENT)) return;
        mNotificationPulseTime = SystemClock.elapsedRealtime();
        requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
    }
Loading