OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 private AppRTCProximitySensor(Context context, Runnable sensorStateListener) { | 52 private AppRTCProximitySensor(Context context, Runnable sensorStateListener) { |
53 Log.d(TAG, "AppRTCProximitySensor" + AppRTCUtils.getThreadInfo()); | 53 Log.d(TAG, "AppRTCProximitySensor" + AppRTCUtils.getThreadInfo()); |
54 onSensorStateListener = sensorStateListener; | 54 onSensorStateListener = sensorStateListener; |
55 sensorManager = ((SensorManager) context.getSystemService( | 55 sensorManager = ((SensorManager) context.getSystemService( |
56 Context.SENSOR_SERVICE)); | 56 Context.SENSOR_SERVICE)); |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * Activate the proximity sensor. Also do initializtion if called for the | 60 * Activate the proximity sensor. Also do initialization if called for the |
61 * first time. | 61 * first time. |
62 */ | 62 */ |
63 public boolean start() { | 63 public boolean start() { |
64 checkIfCalledOnValidThread(); | 64 checkIfCalledOnValidThread(); |
65 Log.d(TAG, "start" + AppRTCUtils.getThreadInfo()); | 65 Log.d(TAG, "start" + AppRTCUtils.getThreadInfo()); |
66 if (!initDefaultSensor()) { | 66 if (!initDefaultSensor()) { |
67 // Proximity sensor is not supported on this device. | 67 // Proximity sensor is not supported on this device. |
68 return false; | 68 return false; |
69 } | 69 } |
70 sensorManager.registerListener( | 70 sensorManager.registerListener( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 onSensorStateListener.run(); | 118 onSensorStateListener.run(); |
119 } | 119 } |
120 | 120 |
121 Log.d(TAG, "onSensorChanged" + AppRTCUtils.getThreadInfo() + ": " | 121 Log.d(TAG, "onSensorChanged" + AppRTCUtils.getThreadInfo() + ": " |
122 + "accuracy=" + event.accuracy | 122 + "accuracy=" + event.accuracy |
123 + ", timestamp=" + event.timestamp + ", distance=" + event.values[0]); | 123 + ", timestamp=" + event.timestamp + ", distance=" + event.values[0]); |
124 } | 124 } |
125 | 125 |
126 /** | 126 /** |
127 * Get default proximity sensor if it exists. Tablet devices (e.g. Nexus 7) | 127 * Get default proximity sensor if it exists. Tablet devices (e.g. Nexus 7) |
128 * does not support this type of sensor and false will be retured in such | 128 * does not support this type of sensor and false will be returned in such |
129 * cases. | 129 * cases. |
130 */ | 130 */ |
131 private boolean initDefaultSensor() { | 131 private boolean initDefaultSensor() { |
132 if (proximitySensor != null) { | 132 if (proximitySensor != null) { |
133 return true; | 133 return true; |
134 } | 134 } |
135 proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); | 135 proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); |
136 if (proximitySensor == null) { | 136 if (proximitySensor == null) { |
137 return false; | 137 return false; |
138 } | 138 } |
139 logProximitySensorInfo(); | 139 logProximitySensorInfo(); |
140 return true; | 140 return true; |
141 } | 141 } |
142 | 142 |
143 /** Helper method for logging information about the proximity sensor. */ | 143 /** Helper method for logging information about the proximity sensor. */ |
144 private void logProximitySensorInfo() { | 144 private void logProximitySensorInfo() { |
145 if (proximitySensor == null) { | 145 if (proximitySensor == null) { |
146 return; | 146 return; |
147 } | 147 } |
148 StringBuilder info = new StringBuilder("Proximity sensor: "); | 148 StringBuilder info = new StringBuilder("Proximity sensor: "); |
149 info.append("name=" + proximitySensor.getName()); | 149 info.append("name=").append(proximitySensor.getName()); |
150 info.append(", vendor: " + proximitySensor.getVendor()); | 150 info.append(", vendor: ").append(proximitySensor.getVendor()); |
151 info.append(", power: " + proximitySensor.getPower()); | 151 info.append(", power: ").append(proximitySensor.getPower()); |
152 info.append(", resolution: " + proximitySensor.getResolution()); | 152 info.append(", resolution: ").append(proximitySensor.getResolution()); |
153 info.append(", max range: " + proximitySensor.getMaximumRange()); | 153 info.append(", max range: ").append(proximitySensor.getMaximumRange()); |
154 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { | 154 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { |
155 // Added in API level 9. | 155 // Added in API level 9. |
156 info.append(", min delay: " + proximitySensor.getMinDelay()); | 156 info.append(", min delay: ").append(proximitySensor.getMinDelay()); |
157 } | 157 } |
158 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { | 158 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { |
159 // Added in API level 20. | 159 // Added in API level 20. |
160 info.append(", type: " + proximitySensor.getStringType()); | 160 info.append(", type: ").append(proximitySensor.getStringType()); |
161 } | 161 } |
162 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 162 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
163 // Added in API level 21. | 163 // Added in API level 21. |
164 info.append(", max delay: " + proximitySensor.getMaxDelay()); | 164 info.append(", max delay: ").append(proximitySensor.getMaxDelay()); |
165 info.append(", reporting mode: " + proximitySensor.getReportingMode()); | 165 info.append(", reporting mode: ").append(proximitySensor.getReportingMode(
)); |
166 info.append(", isWakeUpSensor: " + proximitySensor.isWakeUpSensor()); | 166 info.append(", isWakeUpSensor: ").append(proximitySensor.isWakeUpSensor())
; |
167 } | 167 } |
168 Log.d(TAG, info.toString()); | 168 Log.d(TAG, info.toString()); |
169 } | 169 } |
170 | 170 |
171 /** | 171 /** |
172 * Helper method for debugging purposes. Ensures that method is | 172 * Helper method for debugging purposes. Ensures that method is |
173 * called on same thread as this object was created on. | 173 * called on same thread as this object was created on. |
174 */ | 174 */ |
175 private void checkIfCalledOnValidThread() { | 175 private void checkIfCalledOnValidThread() { |
176 if (!nonThreadSafe.calledOnValidThread()) { | 176 if (!nonThreadSafe.calledOnValidThread()) { |
177 throw new IllegalStateException("Method is not called on valid thread"); | 177 throw new IllegalStateException("Method is not called on valid thread"); |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
OLD | NEW |