[Onetouch Idol 3 Original Android Development] idolowner:
Hi Folks,

It seems there is still some people interested in custom room development for the Idol. I'm owning this phone for more than 2 years and finally decided to unlock bootloader and flash LOS14.1 (latest Guinol version). It works great in comparison with stock MM that was terribly slowed down by alcated apps after they updated them few months ago.

I'd really like to help to troubleshoot the proximity sensor issue thus I took a few moment to investigate. I'm posting here my results:

1. found out that (as Demetris wrote long ago) that the driver is working at kernel level. Driver is tsl2772-ps

2. found out by writing a small app that proximity sensor is a "non wakeup sensor" although proximity sensors must be a "wakeup sensor" according to Android SDK

3. found out that acquiring a "PROXIMITY_SCREEN_OFF_WAKE_LOCK" doesn't work due to point 2. However, the android dialer app uses this mechanism to switch off the screen when the proximity sensor detects proximity of user's face

4. locked at tsl2772.c in the kernel source and found it supports wake locks which doesn't match with my previous discover

5. maybe something is going wrong in between in the HAL. However, I didn't find the sources only a binary sensor.native.so and I'm stuck there

Maybe someone will be able to push this further (if those discovers are valuable).

My sources (please add https before the links I removed them because XDA forum didn't allow me to put links as I'm a new user)

source code of the dialer app where the PROXIMITY_SCREEN_OFF_WAKE_LOCK is being used github.com/LineageOS/android_packages_apps_Dialer/blob/cm-14.1/InCallUI/src/com/android/incallui/ProximitySensor.java

source code of the tsl2772 driver in the kernel source line 2884 there's something indicating PS can wake github.com/IDOL-3/android_kernel_alcatel_msm8916/blob/cm-14.1-new/drivers/misc/idol347_sensor/tsl277x.c

source code of my app

package proximitysensortest;

import android.content.Context;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorManager;
import android.hardware.SensorEventListener;
import android.os.PowerManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import java.util.List;

public class MainActivity extends AppCompatActivity {

private SensorManager sensorManager;
private Sensor proximitySensor;
private SensorEventListener proximitySensorListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sensorManager =
(SensorManager) getSystemService(SENSOR_SERVICE);

// This should return the default proximity sensor but it returs null as if there was no PS
proximitySensor =
sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

// This returns all sensors including those that are "non wakeup" sensors
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

// This loops through all the sensors and put the last proximity sensor in the list into the proximitySensor variable
for(Sensor sensor : sensors) {
Log.v("ProximitySensorTest", sensor.getName());
if(Sensor.TYPE_PROXIMITY == sensor.getType()) {
proximitySensor = sensor;
}
}

// This returns FALSE !!!!!!
proximitySensor.isWakeUpSensor();

// Create listener
proximitySensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if(sensorEvent.values[0] < proximitySensor.getMaximumRange()) {
// This works
getWindow().getDecorView().setBackgroundColor(Color.RED);
} else {
// This works too
getWindow().getDecorView().setBackgroundColor(Color.GREEN);
}
TextView textView = (TextView) getWindow().findViewById(R.id.proximityValue);
textView.setText(Float.toString(sensorEvent.values[0]));
}

@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
};

// This tests the PROXIMITY_SCREEN_OFF_WAKE_LOCK like in the dialer app. If we break the execution after the acquire() using the debugger nothing happends when using the proximity sensor whereas it works (screen off) this another phone
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock proximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");

proximityWakeLock.acquire();
proximityWakeLock.isHeld();
proximityWakeLock.release();
}

@Override
protected void onResume() {
super.onResume();
// Register it, specifying the polling interval in
// microseconds
sensorManager.registerListener(proximitySensorListener,
proximitySensor, 2 * 1000 * 1000);
}

@Override
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(proximitySensorListener);
}
}