Android4.0-4.4 Method for adding support for entity button vibration (java + smali Version)

Source: Internet
Author: User

Some mobile phones such as pantai A820L, pantai A890 A900, and Nubia Z5S and Z5S mini have solid buttons (The entity buttons mentioned here are compared with virtual keys, including physical keys and touch keys displayed on the touch screen.When compiling a third-party ROM, such as CM, Mokee, Or Omni, you will find that if you do not modify the ROM, the default touch button is not supported by vibration, even some systems such as MIUI or ColorOS of patchrom may not support it. I don't know whether the CM code is a problem or the compiled Config is not completely written. Later I modified it to support button vibration, but it can only be used as a temporary solution reference.


Please indicate the source and URL source for the post:

Http://blog.csdn.net/syhost/article/details/32067695


Java version code

The cm review submitted by myself is not passed, because if it is not modified after it is added, the vibration of the virtual key will be affected, and the home key will vibrate twice, however, it can only be used to support the vibration of entity buttons:

Http://review.cyanogenmod.org/#/c/55274/1/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java


The modified location is in the source code of android. policy. jar.Frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager. java


Diff -- git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager. java B/policy/src/com/android/internal/policy/impl/PhoneWindowManager. javaindex f0719e3 .. ca38166 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager. java ++ B/policy/src/com/android/internal/policy/impl/PhoneWindowManager. java @-2333,6 + 2333,22 @ public class PhoneWindowManager implements WindowMana GerPolicy {WindowManager. layoutParams. TYPE_SYSTEM_ALERT, WindowManager. layoutParams. TYPE_SYSTEM_ERROR,}; ++ private void setKeyVib (WindowState win) {+ WindowManager. layoutParams attrs; + Intent service; + ContentResolver res; ++ // If a system window has focus, then it doesn' t make sense + // right now to interact with applications. + attrs = win! = Null? Win. getAttrs (): null; + service = new Intent (); + res = mContext. getContentResolver (); + if (1 = Settings. system. getInt (res, Settings. system. HAPTIC_FEEDBACK_ENABLED, 0) // when setting feedback enable + {+ running mhapticfeedbacklw (null, HapticFeedbackConstants. KEYBOARD_TAP, true); // start the vibration by syhost ++}/** {@ inheritDoc} */@ Override @-2441,7 + 2457,8 @ public class PhoneWindowManager implements WindowManage RPolicy {ViewConfiguration. getDoubleTapTimeout (); return-1 ;}- ++ setKeyVib (win); // Go home! LaunchHomeFromHotKey (); return-1; @-2514,6 + 2531,7 @ public class PhoneWindowManager implements WindowManagerPolicy {} if (repeatCount = 0) {mMenuPressed = true; + setKeyVib (win); if (mEnableShiftMenuBugReports & (metaState & chordBug) = chordBug) {Intent intent Intent = new Intent (Intent. ACTION_BUG_REPORT); mContext. sendOrderedBroadcast (intent, null); @-2645,9 + 2663,13 @ public class PhoneWindowManager implements WindowManagerPolicy {} return-1;} else if (keyCode = KeyEvent. KEYCODE_BACK) {+ if (down & repeatCount = 0) {+ setKeyVib (win); ++} if (Settings. secure. getIntForUser (mContext. getContentResolver (), Settings. secure. KILL_APP_LONGPRESS_BACK, 0, UserHandle. USER_CURRENT) = 1) {if (down & repeatCount = 0) {+ setKeyVib (win); mHandler. postDelayed (mBackLongPress, mBackKillTimeout );}}




Corresponding smali version,

You can find it in the cm10 ROM of pantai A820L that I have adapted. It is completed several times:


Pattern:

Https://github.com/syhost/lewa_patchrom_ef65l/commit/18afafa2c7b770bdb593fee086c7cc07f8789e58

    goto :goto_0  .end method   +.method private setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V +    .locals 7 +    .parameter "win" + +    .prologue +    const/4 v3, 0x0 + +    const/4 v6, 0x1 + +    .line 2110 +    if-eqz p1, :cond_1 + +    invoke-interface {p1}, Landroid/view/WindowManagerPolicy$WindowState;->getAttrs()Landroid/view/WindowManager$LayoutParams; + +    move-result-object v0 + +    .line 2111 +    .local v0, attrs:Landroid/view/WindowManager$LayoutParams; +    :goto_0 +    new-instance v2, Landroid/content/Intent; + +    invoke-direct {v2}, Landroid/content/Intent;-><init>()V + +    .line 2112 +    .local v2, service:Landroid/content/Intent; +    iget-object v4, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context; + +    invoke-virtual {v4}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver; + +    move-result-object v1 + +    .line 2113 +    .local v1, res:Landroid/content/ContentResolver; +    const-string v4, "haptic_feedback_enabled" + +    const/4 v5, 0x0 + +    invoke-static {v1, v4, v5}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I + +    move-result v4 + +    if-ne v6, v4, :cond_0 + +    .line 2115 +    const/4 v4, 0x3 + +    invoke-virtual {p0, v3, v4, v6}, Lcom/android/internal/policy/impl/PhoneWindowManager;->performHapticFeedbackLw(Landroid/view/WindowManagerPolicy$WindowState;IZ)Z + +    .line 2117 +    :cond_0 +    return-void + +    .end local v0           #attrs:Landroid/view/WindowManager$LayoutParams; +    .end local v1           #res:Landroid/content/ContentResolver; +    .end local v2           #service:Landroid/content/Intent; +    :cond_1 +    move-object v0, v3 + +    .line 2110 +    goto :goto_0 +.end method +  .method private takeScreenshot()V      .locals 8   @@ -8384,6 +8446,7 @@      .line 1799      .end local v11           #ex:Landroid/os/RemoteException;      :cond_6 +    invoke-direct/range {p0 .. p1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V      invoke-virtual/range {p0 .. p0}, Lcom/android/internal/policy/impl/PhoneWindowManager;->launchHomeFromHotKey()V        goto :goto_4 @@ -8631,6 +8694,8 @@        if-nez v23, :cond_1c   +    invoke-direct/range {p0 .. p1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V +      .line 1853      move-object/from16 v0, p0



Patch2:

Https://github.com/syhost/lewa_patchrom_ef65l/commit/0e5ff497456e9428546be24bae36dfcf4544863f

       move/from16 v1, v32   -    if-ne v0, v1, :cond_1c +    if-ne v0, v1, :cond_34        .line 1894      if-eqz v9, :cond_1a @@ -8887,7 +8887,25 @@      const-wide/16 v32, -0x1        goto/16 :goto_1 +     +    :cond_34 +    const/16 v32, 0x4 + +    move/from16 v0, v18 + +    move/from16 v1, v32 + +    if-ne v0, v1, :cond_1c + +    if-eqz v9, :cond_1c   +    if-nez v23, :cond_1c + +    invoke-direct/range {p0 .. p1}, Lcom/android/internal/policy/impl/PhoneWindowManager;->setKeyVib(Landroid/view/WindowManagerPolicy$WindowState;)V +     +    goto/16 :goto_34 +     +          .line 1897      :cond_19      const/16 v32, 0x1 @@ -8946,6 +8964,7 @@      goto :goto_9        .line 1920 +    :goto_34      :cond_1c      move-object/from16 v0, p0

The above patch2 is mainly used to prevent long-pressed home keys. The corresponding java part is:

+        if (down && repeatCount == 0) {+        setKeyVib(win);+        }






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.