diff options
-rw-r--r-- | core/java/com/android/internal/os/DeviceKeyHandler.java | 26 | ||||
-rwxr-xr-x | core/res/res/values/config.xml | 6 | ||||
-rwxr-xr-x | core/res/res/values/symbols.xml | 4 | ||||
-rw-r--r-- | services/core/java/com/android/server/policy/PhoneWindowManager.java | 57 |
4 files changed, 93 insertions, 0 deletions
diff --git a/core/java/com/android/internal/os/DeviceKeyHandler.java b/core/java/com/android/internal/os/DeviceKeyHandler.java new file mode 100644 index 0000000..e7d103d --- /dev/null +++ b/core/java/com/android/internal/os/DeviceKeyHandler.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2012 The CyanogenMod 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.internal.os; + +import android.view.KeyEvent; + +public interface DeviceKeyHandler { + + /** + * Invoked when an unknown key was detected by the system, letting the device handle + * this special keys prior to pass the key to the active app. + * + * @param event The key event to be handled + * @return If the event is consume + */ + public boolean handleKeyEvent(KeyEvent event); +} diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index e3e38c7..bc95f43 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2091,6 +2091,12 @@ <bool name="config_networkSamplingWakesDevice">true</bool> + <!-- Path to the library that contains a device specific key handler --> + <string name="config_deviceKeyHandlerLib" translatable="false"></string> + + <!-- Name of that key handler class --> + <string name="config_deviceKeyHandlerClass" translatable="false"></string> + <string-array translatable="false" name="config_cdma_home_system" /> <!--From SmsMessage--> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 138768e..0fe919d 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2037,6 +2037,10 @@ <java-symbol type="layout" name="year_label_text_view" /> <java-symbol type="layout" name="date_picker_material" /> + <!-- Config.xml entries --> + <java-symbol type="string" name="config_deviceKeyHandlerLib" /> + <java-symbol type="string" name="config_deviceKeyHandlerClass" /> + <java-symbol type="id" name="time_header" /> <java-symbol type="id" name="hours" /> <java-symbol type="id" name="minutes" /> diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index cb8b41b..00e8c6f 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -31,6 +31,7 @@ import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; @@ -115,6 +116,8 @@ import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import com.android.internal.R; +import com.android.internal.os.DeviceKeyHandler; +import com.android.internal.policy.IKeyguardService; import com.android.internal.statusbar.IStatusBarService; import com.android.internal.util.ScreenShapeHelper; import com.android.internal.widget.PointerLocationView; @@ -122,6 +125,8 @@ import com.android.server.LocalServices; import com.android.server.policy.keyguard.KeyguardServiceDelegate; import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; +import dalvik.system.DexClassLoader; + import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -129,6 +134,7 @@ import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.lang.reflect.Constructor; import static android.view.WindowManager.LayoutParams.*; import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; @@ -289,6 +295,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; + private DeviceKeyHandler mDeviceKeyHandler; + /** * Lock protecting internal state. Must not call out into window * manager with lock held. (This lock will be acquired in places @@ -1650,6 +1658,31 @@ public class PhoneWindowManager implements WindowManagerPolicy { mWindowManagerInternal.registerAppTransitionListener( mStatusBarController.getAppTransitionListener()); + + String deviceKeyHandlerLib = mContext.getResources().getString( + com.android.internal.R.string.config_deviceKeyHandlerLib); + + String deviceKeyHandlerClass = mContext.getResources().getString( + com.android.internal.R.string.config_deviceKeyHandlerClass); + + if (!deviceKeyHandlerLib.isEmpty() && !deviceKeyHandlerClass.isEmpty()) { + DexClassLoader loader = new DexClassLoader(deviceKeyHandlerLib, + new ContextWrapper(mContext).getCacheDir().getAbsolutePath(), + null, + ClassLoader.getSystemClassLoader()); + try { + Class<?> klass = loader.loadClass(deviceKeyHandlerClass); + Constructor<?> constructor = klass.getConstructor(Context.class); + mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance( + mContext); + if(DEBUG) Slog.d(TAG, "Device key handler loaded"); + } catch (Exception e) { + Slog.w(TAG, "Could not instantiate device key handler " + + deviceKeyHandlerClass + " from class " + + deviceKeyHandlerLib, e); + } + } + } private void updateKeyAssignments() { @@ -3243,6 +3276,18 @@ public class PhoneWindowManager implements WindowManagerPolicy { return -1; } + // Specific device key handling + if (mDeviceKeyHandler != null) { + try { + // The device only should consume known keys. + if (mDeviceKeyHandler.handleKeyEvent(event)) { + return -1; + } + } catch (Exception e) { + Slog.w(TAG, "Could not dispatch event to device key handler", e); + } + } + // Reserve all the META modifier combos for system behavior if ((metaState & KeyEvent.META_META_ON) != 0) { return -1; @@ -3274,6 +3319,18 @@ public class PhoneWindowManager implements WindowManagerPolicy { final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0; + // Specific device key handling + if (mDeviceKeyHandler != null) { + try { + // The device only should consume known keys. + if (mDeviceKeyHandler.handleKeyEvent(event)) { + return null; + } + } catch (Exception e) { + Slog.w(TAG, "Could not dispatch event to device key handler", e); + } + } + // Check for fallback actions specified by the key character map. final FallbackAction fallbackAction; if (initialDown) { |