Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dbb1f9b5 authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

DeviceKeyHandle: The device should consume only known keys



When the device receive the key, only should consume it if the device
know about the key. Otherwise, the key must be handle by the active app.
Also make mDeviceKeyHandler private (is not useful outside this class)

Change-Id: I4b9ea57b802e8c8c88c8b93a63d510f5952b0700
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent 4b662bd4
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -14,8 +14,13 @@ package com.android.internal.os;
import android.view.KeyEvent;

public interface DeviceKeyHandler {
    public static final int KEYEVENT_CAUGHT = -1;
    public static final int KEYEVENT_UNCAUGHT = 0;

    public int handleKeyEvent(KeyEvent event);
    /**
     * 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);
}
+9 −5
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
    }

    DeviceKeyHandler mDeviceKeyHandler;
    private DeviceKeyHandler mDeviceKeyHandler;

    /**
     * Lock protecting internal state.  Must not call out into window
@@ -1222,9 +1222,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                Constructor<?> constructor = klass.getConstructor(Context.class);
                mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance(
                        mContext);
                Slog.d(TAG, "Device key handler loaded");
                if(DEBUG) Slog.d(TAG, "Device key handler loaded");
            } catch (Exception e) {
                Slog.d(TAG, "Could not instantiate device key handler "
                Slog.w(TAG, "Could not instantiate device key handler "
                        + deviceKeyHandlerClass + " from class "
                        + deviceKeyHandlerLib, e);
            }
@@ -2527,11 +2527,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            return -1;
        }

        // Specific device key handling
        if (mDeviceKeyHandler != null) {
            try {
                return mDeviceKeyHandler.handleKeyEvent(event);
                // The device only should consume known keys.
                if (mDeviceKeyHandler.handleKeyEvent(event)) {
                    return -1;
                }
            } catch (Exception e) {
                Slog.d(TAG, "Could not dispatch event to device key handler", e);
                Slog.w(TAG, "Could not dispatch event to device key handler", e);
            }
        }