Add settings for the new configuration of config. xml for the Android system

  • 2021-11-29 08:34:30
  • OfStack

In daily system development, it is often necessary to modify or add your own configuration in framework of adroid. For example, add a new variable in config. xml. My test here found that if you simply add configuration items, you can't access them in the code. In order to solve this problem, I carefully looked at the code 1, and finally found that it needs to be defined in public. xml.

Let's use an example to illustrate the following.

1. Add default input configuration in framework/base/core/res/res/valus/config. xml:

< !--
set default inputmethod.
-- >
< string translatable="false" name="config_def_input_method" > com.taypo.android.trskb/.TRSoftKeyboard < /string >

This is the default input method for Turkish.

After modification, it needs to be modified under mm Compilation 1 performed by framework/base/core/res/res z.

After completion, croot goes to the root directory and executes api under make update-api Update 1.

2. If you use this configuration item

My resetDefaultIMeLocked function in framework/base/service/java/com/android/interanl/InputMethodManangerService. java uses this variable


 private void resetDefaultImeLocked(Context context) {
    // Do not reset the default (current) IME when it is a 3rd-party IME
    if (mCurMethodId != null
        && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
      return;
    }
 
 
    InputMethodInfo defIm = null;
 String id=context.getResources().getString(com.android.internal.R.string.config_def_input_method);
 Slog.i(TAG, "internal.id: " + id);
    for (InputMethodInfo imi : mMethodList) {
 
  if(imi.getId().equals(id)) defIm=imi;
  
   
     }
  
     /* if (defIm == null) {
        if (InputMethodUtils.isValidSystemDefaultIme(
            mSystemReady, imi, context)) {
          defIm = imi;
          Slog.i(TAG, "Selected default: " + imi.getId());
        }
      }
    }
    if (defIm == null && mMethodList.size() > 0) {
      defIm = InputMethodUtils.getMostApplicableDefaultIME(
          mSettings.getEnabledInputMethodListLocked());
      Slog.i(TAG, "No default found, using " + defIm.getId());
    }
    */
    if (defIm != null) {
      setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
    }
  }

It's very simple to use this way. At first, I thought it was like this. I checked a lot of information and everyone used it like this. Finally, the compilation bar reported the following error

frameworks/base/services/java/com/android/server/InputMethodManagerService. java: 726: Symbol not found

Symbol: Variable

config_def_input_method

Location: Class

com.android.internal.R.string
String id=context.getResources().getString(com.android.internal.R.string.config_def_input_method);

But I clearly defined why I still can't find it.

Solution:

1. Add a declaration of these string in the framework/base/core/res/res/values/public. xml file.

2. Compilation of mm under framework/base/core/res/res/

3. Perform make update-api to update api under the root directory.

< public type="string" name="config_def_input_method" id="0x01040018" / >

Note in the id when 1 incremental value, in the system is only 1, do not repeat.

At this point, pass can be obtained by mutating inputmethodmanagerService. java.

Additional knowledge: Add 1 configuration item to config. xml

1. Add 1 entry to config. xml (path: frameworks/base/core/res/res/values/)

Such as:

< bool name="config_myValue" > true < /bool >

2. In frameworks/base/core/res/res/values/symbols. xml, add:

< java-symbol type="bool" name="config_myValue"/ >

3. In frameworks/base/core/res/res/values/android. xml, add

1 with an id, but how is this id generated? Follow these steps:

First: In frameowrks/base/tools/aapt/ResourceTable. cpp

In the addSymbols () function, remove the following comment:

//printf(" < android type=\"%\" name=\"%\" id=... > ,

Then, in the root directory of the code, execute:

make framework-res > res.txt

You can export the android raw resources to the res. txt file.

Then, put one of them

< android type="bool" name="config_myValue" id="0x0111005b"/ >

Copy the code and put it in android. xml file.


Related articles: