blob: 2a3d67fd7a8dde5a84735cc549049fba64ecde65 (
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* 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.doze;
import android.hardware.display.AmbientDisplayConfiguration;
import android.os.UserHandle;
import android.util.Log;
import com.android.systemui.dock.DockManager;
import com.android.systemui.doze.DozeMachine.State;
import com.android.systemui.doze.dagger.DozeScope;
import java.io.PrintWriter;
import javax.inject.Inject;
/**
* Handles dock events for ambient state changes.
*/
@DozeScope
public class DozeDockHandler implements DozeMachine.Part {
private static final String TAG = "DozeDockHandler";
private static final boolean DEBUG = DozeService.DEBUG;
private final AmbientDisplayConfiguration mConfig;
private DozeMachine mMachine;
private final DockManager mDockManager;
private final DockEventListener mDockEventListener;
private int mDockState = DockManager.STATE_NONE;
@Inject
DozeDockHandler(AmbientDisplayConfiguration config, DockManager dockManager) {
mConfig = config;
mDockManager = dockManager;
mDockEventListener = new DockEventListener();
}
@Override
public void setDozeMachine(DozeMachine dozeMachine) {
mMachine = dozeMachine;
}
@Override
public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
switch (newState) {
case INITIALIZED:
mDockEventListener.register();
break;
case FINISH:
mDockEventListener.unregister();
break;
default:
// no-op
}
}
@Override
public void dump(PrintWriter pw) {
pw.println("DozeDockHandler:");
pw.println(" dockState=" + mDockState);
}
private class DockEventListener implements DockManager.DockEventListener {
private boolean mRegistered;
@Override
public void onEvent(int dockState) {
if (DEBUG) Log.d(TAG, "dock event = " + dockState);
// Only act upon state changes, otherwise we might overwrite other transitions,
// like proximity sensor initialization.
if (mDockState == dockState) {
return;
}
mDockState = dockState;
if (isPulsing()) {
return;
}
DozeMachine.State nextState;
switch (mDockState) {
case DockManager.STATE_DOCKED:
nextState = State.DOZE_AOD_DOCKED;
break;
case DockManager.STATE_NONE:
nextState = mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT) ? State.DOZE_AOD
: State.DOZE;
break;
case DockManager.STATE_DOCKED_HIDE:
nextState = State.DOZE;
break;
default:
return;
}
mMachine.requestState(nextState);
}
private boolean isPulsing() {
DozeMachine.State state = mMachine.getState();
return state == State.DOZE_REQUEST_PULSE || state == State.DOZE_PULSING
|| state == State.DOZE_PULSING_BRIGHT;
}
void register() {
if (mRegistered) {
return;
}
if (mDockManager != null) {
mDockManager.addListener(this);
}
mRegistered = true;
}
void unregister() {
if (!mRegistered) {
return;
}
if (mDockManager != null) {
mDockManager.removeListener(this);
}
mRegistered = false;
}
}
}
|