1818#include <libgen.h>
1919char * gamestart = NULL ;
2020pid_t game_pid = 0 ;
21+ GameOptions opts ;
2122
2223int main (int argc , char * argv []) {
2324
@@ -89,7 +90,9 @@ int main(int argc, char* argv[]) {
8990 bool need_profile_checkup = false;
9091 MLBBState mlbb_is_running = MLBB_NOT_RUNNING ;
9192 static bool is_initialize_complete = false;
92- ProfileMode cur_mode = PERFCOMMON ;
93+ ProfileMode cur_mode = PERFCOMMON ;
94+ static bool dnd_enabled = false;
95+ static int saved_refresh_rate = -1 ;
9396
9497 log_zenith (LOG_INFO , "Daemon started as PID %d" , getpid ());
9598 setspid ();
@@ -170,17 +173,17 @@ int main(int argc, char* argv[]) {
170173
171174 // Only fetch gamestart when user not in-game
172175 // prevent overhead from dumpsys commands.
173- if (!gamestart ) {
174- gamestart = get_gamestart ();
176+ if (!gamestart ) {
177+ gamestart = get_gamestart (& opts );
175178 } else if (game_pid != 0 && kill (game_pid , 0 ) == -1 ) [[clang ::unlikely ]] {
176179 log_zenith (LOG_INFO , "Game %s exited, resetting profile..." , gamestart );
177180 game_pid = 0 ;
178181 free (gamestart );
179- gamestart = get_gamestart ();
182+ gamestart = get_gamestart (& opts );
180183 // Force profile recheck to make sure new game session get boosted
181184 need_profile_checkup = true;
182185 }
183-
186+
184187 if (gamestart )
185188 mlbb_is_running = handle_mlbb (gamestart );
186189
@@ -198,18 +201,90 @@ int main(int argc, char* argv[]) {
198201 gamestart = NULL ;
199202 continue ;
200203 }
201-
204+
202205 cur_mode = PERFORMANCE_PROFILE ;
203206 need_profile_checkup = false;
204207 log_zenith (LOG_INFO , "Applying performance profile for %s" , gamestart );
205- toast ("Applying Performance Profile" );
206- set_priority (game_pid );
208+ toast ("Applying Performance Profile" );
209+
210+ if (IS_TRUE (opts .perf_lite_mode )) {
211+ systemv ("setprop persist.sys.azenithconf.litemode 1" );
212+ } else if (IS_FALSE (opts .perf_lite_mode )) {
213+ systemv ("setprop persist.sys.azenithconf.litemode 0" );
214+ } else {
215+ char lite_prop [PROP_VALUE_MAX ] = {0 };
216+ __system_property_get ("persist.sys.azenithconf.cpulimit" , lite_prop );
217+ if (strcmp (lite_prop , "1" ) == 0 ) {
218+ systemv ("setprop persist.sys.azenithconf.litemode 1" );
219+ } else {
220+ systemv ("setprop persist.sys.azenithconf.litemode 0" );
221+ }
222+ }
223+
224+ if (strcmp (opts .renderer , "vulkan" ) == 0 ) {
225+ systemv ("sys.azenith-utilityconf setrender skiavk" );
226+ } else if (strcmp (opts .renderer , "skiagl" ) == 0 ) {
227+ systemv ("sys.azenith-utilityconf setrender skiagl" );
228+ } else {
229+ // Do Nothing
230+ }
231+
232+ if (IS_TRUE (opts .app_priority )) {
233+ set_priority (game_pid );
234+ } else if (IS_FALSE (opts .app_priority )) {
235+ // do nothing
236+ } else {
237+ char val [PROP_VALUE_MAX ] = {0 };
238+ if (__system_property_get ("persist.sys.azenithconf.iosched" , val ) > 0 ) {
239+ if (val [0 ] == '1' ) {
240+ set_priority (game_pid );
241+ }
242+ }
243+ }
244+
245+ if (IS_TRUE (opts .dnd_on_gaming )) {
246+ systemv ("sys.azenith-utilityconf enableDND" );
247+ dnd_enabled = true;
248+ } else if (IS_FALSE (opts .dnd_on_gaming )) {
249+ // do nothing
250+ } else {
251+ char dnd_state [PROP_VALUE_MAX ] = {0 };
252+ __system_property_get ("persist.sys.azenithconf.dnd" , dnd_state );
253+ if (strcmp (dnd_state , "1" ) == 0 ) {
254+ systemv ("sys.azenith-utilityconf enableDND" );
255+ dnd_enabled = true;
256+ }
257+ }
258+
259+ if (!IS_DEFAULT (opts .refresh_rate )) {
260+ int rr = atoi (opts .refresh_rate );
261+
262+ if (rr >= 60 && rr <= 144 ) {
263+
264+ if (saved_refresh_rate < 0 ) {
265+ saved_refresh_rate = get_current_refresh_rate ();
266+ log_zenith (LOG_INFO , "Saved refresh rate: %d" , saved_refresh_rate );
267+ }
268+
269+ systemv ("sys.azenith-utilityconf setrefreshrates %d" , rr );
270+ }
271+
272+ } else {
273+ // do nothing
274+ }
275+
207276 run_profiler (PERFORMANCE_PROFILE );
208-
209- char preload_active [PROP_VALUE_MAX ] = {0 };
210- __system_property_get ("persist.sys.azenithconf.APreload" , preload_active );
211- if (strcmp (preload_active , "1" ) == 0 ) {
277+
278+ if (IS_TRUE (opts .game_preload )) {
212279 GamePreload (gamestart );
280+ } else if (IS_FALSE (opts .game_preload )) {
281+ // do nothing
282+ } else {
283+ char preload_active [PROP_VALUE_MAX ] = {0 };
284+ __system_property_get ("persist.sys.azenithconf.APreload" , preload_active );
285+ if (strcmp (preload_active , "1" ) == 0 ) {
286+ GamePreload (gamestart );
287+ }
213288 }
214289 } else if (is_initialize_complete && get_low_power_state ()) {
215290 // Bail out if we already on powersave profile
@@ -220,8 +295,24 @@ int main(int argc, char* argv[]) {
220295 need_profile_checkup = false;
221296 log_zenith (LOG_INFO , "Applying ECO Mode" );
222297 toast ("Applying Eco Mode" );
223- run_profiler (ECO_MODE );
224-
298+ char renderer [PROP_VALUE_MAX ] = {0 };
299+ __system_property_get ("persist.sys.azenithconf.renderer" , renderer );
300+ if (strcmp (renderer , "vulkan" ) == 0 ) {
301+ systemv ("sys.azenith-utilityconf setrender skiavk" );
302+
303+ } else {
304+ systemv ("sys.azenith-utilityconf setrender skiagl" );
305+
306+ }
307+ if (saved_refresh_rate > 0 ) {
308+ systemv ("sys.azenith-utilityconf setrefreshrates %d" , saved_refresh_rate );
309+ saved_refresh_rate = -1 ;
310+ }
311+ if (dnd_enabled ) {
312+ systemv ("sys.azenith-utilityconf disableDND" );
313+ dnd_enabled = false;
314+ }
315+ run_profiler (ECO_MODE );
225316 } else {
226317 // Bail out if we already on normal profile
227318 if (cur_mode == BALANCED_PROFILE )
@@ -230,7 +321,24 @@ int main(int argc, char* argv[]) {
230321 cur_mode = BALANCED_PROFILE ;
231322 need_profile_checkup = false;
232323 log_zenith (LOG_INFO , "Applying Balanced profile" );
233- toast ("Applying Balanced profile" );
324+ toast ("Applying Balanced profile" );
325+ char renderer [PROP_VALUE_MAX ] = {0 };
326+ __system_property_get ("persist.sys.azenithconf.renderer" , renderer );
327+ if (strcmp (renderer , "vulkan" ) == 0 ) {
328+ systemv ("sys.azenith-utilityconf setrender skiavk" );
329+
330+ } else {
331+ systemv ("sys.azenith-utilityconf setrender skiagl" );
332+
333+ }
334+ if (saved_refresh_rate > 0 ) {
335+ systemv ("sys.azenith-utilityconf setrefreshrates %d" , saved_refresh_rate );
336+ saved_refresh_rate = -1 ;
337+ }
338+ if (dnd_enabled ) {
339+ systemv ("sys.azenith-utilityconf disableDND" );
340+ dnd_enabled = false;
341+ }
234342 if (!is_initialize_complete ) {
235343 notify ("AZenith is running successfully" );
236344 is_initialize_complete = true;
0 commit comments