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

Commit 84de7d53 authored by Darrell Shi's avatar Darrell Shi
Browse files

Remove idle directory in SystemUI.

Test: locally on device
Fix: 215240309
Change-Id: I548c554acfb4f7ba55eedb8e54c7a7bebafe8f8a
parent dd0811a6
Loading
Loading
Loading
Loading
+0 −23
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2021 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.
  -->


<com.android.systemui.idle.IdleHostView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/idle_host_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
+0 −5
Original line number Diff line number Diff line
@@ -89,11 +89,6 @@
            layout="@layout/keyguard_status_view"
            android:visibility="gone"/>

        <include layout="@layout/idle_host_view"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:visibility="gone"/>

        <include layout="@layout/dock_info_overlay"/>

        <FrameLayout
+0 −25
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;

@@ -30,9 +28,6 @@ import com.android.systemui.communal.CommunalSource;
import com.android.systemui.communal.PackageObserver;
import com.android.systemui.communal.conditions.CommunalSettingCondition;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.idle.AmbientLightModeMonitor;
import com.android.systemui.idle.LightSensorEventsDebounceAlgorithm;
import com.android.systemui.idle.dagger.IdleViewComponent;
import com.android.systemui.util.condition.Condition;
import com.android.systemui.util.condition.Monitor;
import com.android.systemui.util.condition.dagger.MonitorComponent;
@@ -46,7 +41,6 @@ import java.util.Set;
import javax.inject.Named;
import javax.inject.Provider;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;
@@ -58,20 +52,10 @@ import dagger.multibindings.StringKey;
 */
@Module(subcomponents = {
        CommunalViewComponent.class,
        IdleViewComponent.class,
})
public interface CommunalModule {
    String IDLE_VIEW = "idle_view";
    String COMMUNAL_CONDITIONS = "communal_conditions";

    /** */
    @Provides
    @Named(IDLE_VIEW)
    static View provideIdleView(Context context) {
        FrameLayout view = new FrameLayout(context);
        return view;
    }

    /** */
    @Provides
    static Optional<CommunalSource.Observer> provideCommunalSourcePackageObserver(
@@ -86,15 +70,6 @@ public interface CommunalModule {
                ComponentName.unflattenFromString(componentName).getPackageName()));
    }

    /**
     * Provides LightSensorEventsDebounceAlgorithm as an instance to DebounceAlgorithm interface.
     * @param algorithm the instance of algorithm that is bound to the interface.
     * @return the interface that is bound to.
     */
    @Binds
    AmbientLightModeMonitor.DebounceAlgorithm ambientLightDebounceAlgorithm(
            LightSensorEventsDebounceAlgorithm algorithm);

    /**
     * Provides a set of conditions that need to be fulfilled in order for Communal Mode to display.
     */
+0 −116
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.systemui.idle

import android.annotation.IntDef
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.util.Log
import com.android.systemui.util.sensors.AsyncSensorManager
import javax.inject.Inject

/**
 * Monitors ambient light signals, applies a debouncing algorithm, and produces the current
 * ambient light mode.
 *
 * @property algorithm the debounce algorithm which transforms light sensor events into an
 * ambient light mode.
 * @property sensorManager the sensor manager used to register sensor event updates.
 */
class AmbientLightModeMonitor @Inject constructor(
    private val algorithm: DebounceAlgorithm,
    private val sensorManager: AsyncSensorManager
) {
    companion object {
        private const val TAG = "AmbientLightModeMonitor"
        private val DEBUG = Log.isLoggable(TAG, Log.DEBUG)

        const val AMBIENT_LIGHT_MODE_LIGHT = 0
        const val AMBIENT_LIGHT_MODE_DARK = 1
        const val AMBIENT_LIGHT_MODE_UNDECIDED = 2
    }

    // Light sensor used to detect ambient lighting conditions.
    private val lightSensor: Sensor? = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT)

    // Represents all ambient light modes.
    @Retention(AnnotationRetention.SOURCE)
    @IntDef(AMBIENT_LIGHT_MODE_LIGHT, AMBIENT_LIGHT_MODE_DARK, AMBIENT_LIGHT_MODE_UNDECIDED)
    annotation class AmbientLightMode

    /**
     * Start monitoring the current ambient light mode.
     *
     * @param callback callback that gets triggered when the ambient light mode changes.
     */
    fun start(callback: Callback) {
        if (DEBUG) Log.d(TAG, "start monitoring ambient light mode")

        if (lightSensor == null) {
            if (DEBUG) Log.w(TAG, "light sensor not available")
            return
        }

        algorithm.start(callback)
        sensorManager.registerListener(mSensorEventListener, lightSensor,
                SensorManager.SENSOR_DELAY_NORMAL)
    }

    /**
     * Stop monitoring the current ambient light mode.
     */
    fun stop() {
        if (DEBUG) Log.d(TAG, "stop monitoring ambient light mode")

        algorithm.stop()
        sensorManager.unregisterListener(mSensorEventListener)
    }

    private val mSensorEventListener: SensorEventListener = object : SensorEventListener {
        override fun onSensorChanged(event: SensorEvent) {
            if (event.values.isEmpty()) {
                if (DEBUG) Log.w(TAG, "SensorEvent doesn't have any value")
                return
            }

            algorithm.onUpdateLightSensorEvent(event.values[0])
        }

        override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {
            // Do nothing.
        }
    }

    /**
     * Interface of the ambient light mode callback, which gets triggered when the mode changes.
     */
    interface Callback {
        fun onChange(@AmbientLightMode mode: Int)
    }

    /**
     * Interface of the algorithm that transforms light sensor events to an ambient light mode.
     */
    interface DebounceAlgorithm {
        // Setting Callback to nullable so mockito can verify without throwing NullPointerException.
        fun start(callback: Callback?)
        fun stop()
        fun onUpdateLightSensorEvent(value: Float)
    }
}
 No newline at end of file
+0 −42
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.systemui.idle;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * {@link IdleHostView} houses a surface to be displayed when the device idle.
 */
public class IdleHostView extends FrameLayout {
    public IdleHostView(@NonNull Context context) {
        this(context, null);
    }

    public IdleHostView(@NonNull Context context,
            @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public IdleHostView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}
Loading