summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-05-17 14:56:53 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-05-17 14:56:53 -0700
commit3e9e9696f147c8df1236c1d7aa9496124864a81c (patch)
tree8865c55bdf193d4cd85eb46dca965de5cdfb001a /services
parent8ea405d196c8b536047d961801bb2b6c18a3ea2a (diff)
parenteb9cbb8fdddf4c887004b20b504083035d57a15f (diff)
downloadframeworks_base-3e9e9696f147c8df1236c1d7aa9496124864a81c.zip
frameworks_base-3e9e9696f147c8df1236c1d7aa9496124864a81c.tar.gz
frameworks_base-3e9e9696f147c8df1236c1d7aa9496124864a81c.tar.bz2
am eb9cbb8f: Resurrect flashlight support in obsolete IHardwareService Binder API.
Merge commit 'eb9cbb8fdddf4c887004b20b504083035d57a15f' into froyo-plus-aosp * commit 'eb9cbb8fdddf4c887004b20b504083035d57a15f': Resurrect flashlight support in obsolete IHardwareService Binder API.
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/LightsService.java49
1 files changed, 49 insertions, 0 deletions
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);
}