|
28 | 28 | import android.content.ComponentName; |
29 | 29 | import android.content.ContentResolver; |
30 | 30 | import android.content.Context; |
| 31 | +import android.content.ContextWrapper; |
31 | 32 | import android.content.Intent; |
32 | 33 | import android.content.IntentFilter; |
33 | 34 | import android.content.ServiceConnection; |
|
67 | 68 |
|
68 | 69 | import com.android.internal.R; |
69 | 70 | import com.android.internal.app.ThemeUtils; |
| 71 | +import com.android.internal.os.DeviceKeyHandler; |
70 | 72 | import com.android.internal.policy.PolicyManager; |
71 | 73 | import com.android.internal.policy.impl.keyguard.KeyguardViewManager; |
72 | 74 | import com.android.internal.policy.impl.keyguard.KeyguardViewMediator; |
73 | 75 | import com.android.internal.statusbar.IStatusBarService; |
74 | 76 | import com.android.internal.telephony.ITelephony; |
75 | 77 | import com.android.internal.widget.PointerLocationView; |
76 | 78 |
|
| 79 | +import dalvik.system.DexClassLoader; |
| 80 | + |
77 | 81 | import android.util.DisplayMetrics; |
78 | 82 | import android.util.EventLog; |
79 | 83 | import android.util.Log; |
|
166 | 170 | import java.io.IOException; |
167 | 171 | import java.io.PrintWriter; |
168 | 172 | import java.util.List; |
| 173 | +import java.lang.reflect.Constructor; |
169 | 174 |
|
170 | 175 | /** |
171 | 176 | * WindowManagerPolicy implementation for the Android phone UI. This |
@@ -254,6 +259,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { |
254 | 259 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
255 | 260 | } |
256 | 261 |
|
| 262 | + DeviceKeyHandler mDeviceKeyHandler; |
| 263 | + |
257 | 264 | /** |
258 | 265 | * Lock protecting internal state. Must not call out into window |
259 | 266 | * manager with lock held. (This lock will be acquired in places |
@@ -1198,6 +1205,30 @@ public void init(Context context, IWindowManager windowManager, |
1198 | 1205 | } else { |
1199 | 1206 | screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
1200 | 1207 | } |
| 1208 | + |
| 1209 | + String deviceKeyHandlerLib = mContext.getResources().getString( |
| 1210 | + com.android.internal.R.string.config_deviceKeyHandlerLib); |
| 1211 | + |
| 1212 | + String deviceKeyHandlerClass = mContext.getResources().getString( |
| 1213 | + com.android.internal.R.string.config_deviceKeyHandlerClass); |
| 1214 | + |
| 1215 | + if (!deviceKeyHandlerLib.isEmpty() && !deviceKeyHandlerClass.isEmpty()) { |
| 1216 | + DexClassLoader loader = new DexClassLoader(deviceKeyHandlerLib, |
| 1217 | + new ContextWrapper(mContext).getCacheDir().getAbsolutePath(), |
| 1218 | + null, |
| 1219 | + ClassLoader.getSystemClassLoader()); |
| 1220 | + try { |
| 1221 | + Class<?> klass = loader.loadClass(deviceKeyHandlerClass); |
| 1222 | + Constructor<?> constructor = klass.getConstructor(Context.class); |
| 1223 | + mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance( |
| 1224 | + mContext); |
| 1225 | + Slog.d(TAG, "Device key handler loaded"); |
| 1226 | + } catch (Exception e) { |
| 1227 | + Slog.d(TAG, "Could not instantiate device key handler " |
| 1228 | + + deviceKeyHandlerClass + " from class " |
| 1229 | + + deviceKeyHandlerLib, e); |
| 1230 | + } |
| 1231 | + } |
1201 | 1232 | } |
1202 | 1233 |
|
1203 | 1234 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
@@ -2496,6 +2527,14 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p |
2496 | 2527 | return -1; |
2497 | 2528 | } |
2498 | 2529 |
|
| 2530 | + if (mDeviceKeyHandler != null) { |
| 2531 | + try { |
| 2532 | + return mDeviceKeyHandler.handleKeyEvent(event); |
| 2533 | + } catch (Exception e) { |
| 2534 | + Slog.d(TAG, "Could not dispatch event to device key handler", e); |
| 2535 | + } |
| 2536 | + } |
| 2537 | + |
2499 | 2538 | // Let the application handle the key. |
2500 | 2539 | return 0; |
2501 | 2540 | } |
|
0 commit comments