Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class SecureKeyboard

  1. Object
  2. Component
  3. SecureKeyboard

ImplementsAnimation, Editable, StyleListener

An on-screen keyboard drawn by the application itself, for fields a keylogging keyboard must never see.

On Android the system keyboard is an app the user chose, and it receives every keystroke typed into every other app. A malicious one is a keylogger nothing in the app can switch off: password and TextArea.SENSITIVE fields already ask the keyboard not to learn what is typed, but only a well-behaved keyboard honours the request. A field with a SecureKeyboard installed is never handed to the system keyboard at all. It is made uneditable, so the platform editor cannot open on it, and a tap shows this keyboard instead, which writes into the field directly.

TextField pin = new TextField("", "PIN", 6, TextArea.NUMERIC | TextArea.PASSWORD);
SecureKeyboard kb = SecureKeyboard.install(pin);
kb.setScrambled(true);

A common pattern is to install it only when DeviceIntegrity.isThirdPartyKeyboardActive(String...) reports a user-installed keyboard, so most users keep the keyboard they know.

What it does against the threats a penetration test checks for:

The layout follows the field’s constraint: a number pad for TextArea.NUMERIC, TextArea.DECIMAL and TextArea.PHONENUMBER, letters with @ or / for TextArea.EMAILADDR and TextArea.URL, and letters otherwise. It draws its own keys in the style of the platform keyboards, light or dark following the theme’s dark mode, under a strip with a lock icon that tells the user this is not their usual keyboard.

It types ASCII only: no accented letters, no other scripts, no dictation, no autofill. That is the price of keeping input away from the platform, and why it suits credentials and codes rather than free text.

Nested types

enum SecureKeyboard.LayoutThe key set, chosen from the field’s constraint by layoutFor(int).

Methods

public static SecureKeyboard install(TextArea field)Routes a field’s input through a secure keyboard instead of the system keyboard.
public static void uninstall(TextArea field)Removes a keyboard added by install(TextArea) and restores the field’s editability.
public static SecureKeyboard getInstalled(TextArea field)The keyboard installed on a field, or null.
public static SecureKeyboard.Layout layoutFor(int constraint)Picks the layout a field with this TextArea constraint gets.
public TextArea getField()The field this keyboard types into.
public SecureKeyboard.Layout getLayout()The current layout.
public void setLayout(SecureKeyboard.Layout layout)Overrides the layout chosen from the field’s constraint.
public boolean isScrambled()Whether the digit keys are shuffled each time the keyboard opens.
public void setScrambled(boolean scrambled)Shuffles the digit keys every time the keyboard opens, with SecureRandom, so touch coordinates recorded by malware do not reveal which digits were typed.
public void setDigitOrder(String order)Puts the digit keys in a fixed order, for documentation screenshots and tests that need the same picture every time.
public boolean isShowing()Whether the keyboard is on screen.
public void show()Shows the keyboard at the bottom of the field’s form.
public void hide()Hides the keyboard and reports the edit as complete, as the platform editor does when it closes: the field’s action listeners fire.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
public void paint(Graphics g)This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyPressed, keyReleased, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Method details

install

public static SecureKeyboard install(TextArea field)

Routes a field’s input through a secure keyboard instead of the system keyboard.

The field is made uneditable, which is what keeps the platform editor from ever opening on it, and a tap on it shows the returned keyboard. Installing twice returns the keyboard already installed.

Parameters

field TextArea
the field to protect

Returns

the keyboard now serving the field

uninstall

public static void uninstall(TextArea field)
Removes a keyboard added by install(TextArea) and restores the field’s editability.

Parameters

field TextArea
the protected field

getInstalled

public static SecureKeyboard getInstalled(TextArea field)
The keyboard installed on a field, or null.

Parameters

field TextArea
the field to look up

Returns

its keyboard, or null when none is installed

layoutFor

public static SecureKeyboard.Layout layoutFor(int constraint)
Picks the layout a field with this TextArea constraint gets.

Parameters

constraint int
a TextArea constraint, flags included

Returns

the matching layout

getField

public TextArea getField()
The field this keyboard types into.

Returns

the protected field

getLayout

public SecureKeyboard.Layout getLayout()
The current layout.

Returns

the layout in use

setLayout

public void setLayout(SecureKeyboard.Layout layout)
Overrides the layout chosen from the field’s constraint.

Parameters

layout SecureKeyboard.Layout
the layout to use; null restores the one the constraint picks

isScrambled

public boolean isScrambled()
Whether the digit keys are shuffled each time the keyboard opens.

Returns

true when the digits are scrambled

setScrambled

public void setScrambled(boolean scrambled)
Shuffles the digit keys every time the keyboard opens, with SecureRandom, so touch coordinates recorded by malware do not reveal which digits were typed. Off by default: it slows typing down, so keep it for PINs and one-time codes.

Parameters

scrambled boolean
true to shuffle the digits

setDigitOrder

public void setDigitOrder(String order)
Puts the digit keys in a fixed order, for documentation screenshots and tests that need the same picture every time. A fixed order is exactly what scrambling exists to avoid, so do not use this in place of setScrambled(boolean); it also turns scrambling off, since the next show() would otherwise replace the order.

Parameters

order String
the ten digits, each exactly once, in the order the keys show them

isShowing

public boolean isShowing()
Whether the keyboard is on screen.

Returns

true while it is showing

show

public void show()
Shows the keyboard at the bottom of the field’s form. Called by a tap on the field; call it yourself to open the keyboard when a screen appears.

hide

public void hide()
Hides the keyboard and reports the edit as complete, as the platform editor does when it closes: the field’s action listeners fire.

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

pointerPressed

public void pointerPressed(int x, int y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerDragged

public void pointerDragged(int x, int y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

animate

public boolean animate()
Allows the animation to reduce “repaint” calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

paint

public void paint(Graphics g)
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Parameters

g Graphics
the component graphics