IpConfigStore: Changes for parsing old wifi backup
Some changes in IpConfigStore to parse old backup data. The old backup
data contained a raw byte dump of the ipconfig.txt. So, make changes in
IpConfigStore to parse the inputstream from backup data into
IpConfiguration objects.
Changes in the CL:
1. Make the |readIpAndProxyConfigurations| method static so that
it can be used as a utility for parsing the backup data.
2. Create a new version of |readIpAndProxyConfigurations| method to
accept an input stream parameter.
3. Make |writeConfig| method static so that it can be used for
unit-testing the backup migration logic.
BUG: 29075035
Change-Id: Ic074952d9f9ef143089a371e6c527470cb1c229c
(cherry picked from commit ad683cadb2)
This commit is contained in:
committed by
Mitchell Wills
parent
55e82ab60f
commit
88e33a2864
@@ -27,6 +27,7 @@ import android.net.StaticIpConfiguration;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.server.net.DelayedDiskWrite;
|
import com.android.server.net.DelayedDiskWrite;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@@ -34,7 +35,9 @@ import java.io.DataInputStream;
|
|||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
|
|
||||||
@@ -67,7 +70,8 @@ public class IpConfigStore {
|
|||||||
this(new DelayedDiskWrite());
|
this(new DelayedDiskWrite());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeConfig(DataOutputStream out, int configKey,
|
@VisibleForTesting
|
||||||
|
public static boolean writeConfig(DataOutputStream out, int configKey,
|
||||||
IpConfiguration config) throws IOException {
|
IpConfiguration config) throws IOException {
|
||||||
boolean written = false;
|
boolean written = false;
|
||||||
|
|
||||||
@@ -171,12 +175,25 @@ public class IpConfigStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
|
public static SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
|
||||||
SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
|
BufferedInputStream bufferedInputStream;
|
||||||
|
try {
|
||||||
|
bufferedInputStream = new BufferedInputStream(new FileInputStream(filePath));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// Return an empty array here because callers expect an empty array when the file is
|
||||||
|
// not present.
|
||||||
|
loge("Error opening configuration file: " + e);
|
||||||
|
return new SparseArray<>();
|
||||||
|
}
|
||||||
|
return readIpAndProxyConfigurations(bufferedInputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SparseArray<IpConfiguration> readIpAndProxyConfigurations(
|
||||||
|
InputStream inputStream) {
|
||||||
|
SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
|
||||||
DataInputStream in = null;
|
DataInputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath)));
|
in = new DataInputStream(inputStream);
|
||||||
|
|
||||||
int version = in.readInt();
|
int version = in.readInt();
|
||||||
if (version != 2 && version != 1) {
|
if (version != 2 && version != 1) {
|
||||||
@@ -327,11 +344,11 @@ public class IpConfigStore {
|
|||||||
return networks;
|
return networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loge(String s) {
|
protected static void loge(String s) {
|
||||||
Log.e(TAG, s);
|
Log.e(TAG, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void log(String s) {
|
protected static void log(String s) {
|
||||||
Log.d(TAG, s);
|
Log.d(TAG, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user