Android4.0-4.4 添加實體按鍵震動支援的方法(java + smali版本)

來源:互聯網
上載者:User

有些手機比如泛泰A820L, 泛泰A890 A900 以及Nubia Z5S 和Z5S mini具有實體按鍵(這裡所說的實體按鍵是相對於虛擬按鍵而言, 包含物理按鍵和觸控螢幕上多出來的觸摸實體按鍵), 當編譯第三方ROM比如CM或者Mokee或者Omni時就會發現如果不做修改的話預設觸摸實體按鍵時是沒有震動支援的, 甚至有些patchrom的MIUI或者ColorOS等系統也可能不支援. 不知道是CM代碼的問題還是編譯的Config沒寫完全造成的, 後來經過本人修改後是可以支援按鍵震動, 不過只能作為臨時解決方案參考.


轉帖請註明出處和網址來源:

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


java版本代碼

在本人提交的cm的review上, 沒有被通過,因為如果加進來不修改的話,會影響虛擬鍵的震動,會導致home鍵震動兩次, 不過只是作為支援實體按鍵震動的話還是可以的:

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


修改的位置為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 WindowManagerPolicy {             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+{+performHapticFeedbackLw(null, HapticFeedbackConstants.KEYBOARD_TAP, true); //啟動震動 by syhost+}+    }      /** {@inheritDoc} */     @Override@@ -2441,7 +2457,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {                             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 = 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);                 }             }




對應的smali版本, 

在本人之前適配的泛泰A820L的cm10版本的樂蛙ROM裡可以找到, 是分幾次完成的:


patch1:

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

上面的patch2主要是加了防止長按home鍵長振, 對應的java部分是:

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






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.