summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-05-17 14:59:39 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-05-17 14:59:39 -0700
commitc5859388bd6c666a83017869bf8a9935defe0bd0 (patch)
tree58a4f14842bdabbbaa945a98152cc7e004f5aa5c
parent23100fd1ec5411876b13f3cac9a457dc863f932c (diff)
parent3e9e9696f147c8df1236c1d7aa9496124864a81c (diff)
downloadframeworks_base-c5859388bd6c666a83017869bf8a9935defe0bd0.zip
frameworks_base-c5859388bd6c666a83017869bf8a9935defe0bd0.tar.gz
frameworks_base-c5859388bd6c666a83017869bf8a9935defe0bd0.tar.bz2
am 3e9e9696: am eb9cbb8f: Resurrect flashlight support in obsolete IHardwareService Binder API.
Merge commit '3e9e9696f147c8df1236c1d7aa9496124864a81c' into kraken * commit '3e9e9696f147c8df1236c1d7aa9496124864a81c': Resurrect flashlight support in obsolete IHardwareService Binder API.
-rw-r--r--Android.mk3
-rwxr-xr-xcore/java/android/os/IHardwareService.aidl26
-rw-r--r--services/java/com/android/server/LightsService.java49
3 files changed, 77 insertions, 1 deletions
diff --git a/Android.mk b/Android.mk
index 8359d3b..2ff2a42 100644
--- a/Android.mk
+++ b/Android.mk
@@ -117,7 +117,8 @@ LOCAL_SRC_FILES += \
core/java/android/hardware/ISensorService.aidl \
core/java/android/net/IConnectivityManager.aidl \
core/java/android/net/INetworkManagementEventObserver.aidl \
- core/java/android/net/IThrottleManager.aidl \
+ core/java/android/net/IThrottleManager.aidl \
+ core/java/android/os/IHardwareService.aidl \
core/java/android/os/IMessenger.aidl \
core/java/android/os/storage/IMountService.aidl \
core/java/android/os/storage/IMountServiceListener.aidl \
diff --git a/core/java/android/os/IHardwareService.aidl b/core/java/android/os/IHardwareService.aidl
new file mode 100755
index 0000000..38abfc0
--- /dev/null
+++ b/core/java/android/os/IHardwareService.aidl
@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2007, 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} */
+interface IHardwareService
+{
+ // obsolete flashlight support
+ boolean getFlashlightEnabled();
+ void setFlashlightEnabled(boolean on);
+}
+
diff --git a/services/java/com/android/server/LightsService.java b/services/java/com/android/server/LightsService.java
index c056eef..9b57735 100644
--- a/services/java/com/android/server/LightsService.java
+++ b/services/java/com/android/server/LightsService.java
@@ -17,10 +17,17 @@
package com.android.server;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.Handler;
+import android.os.IHardwareService;
+import android.os.ServiceManager;
import android.os.Message;
import android.util.Slog;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
public class LightsService {
private static final String TAG = "LightsService";
@@ -124,11 +131,53 @@ public class LightsService {
private boolean mFlashing;
}
+ /* This class implements an obsolete API that was removed after eclair and re-added during the
+ * final moments of the froyo release to support flashlight apps that had been using the private
+ * IHardwareService API. This is expected to go away in the next release.
+ */
+ private final IHardwareService.Stub mLegacyFlashlightHack = new IHardwareService.Stub() {
+
+ private static final String FLASHLIGHT_FILE = "/sys/class/leds/spotlight/brightness";
+
+ public boolean getFlashlightEnabled() {
+ try {
+ FileInputStream fis = new FileInputStream(FLASHLIGHT_FILE);
+ int result = fis.read();
+ fis.close();
+ return (result != '0');
+ } catch (Exception e) {
+ Slog.e(TAG, "getFlashlightEnabled failed", e);
+ return false;
+ }
+ }
+
+ 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");
+ }
+ try {
+ FileOutputStream fos = new FileOutputStream(FLASHLIGHT_FILE);
+ byte[] bytes = new byte[2];
+ bytes[0] = (byte)(on ? '1' : '0');
+ bytes[1] = '\n';
+ fos.write(bytes);
+ fos.close();
+ } catch (Exception e) {
+ Slog.e(TAG, "setFlashlightEnabled failed", e);
+ }
+ }
+ };
+
LightsService(Context context) {
mNativePointer = init_native();
mContext = context;
+ ServiceManager.addService("hardware", mLegacyFlashlightHack);
+
for (int i = 0; i < LIGHT_ID_COUNT; i++) {
mLights[i] = new Light(i);
}