diff options
-rw-r--r-- | camera/libcameraservice/CameraService.cpp | 87 | ||||
-rw-r--r-- | camera/libcameraservice/CameraService.h | 6 | ||||
-rw-r--r-- | core/java/android/os/IPowerManager.aidl | 3 | ||||
-rw-r--r-- | core/java/android/provider/Settings.java | 12 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 14 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 1 | ||||
-rw-r--r-- | libs/rs/rsProgram.h | 4 | ||||
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java | 26 | ||||
-rw-r--r-- | services/java/com/android/server/PowerManagerService.java | 172 | ||||
-rw-r--r-- | services/java/com/android/server/status/StatusBarService.java | 28 |
10 files changed, 225 insertions, 128 deletions
diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index b63e97f..6880144 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -309,7 +309,7 @@ status_t CameraService::Client::connect(const sp<ICameraClient>& client) oldClient = mCameraClient; // did the client actually change? - if (client->asBinder() == mCameraClient->asBinder()) { + if ((mCameraClient != NULL) && (client->asBinder() == mCameraClient->asBinder())) { LOGD("Connect to the same client"); return NO_ERROR; } @@ -878,7 +878,10 @@ void CameraService::Client::handleShutter() mSurface->unregisterBuffers(); } - mCameraClient->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0); + sp<ICameraClient> c = mCameraClient; + if (c != NULL) { + c->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0); + } mHardware->disableMsgType(CAMERA_MSG_SHUTTER); // It takes some time before yuvPicture callback to be called. @@ -932,31 +935,38 @@ void CameraService::Client::handlePreviewData(const sp<IMemory>& mem) } } - // Is the callback enabled or not? - if (!(mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ENABLE_MASK)) { + // local copy of the callback flags + int flags = mPreviewCallbackFlag; + + // is callback enabled? + if (!(flags & FRAME_CALLBACK_FLAG_ENABLE_MASK)) { // If the enable bit is off, the copy-out and one-shot bits are ignored LOGV("frame callback is diabled"); return; } - // Is the received frame copied out or not? - if (mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_COPY_OUT_MASK) { - LOGV("frame is copied out"); - copyFrameAndPostCopiedFrame(heap, offset, size); - } else { - LOGV("frame is directly sent out without copying"); - mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, mem); - } + // hold a strong pointer to the client + sp<ICameraClient> c = mCameraClient; - // Is this is one-shot only? - if (mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ONE_SHOT_MASK) { - LOGV("One-shot only, thus clear the bits and disable frame callback"); + // clear callback flags if no client or one-shot mode + if ((c == NULL) || (mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ONE_SHOT_MASK)) { + LOGV("Disable preview callback"); mPreviewCallbackFlag &= ~(FRAME_CALLBACK_FLAG_ONE_SHOT_MASK | FRAME_CALLBACK_FLAG_COPY_OUT_MASK | FRAME_CALLBACK_FLAG_ENABLE_MASK); + // TODO: Shouldn't we use this API for non-overlay hardware as well? if (mUseOverlay) mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME); } + + // Is the received frame copied out or not? + if (flags & FRAME_CALLBACK_FLAG_COPY_OUT_MASK) { + LOGV("frame is copied"); + copyFrameAndPostCopiedFrame(c, heap, offset, size); + } else { + LOGV("frame is forwarded"); + c->dataCallback(CAMERA_MSG_PREVIEW_FRAME, mem); + } } // picture callback - postview image ready @@ -972,7 +982,10 @@ void CameraService::Client::handlePostview(const sp<IMemory>& mem) } #endif - mCameraClient->dataCallback(CAMERA_MSG_POSTVIEW_FRAME, mem); + sp<ICameraClient> c = mCameraClient; + if (c != NULL) { + c->dataCallback(CAMERA_MSG_POSTVIEW_FRAME, mem); + } mHardware->disableMsgType(CAMERA_MSG_POSTVIEW_FRAME); } @@ -997,7 +1010,10 @@ void CameraService::Client::handleRawPicture(const sp<IMemory>& mem) mSurface->postBuffer(offset); } - mCameraClient->dataCallback(CAMERA_MSG_RAW_IMAGE, mem); + sp<ICameraClient> c = mCameraClient; + if (c != NULL) { + c->dataCallback(CAMERA_MSG_RAW_IMAGE, mem); + } mHardware->disableMsgType(CAMERA_MSG_RAW_IMAGE); } @@ -1014,7 +1030,10 @@ void CameraService::Client::handleCompressedPicture(const sp<IMemory>& mem) } #endif - mCameraClient->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem); + sp<ICameraClient> c = mCameraClient; + if (c != NULL) { + c->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem); + } mHardware->disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE); } @@ -1032,7 +1051,10 @@ void CameraService::Client::notifyCallback(int32_t msgType, int32_t ext1, int32_ client->handleShutter(); break; default: - client->mCameraClient->notifyCallback(msgType, ext1, ext2); + sp<ICameraClient> c = client->mCameraClient; + if (c != NULL) { + c->notifyCallback(msgType, ext1, ext2); + } break; } @@ -1053,10 +1075,13 @@ void CameraService::Client::dataCallback(int32_t msgType, const sp<IMemory>& dat return; } + sp<ICameraClient> c = client->mCameraClient; if (dataPtr == NULL) { LOGE("Null data returned in data callback"); - client->mCameraClient->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0); - client->mCameraClient->dataCallback(msgType, NULL); + if (c != NULL) { + c->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0); + c->dataCallback(msgType, NULL); + } return; } @@ -1074,7 +1099,9 @@ void CameraService::Client::dataCallback(int32_t msgType, const sp<IMemory>& dat client->handleCompressedPicture(dataPtr); break; default: - client->mCameraClient->dataCallback(msgType, dataPtr); + if (c != NULL) { + c->dataCallback(msgType, dataPtr); + } break; } @@ -1095,15 +1122,20 @@ void CameraService::Client::dataCallbackTimestamp(nsecs_t timestamp, int32_t msg if (client == 0) { return; } + sp<ICameraClient> c = client->mCameraClient; if (dataPtr == NULL) { LOGE("Null data returned in data with timestamp callback"); - client->mCameraClient->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0); - client->mCameraClient->dataCallbackTimestamp(0, msgType, NULL); + if (c != NULL) { + c->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0); + c->dataCallbackTimestamp(0, msgType, NULL); + } return; } - client->mCameraClient->dataCallbackTimestamp(timestamp, msgType, dataPtr); + if (c != NULL) { + c->dataCallbackTimestamp(timestamp, msgType, dataPtr); + } #if DEBUG_CLIENT_REFERENCES if (client->getStrongCount() == 1) { @@ -1161,7 +1193,8 @@ status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t a return mHardware->sendCommand(cmd, arg1, arg2); } -void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size) +void CameraService::Client::copyFrameAndPostCopiedFrame(const sp<ICameraClient>& client, + const sp<IMemoryHeap>& heap, size_t offset, size_t size) { LOGV("copyFrameAndPostCopiedFrame"); // It is necessary to copy out of pmem before sending this to @@ -1186,7 +1219,7 @@ void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, si LOGE("failed to allocate space for frame callback"); return; } - mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame); + client->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame); } status_t CameraService::dump(int fd, const Vector<String16>& args) diff --git a/camera/libcameraservice/CameraService.h b/camera/libcameraservice/CameraService.h index 2e3597f..2fcf839 100644 --- a/camera/libcameraservice/CameraService.h +++ b/camera/libcameraservice/CameraService.h @@ -23,10 +23,9 @@ #include <ui/CameraHardwareInterface.h> #include <ui/Camera.h> -class android::MemoryHeapBase; - namespace android { +class MemoryHeapBase; class MediaPlayer; // ---------------------------------------------------------------------------- @@ -151,7 +150,8 @@ private: void handleRawPicture(const sp<IMemory>&); void handleCompressedPicture(const sp<IMemory>&); - void copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size); + void copyFrameAndPostCopiedFrame(const sp<ICameraClient>& client, + const sp<IMemoryHeap>& heap, size_t offset, size_t size); // camera operation mode enum camera_mode { diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 189335e..5ac543d 100644 --- a/core/java/android/os/IPowerManager.aidl +++ b/core/java/android/os/IPowerManager.aidl @@ -34,7 +34,4 @@ interface IPowerManager // sets the brightness of the backlights (screen, keyboard, button) 0-255 void setBacklightBrightness(int brightness); - - // enables or disables automatic brightness mode - void setAutoBrightness(boolean on); } diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 8c9581d..cb3dc16 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -1081,6 +1081,18 @@ public final class Settings { public static final String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode"; /** + * SCREEN_BRIGHTNESS_MODE value for manual mode. + * @hide + */ + public static final int SCREEN_BRIGHTNESS_MODE_MANUAL = 0; + + /** + * SCREEN_BRIGHTNESS_MODE value for manual mode. + * @hide + */ + public static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1; + + /** * Control whether the process CPU usage meter should be shown. */ public static final String SHOW_PROCESSES = "show_processes"; diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 4bc1a0e..eb09c66 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -2926,12 +2926,12 @@ public class WebView extends AbsoluteLayout animateScroll); if (mNativeClass == 0) return; - if (mShiftIsPressed) { + if (mShiftIsPressed && !animateZoom) { if (mTouchSelection) { nativeDrawSelectionRegion(canvas); } else { - nativeDrawSelection(canvas, mSelectX, mSelectY, - mExtendSelection); + nativeDrawSelection(canvas, mInvActualScale, getTitleHeight(), + mSelectX, mSelectY, mExtendSelection); } } else if (drawCursorRing) { if (mTouchMode == TOUCH_SHORTPRESS_START_MODE) { @@ -4065,6 +4065,9 @@ public class WebView extends AbsoluteLayout return true; } if (ev.getAction() == MotionEvent.ACTION_DOWN) { + if (mShiftIsPressed) { + return true; // discard press if copy in progress + } mTrackballDown = true; if (mNativeClass == 0) { return false; @@ -4093,6 +4096,7 @@ public class WebView extends AbsoluteLayout } else { mExtendSelection = true; } + return true; // discard press if copy in progress } if (DebugFlags.WEB_VIEW) { Log.v(LOGTAG, "onTrackballEvent up ev=" + ev @@ -5600,8 +5604,8 @@ public class WebView extends AbsoluteLayout private native void nativeDestroy(); private native void nativeDrawCursorRing(Canvas content); private native void nativeDrawMatches(Canvas canvas); - private native void nativeDrawSelection(Canvas content - , int x, int y, boolean extendSelection); + private native void nativeDrawSelection(Canvas content, float scale, + int offset, int x, int y, boolean extendSelection); private native void nativeDrawSelectionRegion(Canvas content); private native void nativeDumpDisplayTree(String urlOrNull); private native int nativeFindAll(String findLower, String findUpper); diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 2b3d076..cc39dac 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -438,6 +438,7 @@ void Context::setVertex(ProgramVertex *pv) } else { mVertex.set(pv); } + mVertex->forceDirty(); } void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h index 26b78dd..57c654f 100644 --- a/libs/rs/rsProgram.h +++ b/libs/rs/rsProgram.h @@ -44,6 +44,10 @@ protected: ObjectBaseRef<Allocation> mConstants; mutable bool mDirty; + + +public: + void forceDirty() {mDirty = true;} }; diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java index 3b91a38..153a5ea 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java @@ -45,7 +45,6 @@ public class SettingsHelper { private boolean mSilent; private boolean mVibrate; - private boolean mHasAutoBrightness; public SettingsHelper(Context context) { mContext = context; @@ -54,9 +53,6 @@ public class SettingsHelper { mContentService = ContentResolver.getContentService(); mPowerManager = IPowerManager.Stub.asInterface( ServiceManager.getService("power")); - - mHasAutoBrightness = context.getResources().getBoolean( - com.android.internal.R.bool.config_automatic_brightness_available); } /** @@ -71,18 +67,6 @@ public class SettingsHelper { public boolean restoreValue(String name, String value) { if (Settings.System.SCREEN_BRIGHTNESS.equals(name)) { setBrightness(Integer.parseInt(value)); - } else if (Settings.System.SCREEN_BRIGHTNESS_MODE.equals(name)) { - if (mHasAutoBrightness) { - // When setting auto-brightness, must reset the brightness afterwards - try { - int curBrightness = Settings.System.getInt(mContext.getContentResolver(), - Settings.System.SCREEN_BRIGHTNESS); - setAutoBrightness(Integer.parseInt(value) != 0); - setBrightness(curBrightness); - } catch (Settings.SettingNotFoundException e) { - // no brightness setting at all? weird. skip this then. - } - } } else if (Settings.System.SOUND_EFFECTS_ENABLED.equals(name)) { setSoundEffects(Integer.parseInt(value) == 1); } else if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) { @@ -92,16 +76,6 @@ public class SettingsHelper { return true; } - private void setAutoBrightness(boolean value) { - if (mPowerManager != null) { - try { - mPowerManager.setAutoBrightness(value); - } catch (RemoteException e) { - // unable to reach the power manager; skip - } - } - } - private void setGpsLocation(String value) { final String GPS = LocationManager.GPS_PROVIDER; boolean enabled = diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index e1bea37..99e008c 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -53,6 +53,7 @@ import android.view.WindowManagerPolicy; import static android.provider.Settings.System.DIM_SCREEN; import static android.provider.Settings.System.SCREEN_BRIGHTNESS; import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE; +import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN; @@ -64,7 +65,7 @@ import java.util.Observable; import java.util.Observer; class PowerManagerService extends IPowerManager.Stub - implements LocalPowerManager, Watchdog.Monitor, SensorEventListener { + implements LocalPowerManager, Watchdog.Monitor { private static final String TAG = "PowerManagerService"; static final String PARTIAL_NAME = "PowerManagerService"; @@ -189,6 +190,9 @@ class PowerManagerService extends IPowerManager.Stub private BatteryService mBatteryService; private SensorManager mSensorManager; private Sensor mProximitySensor; + private Sensor mLightSensor; + private boolean mLightSensorEnabled; + private float mLightSensorValue = -1; private boolean mDimScreen = true; private long mNextTimeout; private volatile int mPokey = 0; @@ -199,6 +203,8 @@ class PowerManagerService extends IPowerManager.Stub private long mScreenOnStartTime; private boolean mPreventScreenOn; private int mScreenBrightnessOverride = -1; + private boolean mHasHardwareAutoBrightness; + private boolean mAutoBrightessEnabled; // Used when logging number and duration of touch-down cycles private long mTotalTouchDownTime; @@ -207,6 +213,7 @@ class PowerManagerService extends IPowerManager.Stub // could be either static or controllable at runtime private static final boolean mSpew = false; + private static final boolean mDebugLightSensor = false; /* static PrintStream mLog; @@ -344,6 +351,9 @@ class PowerManagerService extends IPowerManager.Stub // DIM_SCREEN //mDimScreen = getInt(DIM_SCREEN) != 0; + // SCREEN_BRIGHTNESS_MODE + setScreenBrightnessMode(getInt(SCREEN_BRIGHTNESS_MODE)); + // recalculate everything setScreenOffTimeoutsLocked(); } @@ -415,12 +425,17 @@ class PowerManagerService extends IPowerManager.Stub mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF); mScreenOffIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); - ContentResolver resolver = mContext.getContentResolver(); + mHasHardwareAutoBrightness = mContext.getResources().getBoolean( + com.android.internal.R.bool.config_hardware_automatic_brightness_available); + + ContentResolver resolver = mContext.getContentResolver(); Cursor settingsCursor = resolver.query(Settings.System.CONTENT_URI, null, "(" + Settings.System.NAME + "=?) or (" + Settings.System.NAME + "=?) or (" + + Settings.System.NAME + "=?) or (" + Settings.System.NAME + "=?)", - new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN}, + new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN, + SCREEN_BRIGHTNESS_MODE}, null); mSettings = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, mHandler); SettingsObserver settingsObserver = new SettingsObserver(); @@ -444,10 +459,6 @@ class PowerManagerService extends IPowerManager.Stub // turn everything on setPowerState(ALL_BRIGHT); - // set auto brightness mode to user setting - boolean brightnessMode = Settings.System.getInt(resolver, SCREEN_BRIGHTNESS_MODE, 1) != 0; - mHardware.setAutoBrightness_UNCHECKED(brightnessMode); - synchronized (mHandlerThread) { mInitComplete = true; mHandlerThread.notifyAll(); @@ -1164,7 +1175,7 @@ class PowerManagerService extends IPowerManager.Stub // Finally, set the flag that prevents the screen from turning on. // (Below, in setPowerState(), we'll check mPreventScreenOn and - // we *won't* call Power.setScreenState(true) if it's set.) + // we *won't* call setScreenStateLocked(true) if it's set.) mPreventScreenOn = true; } else { // (Re)enable the screen. @@ -1182,9 +1193,9 @@ class PowerManagerService extends IPowerManager.Stub Log.d(TAG, "preventScreenOn: turning on after a prior preventScreenOn(true)!"); } - int err = Power.setScreenState(true); + int err = setScreenStateLocked(true); if (err != 0) { - Log.w(TAG, "preventScreenOn: error from Power.setScreenState(): " + err); + Log.w(TAG, "preventScreenOn: error from setScreenStateLocked(): " + err); } } @@ -1239,6 +1250,14 @@ class PowerManagerService extends IPowerManager.Stub } }; + private int setScreenStateLocked(boolean on) { + int err = Power.setScreenState(on); + if (err == 0) { + enableLightSensor(on && mAutoBrightessEnabled); + } + return err; + } + private void setPowerState(int state) { setPowerState(state, false, false); @@ -1327,7 +1346,7 @@ class PowerManagerService extends IPowerManager.Stub reallyTurnScreenOn = false; } if (reallyTurnScreenOn) { - err = Power.setScreenState(true); + err = setScreenStateLocked(true); long identity = Binder.clearCallingIdentity(); try { mBatteryStats.noteScreenBrightness( @@ -1339,7 +1358,7 @@ class PowerManagerService extends IPowerManager.Stub Binder.restoreCallingIdentity(identity); } } else { - Power.setScreenState(false); + setScreenStateLocked(false); // But continue as if we really did turn the screen on... err = 0; } @@ -1384,7 +1403,7 @@ class PowerManagerService extends IPowerManager.Stub EventLog.writeEvent(LOG_POWER_SCREEN_STATE, 0, becauseOfUser ? 1 : 0, mTotalTouchDownTime, mTouchCycles); mLastTouchDown = 0; - int err = Power.setScreenState(false); + int err = setScreenStateLocked(false); if (mScreenOnStartTime != 0) { mScreenOnTime += SystemClock.elapsedRealtime() - mScreenOnStartTime; mScreenOnStartTime = 0; @@ -1802,6 +1821,14 @@ class PowerManagerService extends IPowerManager.Stub } } + private void lightSensorChangedLocked(float value) { + if (mDebugLightSensor) { + Log.d(TAG, "lightSensorChangedLocked " + value); + } + mLightSensorValue = value; + // more to do here + } + /** * The user requested that we go to sleep (probably with the power button). * This overrides all wake locks that are held. @@ -1885,6 +1912,18 @@ class PowerManagerService extends IPowerManager.Stub } } + private void setScreenBrightnessMode(int mode) { + mAutoBrightessEnabled = (mode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC); + + if (mHasHardwareAutoBrightness) { + // When setting auto-brightness, must reset the brightness afterwards + mHardware.setAutoBrightness_UNCHECKED(mAutoBrightessEnabled); + setBacklightBrightness((int)mScreenBrightness.curValue); + } else { + enableLightSensor(screenIsOn() && mAutoBrightessEnabled); + } + } + /** Sets the screen off timeouts: * mKeylightDelay * mDimDelay @@ -2031,6 +2070,14 @@ class PowerManagerService extends IPowerManager.Stub } void systemReady() { + mSensorManager = new SensorManager(mHandlerThread.getLooper()); + mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); + // don't bother with the light sensor if auto brightness is handled in hardware + if (!mHasHardwareAutoBrightness) { + mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); + enableLightSensor(mAutoBrightessEnabled); + } + synchronized (mLocks) { Log.d(TAG, "system ready!"); mDoneBooting = true; @@ -2058,8 +2105,6 @@ class PowerManagerService extends IPowerManager.Stub | PowerManager.FULL_WAKE_LOCK | PowerManager.SCREEN_DIM_WAKE_LOCK; - // call getSensorManager() to make sure mProximitySensor is initialized - getSensorManager(); if (mProximitySensor != null) { result |= PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK; } @@ -2098,31 +2143,19 @@ class PowerManagerService extends IPowerManager.Stub } } - public void setAutoBrightness(boolean on) { - mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); - mHardware.setAutoBrightness_UNCHECKED(on); - } - - private SensorManager getSensorManager() { - if (mSensorManager == null) { - mSensorManager = new SensorManager(mHandlerThread.getLooper()); - mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); - } - return mSensorManager; - } - private void enableProximityLockLocked() { if (mSpew) { Log.d(TAG, "enableProximityLockLocked"); } - mSensorManager.registerListener(this, mProximitySensor, SensorManager.SENSOR_DELAY_NORMAL); + mSensorManager.registerListener(mProximityListener, mProximitySensor, + SensorManager.SENSOR_DELAY_NORMAL); } private void disableProximityLockLocked() { if (mSpew) { Log.d(TAG, "disableProximityLockLocked"); } - mSensorManager.unregisterListener(this); + mSensorManager.unregisterListener(mProximityListener); synchronized (mLocks) { if (mProximitySensorActive) { mProximitySensorActive = false; @@ -2131,32 +2164,65 @@ class PowerManagerService extends IPowerManager.Stub } } - public void onSensorChanged(SensorEvent event) { - long milliseconds = event.timestamp / 1000000; - synchronized (mLocks) { - float distance = event.values[0]; - // compare against getMaximumRange to support sensors that only return 0 or 1 - if (distance >= 0.0 && distance < PROXIMITY_THRESHOLD && - distance < mProximitySensor.getMaximumRange()) { - if (mSpew) { - Log.d(TAG, "onSensorChanged: proximity active, distance: " + distance); - } - goToSleepLocked(milliseconds); - mProximitySensorActive = true; + private void enableLightSensor(boolean enable) { + if (mDebugLightSensor) { + Log.d(TAG, "enableLightSensor " + enable); + } + if (mSensorManager != null && mLightSensorEnabled != enable) { + mLightSensorEnabled = enable; + if (enable) { + mSensorManager.registerListener(mLightListener, mLightSensor, + SensorManager.SENSOR_DELAY_NORMAL); } else { - // proximity sensor negative events trigger as user activity. - // temporarily set mUserActivityAllowed to true so this will work - // even when the keyguard is on. - if (mSpew) { - Log.d(TAG, "onSensorChanged: proximity inactive, distance: " + distance); - } - mProximitySensorActive = false; - forceUserActivityLocked(); + mSensorManager.unregisterListener(mLightListener); } } } - public void onAccuracyChanged(Sensor sensor, int accuracy) { - // ignore - } + SensorEventListener mProximityListener = new SensorEventListener() { + public void onSensorChanged(SensorEvent event) { + long milliseconds = event.timestamp / 1000000; + synchronized (mLocks) { + float distance = event.values[0]; + // compare against getMaximumRange to support sensors that only return 0 or 1 + if (distance >= 0.0 && distance < PROXIMITY_THRESHOLD && + distance < mProximitySensor.getMaximumRange()) { + if (mSpew) { + Log.d(TAG, "onSensorChanged: proximity active, distance: " + distance); + } + goToSleepLocked(milliseconds); + mProximitySensorActive = true; + } else { + // proximity sensor negative events trigger as user activity. + // temporarily set mUserActivityAllowed to true so this will work + // even when the keyguard is on. + if (mSpew) { + Log.d(TAG, "onSensorChanged: proximity inactive, distance: " + distance); + } + mProximitySensorActive = false; + forceUserActivityLocked(); + } + } + } + + public void onAccuracyChanged(Sensor sensor, int accuracy) { + // ignore + } + }; + + SensorEventListener mLightListener = new SensorEventListener() { + public void onSensorChanged(SensorEvent event) { + synchronized (mLocks) { + int value = (int)event.values[0]; + if (mDebugLightSensor) { + Log.d(TAG, "onSensorChanged: light value: " + value); + } + lightSensorChangedLocked(value); + } + } + + public void onAccuracyChanged(Sensor sensor, int accuracy) { + // ignore + } + }; } diff --git a/services/java/com/android/server/status/StatusBarService.java b/services/java/com/android/server/status/StatusBarService.java index fe761ea..59e9832 100644 --- a/services/java/com/android/server/status/StatusBarService.java +++ b/services/java/com/android/server/status/StatusBarService.java @@ -140,7 +140,7 @@ public class StatusBarService extends IStatusBar.Stub boolean down = event.getAction() == KeyEvent.ACTION_DOWN; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: - if (down) { + if (!down) { StatusBarService.this.deactivate(); } return true; @@ -973,15 +973,24 @@ public class StatusBarService extends IStatusBar.Stub } void animateCollapse() { - if (SPEW) Log.d(TAG, "Animate collapse: expanded=" + mExpanded - + " expanded visible=" + mExpandedVisible); + if (SPEW) { + Log.d(TAG, "animateCollapse(): mExpanded=" + mExpanded + + " mExpandedVisible=" + mExpandedVisible + + " mAnimating=" + mAnimating + + " mAnimVel=" + mAnimVel); + } if (!mExpandedVisible) { return; } - prepareTracking(mDisplay.getHeight()-1); - performFling(mDisplay.getHeight()-1, -2000.0f, true); + if (mAnimating) { + return; + } + + int y = mDisplay.getHeight()-1; + prepareTracking(y); + performFling(y, -2000.0f, true); } void performExpand() { @@ -1096,7 +1105,7 @@ public class StatusBarService extends IStatusBar.Stub mTracking = true; mVelocityTracker = VelocityTracker.obtain(); boolean opening = !mExpanded; - if (!mExpanded) { + if (opening) { mAnimAccel = 2000.0f; mAnimVel = 200; mAnimY = mStatusBarView.getHeight(); @@ -1111,16 +1120,13 @@ public class StatusBarService extends IStatusBar.Stub mAnimating = true; mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE_REVEAL), mCurAnimationTime); + makeExpandedVisible(); } else { // it's open, close it? if (mAnimating) { mAnimating = false; mHandler.removeMessages(MSG_ANIMATE); } - } - if (opening) { - makeExpandedVisible(); - } else { updateExpandedViewPos(y + mViewDelta); } } @@ -1547,7 +1553,7 @@ public class StatusBarService extends IStatusBar.Stub void updateExpandedViewPos(int expandedPosition) { if (SPEW) { - Log.d(TAG, "updateExpandedViewPos before pos=" + expandedPosition + Log.d(TAG, "updateExpandedViewPos before expandedPosition=" + expandedPosition + " mTrackingParams.y=" + mTrackingParams.y + " mTrackingPosition=" + mTrackingPosition); } |