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

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

Merge "SettingsProvider: Use new API for softap config backup/restore"

parents fa4ea4eb 23a864da
Loading
Loading
Loading
Loading
+7 −16
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import android.database.Cursor;
import android.net.NetworkPolicy;
import android.net.NetworkPolicyManager;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.ParcelFileDescriptor;
@@ -875,32 +875,23 @@ public class SettingsBackupAgent extends BackupAgentHelper {
    }

    private byte[] getSoftAPConfiguration() {
        try {
            return mWifiManager.getWifiApConfiguration().getBytesForBackup();
        } catch (IOException ioe) {
            Log.e(TAG, "Failed to marshal SoftAPConfiguration" + ioe.getMessage());
            return new byte[0];
        }
        return mWifiManager.retrieveSoftApBackupData();
    }

    private void restoreSoftApConfiguration(byte[] data) {
        try {
            WifiConfiguration config = WifiConfiguration
                    .getWifiConfigFromBackup(new DataInputStream(new ByteArrayInputStream(data)));
            if (DEBUG) Log.d(TAG, "Successfully unMarshaled WifiConfiguration ");
            int originalApBand = config.apBand;
            mWifiManager.setWifiApConfiguration(config);
        SoftApConfiguration config = mWifiManager.restoreSoftApBackupData(data);
        if (config != null) {
            int originalApBand = config.getBand();
            if (DEBUG) Log.d(TAG, "Successfully unMarshaled SoftApConfiguration ");

            // Depending on device hardware, we may need to notify the user of a setting change for
            // the apBand preference
            boolean dualMode = mWifiManager.isDualModeSupported();
            int storedApBand = mWifiManager.getWifiApConfiguration().apBand;
            int storedApBand = mWifiManager.getSoftApConfiguration().getBand();
            if (dualMode && storedApBand != originalApBand) {
                Log.d(TAG, "restored ap configuration requires a conversion, notify the user");
                WifiSoftApBandChangedNotifier.notifyUserOfApBandConversion(this);
            }
        } catch (IOException | BackupUtils.BadVersionException e) {
            Log.e(TAG, "Failed to unMarshal SoftAPConfiguration " + e.getMessage());
        }
    }