Skip to content

Commit 4b662bd

Browse files
maniac103Gerrit Code Review
authored andcommitted
Merge "Dispatch keys to a device specific key handler" into cm-10.1
2 parents d4dcdc2 + 862f89d commit 4b662bd

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2012 The CyanogenMod Project Licensed under the Apache License,
3+
* Version 2.0 (the "License"); you may not use this file except in compliance
4+
* with the License. You may obtain a copy of the License at
5+
* http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6+
* or agreed to in writing, software distributed under the License is
7+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8+
* KIND, either express or implied. See the License for the specific language
9+
* governing permissions and limitations under the License.
10+
*/
11+
12+
package com.android.internal.os;
13+
14+
import android.view.KeyEvent;
15+
16+
public interface DeviceKeyHandler {
17+
public static final int KEYEVENT_CAUGHT = -1;
18+
public static final int KEYEVENT_UNCAUGHT = 0;
19+
20+
public int handleKeyEvent(KeyEvent event);
21+
}

core/res/res/values/config.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,12 @@
11001100
legacy USB manager should be started. -->
11011101
<string name="config_legacyUmsLunFile">/sys/devices/platform/usb_mass_storage/lun0/file</string>
11021102

1103+
<!-- Path to the library that contains a device specific key handler -->
1104+
<string name="config_deviceKeyHandlerLib" translatable="false"></string>
1105+
1106+
<!-- Name of that key handler class -->
1107+
<string name="config_deviceKeyHandlerClass" translatable="false"></string>
1108+
11031109
<!-- If a dock provides a lid switch, that lid can be removed. This
11041110
setting is used to determine, whether lidOpenRotation has to be
11051111
applied. -->

core/res/res/values/symbols.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,8 @@
18401840
<java-symbol type="bool" name="config_hasRemovableLid" />
18411841
<java-symbol type="bool" name="config_hasDockBattery" />
18421842
<java-symbol type="bool" name="config_noDelayInATwoDP" />
1843+
<java-symbol type="string" name="config_deviceKeyHandlerLib" />
1844+
<java-symbol type="string" name="config_deviceKeyHandlerClass" />
18431845

18441846
<!-- Telephony -->
18451847
<java-symbol type="bool" name="config_smsSamsungCdmaAlternateMessageIDEncoding" />

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.content.ComponentName;
2929
import android.content.ContentResolver;
3030
import android.content.Context;
31+
import android.content.ContextWrapper;
3132
import android.content.Intent;
3233
import android.content.IntentFilter;
3334
import android.content.ServiceConnection;
@@ -67,13 +68,16 @@
6768

6869
import com.android.internal.R;
6970
import com.android.internal.app.ThemeUtils;
71+
import com.android.internal.os.DeviceKeyHandler;
7072
import com.android.internal.policy.PolicyManager;
7173
import com.android.internal.policy.impl.keyguard.KeyguardViewManager;
7274
import com.android.internal.policy.impl.keyguard.KeyguardViewMediator;
7375
import com.android.internal.statusbar.IStatusBarService;
7476
import com.android.internal.telephony.ITelephony;
7577
import com.android.internal.widget.PointerLocationView;
7678

79+
import dalvik.system.DexClassLoader;
80+
7781
import android.util.DisplayMetrics;
7882
import android.util.EventLog;
7983
import android.util.Log;
@@ -166,6 +170,7 @@
166170
import java.io.IOException;
167171
import java.io.PrintWriter;
168172
import java.util.List;
173+
import java.lang.reflect.Constructor;
169174

170175
/**
171176
* WindowManagerPolicy implementation for the Android phone UI. This
@@ -254,6 +259,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
254259
KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
255260
}
256261

262+
DeviceKeyHandler mDeviceKeyHandler;
263+
257264
/**
258265
* Lock protecting internal state. Must not call out into window
259266
* manager with lock held. (This lock will be acquired in places
@@ -1198,6 +1205,30 @@ public void init(Context context, IWindowManager windowManager,
11981205
} else {
11991206
screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
12001207
}
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+
}
12011232
}
12021233

12031234
public void setInitialDisplaySize(Display display, int width, int height, int density) {
@@ -2496,6 +2527,14 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
24962527
return -1;
24972528
}
24982529

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+
24992538
// Let the application handle the key.
25002539
return 0;
25012540
}

0 commit comments

Comments
 (0)