summaryrefslogtreecommitdiff
path: root/packages/SystemUI/plugin/src/com/android/systemui/plugins/SensorManagerPlugin.java
blob: d62c1d411cff1ca1ac8fe88846b1605c180c65e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * Copyright (C) 2018 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.plugins;

import android.hardware.SensorListener;

import com.android.systemui.plugins.annotations.ProvidesInterface;

/**
 * Allows for additional sensors to be retrieved from
 * {@link com.android.systemui.util.sensors.AsyncSensorManager}.
 */
@ProvidesInterface(action = SensorManagerPlugin.ACTION, version = SensorManagerPlugin.VERSION)
public interface SensorManagerPlugin extends Plugin {
    String ACTION = "com.android.systemui.action.PLUGIN_SENSOR_MANAGER";
    int VERSION = 1;

    /**
     * Registers for sensor events. Events will be sent until the listener is unregistered.
     * @param sensor
     * @param listener
     * @see android.hardware.SensorManager#registerListener(SensorListener, int)
     */
    void registerListener(Sensor sensor, SensorEventListener listener);

    /**
     * Unregisters events from the sensor.
     * @param sensor
     * @param listener
     */
    void unregisterListener(Sensor sensor, SensorEventListener listener);

    /**
     * Listener triggered whenever the Sensor has new data.
     */
    interface SensorEventListener {
        void onSensorChanged(SensorEvent event);
    }

    /**
     * Sensor that can be defined in a plugin.
     */
    class Sensor {
        public static final int TYPE_WAKE_LOCK_SCREEN = 1;
        public static final int TYPE_WAKE_DISPLAY = 2;
        public static final int TYPE_SWIPE = 3;
        public static final int TYPE_SKIP_STATUS = 4;

        private int mType;

        public Sensor(int type) {
            mType = type;
        }
        public int getType() {
            return mType;
        }
        public String toString() {
            return "{PluginSensor type=\"" + mType + "\"}";
        }
    }

    /**
     * Event sent by a {@link Sensor}.
     */
    class SensorEvent {
        Sensor mSensor;
        int mVendorType;
        float[] mValues;

        /**
         * Creates a sensor event.
         * @param sensor The type of sensor, e.g. TYPE_WAKE_LOCK_SCREEN
         * @param vendorType The vendor type, which should be unique for each type of sensor,
         *                   e.g. SINGLE_TAP = 1, DOUBLE_TAP = 2, etc.
         */
        public SensorEvent(Sensor sensor, int vendorType) {
            this(sensor, vendorType, null);
        }

        /**
         * Creates a sensor event.
         * @param sensor The type of sensor, e.g. TYPE_WAKE_LOCK_SCREEN
         * @param vendorType The vendor type, which should be unique for each type of sensor,
         *                   e.g. SINGLE_TAP = 1, DOUBLE_TAP = 2, etc.
         * @param values Values captured by the sensor.
         */
        public SensorEvent(Sensor sensor, int vendorType, float[] values) {
            mSensor = sensor;
            mVendorType = vendorType;
            mValues = values;
        }

        public Sensor getSensor() {
            return mSensor;
        }

        public float[] getValues() {
            return mValues;
        }

        public int getVendorType() {
            return mVendorType;
        }
    }
}