summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk2
-rw-r--r--core/java/android/os/Hardware.java49
-rwxr-xr-xcore/java/android/os/IVibratorService.aidl (renamed from core/java/android/os/IHardwareService.aidl)11
-rw-r--r--core/java/android/os/Vibrator.java6
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/AndroidRuntime.cpp2
-rw-r--r--core/jni/android_os_Hardware.cpp62
-rw-r--r--preloaded-classes3
-rw-r--r--services/java/com/android/server/LightsService.java133
-rwxr-xr-xservices/java/com/android/server/NotificationManagerService.java28
-rw-r--r--services/java/com/android/server/PowerManagerService.java58
-rw-r--r--services/java/com/android/server/SystemServer.java16
-rwxr-xr-xservices/java/com/android/server/VibratorService.java (renamed from services/java/com/android/server/HardwareService.java)145
-rw-r--r--services/jni/Android.mk3
-rw-r--r--services/jni/com_android_server_LightsService.cpp (renamed from services/jni/com_android_server_HardwareService.cpp)57
-rw-r--r--services/jni/com_android_server_VibratorService.cpp55
-rw-r--r--services/jni/onload.cpp6
-rw-r--r--tests/permission/src/com/android/framework/permission/tests/VibratorServicePermissionTest.java (renamed from tests/permission/src/com/android/framework/permission/tests/HardwareServicePermissionTest.java)56
18 files changed, 289 insertions, 404 deletions
diff --git a/Android.mk b/Android.mk
index be3f569..1d4b10f 100644
--- a/Android.mk
+++ b/Android.mk
@@ -108,13 +108,13 @@ LOCAL_SRC_FILES += \
core/java/android/hardware/ISensorService.aidl \
core/java/android/net/IConnectivityManager.aidl \
core/java/android/os/ICheckinService.aidl \
- core/java/android/os/IHardwareService.aidl \
core/java/android/os/IMessenger.aidl \
core/java/android/os/IMountService.aidl \
core/java/android/os/INetStatService.aidl \
core/java/android/os/IParentalControlCallback.aidl \
core/java/android/os/IPermissionController.aidl \
core/java/android/os/IPowerManager.aidl \
+ core/java/android/os/IVibratorService.aidl \
core/java/android/service/wallpaper/IWallpaperConnection.aidl \
core/java/android/service/wallpaper/IWallpaperEngine.aidl \
core/java/android/service/wallpaper/IWallpaperService.aidl \
diff --git a/core/java/android/os/Hardware.java b/core/java/android/os/Hardware.java
deleted file mode 100644
index efc5617..0000000
--- a/core/java/android/os/Hardware.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.os;
-
-/**
- * {@hide}
- */
-public class Hardware
-{
-
-
- /* ********************************************************************************
- *
- *
- *
- *
- *
- *
- *
- *
- * Don't add anything else to this class. Add it to HardwareService instead.
- *
- *
- *
- *
- *
- *
- *
- * ********************************************************************************/
-
-
- public static native boolean getFlashlightEnabled();
- public static native void setFlashlightEnabled(boolean on);
- public static native void enableCameraFlash(int milliseconds);
-}
diff --git a/core/java/android/os/IHardwareService.aidl b/core/java/android/os/IVibratorService.aidl
index 34f30a7..c98fb56 100755
--- a/core/java/android/os/IHardwareService.aidl
+++ b/core/java/android/os/IVibratorService.aidl
@@ -17,19 +17,10 @@
package android.os;
/** {@hide} */
-interface IHardwareService
+interface IVibratorService
{
- // Vibrator support
void vibrate(long milliseconds, IBinder token);
void vibratePattern(in long[] pattern, int repeat, IBinder token);
void cancelVibrate(IBinder token);
-
- // flashlight support
- boolean getFlashlightEnabled();
- void setFlashlightEnabled(boolean on);
- void enableCameraFlash(int milliseconds);
-
- // for the phone
- void setAttentionLight(boolean on, int color);
}
diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java
index 51dcff1..1895cf8 100644
--- a/core/java/android/os/Vibrator.java
+++ b/core/java/android/os/Vibrator.java
@@ -23,14 +23,14 @@ package android.os;
*/
public class Vibrator
{
- IHardwareService mService;
+ IVibratorService mService;
private final Binder mToken = new Binder();
/** @hide */
public Vibrator()
{
- mService = IHardwareService.Stub.asInterface(
- ServiceManager.getService("hardware"));
+ mService = IVibratorService.Stub.asInterface(
+ ServiceManager.getService("vibrator"));
}
/**
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index b9042f9..edb0b78 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -54,7 +54,6 @@ LOCAL_SRC_FILES:= \
android_os_SystemClock.cpp \
android_os_SystemProperties.cpp \
android_os_UEventObserver.cpp \
- android_os_Hardware.cpp \
android_net_LocalSocketImpl.cpp \
android_net_NetUtils.cpp \
android_net_wifi_Wifi.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index d069d7d..9f617fb 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -130,7 +130,6 @@ extern int register_android_os_ParcelFileDescriptor(JNIEnv *env);
extern int register_android_os_Power(JNIEnv *env);
extern int register_android_os_StatFs(JNIEnv *env);
extern int register_android_os_SystemProperties(JNIEnv *env);
-extern int register_android_os_Hardware(JNIEnv* env);
extern int register_android_os_SystemClock(JNIEnv* env);
extern int register_android_os_FileObserver(JNIEnv *env);
extern int register_android_os_FileUtils(JNIEnv *env);
@@ -1166,7 +1165,6 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_text_KeyCharacterMap),
REG_JNI(register_android_os_Process),
REG_JNI(register_android_os_Binder),
- REG_JNI(register_android_os_Hardware),
REG_JNI(register_android_view_Display),
REG_JNI(register_android_nio_utils),
REG_JNI(register_android_graphics_PixelFormat),
diff --git a/core/jni/android_os_Hardware.cpp b/core/jni/android_os_Hardware.cpp
deleted file mode 100644
index 8007662..0000000
--- a/core/jni/android_os_Hardware.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2006, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-#include <hardware_legacy/flashlight.h>
-#include <hardware_legacy/power.h>
-
-#include <nativehelper/jni.h>
-#include <android_runtime/AndroidRuntime.h>
-#include <nativehelper/JNIHelp.h>
-
-namespace android {
-
-static jint
-getFlashlightEnabled(JNIEnv *env, jobject clazz)
-{
- return get_flashlight_enabled();
-}
-
-static void
-setFlashlightEnabled(JNIEnv *env, jobject clazz, jboolean on)
-{
- set_flashlight_enabled(on);
-}
-
-static void
-enableCameraFlash(JNIEnv *env, jobject clazz, jint milliseconds)
-{
- enable_camera_flash(milliseconds);
-}
-
-// ============================================================================
-/*
- * JNI registration.
- */
-
-static JNINativeMethod g_methods[] = {
- /* name, signature, funcPtr */
- { "getFlashlightEnabled", "()Z", (void*)getFlashlightEnabled },
- { "setFlashlightEnabled", "(Z)V", (void*)setFlashlightEnabled },
- { "enableCameraFlash", "(I)V", (void*)enableCameraFlash },
-};
-
-int register_android_os_Hardware(JNIEnv* env)
-{
- return AndroidRuntime::registerNativeMethods(env,
- "android/os/Hardware", g_methods, NELEM(g_methods));
-}
-
-}; // namespace android
diff --git a/preloaded-classes b/preloaded-classes
index 08fc2a1..73bab87 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -501,10 +501,8 @@ android.os.FileUtils
android.os.FileUtils$FileStatus
android.os.Handler
android.os.HandlerThread
-android.os.Hardware
android.os.IBinder
android.os.ICheckinService$Stub
-android.os.IHardwareService$Stub
android.os.IInterface
android.os.IMountService$Stub
android.os.IMountService$Stub$Proxy
@@ -512,6 +510,7 @@ android.os.INetStatService$Stub
android.os.IParentalControlCallback$Stub
android.os.IPowerManager$Stub
android.os.IPowerManager$Stub$Proxy
+android.os.IVibratorService$Stub
android.os.Looper
android.os.MemoryFile
android.os.Message
diff --git a/services/java/com/android/server/LightsService.java b/services/java/com/android/server/LightsService.java
new file mode 100644
index 0000000..ae8d321
--- /dev/null
+++ b/services/java/com/android/server/LightsService.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+public class LightsService {
+ private static final String TAG = "LightsService";
+
+ static final int LIGHT_ID_BACKLIGHT = 0;
+ static final int LIGHT_ID_KEYBOARD = 1;
+ static final int LIGHT_ID_BUTTONS = 2;
+ static final int LIGHT_ID_BATTERY = 3;
+ static final int LIGHT_ID_NOTIFICATIONS = 4;
+ static final int LIGHT_ID_ATTENTION = 5;
+
+ static final int LIGHT_FLASH_NONE = 0;
+ static final int LIGHT_FLASH_TIMED = 1;
+ static final int LIGHT_FLASH_HARDWARE = 2;
+
+ /**
+ * Light brightness is managed by a user setting.
+ */
+ static final int BRIGHTNESS_MODE_USER = 0;
+
+ /**
+ * Light brightness is managed by a light sensor.
+ */
+ static final int BRIGHTNESS_MODE_SENSOR = 1;
+
+ private boolean mAttentionLightOn;
+ private boolean mPulsing;
+
+ LightsService(Context context) {
+
+ mNativePointer = init_native();
+ mContext = context;
+ }
+
+ protected void finalize() throws Throwable {
+ finalize_native(mNativePointer);
+ super.finalize();
+ }
+
+ void setLightOff(int light) {
+ setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0, 0);
+ }
+
+ void setLightBrightness(int light, int brightness, int brightnessMode) {
+ int b = brightness & 0x000000ff;
+ b = 0xff000000 | (b << 16) | (b << 8) | b;
+ setLight_native(mNativePointer, light, b, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
+ }
+
+ void setLightColor(int light, int color) {
+ setLight_native(mNativePointer, light, color, LIGHT_FLASH_NONE, 0, 0, 0);
+ }
+
+ void setLightFlashing(int light, int color, int mode, int onMS, int offMS) {
+ setLight_native(mNativePointer, light, color, mode, onMS, offMS, 0);
+ }
+
+ public void setAttentionLight(boolean on, int color) {
+ // Not worthy of a permission. We shouldn't have a flashlight permission.
+ synchronized (this) {
+ mAttentionLightOn = on;
+ mPulsing = false;
+ setLight_native(mNativePointer, LIGHT_ID_ATTENTION, color,
+ LIGHT_FLASH_HARDWARE, on ? 3 : 0, 0, 0);
+ }
+ }
+
+ public void pulseBreathingLight() {
+ synchronized (this) {
+ // HACK: Added at the last minute of cupcake -- design this better;
+ // Don't reuse the attention light -- make another one.
+ if (false) {
+ Log.d(TAG, "pulseBreathingLight mAttentionLightOn=" + mAttentionLightOn
+ + " mPulsing=" + mPulsing);
+ }
+ if (!mAttentionLightOn && !mPulsing) {
+ mPulsing = true;
+ setLight_native(mNativePointer, LIGHT_ID_ATTENTION, 0x00ffffff,
+ LIGHT_FLASH_HARDWARE, 7, 0, 0);
+ mH.sendMessageDelayed(Message.obtain(mH, 1), 3000);
+ }
+ }
+ }
+
+ private Handler mH = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ synchronized (this) {
+ if (false) {
+ Log.d(TAG, "pulse cleanup handler firing mPulsing=" + mPulsing);
+ }
+ if (mPulsing) {
+ mPulsing = false;
+ setLight_native(mNativePointer, LIGHT_ID_ATTENTION,
+ mAttentionLightOn ? 0xffffffff : 0,
+ LIGHT_FLASH_NONE, 0, 0, 0);
+ }
+ }
+ }
+ };
+
+ private static native int init_native();
+ private static native void finalize_native(int ptr);
+
+ private static native void setLight_native(int ptr, int light, int color, int mode,
+ int onMS, int offMS, int brightnessMode);
+
+ private final Context mContext;
+
+ private int mNativePointer;
+}
diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java
index ff23a13..b89cd3f 100755
--- a/services/java/com/android/server/NotificationManagerService.java
+++ b/services/java/com/android/server/NotificationManagerService.java
@@ -86,7 +86,7 @@ class NotificationManagerService extends INotificationManager.Stub
private WorkerHandler mHandler;
private StatusBarService mStatusBarService;
- private HardwareService mHardware;
+ private LightsService mLightsService;
private NotificationRecord mSoundNotification;
private AsyncPlayer mSound;
@@ -363,11 +363,11 @@ class NotificationManagerService extends INotificationManager.Stub
private final SettingsObserver mSettingsObserver;
NotificationManagerService(Context context, StatusBarService statusBar,
- HardwareService hardware)
+ LightsService lights)
{
super();
mContext = context;
- mHardware = hardware;
+ mLightsService = lights;
mAm = ActivityManagerNative.getDefault();
mSound = new AsyncPlayer(TAG);
mSound.setUsesWakeLock(context);
@@ -678,7 +678,7 @@ class NotificationManagerService extends INotificationManager.Stub
long identity = Binder.clearCallingIdentity();
try {
r.statusBarKey = mStatusBarService.addIcon(icon, n);
- mHardware.pulseBreathingLight();
+ mLightsService.pulseBreathingLight();
}
finally {
Binder.restoreCallingIdentity(identity);
@@ -969,24 +969,24 @@ class NotificationManagerService extends INotificationManager.Stub
// Battery low always shows, other states only show if charging.
if (mBatteryLow) {
if (mBatteryCharging) {
- mHardware.setLightColor_UNCHECKED(HardwareService.LIGHT_ID_BATTERY,
+ mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY,
BATTERY_LOW_ARGB);
} else {
// Flash when battery is low and not charging
- mHardware.setLightFlashing_UNCHECKED(HardwareService.LIGHT_ID_BATTERY,
- BATTERY_LOW_ARGB, HardwareService.LIGHT_FLASH_TIMED,
+ mLightsService.setLightFlashing(LightsService.LIGHT_ID_BATTERY,
+ BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED,
BATTERY_BLINK_ON, BATTERY_BLINK_OFF);
}
} else if (mBatteryCharging) {
if (mBatteryFull) {
- mHardware.setLightColor_UNCHECKED(HardwareService.LIGHT_ID_BATTERY,
+ mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY,
BATTERY_FULL_ARGB);
} else {
- mHardware.setLightColor_UNCHECKED(HardwareService.LIGHT_ID_BATTERY,
+ mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY,
BATTERY_MEDIUM_ARGB);
}
} else {
- mHardware.setLightOff_UNCHECKED(HardwareService.LIGHT_ID_BATTERY);
+ mLightsService.setLightOff(LightsService.LIGHT_ID_BATTERY);
}
// handle notification lights
@@ -998,12 +998,12 @@ class NotificationManagerService extends INotificationManager.Stub
}
}
if (mLedNotification == null) {
- mHardware.setLightOff_UNCHECKED(HardwareService.LIGHT_ID_NOTIFICATIONS);
+ mLightsService.setLightOff(LightsService.LIGHT_ID_NOTIFICATIONS);
} else {
- mHardware.setLightFlashing_UNCHECKED(
- HardwareService.LIGHT_ID_NOTIFICATIONS,
+ mLightsService.setLightFlashing(
+ LightsService.LIGHT_ID_NOTIFICATIONS,
mLedNotification.notification.ledARGB,
- HardwareService.LIGHT_FLASH_TIMED,
+ LightsService.LIGHT_FLASH_TIMED,
mLedNotification.notification.ledOnMS,
mLedNotification.notification.ledOffMS);
}
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index feab7d2..b1ecb3c 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -181,7 +181,7 @@ class PowerManagerService extends IPowerManager.Stub
private final LockList mLocks = new LockList();
private Intent mScreenOffIntent;
private Intent mScreenOnIntent;
- private HardwareService mHardware;
+ private LightsService mLightsService;
private Context mContext;
private UnsynchronizedWakeLock mBroadcastWakeLock;
private UnsynchronizedWakeLock mStayOnWhilePluggedInScreenDimLock;
@@ -420,9 +420,9 @@ class PowerManagerService extends IPowerManager.Stub
private ContentQueryMap mSettings;
- void init(Context context, HardwareService hardware, IActivityManager activity,
+ void init(Context context, LightsService lights, IActivityManager activity,
BatteryService battery) {
- mHardware = hardware;
+ mLightsService = lights;
mContext = context;
mActivityService = activity;
mBatteryStats = BatteryStatsService.getService();
@@ -1363,11 +1363,11 @@ class PowerManagerService extends IPowerManager.Stub
if (!on) {
// make sure button and key backlights are off too
int brightnessMode = (mUseSoftwareAutoBrightness
- ? HardwareService.BRIGHTNESS_MODE_SENSOR
- : HardwareService.BRIGHTNESS_MODE_USER);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, 0,
+ ? LightsService.BRIGHTNESS_MODE_SENSOR
+ : LightsService.BRIGHTNESS_MODE_USER);
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, 0,
brightnessMode);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, 0,
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, 0,
brightnessMode);
// clear current value so we will update based on the new conditions
// when the sensor is reenabled.
@@ -1720,21 +1720,21 @@ class PowerManagerService extends IPowerManager.Stub
private void setLightBrightness(int mask, int value) {
int brightnessMode = (mAutoBrightessEnabled
- ? HardwareService.BRIGHTNESS_MODE_SENSOR
- : HardwareService.BRIGHTNESS_MODE_USER);
+ ? LightsService.BRIGHTNESS_MODE_SENSOR
+ : LightsService.BRIGHTNESS_MODE_USER);
if ((mask & SCREEN_BRIGHT_BIT) != 0) {
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, value,
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, value,
brightnessMode);
}
brightnessMode = (mUseSoftwareAutoBrightness
- ? HardwareService.BRIGHTNESS_MODE_SENSOR
- : HardwareService.BRIGHTNESS_MODE_USER);
+ ? LightsService.BRIGHTNESS_MODE_SENSOR
+ : LightsService.BRIGHTNESS_MODE_USER);
if ((mask & BUTTON_BRIGHT_BIT) != 0) {
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, value,
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, value,
brightnessMode);
}
if ((mask & KEYBOARD_BRIGHT_BIT) != 0) {
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, value,
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, value,
brightnessMode);
}
}
@@ -2081,9 +2081,9 @@ class PowerManagerService extends IPowerManager.Stub
}
} else {
int brightnessMode = (mAutoBrightessEnabled
- ? HardwareService.BRIGHTNESS_MODE_SENSOR
- : HardwareService.BRIGHTNESS_MODE_USER);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT,
+ ? LightsService.BRIGHTNESS_MODE_SENSOR
+ : LightsService.BRIGHTNESS_MODE_USER);
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT,
lcdValue, brightnessMode);
}
}
@@ -2096,9 +2096,9 @@ class PowerManagerService extends IPowerManager.Stub
}
} else {
int brightnessMode = (mUseSoftwareAutoBrightness
- ? HardwareService.BRIGHTNESS_MODE_SENSOR
- : HardwareService.BRIGHTNESS_MODE_USER);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS,
+ ? LightsService.BRIGHTNESS_MODE_SENSOR
+ : LightsService.BRIGHTNESS_MODE_USER);
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS,
buttonValue, brightnessMode);
}
}
@@ -2111,9 +2111,9 @@ class PowerManagerService extends IPowerManager.Stub
}
} else {
int brightnessMode = (mUseSoftwareAutoBrightness
- ? HardwareService.BRIGHTNESS_MODE_SENSOR
- : HardwareService.BRIGHTNESS_MODE_USER);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD,
+ ? LightsService.BRIGHTNESS_MODE_SENSOR
+ : LightsService.BRIGHTNESS_MODE_USER);
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD,
keyboardValue, brightnessMode);
}
}
@@ -2443,12 +2443,12 @@ class PowerManagerService extends IPowerManager.Stub
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
// Don't let applications turn the screen all the way off
brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, brightness,
- HardwareService.BRIGHTNESS_MODE_USER);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD,
- (mKeyboardVisible ? brightness : 0), HardwareService.BRIGHTNESS_MODE_USER);
- mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, brightness,
- HardwareService.BRIGHTNESS_MODE_USER);
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, brightness,
+ LightsService.BRIGHTNESS_MODE_USER);
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD,
+ (mKeyboardVisible ? brightness : 0), LightsService.BRIGHTNESS_MODE_USER);
+ mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, brightness,
+ LightsService.BRIGHTNESS_MODE_USER);
long identity = Binder.clearCallingIdentity();
try {
mBatteryStats.noteScreenBrightness(brightness);
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 3cfd1a9..a0a9a93 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -84,7 +84,7 @@ class ServerThread extends Thread {
int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
: Integer.parseInt(factoryTestStr);
- HardwareService hardware = null;
+ LightsService lights = null;
PowerManagerService power = null;
BatteryService battery = null;
ConnectivityService connectivity = null;
@@ -141,13 +141,15 @@ class ServerThread extends Thread {
battery = new BatteryService(context);
ServiceManager.addService("battery", battery);
- Log.i(TAG, "Hardware Service");
- hardware = new HardwareService(context);
- ServiceManager.addService("hardware", hardware);
+ Log.i(TAG, "Lights Service");
+ lights = new LightsService(context);
+
+ Log.i(TAG, "Vibrator Service");
+ ServiceManager.addService("vibrator", new VibratorService(context));
// only initialize the power service after we have started the
- // hardware service, content providers and the battery service.
- power.init(context, hardware, ActivityManagerService.getDefault(), battery);
+ // lights service, content providers and the battery service.
+ power.init(context, lights, ActivityManagerService.getDefault(), battery);
Log.i(TAG, "Alarm Manager");
AlarmManagerService alarm = new AlarmManagerService(context);
@@ -253,7 +255,7 @@ class ServerThread extends Thread {
try {
Log.i(TAG, "Notification Manager");
- notification = new NotificationManagerService(context, statusBar, hardware);
+ notification = new NotificationManagerService(context, statusBar, lights);
ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
} catch (Throwable e) {
Log.e(TAG, "Failure starting Notification Manager", e);
diff --git a/services/java/com/android/server/HardwareService.java b/services/java/com/android/server/VibratorService.java
index 88074c2..5282ba2 100755
--- a/services/java/com/android/server/HardwareService.java
+++ b/services/java/com/android/server/VibratorService.java
@@ -16,19 +16,13 @@
package com.android.server;
-import com.android.internal.app.IBatteryStats;
-import com.android.server.am.BatteryStatsService;
-
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Handler;
-import android.os.Hardware;
-import android.os.IHardwareService;
-import android.os.Message;
-import android.os.Power;
+import android.os.IVibratorService;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
@@ -40,36 +34,12 @@ import android.util.Log;
import java.util.LinkedList;
import java.util.ListIterator;
-public class HardwareService extends IHardwareService.Stub {
- private static final String TAG = "HardwareService";
-
- static final int LIGHT_ID_BACKLIGHT = 0;
- static final int LIGHT_ID_KEYBOARD = 1;
- static final int LIGHT_ID_BUTTONS = 2;
- static final int LIGHT_ID_BATTERY = 3;
- static final int LIGHT_ID_NOTIFICATIONS = 4;
- static final int LIGHT_ID_ATTENTION = 5;
-
- static final int LIGHT_FLASH_NONE = 0;
- static final int LIGHT_FLASH_TIMED = 1;
- static final int LIGHT_FLASH_HARDWARE = 2;
-
- /**
- * Light brightness is managed by a user setting.
- */
- static final int BRIGHTNESS_MODE_USER = 0;
-
- /**
- * Light brightness is managed by a light sensor.
- */
- static final int BRIGHTNESS_MODE_SENSOR = 1;
+public class VibratorService extends IVibratorService.Stub {
+ private static final String TAG = "VibratorService";
private final LinkedList<Vibration> mVibrations;
private Vibration mCurrentVibration;
- private boolean mAttentionLightOn;
- private boolean mPulsing;
-
private class Vibration implements IBinder.DeathRecipient {
private final IBinder mToken;
private final long mTimeout;
@@ -120,13 +90,11 @@ public class HardwareService extends IHardwareService.Stub {
}
}
- HardwareService(Context context) {
+ VibratorService(Context context) {
// Reset the hardware to a default state, in case this is a runtime
// restart instead of a fresh boot.
vibratorOff();
- mNativePointer = init_native();
-
mContext = context;
PowerManager pm = (PowerManager)context.getSystemService(
Context.POWER_SERVICE);
@@ -135,18 +103,11 @@ public class HardwareService extends IHardwareService.Stub {
mVibrations = new LinkedList<Vibration>();
- mBatteryStats = BatteryStatsService.getService();
-
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(mIntentReceiver, filter);
}
- protected void finalize() throws Throwable {
- finalize_native(mNativePointer);
- super.finalize();
- }
-
public void vibrate(long milliseconds, IBinder token) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.VIBRATE)
!= PackageManager.PERMISSION_GRANTED) {
@@ -251,92 +212,6 @@ public class HardwareService extends IHardwareService.Stub {
}
}
- public boolean getFlashlightEnabled() {
- return Hardware.getFlashlightEnabled();
- }
-
- public void setFlashlightEnabled(boolean on) {
- if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.FLASHLIGHT)
- != PackageManager.PERMISSION_GRANTED &&
- mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
- != PackageManager.PERMISSION_GRANTED) {
- throw new SecurityException("Requires FLASHLIGHT or HARDWARE_TEST permission");
- }
- Hardware.setFlashlightEnabled(on);
- }
-
- public void enableCameraFlash(int milliseconds) {
- if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.CAMERA)
- != PackageManager.PERMISSION_GRANTED &&
- mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
- != PackageManager.PERMISSION_GRANTED) {
- throw new SecurityException("Requires CAMERA or HARDWARE_TEST permission");
- }
- Hardware.enableCameraFlash(milliseconds);
- }
-
- void setLightOff_UNCHECKED(int light) {
- setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0, 0);
- }
-
- void setLightBrightness_UNCHECKED(int light, int brightness, int brightnessMode) {
- int b = brightness & 0x000000ff;
- b = 0xff000000 | (b << 16) | (b << 8) | b;
- setLight_native(mNativePointer, light, b, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
- }
-
- void setLightColor_UNCHECKED(int light, int color) {
- setLight_native(mNativePointer, light, color, LIGHT_FLASH_NONE, 0, 0, 0);
- }
-
- void setLightFlashing_UNCHECKED(int light, int color, int mode, int onMS, int offMS) {
- setLight_native(mNativePointer, light, color, mode, onMS, offMS, 0);
- }
-
- public void setAttentionLight(boolean on, int color) {
- // Not worthy of a permission. We shouldn't have a flashlight permission.
- synchronized (this) {
- mAttentionLightOn = on;
- mPulsing = false;
- setLight_native(mNativePointer, LIGHT_ID_ATTENTION, color,
- LIGHT_FLASH_HARDWARE, on ? 3 : 0, 0, 0);
- }
- }
-
- public void pulseBreathingLight() {
- synchronized (this) {
- // HACK: Added at the last minute of cupcake -- design this better;
- // Don't reuse the attention light -- make another one.
- if (false) {
- Log.d(TAG, "pulseBreathingLight mAttentionLightOn=" + mAttentionLightOn
- + " mPulsing=" + mPulsing);
- }
- if (!mAttentionLightOn && !mPulsing) {
- mPulsing = true;
- setLight_native(mNativePointer, LIGHT_ID_ATTENTION, 0x00ffffff,
- LIGHT_FLASH_HARDWARE, 7, 0, 0);
- mH.sendMessageDelayed(Message.obtain(mH, 1), 3000);
- }
- }
- }
-
- private Handler mH = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- synchronized (this) {
- if (false) {
- Log.d(TAG, "pulse cleanup handler firing mPulsing=" + mPulsing);
- }
- if (mPulsing) {
- mPulsing = false;
- setLight_native(mNativePointer, LIGHT_ID_ATTENTION,
- mAttentionLightOn ? 0xffffffff : 0,
- LIGHT_FLASH_NONE, 0, 0, 0);
- }
- }
- }
- };
-
private final Runnable mVibrationRunnable = new Runnable() {
public void run() {
synchronized (mVibrations) {
@@ -452,7 +327,7 @@ public class HardwareService extends IHardwareService.Stub {
// duration is saved for delay() at top of loop
duration = pattern[index++];
if (duration > 0) {
- HardwareService.this.vibratorOn(duration);
+ VibratorService.this.vibratorOn(duration);
}
} else {
if (repeat < 0) {
@@ -490,21 +365,13 @@ public class HardwareService extends IHardwareService.Stub {
}
};
- private static native int init_native();
- private static native void finalize_native(int ptr);
-
- private static native void setLight_native(int ptr, int light, int color, int mode,
- int onMS, int offMS, int brightnessMode);
+ private Handler mH = new Handler();
private final Context mContext;
private final PowerManager.WakeLock mWakeLock;
- private final IBatteryStats mBatteryStats;
-
volatile VibrateThread mThread;
- private int mNativePointer;
-
native static void vibratorOn(long milliseconds);
native static void vibratorOff();
}
diff --git a/services/jni/Android.mk b/services/jni/Android.mk
index 2f48edf..9d2760e 100644
--- a/services/jni/Android.mk
+++ b/services/jni/Android.mk
@@ -4,10 +4,11 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
com_android_server_AlarmManagerService.cpp \
com_android_server_BatteryService.cpp \
- com_android_server_HardwareService.cpp \
com_android_server_KeyInputQueue.cpp \
+ com_android_server_LightsService.cpp \
com_android_server_SensorService.cpp \
com_android_server_SystemServer.cpp \
+ com_android_server_VibratorService.cpp \
onload.cpp
LOCAL_C_INCLUDES += \
diff --git a/services/jni/com_android_server_HardwareService.cpp b/services/jni/com_android_server_LightsService.cpp
index 253e655..1df9c81 100644
--- a/services/jni/com_android_server_HardwareService.cpp
+++ b/services/jni/com_android_server_LightsService.cpp
@@ -1,21 +1,20 @@
-/* //device/libs/android_runtime/android_os_Vibrator.cpp
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#define LOG_TAG "HardwareService"
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "LightsService"
#include "jni.h"
#include "JNIHelp.h"
@@ -23,18 +22,16 @@
#include <utils/misc.h>
#include <utils/Log.h>
-#include <hardware_legacy/vibrator.h>
#include <hardware/hardware.h>
#include <hardware/lights.h>
#include <stdio.h>
-//#include <string.h>
namespace android
{
// These values must correspond with the LIGHT_ID constants in
-// HardwareService.java
+// LightsService.java
enum {
LIGHT_INDEX_BACKLIGHT = 0,
LIGHT_INDEX_KEYBOARD = 1,
@@ -120,29 +117,15 @@ static void setLight_native(JNIEnv *env, jobject clazz, int ptr,
devices->lights[light]->set_light(devices->lights[light], &state);
}
-static void vibratorOn(JNIEnv *env, jobject clazz, jlong timeout_ms)
-{
- // LOGI("vibratorOn\n");
- vibrator_on(timeout_ms);
-}
-
-static void vibratorOff(JNIEnv *env, jobject clazz)
-{
- // LOGI("vibratorOff\n");
- vibrator_off();
-}
-
static JNINativeMethod method_table[] = {
{ "init_native", "()I", (void*)init_native },
{ "finalize_native", "(I)V", (void*)finalize_native },
{ "setLight_native", "(IIIIIII)V", (void*)setLight_native },
- { "vibratorOn", "(J)V", (void*)vibratorOn },
- { "vibratorOff", "()V", (void*)vibratorOff }
};
-int register_android_server_HardwareService(JNIEnv *env)
+int register_android_server_LightsService(JNIEnv *env)
{
- return jniRegisterNativeMethods(env, "com/android/server/HardwareService",
+ return jniRegisterNativeMethods(env, "com/android/server/LightsService",
method_table, NELEM(method_table));
}
diff --git a/services/jni/com_android_server_VibratorService.cpp b/services/jni/com_android_server_VibratorService.cpp
new file mode 100644
index 0000000..6ec5c07
--- /dev/null
+++ b/services/jni/com_android_server_VibratorService.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "VibratorService"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include "android_runtime/AndroidRuntime.h"
+
+#include <utils/misc.h>
+#include <utils/Log.h>
+#include <hardware_legacy/vibrator.h>
+
+#include <stdio.h>
+
+namespace android
+{
+
+static void vibratorOn(JNIEnv *env, jobject clazz, jlong timeout_ms)
+{
+ // LOGI("vibratorOn\n");
+ vibrator_on(timeout_ms);
+}
+
+static void vibratorOff(JNIEnv *env, jobject clazz)
+{
+ // LOGI("vibratorOff\n");
+ vibrator_off();
+}
+
+static JNINativeMethod method_table[] = {
+ { "vibratorOn", "(J)V", (void*)vibratorOn },
+ { "vibratorOff", "()V", (void*)vibratorOff }
+};
+
+int register_android_server_VibratorService(JNIEnv *env)
+{
+ return jniRegisterNativeMethods(env, "com/android/server/VibratorService",
+ method_table, NELEM(method_table));
+}
+
+};
diff --git a/services/jni/onload.cpp b/services/jni/onload.cpp
index 26200d3..c16fdb8 100644
--- a/services/jni/onload.cpp
+++ b/services/jni/onload.cpp
@@ -7,8 +7,9 @@ namespace android {
int register_android_server_AlarmManagerService(JNIEnv* env);
int register_android_server_BatteryService(JNIEnv* env);
int register_android_server_KeyInputQueue(JNIEnv* env);
-int register_android_server_HardwareService(JNIEnv* env);
+int register_android_server_LightsService(JNIEnv* env);
int register_android_server_SensorService(JNIEnv* env);
+int register_android_server_VibratorService(JNIEnv* env);
int register_android_server_SystemServer(JNIEnv* env);
};
@@ -26,10 +27,11 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
LOG_ASSERT(env, "Could not retrieve the env!");
register_android_server_KeyInputQueue(env);
- register_android_server_HardwareService(env);
+ register_android_server_LightsService(env);
register_android_server_AlarmManagerService(env);
register_android_server_BatteryService(env);
register_android_server_SensorService(env);
+ register_android_server_VibratorService(env);
register_android_server_SystemServer(env);
return JNI_VERSION_1_4;
diff --git a/tests/permission/src/com/android/framework/permission/tests/HardwareServicePermissionTest.java b/tests/permission/src/com/android/framework/permission/tests/VibratorServicePermissionTest.java
index 2290c1d..274ac00 100644
--- a/tests/permission/src/com/android/framework/permission/tests/HardwareServicePermissionTest.java
+++ b/tests/permission/src/com/android/framework/permission/tests/VibratorServicePermissionTest.java
@@ -19,7 +19,7 @@ package com.android.framework.permission.tests;
import junit.framework.TestCase;
import android.os.Binder;
-import android.os.IHardwareService;
+import android.os.IVibratorService;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.test.suitebuilder.annotation.SmallTest;
@@ -28,25 +28,25 @@ import android.test.suitebuilder.annotation.SmallTest;
* Verify that Hardware apis cannot be called without required permissions.
*/
@SmallTest
-public class HardwareServicePermissionTest extends TestCase {
+public class VibratorServicePermissionTest extends TestCase {
- private IHardwareService mHardwareService;
+ private IVibratorService mVibratorService;
@Override
protected void setUp() throws Exception {
- mHardwareService = IHardwareService.Stub.asInterface(
- ServiceManager.getService("hardware"));
+ mVibratorService = IVibratorService.Stub.asInterface(
+ ServiceManager.getService("vibrator"));
}
/**
- * Test that calling {@link android.os.IHardwareService#vibrate(long)} requires permissions.
+ * Test that calling {@link android.os.IVibratorService#vibrate(long)} requires permissions.
* <p>Tests permission:
* {@link android.Manifest.permission#VIBRATE}
* @throws RemoteException
*/
public void testVibrate() throws RemoteException {
try {
- mHardwareService.vibrate(2000, new Binder());
+ mVibratorService.vibrate(2000, new Binder());
fail("vibrate did not throw SecurityException as expected");
} catch (SecurityException e) {
// expected
@@ -54,7 +54,7 @@ public class HardwareServicePermissionTest extends TestCase {
}
/**
- * Test that calling {@link android.os.IHardwareService#vibratePattern(long[],
+ * Test that calling {@link android.os.IVibratorService#vibratePattern(long[],
* int, android.os.IBinder)} requires permissions.
* <p>Tests permission:
* {@link android.Manifest.permission#VIBRATE}
@@ -62,7 +62,7 @@ public class HardwareServicePermissionTest extends TestCase {
*/
public void testVibratePattern() throws RemoteException {
try {
- mHardwareService.vibratePattern(new long[] {0}, 0, new Binder());
+ mVibratorService.vibratePattern(new long[] {0}, 0, new Binder());
fail("vibratePattern did not throw SecurityException as expected");
} catch (SecurityException e) {
// expected
@@ -70,51 +70,17 @@ public class HardwareServicePermissionTest extends TestCase {
}
/**
- * Test that calling {@link android.os.IHardwareService#cancelVibrate()} requires permissions.
+ * Test that calling {@link android.os.IVibratorService#cancelVibrate()} requires permissions.
* <p>Tests permission:
* {@link android.Manifest.permission#VIBRATE}
* @throws RemoteException
*/
public void testCancelVibrate() throws RemoteException {
try {
- mHardwareService.cancelVibrate(new Binder());
+ mVibratorService.cancelVibrate(new Binder());
fail("cancelVibrate did not throw SecurityException as expected");
} catch (SecurityException e) {
// expected
}
}
-
- /**
- * Test that calling {@link android.os.IHardwareService#setFlashlightEnabled(boolean)}
- * requires permissions.
- * <p>Tests permissions:
- * {@link android.Manifest.permission#HARDWARE_TEST}
- * {@link android.Manifest.permission#FLASHLIGHT}
- * @throws RemoteException
- */
- public void testSetFlashlightEnabled() throws RemoteException {
- try {
- mHardwareService.setFlashlightEnabled(true);
- fail("setFlashlightEnabled did not throw SecurityException as expected");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * Test that calling {@link android.os.IHardwareService#enableCameraFlash(int)} requires
- * permissions.
- * <p>Tests permission:
- * {@link android.Manifest.permission#HARDWARE_TEST}
- * {@link android.Manifest.permission#CAMERA}
- * @throws RemoteException
- */
- public void testEnableCameraFlash() throws RemoteException {
- try {
- mHardwareService.enableCameraFlash(100);
- fail("enableCameraFlash did not throw SecurityException as expected");
- } catch (SecurityException e) {
- // expected
- }
- }
}