[Android General] Grouxho:
Screen off TimeOuts Tile - User Screen and Lock Screen (normal mode and power save mode)

Features

- Tile fully embedded in ui

- The tile allows to change the screen off time out (synchronized withe the settings option).

- The detailed view (when clicking on the text) allows us to change the normal lockscreen screen off time both in normal and power save mode (between 3 and 30secs each)

Guide

- Download and extract attached zip

- Decompile SystemUI

1- Put the provided pngs into res - drawables inside SystemUI

2.- Edit res - values - strings.xml and add provided strings. Do the same for spanish languaje if you want to in res - values-es - strings.xml

3.- Take from attached files the qs_detail_grxscreenofftime.xml and place it in your ui in res-layout

4.- This step is optional. Because of sammy code all non stock tiles generated an exception log lin when it is clicked. It is not important, but.... i do not like to see it, so if you want to avoid it do the following:

In Systemui edit res-values-arrays.xml, look for this array : <string-array name="tile_ids"> and befor the array is closed add the following 4 lines

<item>GrxScreenOnTime</item>
<item>999</item>
<item>9999</item>
<item>9999</item>
</string-array>

5.- Copy from the attached files the 5 smalies you will find in smali\com\android\systemui\qs\tiles. Copy them in your ui, in the same path.

Now we are going to add the support for the mod to control screen off times in lock screen

6.- Edit statusbar.smali and at the end of the smali add the following method

.method public grxUpdateLockScreenTimeOff()V
.locals 1

iget-object v0, p0, Lcom/android/systemui/statusbar/phone/StatusBar;->mStatusBarWindowManager:Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;

if-eqz v0, :cond_0

iget-object v0, p0, Lcom/android/systemui/statusbar/phone/StatusBar;->mStatusBarWindowManager:Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;

invoke-virtual {v0}, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->grxUpdateLockScreenTimeOff()V

:cond_0
return-void
.end method

This is the code called from the tile when we change the value of the seekbars. We have to do this because mStatusBarWindowManager is a protected var, so instead of changing that class of var it is better to add this little method.

7.- Finally, we edit StatusBarWindowManager.smali to add the screen off timeout mod for lock screen by adding the following changes:

- Add these 2 vars after the instance fields tag

# instance fields

.field private mGrxLsTimeOutNormal:J

.field private mGrxLsTimeOutPowerSave:J

- Look for this method .method public constructor <init>(Landroid/content/Context;)V

Find the line where context is set and add the following line

...
...
iput-object p1, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mContext:Landroid/content/Context; ### buscamos esta línea

invoke-virtual {p0}, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->grxReadScreenOffTimeOutValues()V ## añadimos esta línea

const-string/jumbo v0, "window"
...

- At the end of the smali add these 2 methods

.method public grxReadScreenOffTimeOutValues()V
.locals 4

iget-object v0, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mContext:Landroid/content/Context;

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

move-result-object v0

const-string v1, "toff_ls_normal"

const v2, 0x5

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

move-result v2
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

:goto_0
const v1, 0x3e8

mul-int v2, v2, v1

int-to-long v2, v2

iput-wide v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mGrxLsTimeOutNormal:J

const-string v1, "toff_ls_psm"

const v2, 0x3

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

move-result v2
:try_end_1
.catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1

:goto_1
const v1, 0x3e8

mul-int v2, v2, v1

int-to-long v2, v2

iput-wide v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mGrxLsTimeOutPowerSave:J

return-void

:catch_0
move-exception v1

const v2, 0x5

goto :goto_0

:catch_1
move-exception v1

const v2, 0x3

goto :goto_1
.end method

.method public grxUpdateLockScreenTimeOff()V
.locals 1

invoke-virtual {p0}, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->grxReadScreenOffTimeOutValues()V

const/4 v0, 0x1

invoke-virtual {p0, v0}, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->updateUserActivityTimeout(Z)V

return-void
.end method

- And finally, look for the .method public getUserActivityTimeout()J and do the following changes

.method public getUserActivityTimeout()J
.locals 8

##const-wide/16 v6, 0x1388 ## remove this line

##const-wide/16 v4, 0xbb8 ## remove this line

iget-wide v6, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mGrxLsTimeOutNormal:J ### add this line

iget-wide v4, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mGrxLsTimeOutPowerSave:J ### add this line

sget v2, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->AWAKE_INTERVAL_DEFAULT_MS_DEFAULT:I

int-to-long v0, v2

invoke-static {}, Lcom/android/systemui/util/SettingsHelper;->getInstance()Lcom/android/systemui/util/SettingsHelper;

move-result-object v2

invoke-virtual {v2}, Lcom/android/systemui/util/SettingsHelper;->isSmartStayEnabled()Z

move-result v2

if-eqz v2, :cond_0

## invoke-static {v6, v7, v0, v1}, Ljava/lang/Math;->min(JJ)J ## remove this line

### move-result-wide v0 ## remove this line

move-wide v0, v6 ### add this line

:cond_0
sget-boolean v2, Lcom/android/systemui/Rune;->KEYGUARD_SUPPORT_HIGH_PERFORMANCE_MODE:Z

if-eqz v2, :cond_1

invoke-static {}, Lcom/android/systemui/util/SettingsHelper;->getInstance()Lcom/android/systemui/util/SettingsHelper;

move-result-object v2

invoke-virtual {v2}, Lcom/android/systemui/util/SettingsHelper;->isNormalInHighPerformanceMode()Z

move-result v2

if-eqz v2, :cond_1

##invoke-static {v6, v7, v0, v1}, Ljava/lang/Math;->min(JJ)J ## remove this line

##move-result-wide v0 ## remove this line

move-wide v0, v6 ### add this line

:cond_1
iget-object v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mContext:Landroid/content/Context;

invoke-static {v2}, Lcom/android/keyguard/KeyguardUpdateMonitor;->getInstance(Landroid/content/Context;)Lcom/android/keyguard/KeyguardUpdateMonitor;

move-result-object v2

invoke-virtual {v2}, Lcom/android/keyguard/KeyguardUpdateMonitor;->isDexMode()Z

move-result v2

if-eqz v2, :cond_2

sget v2, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->AWAKE_INTERVAL_DEFAULT_MS_DEFAULT:I

int-to-long v0, v2

:cond_2
invoke-static {}, Lcom/android/systemui/util/SettingsHelper;->getInstance()Lcom/android/systemui/util/SettingsHelper;

move-result-object v2

invoke-virtual {v2}, Lcom/android/systemui/util/SettingsHelper;->isEmergencyMode()Z

move-result v2

if-eqz v2, :cond_4

###invoke-static {v4, v5, v0, v1}, Ljava/lang/Math;->min(JJ)J ### remove this line

### move-result-wide v0 ### remove this line

move-wide v0, v4 ## add this line

:cond_3
:goto_0
const-string/jumbo v2, "StatusBarWindowManager"

new-instance v3, Ljava/lang/StringBuilder;

invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

const-string/jumbo v4, "getUserActivityTimeout()"

invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v3

invoke-virtual {v3, v0, v1}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

move-result-object v3

invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v3

invoke-static {v2, v3}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

return-wide v0

:cond_4
invoke-static {}, Lcom/android/systemui/util/SettingsHelper;->getInstance()Lcom/android/systemui/util/SettingsHelper;

move-result-object v2

invoke-virtual {v2}, Lcom/android/systemui/util/SettingsHelper;->isPowerSavingMode()Z

move-result v2

if-eqz v2, :cond_3

iget-object v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mPowerManager:Landroid/os/PowerManager;

if-nez v2, :cond_5

iget-object v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mContext:Landroid/content/Context;

const-string/jumbo v3, "power"

invoke-virtual {v2, v3}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

move-result-object v2

check-cast v2, Landroid/os/PowerManager;

iput-object v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mPowerManager:Landroid/os/PowerManager;

:cond_5
iget-object v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mPowerManager:Landroid/os/PowerManager;

if-eqz v2, :cond_3

iget-object v2, p0, Lcom/android/systemui/statusbar/phone/StatusBarWindowManager;->mPowerManager:Landroid/os/PowerManager;

invoke-virtual {v2}, Landroid/os/PowerManager;->isPowerSaveMode()Z

move-result v2

if-eqz v2, :cond_3

### invoke-static {v4, v5, v0, v1}, Ljava/lang/Math;->min(JJ)J # remove this line

### move-result-wide v0 ## remove this line

move-wide v0, v4 ### add this line

goto :goto_0

.end method

Done

To Enable the toggle

- Clean Install

a.- You can edit strings.xml in SystemUi, look for the following string and add the tile there

<string name="quick_settings_tiles_default">GrxScreenOnTime,Wifi,Sound .....

b.- or edit your csc and look into others.xml or cscfeatures and find (or add if you have not got it, look in google how to) the following

<CscFeature_SystemUI_ConfigDefQuickSettingItem>GrxScreenOnTime,Wifi ....

- Dirty install

Better use method b for clean installs

Well, i think i do not forget anything