File: LightsManager.java

package info (click to toggle)
android-platform-frameworks-base 1%3A14~beta1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 326,096 kB
  • sloc: java: 2,032,373; xml: 343,016; cpp: 304,183; python: 3,683; ansic: 2,090; sh: 1,871; makefile: 120; sed: 19
file content (142 lines) | stat: -rw-r--r-- 4,564 bytes parent folder | download | duplicates (2)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (C) 2020 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 android.hardware.lights;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;

import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
 * The LightsManager class allows control over device lights.
 *
 */
@SystemService(Context.LIGHTS_SERVICE)
public abstract class LightsManager {
    private static final String TAG = "LightsManager";

    @NonNull private final Context mContext;
    // These enum values copy the values from {@link com.android.server.lights.LightsManager}
    // and the light HAL. Since 0-7 are lights reserved for system use, only the microphone light
    // and following types are available through this API.
    /** Type for lights that indicate microphone usage
     * @deprecated this has been moved to {@link android.hardware.lights.Light }
     * @hide
     */
    @Deprecated
    @SystemApi
    public static final int LIGHT_TYPE_MICROPHONE = 8;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = {"LIGHT_TYPE_"},
        value = {
            LIGHT_TYPE_MICROPHONE,
        })
    public @interface LightType {}

    /**
     * @hide to prevent subclassing from outside of the framework
     */
    public LightsManager(Context context) {
        mContext = Preconditions.checkNotNull(context);
    }

    /**
     * Returns the lights available on the device.
     *
     * @return A list of available lights
     */
    public @NonNull abstract List<Light> getLights();

    /**
     * Returns the state of a specified light.
     *
     */
    public abstract @NonNull LightState getLightState(@NonNull Light light);

    /**
     * Creates a new LightsSession that can be used to control the device lights.
     */
    public abstract @NonNull LightsSession openSession();

    /**
     *
     * Creates a new {@link LightsSession}
     *
     * @param priority the larger this number, the higher the priority of this session when multiple
     *                 light state requests arrive simultaneously.
     *
     * @hide
     */
    @TestApi
    public abstract @NonNull LightsSession openSession(int priority);

    /**
     * Encapsulates a session that can be used to control device lights and represents the lifetime
     * of the requests.
     *
     * <p>Any lights requests always live in a lights session which defines the lifecycle of the
     * lights requests. A lights session is AutoCloseable that will get closed when leaving the
     * session context.
     *
     * <p>Multiple sessions can make lights requests which contains same light. In the case the
     * LightsManager implementation will arbitrate and honor one of the session's request. When
     * the session hold the current light request closed, LightsManager implementation will choose
     * another live session to honor its lights requests.
     */
    public abstract static class LightsSession implements AutoCloseable {
        private final IBinder mToken = new Binder();

        /**
         * @hide to prevent subclassing from outside of the framework
         */
        public LightsSession() {
        }

        /**
         * Sends a request to modify the states of multiple lights.
         *
         * @param request the settings for lights that should change
         */
        public abstract void requestLights(@NonNull LightsRequest request);

        @Override
        public abstract void close();

        /**
         * Get the token of a light session.
         *
         * @return Binder token of the light session.
         * @hide
         */
        public @NonNull IBinder getToken() {
            return mToken;
        }
    }

}