diff options
| -rw-r--r-- | camera/libcameraservice/CameraHardwareStub.cpp | 5 | ||||
| -rw-r--r-- | camera/libcameraservice/CameraHardwareStub.h | 1 | ||||
| -rw-r--r-- | camera/libcameraservice/CameraService.cpp | 17 | ||||
| -rw-r--r-- | camera/libcameraservice/CameraService.h | 3 | ||||
| -rw-r--r-- | core/java/android/hardware/Camera.java | 16 | ||||
| -rwxr-xr-x | core/java/android/os/IHardwareService.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/provider/Settings.java | 6 | ||||
| -rw-r--r-- | core/jni/android_hardware_Camera.cpp | 15 | ||||
| -rw-r--r-- | core/res/res/values/config.xml | 2 | ||||
| -rw-r--r-- | include/ui/Camera.h | 3 | ||||
| -rw-r--r-- | include/ui/CameraHardwareInterface.h | 8 | ||||
| -rw-r--r-- | include/ui/ICamera.h | 3 | ||||
| -rw-r--r-- | libs/ui/Camera.cpp | 8 | ||||
| -rw-r--r-- | libs/ui/ICamera.cpp | 18 | ||||
| -rw-r--r-- | packages/SettingsProvider/res/values/defaults.xml | 1 | ||||
| -rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java | 21 | ||||
| -rwxr-xr-x | services/java/com/android/server/HardwareService.java | 20 | ||||
| -rw-r--r-- | services/java/com/android/server/PowerManagerService.java | 19 | ||||
| -rw-r--r-- | services/jni/com_android_server_HardwareService.cpp | 13 |
19 files changed, 173 insertions, 9 deletions
diff --git a/camera/libcameraservice/CameraHardwareStub.cpp b/camera/libcameraservice/CameraHardwareStub.cpp index 24496bb7e2f8..35f4846f9b72 100644 --- a/camera/libcameraservice/CameraHardwareStub.cpp +++ b/camera/libcameraservice/CameraHardwareStub.cpp @@ -265,6 +265,11 @@ status_t CameraHardwareStub::autoFocus() return NO_ERROR; } +status_t CameraHardwareStub::cancelAutoFocus() +{ + return NO_ERROR; +} + /*static*/ int CameraHardwareStub::beginPictureThread(void *cookie) { CameraHardwareStub *c = (CameraHardwareStub *)cookie; diff --git a/camera/libcameraservice/CameraHardwareStub.h b/camera/libcameraservice/CameraHardwareStub.h index 000906a74376..f957fa87acfd 100644 --- a/camera/libcameraservice/CameraHardwareStub.h +++ b/camera/libcameraservice/CameraHardwareStub.h @@ -51,6 +51,7 @@ public: virtual void releaseRecordingFrame(const sp<IMemory>& mem); virtual status_t autoFocus(); + virtual status_t cancelAutoFocus(); virtual status_t takePicture(); virtual status_t cancelPicture(); virtual status_t dump(int fd, const Vector<String16>& args) const; diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index f425f6bc184e..bab7d086a111 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -798,7 +798,6 @@ static void dump_to_file(const char *fname, } #endif -// take a picture - image is returned in callback status_t CameraService::Client::autoFocus() { LOGD("autoFocus (pid %d)", getCallingPid()); @@ -815,6 +814,22 @@ status_t CameraService::Client::autoFocus() return mHardware->autoFocus(); } +status_t CameraService::Client::cancelAutoFocus() +{ + LOGD("cancelAutoFocus (pid %d)", getCallingPid()); + + Mutex::Autolock lock(mLock); + status_t result = checkPid(); + if (result != NO_ERROR) return result; + + if (mHardware == 0) { + LOGE("mHardware is NULL, returning."); + return INVALID_OPERATION; + } + + return mHardware->cancelAutoFocus(); +} + // take a picture - image is returned in callback status_t CameraService::Client::takePicture() { diff --git a/camera/libcameraservice/CameraService.h b/camera/libcameraservice/CameraService.h index f8c72167068e..0a909cf01a19 100644 --- a/camera/libcameraservice/CameraService.h +++ b/camera/libcameraservice/CameraService.h @@ -110,6 +110,9 @@ private: // auto focus virtual status_t autoFocus(); + // cancel auto focus + virtual status_t cancelAutoFocus(); + // take a picture - returns an IMemory (ref-counted mmap) virtual status_t takePicture(); diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java index 04daa1cd9645..9991600e64da 100644 --- a/core/java/android/hardware/Camera.java +++ b/core/java/android/hardware/Camera.java @@ -383,6 +383,20 @@ public class Camera { private native final void native_autoFocus(); /** + * Cancels auto-focus function. If the auto-focus is still in progress, + * this function will cancel it. Whether the auto-focus is in progress + * or not, this function will return the focus position to the default. + * If the camera does not support auto-focus, this is a no-op. + * @hide + */ + public final void cancelAutoFocus() + { + mAutoFocusCallback = null; + native_cancelAutoFocus(); + } + private native final void native_cancelAutoFocus(); + + /** * An interface which contains a callback for the shutter closing after taking a picture. */ public interface ShutterCallback @@ -1338,5 +1352,3 @@ public class Camera { } }; } - - diff --git a/core/java/android/os/IHardwareService.aidl b/core/java/android/os/IHardwareService.aidl index aebcb3c049fc..a6ef64739434 100755 --- a/core/java/android/os/IHardwareService.aidl +++ b/core/java/android/os/IHardwareService.aidl @@ -32,6 +32,9 @@ interface IHardwareService // sets the brightness of the backlights (screen, keyboard, button) 0-255 void setBacklights(int brightness); + // enables or disables automatic brightness mode + void setAutoBrightness(boolean on); + // for the phone void setAttentionLight(boolean on); } diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 688f37720541..0bbd1fc57f20 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -1061,6 +1061,12 @@ public final class Settings { public static final String SCREEN_BRIGHTNESS = "screen_brightness"; /** + * Control whether to enable automatic brightness mode. + * @hide + */ + public static final String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode"; + + /** * Control whether the process CPU usage meter should be shown. */ public static final String SHOW_PROCESSES = "show_processes"; diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp index 8a312d935d84..ce2b10c2f3d5 100644 --- a/core/jni/android_hardware_Camera.cpp +++ b/core/jni/android_hardware_Camera.cpp @@ -327,6 +327,18 @@ static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz) } } +static void android_hardware_Camera_cancelAutoFocus(JNIEnv *env, jobject thiz) +{ + LOGV("cancelAutoFocus"); + JNICameraContext* context; + sp<Camera> c = get_native_camera(env, thiz, &context); + if (c == 0) return; + + if (c->cancelAutoFocus() != NO_ERROR) { + jniThrowException(env, "java/lang/RuntimeException", "cancelAutoFocus failed"); + } +} + static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz) { LOGV("takePicture"); @@ -422,6 +434,9 @@ static JNINativeMethod camMethods[] = { { "native_autoFocus", "()V", (void *)android_hardware_Camera_autoFocus }, + { "native_cancelAutoFocus", + "()V", + (void *)android_hardware_Camera_cancelAutoFocus }, { "native_takePicture", "()V", (void *)android_hardware_Camera_takePicture }, diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index abb575c7d9d0..117e1398e6ea 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -81,4 +81,6 @@ <item>30</item> </integer-array> + <!-- Flag indicating whether the device supports automatic brightness mode. --> + <bool name="config_automatic_brightness_available">false</bool> </resources> diff --git a/include/ui/Camera.h b/include/ui/Camera.h index ae6e255ea910..9ceb8fd43dab 100644 --- a/include/ui/Camera.h +++ b/include/ui/Camera.h @@ -143,6 +143,9 @@ public: // autoFocus - status returned from callback status_t autoFocus(); + // cancel auto focus + status_t cancelAutoFocus(); + // take a picture - picture returned from callback status_t takePicture(); diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h index 535f70e0cdc6..5fbb7d80cb91 100644 --- a/include/ui/CameraHardwareInterface.h +++ b/include/ui/CameraHardwareInterface.h @@ -161,6 +161,14 @@ public: virtual status_t autoFocus() = 0; /** + * Cancels auto-focus function. If the auto-focus is still in progress, + * this function will cancel it. Whether the auto-focus is in progress + * or not, this function will return the focus position to the default. + * If the camera does not support auto-focus, this is a no-op. + */ + virtual status_t cancelAutoFocus() = 0; + + /** * Take a picture. */ virtual status_t takePicture() = 0; diff --git a/include/ui/ICamera.h b/include/ui/ICamera.h index 1df791404156..7595e36e57b6 100644 --- a/include/ui/ICamera.h +++ b/include/ui/ICamera.h @@ -76,6 +76,9 @@ public: // auto focus virtual status_t autoFocus() = 0; + // cancel auto focus + virtual status_t cancelAutoFocus() = 0; + // take a picture virtual status_t takePicture() = 0; diff --git a/libs/ui/Camera.cpp b/libs/ui/Camera.cpp index 12a7725010f3..0c6d3408ab08 100644 --- a/libs/ui/Camera.cpp +++ b/libs/ui/Camera.cpp @@ -242,6 +242,14 @@ status_t Camera::autoFocus() return c->autoFocus(); } +status_t Camera::cancelAutoFocus() +{ + LOGV("cancelAutoFocus"); + sp <ICamera> c = mCamera; + if (c == 0) return NO_INIT; + return c->cancelAutoFocus(); +} + // take a picture status_t Camera::takePicture() { diff --git a/libs/ui/ICamera.cpp b/libs/ui/ICamera.cpp index 805c2ca2be2c..fd7e084d2899 100644 --- a/libs/ui/ICamera.cpp +++ b/libs/ui/ICamera.cpp @@ -32,6 +32,7 @@ enum { START_PREVIEW, STOP_PREVIEW, AUTO_FOCUS, + CANCEL_AUTO_FOCUS, TAKE_PICTURE, SET_PARAMETERS, GET_PARAMETERS, @@ -162,6 +163,17 @@ public: return ret; } + // cancel focus + status_t cancelAutoFocus() + { + LOGV("cancelAutoFocus"); + Parcel data, reply; + data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); + remote()->transact(CANCEL_AUTO_FOCUS, data, &reply); + status_t ret = reply.readInt32(); + return ret; + } + // take a picture - returns an IMemory (ref-counted mmap) status_t takePicture() { @@ -294,6 +306,12 @@ status_t BnCamera::onTransact( reply->writeInt32(autoFocus()); return NO_ERROR; } break; + case CANCEL_AUTO_FOCUS: { + LOGV("CANCEL_AUTO_FOCUS"); + CHECK_INTERFACE(ICamera, data, reply); + reply->writeInt32(cancelAutoFocus()); + return NO_ERROR; + } break; case TAKE_PICTURE: { LOGV("TAKE_PICTURE"); CHECK_INTERFACE(ICamera, data, reply); diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml index 6b2044590e43..d5f1c614192f 100644 --- a/packages/SettingsProvider/res/values/defaults.xml +++ b/packages/SettingsProvider/res/values/defaults.xml @@ -27,6 +27,7 @@ <bool name="def_accelerometer_rotation">true</bool> <!-- Default screen brightness, from 0 to 255. 102 is 40%. --> <integer name="def_screen_brightness">102</integer> + <bool name="def_screen_brightness_automatic_mode">false</bool> <fraction name="def_window_animation_scale">100%</fraction> <fraction name="def_window_transition_scale">0%</fraction> diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index 2524a305b973..f99eb5859d68 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -71,7 +71,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // is properly propagated through your change. Not doing so will result in a loss of user // settings. - private static final int DATABASE_VERSION = 39; + private static final int DATABASE_VERSION = 40; private Context mContext; @@ -465,6 +465,22 @@ public class DatabaseHelper extends SQLiteOpenHelper { upgradeVersion = 39; } + if (upgradeVersion == 39) { + db.beginTransaction(); + try { + String value = + mContext.getResources().getBoolean( + R.bool.def_screen_brightness_automatic_mode) ? "1" : "0"; + db.execSQL("INSERT OR IGNORE INTO system(name,value) values('" + + Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');"); + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + upgradeVersion = 40; + } + if (upgradeVersion != currentVersion) { Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion + ", must wipe the settings provider"); @@ -701,6 +717,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS, R.integer.def_screen_brightness); + loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE, + R.bool.def_screen_brightness_automatic_mode); + loadDefaultAnimationSettings(stmt); loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION, diff --git a/services/java/com/android/server/HardwareService.java b/services/java/com/android/server/HardwareService.java index 6ac72e0d57c8..01daae344197 100755 --- a/services/java/com/android/server/HardwareService.java +++ b/services/java/com/android/server/HardwareService.java @@ -59,6 +59,8 @@ public class HardwareService extends IHardwareService.Stub { private boolean mAttentionLightOn; private boolean mPulsing; + private boolean mAutoBrightnessAvailable; + private class Vibration implements IBinder.DeathRecipient { private final IBinder mToken; private final long mTimeout; @@ -129,6 +131,9 @@ public class HardwareService extends IHardwareService.Stub { IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_OFF); context.registerReceiver(mIntentReceiver, filter); + + mAutoBrightnessAvailable = context.getResources().getBoolean( + com.android.internal.R.bool.config_automatic_brightness_available); } protected void finalize() throws Throwable { @@ -302,6 +307,20 @@ public class HardwareService extends IHardwareService.Stub { setLight_native(mNativePointer, light, color, mode, onMS, offMS); } + public void setAutoBrightness(boolean on) { + if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) + != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException("Requires HARDWARE_TEST permission"); + } + setAutoBrightness_UNCHECKED(on); + } + + void setAutoBrightness_UNCHECKED(boolean on) { + if (mAutoBrightnessAvailable) { + setAutoBrightness_native(mNativePointer, on); + } + } + public void setAttentionLight(boolean on) { // Not worthy of a permission. We shouldn't have a flashlight permission. synchronized (this) { @@ -502,6 +521,7 @@ public class HardwareService extends IHardwareService.Stub { private static native int init_native(); private static native void finalize_native(int ptr); + private static native void setAutoBrightness_native(int ptr, boolean automatic); private static native void setLight_native(int ptr, int light, int color, int mode, int onMS, int offMS); diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index ba65f01ef686..29513849b1d3 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -52,6 +52,7 @@ import android.util.Log; 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_OFF_TIMEOUT; import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN; @@ -87,6 +88,9 @@ class PowerManagerService extends IPowerManager.Stub private static final int LONG_KEYLIGHT_DELAY = 6000; // t+6 sec private static final int LONG_DIM_TIME = 7000; // t+N-5 sec + // trigger proximity if distance is less than 5 cm + private static final float PROXIMITY_THRESHOLD = 5.0f; + // Cached Gservices settings; see updateGservicesValues() private int mShortKeylightDelay = SHORT_KEYLIGHT_DELAY_DEFAULT; @@ -442,7 +446,11 @@ 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(); @@ -2079,18 +2087,19 @@ class PowerManagerService extends IPowerManager.Stub public void onSensorChanged(SensorEvent event) { long milliseconds = event.timestamp / 1000000; synchronized (mLocks) { - if (event.values[0] == 0.0) { + float distance = event.values[0]; + if (distance >= 0.0 && distance < PROXIMITY_THRESHOLD) { if (mSpew) { - Log.d(TAG, "onSensorChanged: proximity active"); + Log.d(TAG, "onSensorChanged: proximity active, distance: " + distance); } goToSleepLocked(milliseconds); mProximitySensorActive = true; } else { - // proximity sensor negative events user activity. + // 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"); + Log.d(TAG, "onSensorChanged: proximity inactive, distance: " + distance); } mProximitySensorActive = false; boolean savedActivityAllowed = mUserActivityAllowed; diff --git a/services/jni/com_android_server_HardwareService.cpp b/services/jni/com_android_server_HardwareService.cpp index 22d4bd8766e8..a17e29fbf60d 100644 --- a/services/jni/com_android_server_HardwareService.cpp +++ b/services/jni/com_android_server_HardwareService.cpp @@ -100,6 +100,18 @@ static void finalize_native(JNIEnv *env, jobject clazz, int ptr) free(devices); } +static void setAutoBrightness_native(JNIEnv *env, jobject clazz, int ptr, + jboolean automatic) +{ + Devices* devices = (Devices*)ptr; + + if (devices->lights[LIGHT_INDEX_BACKLIGHT] == NULL) { + return; + } + + devices->lights[LIGHT_INDEX_BACKLIGHT]->set_als_mode(automatic ? 0 : 1); +} + static void setLight_native(JNIEnv *env, jobject clazz, int ptr, int light, int colorARGB, int flashMode, int onMS, int offMS) { @@ -134,6 +146,7 @@ static void vibratorOff(JNIEnv *env, jobject clazz) static JNINativeMethod method_table[] = { { "init_native", "()I", (void*)init_native }, { "finalize_native", "(I)V", (void*)finalize_native }, + { "setAutoBrightness_native", "(IZ)V", (void*)setAutoBrightness_native }, { "setLight_native", "(IIIIII)V", (void*)setLight_native }, { "vibratorOn", "(J)V", (void*)vibratorOn }, { "vibratorOff", "()V", (void*)vibratorOff } |