settingsoverlayandroid-sourcedefault-valueandroid-settings

How to set default settings in android overlay (captive portal mode)


I am working an aosp project. For this project, I want to set the captive portal check off by default in the aosp build. I figured and tested that I can set the setting via:

settings put global captive_portal_detection_enabled 0 

see also https://www.kuketz-blog.de/android-captive-portal-check-aenderung/

So usually I will set this by using the overlay mechanism for the resources in the device, for example in overlay/frameworks/base/core/packages/settingsprovider/res/value:

<resources>
    <!-- disable lockscreen by default to avoid showing of user switcher -->
    <bool name="def_lockscreen_disabled">true</bool>
</resources>

I figured, that the default value for the captive portal is in the aosp ConnectivityService defined like

        private int getCaptivePortalMode() {
            return Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.CAPTIVE_PORTAL_MODE,
                    Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
        }

I tried several ways to override it but prepending config_ or _def does not work, adding the entry by

<resources>
<!-- disable captive portal checking -->
    <add-resource type="integer" name="config_captive_portal_mode"/>
    <integer name="config_captive_portal_mode">0</integer>
</resources>

now I only have 2 options left, but I do not like any of them: a) patch aosp -> have troubles with updates b) run a script on the first startup -> ugly

Did I miss something?


Solution

  • Alains answer is what I was looking for.

    You'd need to add some logic to check whether the device is booting for the first time or not, through a file in userdata for example.