@@ -29,6 +29,7 @@ import androidx.preference.PreferenceManager
2929import kotlinx.serialization.*
3030import kotlinx.serialization.json.*
3131import java.io.File
32+ import java.io.FileNotFoundException
3233import java.util.UUID
3334
3435
@@ -109,6 +110,40 @@ class Defaults {
109110 */
110111 this .scaling = 1.0f / Utils .getDisplayMetrics(context, Display .DEFAULT_DISPLAY ).density.coerceAtLeast(1.0f )
111112
113+ /*
114+ Try read defaults from app restrictions
115+ */
116+
117+ val restrictionsManager =
118+ context.getSystemService(Context .RESTRICTIONS_SERVICE ) as android.content.RestrictionsManager
119+ val appConfig = restrictionsManager.applicationRestrictions
120+ if (appConfig != null && appConfig.size() > 0 ) {
121+ this .port = appConfig.getInt(" port" , this .port)
122+ this .portReverse = appConfig.getInt(" portReverse" , this .portReverse)
123+ this .portRepeater = appConfig.getInt(" portRepeater" , this .portRepeater)
124+ this .fileTransfer = appConfig.getBoolean(" fileTransfer" , this .fileTransfer)
125+ this .viewOnly = appConfig.getBoolean(" viewOnly" , this .viewOnly)
126+ this .showPointers = appConfig.getBoolean(" showPointers" , this .showPointers)
127+ this .password = appConfig.getString(" password" , this .password) ? : this .password
128+ this .startOnBoot = appConfig.getBoolean(" startOnBoot" , this .startOnBoot)
129+ this .startOnBootDelay = appConfig.getInt(" startOnBootDelay" , this .startOnBootDelay)
130+
131+ val scalingStr = appConfig.getString(" scaling" , " 0.0" )
132+ try {
133+ val scaling = scalingStr.toFloat()
134+ if (scaling > 0.0f )
135+ this .scaling = scaling
136+ } catch (e: NumberFormatException ) {
137+ Log .w(TAG , " Invalid scaling value in app restrictions: $scalingStr " )
138+ }
139+
140+ val accessKey = appConfig.getString(" accessKey" , " " )
141+ if (accessKey != null && accessKey.isNotEmpty())
142+ this .accessKey = accessKey
143+
144+ return
145+ }
146+
112147 /*
113148 read provided defaults
114149 */
@@ -121,7 +156,7 @@ class Defaults {
121156 this .portRepeater = readDefault.portRepeater
122157 this .fileTransfer = readDefault.fileTransfer
123158 // only set new scaling if there is one given; i.e. don't overwrite generated default
124- if (readDefault.scaling > 0 )
159+ if (readDefault.scaling > 0 )
125160 this .scaling = readDefault.scaling
126161 this .viewOnly = readDefault.viewOnly
127162 this .showPointers = readDefault.showPointers
@@ -133,6 +168,8 @@ class Defaults {
133168 this .startOnBoot = readDefault.startOnBoot
134169 this .startOnBootDelay = readDefault.startOnBootDelay
135170 // add here!
171+ } catch (_: FileNotFoundException ) {
172+ // ignore
136173 } catch (e: Exception ) {
137174 Log .w(TAG , " ${e.message} " )
138175 }
0 commit comments