[Galaxy Note GT-N7000 Themes and Apps] majdinj:
Hello xda members,

New day and new mod to learn, isn't it? :D

Today I will explain to you how to be able to change sound track by long pressing volume up or down while the screen is locked using stock Music Player and Google Play Music programs..

OK let's start..

Needed tools:

1) Backsmali/Smali program (Check the utility I made for that here for windows users)

2) Notepad ++ from here.

The procedure:

- Backsmali android.policy.jar

- Navigate to com/android/internal/policy/impl/ folder and open PhoneWindowManager.smali

- Search for this static field ".field static final LONG_PRESS_POWER_SHUT_OFF:I = 0x2" and add this line bellow it (the blue one):

.field static final LONG_PRESS_POWER_SHUT_OFF:I = 0x2

[B][COLOR="Blue"].field private static final LONG_PRESS_TIMEOUT:I = 0x190[/COLOR][/B]

.field static final MINI_APP_DIALOG_LAYER:I = 0x5

- Search for this field ".field private mIsVisibleSPenGestureView:Z" and add these two lines bellow it (the blue ones):

.field private mIsVisibleSPenGestureView:Z

[B][COLOR="Blue"].field mIsVolumeAction:Z

.field mIsVolumeBlocking:Z[/COLOR][/B]

.field mKeyboardTapVibePattern:[J

- Search for the field ".field private mVolumeDownKeyTriggered:Z" and add this line bellow it (the blue one):

.field private mVolumeDownKeyTriggered:Z

[B][COLOR="Blue"].field mVolumeDownLongPress:Ljava/lang/Runnable;[/COLOR][/B]

.field private final mVolumeKeyLongPressforOneTouchReport:Ljava/lang/Runnable;

- Search for the field ".field private mVolumeUpKeyTriggered:Z" and add this line bellow it (the blue one):

.field private mVolumeUpKeyTriggered:Z

[B][COLOR="Blue"].field mVolumeUpLongPress:Ljava/lang/Runnable;[/COLOR][/B]

.field mWindowManager:Landroid/view/IWindowManager;

- Search for the method ".method public constructor <init>()V" and go to the end of this method and add these lines (the blue ones) before "return-void" line:

.line 7234
new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$36;

invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$36;-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V

iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mScreenLockTimeout:Ljava/lang/Runnable;

[B][COLOR="Blue"]new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$Skip1;

invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$Skip1;-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V

iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mVolumeUpLongPress:Ljava/lang/Runnable;

new-instance v0, Lcom/android/internal/policy/impl/PhoneWindowManager$Skip2;

invoke-direct {v0, p0}, Lcom/android/internal/policy/impl/PhoneWindowManager$Skip2;-><init>(Lcom/android/internal/policy/impl/PhoneWindowManager;)V

iput-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mVolumeDownLongPress:Ljava/lang/Runnable;[/COLOR][/B]

.line 8132
return-void
.end method

- Search for the method ".method handleVolumeKey(II)V" and add these lines above "invoke-static" line (the blue ones), and add extra condition line (the blue line) above "goto" command:

.method handleVolumeKey(II)V
.registers 8
.parameter "stream"
.parameter "keycode"

.prologue
.line 5405
[B][COLOR="Blue"]move-object/from16 v0, p0

iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsVolumeBlocking:Z

if-nez v0, :cond_c[/COLOR][/B]

invoke-static {}, Lcom/android/internal/policy/impl/PhoneWindowManager;->getAudioService()Landroid/media/IAudioService;

move-result-object v0

if-nez v0, :cond_d

[B][COLOR="Blue"]:cond_c[/COLOR][/B]
:goto_[B][COLOR="Blue"]c[/COLOR][/B]
return-void

- Still in the same method, search down for "Landroid/os/PowerManager$WakeLock;->release()V" and change :goto value to the same as the one in the previous:

before:

iget-object v2, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBroadcastWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v2}, Landroid/os/PowerManager$WakeLock;->release()V

goto :goto_[B][COLOR="Red"]6[/COLOR][/B]

After:

iget-object v2, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBroadcastWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v2}, Landroid/os/PowerManager$WakeLock;->release()V

goto :goto_[B][COLOR="Blue"]c[/COLOR][/B]

- There is another one..!! Search down again for "Landroid/os/PowerManager$WakeLock;->release()V" and change :goto value to the same as the one in the previous step:

Before:

iget-object v2, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBroadcastWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v2}, Landroid/os/PowerManager$WakeLock;->release()V

goto :goto_[B][COLOR="Red"]6[/COLOR][/B]

After:

iget-object v2, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mBroadcastWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v2}, Landroid/os/PowerManager$WakeLock;->release()V

goto :goto_[B][COLOR="Blue"]c[/COLOR][/B]

- Now at the end of the previous method ".method handleVolumeKey(II)V" and before the next method ".method public hasNavigationBar()Z", add these two new methods:

[B][COLOR="Blue"].method handleVolumeLongPress(I)V
.registers 6

const/4 v1, 0x1

move-object/from16 v0, p0

iput-boolean v1, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsVolumeBlocking:Z

const/4 v1, 0x0

iput-boolean v1, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsVolumeAction:Z

const/16 v1, 0x18

if-ne p1, v1, :cond_majdi

iget-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mVolumeUpLongPress:Ljava/lang/Runnable;

:goto_nj
iget-object v1, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

sget v2, Lcom/android/internal/policy/impl/PhoneWindowManager;->LONG_PRESS_TIMEOUT:I

int-to-long v2, v2

invoke-virtual {v1, v0, v2, v3}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

return-void

:cond_majdi
iget-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mVolumeDownLongPress:Ljava/lang/Runnable;

goto :goto_nj
.end method

.method handleVolumeLongPressAbort()V
.registers 3

const/4 v1, 0x0

move-object/from16 v0, p0

iput-boolean v1, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsVolumeBlocking:Z

iget-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

iget-object v1, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mVolumeUpLongPress:Ljava/lang/Runnable;

invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

iget-object v0, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHandler:Landroid/os/Handler;

iget-object v1, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mVolumeDownLongPress:Ljava/lang/Runnable;

invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

return-void
.end method[/COLOR][/B]

- Now search for the method ".method public interceptKeyBeforeQueueing(Landroid/view/KeyEvent;IZ)I", then search down for "Lcom/android/internal/policy/impl/PhoneWindowManager;->mSamsungVolumeControlThread:Lcom/android/internal/policy/impl/PhoneWindowManager$SamsungVolumeControlThread;" and add these lines ABOVE it (the blue ones):

:cond_51c
move-object/from16 v0, p0

[B][COLOR="Blue"]iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mScreenOnEarly:Z

if-nez v0, :cond_dinj

invoke-virtual/range {p0 .. p0}, Lcom/android/internal/policy/impl/PhoneWindowManager;->isMusicActive()Z

move-result v29

if-eqz p0, :cond_dinj

move-object/from16 v0, p0

move/from16 v15, v19

invoke-virtual {v0, v15}, Lcom/android/internal/policy/impl/PhoneWindowManager;->handleVolumeLongPress(I)V

:cond_dinj
move-object/from16 v0, p0[/COLOR][/B]

iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mSamsungVolumeControlThread:Lcom/android/internal/policy/impl/PhoneWindowManager$SamsungVolumeControlThread;

move-object/from16 v29, v0

- Still in the same method, and after adding the previous lines, just go down for few lines and you will see a line starts with a defined condition (:cond_), just add these lines (the blue ones) bellow that defined condition:

invoke-virtual/range {v29 .. v29}, Lcom/android/internal/policy/impl/PhoneWindowManager$SamsungVolumeControlThread;->start()V

goto/16 :goto_68

:cond_562
[B][COLOR="Blue"]if-nez v5, :cond_newa

move-object/from16 v0, p0

iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsVolumeBlocking:Z

if-eqz v0, :cond_newa

invoke-virtual/range {p0 .. p0}, Lcom/android/internal/policy/impl/PhoneWindowManager;->handleVolumeLongPressAbort()V

move-object/from16 v0, p0

iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsVolumeAction:Z

if-nez v0, :cond_newa

move-object/from16 v0, p0

const/4 v3, 0x0

move/from16 v15, v19

invoke-virtual {v0, v3, v15}, Lcom/android/internal/policy/impl/PhoneWindowManager;->handleVolumeKey(II)V

:cond_newa[/COLOR][/B]
move-object/from16 v0, p0

iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mSamsungVolumeControlThread:Lcom/android/internal/policy/impl/PhoneWindowManager$SamsungVolumeControlThread;

move-object/from16 v29, v0

- Now at the end of the method ".method sendCloseSystemWindows(Ljava/lang/String;)V" and above the method ".method setAttachedWindowFrames(Landroid/view/WindowManagerPolicy$WindowState;IILandroid/view/WindowManagerPolicy$WindowState;ZLandroid/graphics/Rect;Landroid/graphics/Rect;Landroid/graphics/Rect;Landroid/graphics/Rect;I)V" add this new method:

[B][COLOR="Blue"].method protected sendMediaButtonEvent(I)V
.registers 15

invoke-static {}, Landroid/os/SystemClock;->uptimeMillis()J

move-result-wide v1

new-instance v11, Landroid/content/Intent;

const-string v4, "android.intent.action.MEDIA_BUTTON"

const/4 v5, 0x0

invoke-direct {v11, v4, v5}, Landroid/content/Intent;-><init>(Ljava/lang/String;Landroid/net/Uri;)V

new-instance v0, Landroid/view/KeyEvent;

const/4 v5, 0x0

const/4 v7, 0x0

move-wide v3, v1

move v6, p1

invoke-direct/range {v0 .. v7}, Landroid/view/KeyEvent;-><init>(JJIII)V

const-string v4, "android.intent.extra.KEY_EVENT"

invoke-virtual {v11, v4, v0}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Landroid/os/Parcelable;)Landroid/content/Intent;

iget-object v4, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;

const/4 v5, 0x0

invoke-virtual {v4, v11, v5}, Landroid/content/Context;->sendOrderedBroadcast(Landroid/content/Intent;Ljava/lang/String;)V

new-instance v12, Landroid/content/Intent;

const-string v4, "android.intent.action.MEDIA_BUTTON"

const/4 v5, 0x0

invoke-direct {v12, v4, v5}, Landroid/content/Intent;-><init>(Ljava/lang/String;Landroid/net/Uri;)V

new-instance v3, Landroid/view/KeyEvent;

const/4 v8, 0x1

const/4 v10, 0x0

move-wide v4, v1

move-wide v6, v1

move v9, p1

invoke-direct/range {v3 .. v10}, Landroid/view/KeyEvent;-><init>(JJIII)V

const-string v4, "android.intent.extra.KEY_EVENT"

invoke-virtual {v12, v4, v3}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Landroid/os/Parcelable;)Landroid/content/Intent;

iget-object v4, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;

const/4 v5, 0x0

invoke-virtual {v4, v12, v5}, Landroid/content/Context;->sendOrderedBroadcast(Landroid/content/Intent;Ljava/lang/String;)V

const/4 v8, 0x1

move-object/from16 v9, p0

iput-boolean v8, v9, Lcom/android/internal/policy/impl/PhoneWindowManager;->mIsVolumeAction:Z

return-void
.end method[/COLOR][/B]

Save changes..

Now add the two extra smalis resources from the attachment in com/android/internal/policy/impl folder and recompile android.policy.jar and push to your phone and fix permissions to chmod 644.

Have fun.. :cool: