[Android General] Grouxho:
Guide - Long Press Skip Tracks (selectable long press timeout) & Double click for pause/play music (Reference - S7 Edge Nougat Beta 4)

Features

- Long Press Skip tracks when screen off.

- Selectable TimeOut in mSec

- Option for play / pause music if we double click a volume key.

- more to come..

Quick Guide

(The code is a bit long, so, see attached files, read my comments and compare original to modded files for easier implementation. )

1.- Extract classes.dex from services.jar and dissasemble it.

Using latest baksmali.jar:

java -jar baksmali.jar d classes.dex --debug-info false -o output_ser/

(output_ser or whatever, of course. Optional --debug-info false, but it is easier to see the code without debug info..)

2.- Download the attached zip and extract it. Go to xda-mod folder and copy

PhoneWindowManager$GrxDobleTapVol.smali and PhoneWindowManager$GrxLongVol.smali

to smali/com/android/server/policy in your dissasembled classes.dex

3.- Now, compare the provided PhoneWindowManager$SettingsObserver.smali and PhoneWindowManager.smali. I provide original (ori folder in attached zip) and modded (xda-mod folder).

4.- Implement changes in your PhoneWindowManager.smali

Basically:

. Look for # instance fields tag, and just below declare the vars used in the mod

. Look for .method public constructor <init>()V and just before the return-void instruction add the provided block of code in the attached modded smali file.

. Look for # virtual methods and add the 9 provided methods.

. Look for .method public interceptKeyBeforeQueueing(Landroid/view/KeyEvent;I)I and:

Add the goto tag as shown in the provide mod code. DonÂ´t forget this!.

Add the provided block of code just before the ....>getTelecommService()Landroid/telecom/TelecomManager instruction, under the corresponding to 0x18 and 0x19 keycodes sswitch tag, as shown in my code.

- Now letÂ´s modify the existing SettingsObserver, in order to update the preferences values when one of them is changed.

. Compare modded PhoneWindowManager$SettingsObserver.smali to original PhoneWindowManager$SettingsObserver.smali. Changes to be made are:

. Declare the three uris as shown in my code

. Add both the provided block of code (to get observed uris) and the call instruction (to update vars storing the preference values after booting) in method observer()V, as shown in the code

. Add the method .method public onChange(ZLandroid/net/Uri;)V (if existing in your rom, you will need to adapt the code, of course)

5.- Assemble the new classes.dex, put it into services.jar and flash it.

6.- Rom Control/Other prefs app

Default values are:

- Use skip tracks - > true

- Use Double click to play/pause -> true

- Long press timeout -> 600 mSec.

Finally, although I do not use Rom Control but my own preferences application, I think the following (or something like this..) preferences setting will work with Rom Control:

<com.wubydax.romcontrol.v2.prefs.MySwitchPreference android:title="Use Skip Tracks Mod" android:key="b_skip_tracks" android:defaultValue="true" android:summaryOn="Enabled" android:summaryOff="Disabled" />
<com.wubydax.romcontrol.v2.prefs.MyCheckBoxPreference android:title="Kill app checkbox" android:key="b_doble_click_skip_tracks" android:defaultValue="true" android:summaryOn="Enabled" android:summaryOff="Disabled" android:dependency="b_skip_tracks" />
<com.wubydax.romcontrol.v2.prefs.MySeekBarPreference android:title="Long Press TimeOut" android:key="b_timeout_skip_tracks" android:dependency="b_skip_tracks" android:defaultValue="600" app:minValue="300" app:maxValue="1300" app:unitsValue="mSec" />

Basically you need two checkboxes or two switches (or one checkbox and one switch) to control "b_skip_tracks" (main checkbox, if false no mod it is applied) and "b_doble_click_skip_tracks" (for double click to play-pause music).

For long press time out use a seekbar or similar (key -> "b_timeout_skip_tracks"

If you get "Unsigned short value out of range.." while assembling the new classes.dex (for those not knowing why and how..)

smali.jar is able to manage up to 65535 methods per dex file. That is the reason why we get two or three dex files in some jars (services.jar, framework.jar) after deodexing them.

If you get an error similar to:

..Exception in thread "main" org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65593

that was the problem.

To solve this, we will create a new classes3.dex extracting some code from the original classes.dex.

- Dissasemble classes.dex (i.e. to output_ser folder)

- Create a new folder for our new classes3.dex, i.e. output_ser3 and create the com/android/server directory structure.

- Now cut from the dissasembled classes.dex the policy (com-android-server) folder and copy to the output_ser3 dir, taking care of maintaining the original folder structure

Now, output_ser contains the original code except our policy folder and output_ser3 contains our policy folder.

LetÂ´s create new classes.dex and classes3.dex

-> java -Xmx512M -jar smali.jar a otuput_ser -o classes.dex

-> java -Xmx512M -jar smali.jar a otuput_ser3 -o classes3.dex

Put both the new classes.dex and classes3.dex into your services.jar and flash it. IMPORTANT: First time you do this, you need to wipe dalvik and art and cache.

Greetings from Spain.

--->Added attachment with fix in phonewindowmanager settingsobserver (method onchange)