FORUMS

[MOD] Custom Volume Step Count for Everything

4,597 posts
Thanks Meter: 3,549
 
By Zacharee1, Recognized Developer / Retired Forum Moderator on 19th October 2017, 02:13 PM
Post Reply Email Thread
So I've always been annoyed with how the HiFi volume only has 15 steps. For me, 5 is too low and 10 is too loud (cheap earbuds). With the release of the V30, I've learned that it has 75 steps for the HiFi volume, which prompted me to modify our system to get 75 steps as well.

Well, I didn't do that exactly, but I think this is better. I didn't manage to get the 75 steps on just the HiFi volume: I changed every slider, and it's customizable. By default, it's 1 step on the HiFi slider. This is about 1/2 of a step on the ringer volume I think. But if you don't like that, you can change what it uses.

The property is

Code:
volume_step_size
in Settings.Global.

You can set that using ADB. For instance, if you want to go back to the default step size for HiFi mode, you could use

Code:
adb shell settings put global volume_step_size 10
The default step size if 5, but for whatever reason, the system uses double the number you want. It's some weird scaling thing I think.

Attached is the modified services.jar. It goes in /system/framework/ with 0644 permissions.

Enjoy!

Do it Manually

This guide assumes you know how to decompile and recompile APKs/JARs or DEX files. I'm just going to tell you what code you need to edit to add this mod yourself.

- Decompile your services.jar. If you're on an odexed system, you'll either have to deodex the JAR or edit the DEX. That's beyond the scope of this though.

- Find these two files:
Code:
 - /com/android/server/audio/AudioService.smali
 - /com/android/server/audio/AudioService$VolumeStreamState.smali
- In AudioService, you need to add two new methods.
Code:
.method static synthetic -get49(Lcom/android/server/audio/AudioService;)Z
    .locals 1

    iget-boolean v0, p0, Lcom/android/server/audio/AudioService;->mHifiDacMode:Z

    return v0
.end method
You'll want to make sure that -get49 isn't already used as a method name. My latest method was -get48, so the one I added I renamed to -get49.
Code:
.method private getCustomVolumeStepValue()I
    .locals 3

    const-string/jumbo v0, "volume_step_size"
    const v1, 0x2
    iget-object v2, p0, Lcom/android/server/audio/AudioService;->mContext:Landroid/content/Context;

    invoke-virtual {v2}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;
    move-result-object v2

    invoke-static {v2, v0, v1}, Landroid/provider/Settings$Global;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I
    move-result v2

    return v2
.end method
This is the method that grabs the current volume step set in Settings.Global. If there's no value found, it will use "2" by default.

- Now, go into AudioService$VolumeStreamState and find this method: "rescaleDeltaIndex(IIII)I." Comment the entire method out and paste this instead:
Code:
.method private rescaleDeltaIndex(IIII)I
    .locals 3
    .param p1, "deltaIndex"    # I
    .param p2, "flags"    # I
    .param p3, "streamType"    # I
    .param p4, "device"    # I

    .prologue
    .line 4948
    invoke-static {}, Lcom/android/server/audio/AudioService;->-get26()Z

    move-result v2

    if-eqz v2, :cond_4

    const/high16 v2, 0x20000

    and-int/2addr v2, p2

    if-nez v2, :cond_4

    const/4 v2, 0x3

    if-ne p3, v2, :cond_4

    .line 4950
    iget-object v2, p0, Lcom/android/server/audio/AudioService$VolumeStreamState;->this$0:Lcom/android/server/audio/AudioService;

    invoke-static {v2}, Lcom/android/server/audio/AudioService;->-get49(Lcom/android/server/audio/AudioService;)Z

    move-result v2

    if-eqz v2, :cond_0

    and-int/lit16 v2, p2, 0x1000

    if-nez v2, :cond_1

    .line 4951
    :cond_0
    invoke-static {}, Lcom/android/server/audio/AudioService;->-get0()I

    move-result v2

    mul-int/2addr p1, v2

    .line 4953
    :cond_1
    const/4 v1, 0x0

    .line 4954
    .local v1, "rescaledeltaIndex":I
    invoke-virtual {p0, p4}, Lcom/android/server/audio/AudioService$VolumeStreamState;->getIndex(I)I

    move-result v0

    .line 4955
    .local v0, "currentIndex":I
    rem-int v2, v0, p1

    if-eqz v2, :cond_3

    .line 4956
    if-gtz p1, :cond_2

    .line 4957
    rem-int v2, v0, p1

    neg-int v1, v2

    .line 4964
    :goto_0
    return v1

    .line 4959
    :cond_2
    rem-int v2, v0, p1

    sub-int v1, p1, v2

    goto :goto_0

    .line 4962
    :cond_3
    move v1, p1

    goto :goto_0

    .line 4966
    .end local v0    # "currentIndex":I
    .end local v1    # "rescaledeltaIndex":I
    :cond_4
    return p1
.end method
-get49 is the method you pasted earlier.
-get0 is the method that returns HIFI_MEDIA_VOLUME_OFFSET. Just make sure your -get0 is the same one as mine.

- Now, you need to actually get the custom method you pasted to be called. Find "adjustStreamVolume(IIILjava/lang/String;Ljava/lang/String;I)V" in AudioService and find the call to "rescaleIndex(III)I" inside it.
My call looks like this:
Code:
invoke-direct {v0, v6, v1, v13}, Lcom/android/server/audio/AudioService;->rescaleIndex(III)I
Change whatever you have to look like this:
Code:
invoke-direct {v0}, Lcom/android/server/audio/AudioService;->getCustomVolumeStepValue()I
- Rebuild and install!
Attached Files
File Type: jar services.jar - [Click for QR Code] (3.48 MB, 244 views)
The Following 10 Users Say Thank You to Zacharee1 For This Useful Post: [ View ]
19th October 2017, 02:43 PM |#2  
shadavis08's Avatar
Senior Member
Thanks Meter: 317
 
More
Do I remove an old file first or just set this one in there
The Following User Says Thank You to shadavis08 For This Useful Post: [ View ] Gift shadavis08 Ad-Free
19th October 2017, 02:45 PM |#3  
Senior Member
Flag Vikbolandet
Thanks Meter: 56
 
More
THANKS!!
The big step sizes have bothered me a lot!

If I want to use the adb command to set step sizes of 1, should I use 2?

Edit: File works for me!

Cheers
Emil
19th October 2017, 03:23 PM |#4  
carandcar's Avatar
Senior Member
Flag New Jersey
Thanks Meter: 201
 
More
I've been looking for something like this. Thank you! 😊

---------- Post added at 02:23 PM ---------- Previous post was at 02:22 PM ----------

Quote:
Originally Posted by shadavis08

Do I remove an old file first or just set this one in there

I added .bak to the end of the original file so its still there in case I need it.
19th October 2017, 03:53 PM |#5  
Senior Member
Thanks Meter: 39
 
More
I changed the file and softrebooted. Not working.
Am I doing something wrong?
19th October 2017, 03:58 PM |#6  
carandcar's Avatar
Senior Member
Flag New Jersey
Thanks Meter: 201
 
More
Quote:
Originally Posted by Salvaparalyzer

I changed the file and softrebooted. Not working.
Am I doing something wrong?

Did you change the permissions?
I would do a full reboot. A soft boot may not be enough.

Sent from my LG-H918 using Tapatalk
19th October 2017, 03:58 PM |#7  
Zacharee1's Avatar
OP Recognized Developer / Retired Forum Moderator
Thanks Meter: 3,549
 
Donate to Me
More
Quote:
Originally Posted by Salvaparalyzer

I changed the file and softrebooted. Not working.
Am I doing something wrong?

Are you sure it isn't working? Did you put it in the right place?
19th October 2017, 05:03 PM |#8  
RichBordoni's Avatar
Member
Flag New York
Thanks Meter: 21
 
More
A little off-topic, but do you have any idea if something similar can be done for the brightness slider? Basically I would like to be able to set it to stick to increments of 5% or 10% when adjusting. Is there a similar setting I can change using ADB?
19th October 2017, 05:23 PM |#9  
Zacharee1's Avatar
OP Recognized Developer / Retired Forum Moderator
Thanks Meter: 3,549
 
Donate to Me
More
Quote:
Originally Posted by RichBordoni

A little off-topic, but do you have any idea if something similar can be done for the brightness slider? Basically I would like to be able to set it to stick to increments of 5% or 10% when adjusting. Is there a similar setting I can change using ADB?

Every time I fiddle with brightness something bootloops.
19th October 2017, 05:34 PM |#10  
Senior Member
Thanks Meter: 39
 
More
Quote:
Originally Posted by Zacharee1

Are you sure it isn't working? Did you put it in the right place?

Permission are also correct I think
Attached Thumbnails
Click image for larger version

Name:	Capture+_2017-10-19-10-32-16.png
Views:	436
Size:	82.9 KB
ID:	4307863  
19th October 2017, 06:48 PM |#11  
Senior Member
Flag Vikbolandet
Thanks Meter: 56
 
More
Update: Hmm, my phone soft restarts with incoming or out coming calls with this mod, fixed it by restoring my original file.
Just a heads up! Backup your old file.

H990DS V11i-GLOBAL-COM(flashed V10j Indonesia from V10g SEA)
The Following User Says Thank You to 3mL For This Useful Post: [ View ] Gift 3mL Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes