am 30348b0d: Merge change I086d681f into eclair-mr2
Merge commit '30348b0de11b6c6cba43dfc7960e4d2084af6d8b' into eclair-mr2-plus-aosp * commit '30348b0de11b6c6cba43dfc7960e4d2084af6d8b': Remove HardwareService and move vibrator support to VibratorService.
This commit is contained in:
133
services/java/com/android/server/LightsService.java
Normal file
133
services/java/com/android/server/LightsService.java
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user