Find a touch operation source developer options - Android source code reading skills

    In developer mode, the developer options, you can check the "display touch operation", and then clicking the screen will have a circle at the click position is displayed. How to find the code portion of the draw circle, what skills to read such a large amount of code android system source code it? Please follow the following little brother me to analyze it together.

 

    1. android function code is provided in the packages / apps / Settings / inside, so the search key string in the Settings,

In the source directory input terminal

-rn grep " a touch operation " ./packages/apps/Settings/

    Search to the following:

./packages/apps/Settings/res/values-zh-rCN/strings.xml: 2108 : < String name = " show_touches " msgid = " 1,356,420,386,500,834,339 " > " Display touch operation " </ String >

    Familiar android application programming, then you should know that the code show_touches and "display touch operation" is associated.


    2. Enter 

grep -rn "show_touches" --include "*.java" ./packages/apps/Settings/

    get

./packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java:128: private static final String SHOW_TOUCHES_KEY = "show_touches";

 

    3. Start reading the source code, open DevelopmentSettings.java read the following in the order,

private static final String SHOW_TOUCHES_KEY = "show_touches";
mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
private void writeShowTouchesOptions() {
    Settings.System.putInt(getActivity().getContentResolver(),
            Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0);
}

    PutInt guess it should be a function of the data transfer, so in the framework inside the search SHOW_TOUCHES see what happens,

    Entry

grep -rn "SHOW_TOUCHES" frameworks/

    To search a lot, such as the following should be registered and associated data processing,

frameworks/base/core/java/android/provider/Settings.java:3094: public static final String SHOW_TOUCHES = "show_touches";
frameworks/base/core/java/android/provider/Settings.java:3097: public static final Validator SHOW_TOUCHES_VALIDATOR = sBooleanValidator;
frameworks/base/core/java/android/provider/Settings.java:3439: PRIVATE_SETTINGS.add(SHOW_TOUCHES);
frameworks/base/core/java/android/provider/Settings.java:3519: VALIDATORS.put(SHOW_TOUCHES, SHOW_TOUCHES_VALIDATOR);

    Because I do not see any special operation, just some of the statements and add operations, so ignore it. . . . . .

The following is the specific function

frameworks/base/services/core/java/com/android/server/input/InputManagerService.java:1600: Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true,

 

    4. Open InputManagerService.java source,

private void registerShowTouchesSettingObserver() {
    mContext.getContentResolver().registerContentObserver(
            Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true,
            new ContentObserver(mHandler) {
                @Override
                public void onChange(boolean selfChange) {
                    updateShowTouchesFromSettings();
                }
            }, UserHandle.USER_ALL);
}

    Found that the key method getContentResolver just DevelopmentSettings.java in putInt inside the parameters of the same, so you can definitely go here.

    Then with the method updateShowTouchesFromSettings ()

public void updateShowTouchesFromSettings() {
    int setting = getShowTouchesSetting(0);
    nativeSetShowTouches(mPtr, setting != 0);
}

    See native words, description will come with JNI interface cpp written inside.

 

    3. as it has been to JNI, so follow-up are just looking cpp file, and enter

grep -rn "nativeSetShowTouches" --include "*.cpp" ./frameworks/ 

    To search

./frameworks/base/services/core/jni/com_android_server_input_InputManagerService.cpp:1310:static void nativeSetShowTouches(JNIEnv* /* env */,

   Open this file com_android_server_input_InputManagerService.cpp,

static void nativeSetShowTouches(JNIEnv* /* env */,
        jclass /* clazz */, jlong ptr, jboolean enabled) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);

    im->setShowTouches(enabled);
}

    SetShowTouches inside look at what to do,

void NativeInputManager::setShowTouches(bool enabled) {
    { // acquire lock
        AutoMutex _l(mLock);

        if (mLocked.showTouches == enabled) {
            return;
        }

        ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
        mLocked.showTouches = enabled;
    } // release lock

    mInputManager->getReader()->requestRefreshConfiguration(
            InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
}

    Which mLocked.showTouches = enabled; in showTouches is key, as well as CHANGE_SHOW_TOUCHES is also critical.

 

    4. Enter

 grep -rn "CHANGE_SHOW_TOUCHES" --include "*.cpp" ./frameworks/ 

    To search

./frameworks/native/services/inputflinger/InputReader.cpp:3177: | InputReaderConfiguration::CHANGE_SHOW_TOUCHES

    Open InputReader.cpp, was not clear what things in CHANGE_SHOW_TOUCHES, too laborious.

Then you can search showTouches in InputReader.cpp in

    Entry

 grep -rn "showTouches" --include "*.cpp" ./frameworks/ 

    To search

./frameworks/native/services/inputflinger/InputReader.cpp:3476: (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
./frameworks/native/services/inputflinger/InputReader.cpp:4334: && mConfig.showTouches && mPointerController != NULL) {

    How to associate CHANGE_SHOW_TOUCHES showTouches up with it? In InputReader.cpp in

if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO
        | InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT
        | InputReaderConfiguration::CHANGE_SHOW_TOUCHES
        | InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE))) {
    // Configure device sources, surface dimensions, orientation and
    // scaling factors.
    configureSurface(when, &resetNeeded);
}

 

    Enter configureSurface find the following key codes

    // Create pointer controller if needed.
    if (mDeviceMode == DEVICE_MODE_POINTER ||
            (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
        if (mPointerController == NULL) {
            mPointerController = getPolicy()->obtainPointerController(getDeviceId());
        }
    } else {
        mPointerController.clear();
    }

    This comment is interesting // Create pointer controller if needed.

So be sure, the follow-up to carry out his things around showTouches in InputReader.cpp inside, it's important to really showTouches appear in another one,

        if (mDeviceMode == DEVICE_MODE_DIRECT
                && mConfig.showTouches && mPointerController != NULL) {
            mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_SPOT);
            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);

            mPointerController->setButtonState(mCurrentRawState.buttonState);
            mPointerController->setSpots(mCurrentCookedState.cookedPointerData.pointerCoords,
                    mCurrentCookedState.cookedPointerData.idToIndex,
                    mCurrentCookedState.cookedPointerData.touchingIdBits);
        }

    Learned many years of English to play its role, and can be seen in spots setSpots in Chinese means "spots, dots," it is to go here, setSpots pass parameters to be related to the coordinate data and touch.

 

    5. Enter

grep -rn "setSpots" --include "*.cpp" ./frameworks/

    To search

./frameworks/base/libs/input/PointerController.cpp:246:void PointerController::setSpots(const PointerCoords* spotCoords,
./frameworks/base/libs/input/PointerController.cpp:249: ALOGD("setSpots: idBits=%08x", spotIdBits.value);

    Open PointerController.cpp, the function void PointerController :: setSpots (const PointerCoords * spotCoords, const uint32_t * spotIdToIndex, BitSet32 spotIdBits)
are known spot-> updateSprite (& icon, x , y); circle about the display, as the bold prediction icon graphics, x and y are the display coordinates of the display. Add ALOGI print, compiled import discovery, circle time, where each will go display. Conjecture into a truth!

    6. thinking, where icon data from, how it can be displayed on android? x, y data is how it passed? After free and then discuss it together.

 

Guess you like

Origin www.cnblogs.com/songsongman/p/11504744.html