How to check if a built-in / hardware keyboard is used?

I want to check if the native / hardware keyboard is used, and also, if possible, I want to disable third-party keyboards.

My goal is simple. I only use the Android built-in soft keyboard to enter values ​​into my edit fields, and no other keyboard should be able to

thanks

EDIT

I know that it’s not good to do what I'm trying to do, I know that the main idea of ​​an android is to have intentions and actions and services that know how to process certain types of intentions in accordance with the intent filter. But this is an exception in every rule, especially when we talk about security.

I want to disable all third-party keyboards, and if this cannot be done using some kind of API or something like that ... are there any ways to solve this problem?

EDIT

String s=Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); 

This returns the current input method (keyboard), but I need something like a "system keyboard", and I do not see such a flag: - (.

 List<InputMethodInfo> list = m.getInputMethodList(); 

One possible solution is to take list [0] as the keyboard I’m looking for, but I don’t want to relay by order (except when the order is guaranteed that the keyboard with index 0 is the one that comes to install from the phone)

this is the value of the list

 [InputMethodInfo{com.htc.android.htcime/.HTCIMEService, settings: com.htc.android.htcime.HTCIMESettings}, InputMethodInfo{com.volosyukivan/.WiFiInputMethod, settings: null}] 
+4
source share
3 answers

I want to check if the built-in / hardware keyboard is used

You can use the Configuration object to see if the device’s hardware keyboard is hidden. This usually implies that they use this keyboard, as most devices do not show IME when there is a hardware keyboard. However, some devices can support both at the same time, and I do not know how external keyboards (USB, Bluetooth) interact with this value.

Also, if possible, I want to disable third-party keyboards.

Fortunately, this is not possible.

Is there any workaround for this problem?

There is no question in this question related to this question.

Yes, they will not be happy, but they will be much more unhappy if you allow the damage to protected data.

If users prefer to use an alternative keyboard, this is their choice as users. The user is quite capable of switching the keyboard if he wants. The user is quite capable of making these decisions. It is possible that an alternate keyboard is more secure than a built-in one, due to devices loaded with factor spyware such as CarrierIQ . Therefore, your assumption that you are improving security by attacking a custom keyboard selection is fundamentally wrong.

Of course, you don’t need to support any keyboard at all, forcing users to use some kind of on-screen input function that you yourself are developing. It is also not completely safe (for example, attacks using tapjacking), and it can cause usability problems for people who choose certain third-party keyboards for certain reasons (for example, blind users, users with engine control problems).

I don’t know that there is a way to finally determine what IME firmware is, especially since it depends on the device and firmware.

+2
source

Something like this should allow you to check if the user is using a non-standard keyboard. However, instead of stopping them from using this keyboard, what about a useful warning message about possible security risks?

 public boolean isUsingCustomInputMethod() { InputMethodManager imm = (InputMethodManager) mCtx.getSystemService( Context.INPUT_METHOD_SERVICE); List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList(); final int N = mInputMethodProperties.size(); for (int i = 0; i < N; i++) { InputMethodInfo imi = mInputMethodProperties.get(i); if (imi.getId().equals( Settings.Secure.getString(mCtx.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return true; } } } return false; } 
+2
source

I find the exact solution

 InputMethodManager m = (InputMethodManager) ctx.getSystemService("input_method"); List<InputMethodInfo> a = m.getInputMethodList(); for (InputMethodInfo inputMethodInfo : a) { if (inputMethodInfo.getIsDefaultResourceId() == 0) { //it is not default return false; } } //it is default return true; 
+1
source

Source: https://habr.com/ru/post/1381656/


All Articles