[Android General] Grouxho:
Mod-Guide - Volume Safe Warning with checkbox (Reference - S7 Edge Nougat Beta 4)

- Enable and disable volume safe warning with checkbox, no reboot needed.

- Existing observer used.

We work on services.jar

1.- Extract classes.dex and dissasemble it.

2. Go to folder com/android/server/audio and edit Audioservice.smali

. Below # instance fields add

.field public mGrxAvisoVolumen:I

(for future uses.., not needed for now if you don�t want to, in this case delete any reference to it!)

. Look for .method public constructor <init>(Landroid/content/Context;)V and find the return-void instruction. Just above retunr-void add following lines (in blue colour)

(needed to setup the mod on boot)

........
:cond_91f

[COLOR="blue"]	move-object/from16 v0, p0

invoke-virtual {v0}, Lcom/android/server/audio/AudioService;->grx_actualiza_aviso_volumen()V[/COLOR]

return-void

. Look for # virtual methods and just below add this method

[COLOR="RoyalBlue"].method public grx_actualiza_aviso_volumen()V
.registers 5

iget-object v0, p0, Lcom/android/server/audio/AudioService;->mContext:Landroid/content/Context;

invoke-virtual {v0}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

const-string/jumbo v1, "b_aviso_volumen"

const/4 v2, 0x1 #Checkbox default value

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

move-result v2

iput v2, p0, Lcom/android/server/audio/AudioService;->mGrxAvisoVolumen:I #delete this if you did not use the var for future uses..

const/4 v1, 0x0

const/4 v0, 0x0

if-eqz v2, :cond_seguir

const/4 v0, 0x1

:cond_seguir

invoke-direct {p0, v0, v1}, Lcom/android/server/audio/AudioService;->setSafeMediaVolumeEnabled(ZLjava/lang/String;)V #activa o desactiva el aviso

return-void

.end method[/COLOR]

- Now, edit com/android/server/audio/AudioService$SettingsObserver.server and

. just below # instance fields tag, add

.field private mGrxAvisoVolumen:Landroid/net/Uri;

. Just above const-string/jumbo v1, "mode_ringer_streams_affected" (inside .method constructor <init>(Lcom/android/server/audio/AudioService;)V) add the following block of code

[COLOR="RoyalBlue"] const-string/jumbo v1, "b_aviso_volumen"

invoke-static {v1}, Landroid/provider/Settings$System;->getUriFor(Ljava/lang/String;)Landroid/net/Uri;

move-result-object v1

iput-object v1, p0, Lcom/android/server/audio/AudioService$SettingsObserver;->mGrxAvisoVolumen:Landroid/net/Uri;

invoke-virtual {v0, v1, v2, p0}, Landroid/content/ContentResolver;->registerContentObserver(Landroid/net/Uri;ZLandroid/database/ContentObserver;)V[/COLOR]

const-string/jumbo v1, "mode_ringer_streams_affected"

. Finally, add the following method at the end of the smali.

(fixed 8/1/17)

.method public onChange(ZLandroid/net/Uri;)V
.registers 5

iget-object v0, p0, Lcom/android/server/audio/AudioService$SettingsObserver;->mGrxAvisoVolumen:Landroid/net/Uri;

invoke-virtual {p2, v0}, Landroid/net/Uri;->equals(Ljava/lang/Object;)Z

move-result v0

if-eqz v0, :cond_d

invoke-super {p0, p1, p2}, Landroid/database/ContentObserver;->onChange(ZLandroid/net/Uri;)V

iget-object v0, p0, Lcom/android/server/audio/AudioService$SettingsObserver;->this$0:Lcom/android/server/audio/AudioService;

invoke-virtual {v0}, Lcom/android/server/audio/AudioService;->grx_actualiza_aviso_volumen()V

:goto_0

return-void

:cond_d

invoke-virtual {p0, p1}, Lcom/android/server/audio/AudioService$SettingsObserver;->onChange(Z)V

goto: goto_0
.end method

- Assemble classes.dex and put it into services.jar and flash it.

- Rom Control/Other preferences app.

Add a checkbox, similar to the following one:

<[B]..CheckBoxPreference[/B] android:defaultValue="true" android:key="b_aviso_volumen" android:title="Volume Safe Warning" android:summary="If been enabled you disabled the warning in the dialog, you will to enable and disable this checkbox to get it back again." />

Attached you will find the original and modified code for making easier both the implementation and its migration to future releases.

If you want the volume safe warning to be permanently disabled

- Decompile SystemUI.apk

- Look for com/android/systemui/volume/VolumeDialogController.smali

- find .method private onShowSafetyWarningW(I)V and replace the whole method with this one

.method private onShowSafetyWarningW(I)V
.locals 2

iget-object v0, p0, Lcom/android/systemui/volume/VolumeDialogController;->mAudio:Landroid/media/AudioManager;

invoke-virtual {v0}, Landroid/media/AudioManager;->disableSafeMediaVolume()V

return-void

.end method

Enjoy.