| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.input; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.app.ActivityThread; |
| 21 |
import android.hardware.lights.Light; |
| 22 |
import android.hardware.lights.LightState; |
| 23 |
import android.hardware.lights.LightsManager; |
| 24 |
import android.hardware.lights.LightsRequest; |
| 25 |
import android.util.CloseGuard; |
| 26 |
|
| 27 |
import com.android.internal.util.Preconditions; |
| 28 |
|
| 29 |
import java.lang.ref.Reference; |
| 30 |
import java.util.List; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class InputDeviceLightsManager extends LightsManager { |
| 36 |
private static final String TAG = "InputDeviceLightsManager"; |
| 37 |
private static final boolean DEBUG = false; |
| 38 |
|
| 39 |
private final InputManager mInputManager; |
| 40 |
|
| 41 |
|
| 42 |
private final int mDeviceId; |
| 43 |
|
| 44 |
private final String mPackageName; |
| 45 |
|
| 46 |
InputDeviceLightsManager(InputManager inputManager, int deviceId) { |
| 47 |
super(ActivityThread.currentActivityThread().getSystemContext()); |
| 48 |
mInputManager = inputManager; |
| 49 |
mDeviceId = deviceId; |
| 50 |
mPackageName = ActivityThread.currentPackageName(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
@Override |
| 59 |
public @NonNull List<Light> getLights() { |
| 60 |
return mInputManager.getLights(mDeviceId); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
@Override |
| 69 |
public @NonNull LightState getLightState(@NonNull Light light) { |
| 70 |
Preconditions.checkNotNull(light); |
| 71 |
return mInputManager.getLightState(mDeviceId, light); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@Override |
| 78 |
public @NonNull LightsSession openSession() { |
| 79 |
final LightsSession session = new InputDeviceLightsSession(); |
| 80 |
mInputManager.openLightSession(mDeviceId, mPackageName, session.getToken()); |
| 81 |
return session; |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public @NonNull LightsSession openSession(int priority) { |
| 86 |
throw new UnsupportedOperationException(); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public final class InputDeviceLightsSession extends LightsManager.LightsSession |
| 94 |
implements AutoCloseable { |
| 95 |
|
| 96 |
private final CloseGuard mCloseGuard = new CloseGuard(); |
| 97 |
private boolean mClosed = false; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
private InputDeviceLightsSession() { |
| 103 |
mCloseGuard.open("InputDeviceLightsSession.close"); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
@Override |
| 112 |
public void requestLights(@NonNull LightsRequest request) { |
| 113 |
Preconditions.checkNotNull(request); |
| 114 |
Preconditions.checkArgument(!mClosed); |
| 115 |
|
| 116 |
mInputManager.requestLights(mDeviceId, request, getToken()); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
@Override |
| 123 |
public void close() { |
| 124 |
if (!mClosed) { |
| 125 |
mInputManager.closeLightSession(mDeviceId, getToken()); |
| 126 |
mClosed = true; |
| 127 |
mCloseGuard.close(); |
| 128 |
} |
| 129 |
Reference.reachabilityFence(this); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
@Override |
| 134 |
protected void finalize() throws Throwable { |
| 135 |
try { |
| 136 |
mCloseGuard.warnIfOpen(); |
| 137 |
close(); |
| 138 |
} finally { |
| 139 |
super.finalize(); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
} |