Merge change I76127f6f into eclair

* changes:
  Add support for colored LED on jogball backlight.
This commit is contained in:
Android (Google) Code Review
2009-11-04 19:39:29 -05:00
2 changed files with 33 additions and 26 deletions

View File

@@ -1,16 +1,16 @@
/** /**
* Copyright (c) 2007, The Android Open Source Project * Copyright (c) 2007, The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@@ -23,13 +23,13 @@ interface IHardwareService
void vibrate(long milliseconds, IBinder token); void vibrate(long milliseconds, IBinder token);
void vibratePattern(in long[] pattern, int repeat, IBinder token); void vibratePattern(in long[] pattern, int repeat, IBinder token);
void cancelVibrate(IBinder token); void cancelVibrate(IBinder token);
// flashlight support // flashlight support
boolean getFlashlightEnabled(); boolean getFlashlightEnabled();
void setFlashlightEnabled(boolean on); void setFlashlightEnabled(boolean on);
void enableCameraFlash(int milliseconds); void enableCameraFlash(int milliseconds);
// for the phone // for the phone
void setAttentionLight(boolean on); void setAttentionLight(boolean on, int color);
} }

View File

@@ -52,6 +52,7 @@ public class HardwareService extends IHardwareService.Stub {
static final int LIGHT_FLASH_NONE = 0; static final int LIGHT_FLASH_NONE = 0;
static final int LIGHT_FLASH_TIMED = 1; static final int LIGHT_FLASH_TIMED = 1;
static final int LIGHT_FLASH_HARDWARE = 2;
private final LinkedList<Vibration> mVibrations; private final LinkedList<Vibration> mVibrations;
private Vibration mCurrentVibration; private Vibration mCurrentVibration;
@@ -125,7 +126,7 @@ public class HardwareService extends IHardwareService.Stub {
mVibrations = new LinkedList<Vibration>(); mVibrations = new LinkedList<Vibration>();
mBatteryStats = BatteryStatsService.getService(); mBatteryStats = BatteryStatsService.getService();
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(mIntentReceiver, filter); context.registerReceiver(mIntentReceiver, filter);
@@ -239,15 +240,15 @@ public class HardwareService extends IHardwareService.Stub {
Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity);
} }
} }
public boolean getFlashlightEnabled() { public boolean getFlashlightEnabled() {
return Hardware.getFlashlightEnabled(); return Hardware.getFlashlightEnabled();
} }
public void setFlashlightEnabled(boolean on) { public void setFlashlightEnabled(boolean on) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.FLASHLIGHT) if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.FLASHLIGHT)
!= PackageManager.PERMISSION_GRANTED && != PackageManager.PERMISSION_GRANTED &&
mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires FLASHLIGHT or HARDWARE_TEST permission"); throw new SecurityException("Requires FLASHLIGHT or HARDWARE_TEST permission");
} }
@@ -255,9 +256,9 @@ public class HardwareService extends IHardwareService.Stub {
} }
public void enableCameraFlash(int milliseconds) { public void enableCameraFlash(int milliseconds) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.CAMERA) if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED && != PackageManager.PERMISSION_GRANTED &&
mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires CAMERA or HARDWARE_TEST permission"); throw new SecurityException("Requires CAMERA or HARDWARE_TEST permission");
} }
@@ -282,13 +283,19 @@ public class HardwareService extends IHardwareService.Stub {
setLight_native(mNativePointer, light, color, mode, onMS, offMS); setLight_native(mNativePointer, light, color, mode, onMS, offMS);
} }
public void setAttentionLight(boolean on) { void setAutoBrightness_UNCHECKED(boolean on) {
if (mAutoBrightnessAvailable) {
setAutoBrightness_native(mNativePointer, on);
}
}
public void setAttentionLight(boolean on, int color) {
// Not worthy of a permission. We shouldn't have a flashlight permission. // Not worthy of a permission. We shouldn't have a flashlight permission.
synchronized (this) { synchronized (this) {
mAttentionLightOn = on; mAttentionLightOn = on;
mPulsing = false; mPulsing = false;
setLight_native(mNativePointer, LIGHT_ID_ATTENTION, on ? 0xffffffff : 0, setLight_native(mNativePointer, LIGHT_ID_ATTENTION, color,
LIGHT_FLASH_NONE, 0, 0); LIGHT_FLASH_HARDWARE, on ? 3 : 0, 0);
} }
} }
@@ -302,8 +309,8 @@ public class HardwareService extends IHardwareService.Stub {
} }
if (!mAttentionLightOn && !mPulsing) { if (!mAttentionLightOn && !mPulsing) {
mPulsing = true; mPulsing = true;
setLight_native(mNativePointer, LIGHT_ID_ATTENTION, 0xff101010, setLight_native(mNativePointer, LIGHT_ID_ATTENTION, 0x00ffffff,
LIGHT_FLASH_NONE, 0, 0); LIGHT_FLASH_HARDWARE, 7, 0);
mH.sendMessageDelayed(Message.obtain(mH, 1), 3000); mH.sendMessageDelayed(Message.obtain(mH, 1), 3000);
} }
} }
@@ -391,7 +398,7 @@ public class HardwareService extends IHardwareService.Stub {
private class VibrateThread extends Thread { private class VibrateThread extends Thread {
final Vibration mVibration; final Vibration mVibration;
boolean mDone; boolean mDone;
VibrateThread(Vibration vib) { VibrateThread(Vibration vib) {
mVibration = vib; mVibration = vib;
mWakeLock.acquire(); mWakeLock.acquire();
@@ -425,7 +432,7 @@ public class HardwareService extends IHardwareService.Stub {
long duration = 0; long duration = 0;
while (!mDone) { while (!mDone) {
// add off-time duration to any accumulated on-time duration // add off-time duration to any accumulated on-time duration
if (index < len) { if (index < len) {
duration += pattern[index++]; duration += pattern[index++];
} }
@@ -478,7 +485,7 @@ public class HardwareService extends IHardwareService.Stub {
} }
} }
}; };
private static native int init_native(); private static native int init_native();
private static native void finalize_native(int ptr); private static native void finalize_native(int ptr);
@@ -489,7 +496,7 @@ public class HardwareService extends IHardwareService.Stub {
private final PowerManager.WakeLock mWakeLock; private final PowerManager.WakeLock mWakeLock;
private final IBatteryStats mBatteryStats; private final IBatteryStats mBatteryStats;
volatile VibrateThread mThread; volatile VibrateThread mThread;
private int mNativePointer; private int mNativePointer;