Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix bug: flip to silence will draining battery

  • Loading branch information...
commit bb3bad8a65733a21f78b79c1deb976406ffbacd2 1 parent 5ac73b2
@cytown authored
View
53 src/com/android/phone/CallNotifier.java
@@ -50,10 +50,6 @@
import android.util.Log;
import android.preference.PreferenceManager;
-import android.hardware.SensorManager;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorEvent;
-import android.hardware.Sensor;
/**
@@ -188,7 +184,6 @@
public CallNotifier(PhoneApp app, Phone phone, Ringer ringer,
BluetoothHandsfree btMgr, CallLogAsync callLog) {
mSettings = CallFeaturesSetting.getInstance(PreferenceManager.getDefaultSharedPreferences(app));
- mSensorManager = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
mApplication = app;
mCM = app.mCM;
mCallLog = callLog;
@@ -476,7 +471,6 @@ private void onNewRingingConnection(AsyncResult r) {
// - do this before showing the incoming call panel
if (PhoneUtils.isRealIncomingCall(state)) {
startIncomingCallQuery(c);
- startSensor();
} else {
if (mSettings.mVibCallWaiting) {
mApplication.vibrate(200,300,500);
@@ -1264,52 +1258,6 @@ private void onCfiChanged(boolean visible) {
NotificationMgr.getDefault().updateCfi(visible);
}
- private SensorManager mSensorManager;
- private boolean mSensorRunning = false;
- private TurnListener mTurnListener = new TurnListener();
-
- class TurnListener implements SensorEventListener {
- int count = 0;
- public void onSensorChanged(SensorEvent event) {
- if (++count < 5) { // omit the first 5 times
- return;
- }
- float[] values = event.values;
- // Log.i("==="," @ " + values[1] + " : " + values[2]);
- if (count <= 7) { // test 5 to 7 times
- if (Math.abs(values[1]) > 15 || Math.abs(values[2]) > 20) {
- // Log.i("===","force stop sensor! @ " + values[1] + " : " + values[2]);
- stopSensor();
- }
- } else {
- if (Math.abs(values[1]) > 165 && Math.abs(values[2]) < 20) {
- if (DBG) log("turn over!");
- silenceRinger();
- }
- }
- }
- public void onAccuracyChanged(Sensor sensor, int accuracy) {}
- };
-
- void stopSensor() {
- if (mSensorRunning) {
- if (DBG) log("stop sensor!");
- mTurnListener.count = 0;
- mSensorManager.unregisterListener(mTurnListener);
- mSensorRunning = false;
- }
- }
-
-
- void startSensor() {
- if (mSettings.mTurnSilence && !mSensorRunning) {
- if (DBG) log("startSensor()...");
- mSensorManager.registerListener(mTurnListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
- SensorManager.SENSOR_DELAY_NORMAL);
- mSensorRunning = true;
- }
- }
-
/**
* Indicates whether or not this ringer is ringing.
*/
@@ -1325,7 +1273,6 @@ void silenceRinger() {
mSilentRingerRequested = true;
if (DBG) log("stopRing()... (silenceRinger)");
// Log.i("===","silence sensor!");
- stopSensor();
mRinger.stopRing();
}
View
57 src/com/android/phone/Ringer.java
@@ -32,6 +32,12 @@
import android.os.Vibrator;
import android.util.Log;
+import android.preference.PreferenceManager;
+import android.hardware.SensorManager;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorEvent;
+import android.hardware.Sensor;
+
import com.android.internal.telephony.Phone;
/**
* Ringer manager for the Phone app.
@@ -61,9 +67,16 @@
private long mFirstRingEventTime = -1;
private long mFirstRingStartTime = -1;
+ private CallFeaturesSetting mSettings;
+ private SensorManager mSensorManager;
+ private boolean mSensorRunning = false;
+ private TurnListener mTurnListener = new TurnListener();
+
Ringer(Context context) {
mContext = context;
mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
+ mSettings = CallFeaturesSetting.getInstance(PreferenceManager.getDefaultSharedPreferences(context));
+ mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
}
/**
@@ -172,6 +185,7 @@ void ring() {
mFirstRingEventTime = SystemClock.elapsedRealtime();
}
}
+ startSensor();
}
}
@@ -216,6 +230,7 @@ void stopRing() {
}
// Also immediately cancel any vibration in progress.
mVibrator.cancel();
+ stopSensor();
}
}
@@ -320,6 +335,48 @@ public void handleMessage(Message msg) {
}
}
+ class TurnListener implements SensorEventListener {
+ int count = 0;
+ public void onSensorChanged(SensorEvent event) {
+ if (++count < 5) { // omit the first 5 times
+ return;
+ }
+ float[] values = event.values;
+ // Log.i("==="," @ " + values[1] + " : " + values[2]);
+ if (count <= 7) { // test 5 to 7 times
+ if (Math.abs(values[1]) > 15 || Math.abs(values[2]) > 20) {
+ // Log.i("===","force stop sensor! @ " + values[1] + " : " + values[2]);
+ stopSensor();
+ }
+ } else {
+ if (Math.abs(values[1]) > 165 && Math.abs(values[2]) < 20) {
+ if (DBG) log("turn over!");
+ PhoneApp.getInstance().notifier.silenceRinger();
+ }
+ }
+ }
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {}
+ };
+
+ void stopSensor() {
+ if (mSensorRunning) {
+ if (DBG) log("stop sensor!");
+ mTurnListener.count = 0;
+ mSensorManager.unregisterListener(mTurnListener);
+ mSensorRunning = false;
+ }
+ }
+
+
+ void startSensor() {
+ if (mSettings.mTurnSilence && !mSensorRunning) {
+ if (DBG) log("startSensor()...");
+ mSensorManager.registerListener(mTurnListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
+ SensorManager.SENSOR_DELAY_NORMAL);
+ mSensorRunning = true;
+ }
+ }
+
private static void log(String msg) {
Log.d(LOG_TAG, msg);
}
Please sign in to comment.
Something went wrong with that request. Please try again.