Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3779fb5f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "NetworkPolicyManagerService: Allow data saver to be on by default."

parents e60bef09 94bcdbca
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -7744,6 +7744,16 @@ public final class Settings {
         */
        public static final String CDMA_SUBSCRIPTION_MODE = "subscription_mode";

        /**
         * The default value for whether background data is enabled or not.
         *
         * Used by {@code NetworkPolicyManagerService}.
         *
         * @hide
         */
        public static final String DEFAULT_RESTRICT_BACKGROUND_DATA =
                "default_restrict_background_data";

        /** Inactivity timeout to track mobile data activity.
        *
        * If set to a positive integer, it indicates the inactivity timeout value in seconds to
+1 −0
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@ public class SettingsBackupTest {
                    Settings.Global.DEBUG_VIEW_ATTRIBUTES,
                    Settings.Global.DEFAULT_DNS_SERVER,
                    Settings.Global.DEFAULT_INSTALL_LOCATION,
                    Settings.Global.DEFAULT_RESTRICT_BACKGROUND_DATA,
                    Settings.Global.DESK_DOCK_SOUND,
                    Settings.Global.DESK_UNDOCK_SOUND,
                    Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT,
+3 −0
Original line number Diff line number Diff line
@@ -187,4 +187,7 @@

    <!--  default setting for Settings.System.END_BUTTON_BEHAVIOR : END_BUTTON_BEHAVIOR_SLEEP -->
    <integer name="def_end_button_behavior">0x2</integer>

    <!-- default setting for Settings.Global.DEFAULT_RESTRICT_BACKGROUND_DATA -->
    <bool name="def_restrict_background_data">false</bool>
</resources>
+19 −5
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.database.Cursor;
@@ -61,7 +59,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.provider.Settings.Global;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -82,7 +80,6 @@ import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.ByteBuffer;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@@ -2895,7 +2892,7 @@ public class SettingsProvider extends ContentProvider {
        }

        private final class UpgradeController {
            private static final int SETTINGS_VERSION = 146;
            private static final int SETTINGS_VERSION = 147;

            private final int mUserId;

@@ -3422,6 +3419,23 @@ public class SettingsProvider extends ContentProvider {
                    currentVersion = 146;
                }

                if (currentVersion == 146) {
                    // Version 146: Set the default value for DEFAULT_RESTRICT_BACKGROUND_DATA.
                    if (userId == UserHandle.USER_SYSTEM) {
                        final SettingsState globalSettings = getGlobalSettingsLocked();
                        final Setting currentSetting = globalSettings.getSettingLocked(
                                Global.DEFAULT_RESTRICT_BACKGROUND_DATA);
                        if (currentSetting.isNull()) {
                            globalSettings.insertSettingLocked(
                                    Global.DEFAULT_RESTRICT_BACKGROUND_DATA,
                                    getContext().getResources().getBoolean(
                                            R.bool.def_restrict_background_data) ? "1" : "0",
                                    null, true, SettingsState.SYSTEM_PACKAGE_NAME);
                        }
                    }
                    currentVersion = 147;
                }

                // vXXX: Add new settings above this point.

                if (currentVersion != newVersion) {
+18 −11
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
@@ -1896,7 +1897,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {

        } catch (FileNotFoundException e) {
            // missing policy is okay, probably first boot
            upgradeLegacyBackgroundDataUL();
            upgradeDefaultBackgroundDataUL();
        } catch (IOException e) {
            Log.wtf(TAG, "problem reading network policy", e);
        } catch (XmlPullParserException e) {
@@ -1910,16 +1911,22 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
     * Upgrade legacy background data flags, notifying listeners of one last
     * change to always-true.
     */
    private void upgradeLegacyBackgroundDataUL() {
        mRestrictBackground = Settings.Secure.getInt(
                mContext.getContentResolver(), Settings.Secure.BACKGROUND_DATA, 1) != 1;

        // kick off one last broadcast if restricted
        if (mRestrictBackground) {
            final Intent broadcast = new Intent(
                    ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
            mContext.sendBroadcastAsUser(broadcast, UserHandle.ALL);
        }
    private void upgradeDefaultBackgroundDataUL() {
        // This method is only called when we're unable to find the network policy flag, which
        // usually happens on first boot of a new device and not one that has received an OTA.

        // Seed from the default value configured for this device.
        mRestrictBackground = Settings.Global.getInt(
                mContext.getContentResolver(), Global.DEFAULT_RESTRICT_BACKGROUND_DATA, 0) == 1;

        // NOTE: We used to read the legacy setting here :
        //
        // final int legacyFlagValue = Settings.Secure.getInt(
        //        mContext.getContentResolver(), Settings.Secure.BACKGROUND_DATA, ..);
        //
        // This is no longer necessary because we will never upgrade directly from Gingerbread
        // to O+. Devices upgrading from ICS onwards to O will have a netpolicy.xml file that
        // contains the correct value that we will continue to use.
    }

    /**