Merge Android 12
Bug: 202323961 Merged-In: Iba1443da42161f4a41830081f2e1985b30444cc0 Change-Id: I2bebe60bb7114706a3ba6af35522268cdf031f41
This commit is contained in:
@@ -104,7 +104,10 @@ public final class NetworkStateSnapshot implements Parcelable {
|
||||
return mSubscriberId;
|
||||
}
|
||||
|
||||
/** Get the legacy type of the network associated with this snapshot. */
|
||||
/**
|
||||
* Get the legacy type of the network associated with this snapshot.
|
||||
* @return the legacy network type. See {@code ConnectivityManager#TYPE_*}.
|
||||
*/
|
||||
public int getLegacyType() {
|
||||
return mLegacyType;
|
||||
}
|
||||
|
||||
@@ -889,7 +889,7 @@ public class NsdService extends INsdManager.Stub {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("mChannel ").append(mChannel).append("\n");
|
||||
sb.append("mMessenger ").append(mMessenger).append("\n");
|
||||
sb.append("mResolvedService ").append(mResolvedService).append("\n");
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.app.AppOpsManager;
|
||||
import android.app.admin.DevicePolicyManagerInternal;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -108,10 +109,17 @@ public final class NetworkStatsAccess {
|
||||
DevicePolicyManagerInternal.class);
|
||||
final TelephonyManager tm = (TelephonyManager)
|
||||
context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
boolean hasCarrierPrivileges = tm != null &&
|
||||
tm.checkCarrierPrivilegesForPackageAnyPhone(callingPackage) ==
|
||||
TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
|
||||
boolean isDeviceOwner = dpmi != null && dpmi.isActiveDeviceOwner(callingUid);
|
||||
boolean hasCarrierPrivileges;
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
hasCarrierPrivileges = tm != null
|
||||
&& tm.checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
|
||||
== TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
|
||||
final boolean isDeviceOwner = dpmi != null && dpmi.isActiveDeviceOwner(callingUid);
|
||||
final int appId = UserHandle.getAppId(callingUid);
|
||||
if (hasCarrierPrivileges || isDeviceOwner
|
||||
|| appId == Process.SYSTEM_UID || appId == Process.NETWORK_STACK_UID) {
|
||||
|
||||
@@ -54,6 +54,8 @@ import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.FastDataInput;
|
||||
import com.android.internal.util.FastDataOutput;
|
||||
import com.android.internal.util.FileRotator;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
|
||||
@@ -89,6 +91,9 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
|
||||
/** File header magic number: "ANET" */
|
||||
private static final int FILE_MAGIC = 0x414E4554;
|
||||
|
||||
/** Default buffer size from BufferedInputStream */
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
private static final int VERSION_NETWORK_INIT = 1;
|
||||
|
||||
private static final int VERSION_UID_INIT = 1;
|
||||
@@ -435,7 +440,8 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
|
||||
|
||||
@Override
|
||||
public void read(InputStream in) throws IOException {
|
||||
read((DataInput) new DataInputStream(in));
|
||||
final FastDataInput dataIn = new FastDataInput(in, BUFFER_SIZE);
|
||||
read(dataIn);
|
||||
}
|
||||
|
||||
private void read(DataInput in) throws IOException {
|
||||
@@ -474,8 +480,9 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
|
||||
|
||||
@Override
|
||||
public void write(OutputStream out) throws IOException {
|
||||
write((DataOutput) new DataOutputStream(out));
|
||||
out.flush();
|
||||
final FastDataOutput dataOut = new FastDataOutput(out, BUFFER_SIZE);
|
||||
write(dataOut);
|
||||
dataOut.flush();
|
||||
}
|
||||
|
||||
private void write(DataOutput out) throws IOException {
|
||||
|
||||
@@ -39,6 +39,8 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@@ -53,8 +55,8 @@ public class IpConfigStoreTest {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
DataOutputStream outputStream = new DataOutputStream(byteStream);
|
||||
|
||||
IpConfiguration expectedConfig = new IpConfiguration(IpAssignment.DHCP,
|
||||
ProxySettings.NONE, null, null);
|
||||
final IpConfiguration expectedConfig =
|
||||
newIpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null);
|
||||
|
||||
// Emulate writing to old format.
|
||||
writeDhcpConfigV2(outputStream, KEY_CONFIG, expectedConfig);
|
||||
@@ -78,18 +80,23 @@ public class IpConfigStoreTest {
|
||||
final String DNS_IP_ADDR_1 = "1.2.3.4";
|
||||
final String DNS_IP_ADDR_2 = "5.6.7.8";
|
||||
|
||||
StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
|
||||
staticIpConfiguration.ipAddress = new LinkAddress(IP_ADDR_1);
|
||||
staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1));
|
||||
staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2));
|
||||
final ArrayList<InetAddress> dnsServers = new ArrayList<>();
|
||||
dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1));
|
||||
dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2));
|
||||
final StaticIpConfiguration staticIpConfiguration1 = new StaticIpConfiguration.Builder()
|
||||
.setIpAddress(new LinkAddress(IP_ADDR_1))
|
||||
.setDnsServers(dnsServers).build();
|
||||
final StaticIpConfiguration staticIpConfiguration2 = new StaticIpConfiguration.Builder()
|
||||
.setIpAddress(new LinkAddress(IP_ADDR_2))
|
||||
.setDnsServers(dnsServers).build();
|
||||
|
||||
ProxyInfo proxyInfo =
|
||||
ProxyInfo.buildDirectProxy("10.10.10.10", 88, Arrays.asList("host1", "host2"));
|
||||
|
||||
IpConfiguration expectedConfig1 = newIpConfiguration(IpAssignment.STATIC,
|
||||
ProxySettings.STATIC, staticIpConfiguration, proxyInfo);
|
||||
IpConfiguration expectedConfig2 = new IpConfiguration(expectedConfig1);
|
||||
expectedConfig2.getStaticIpConfiguration().ipAddress = new LinkAddress(IP_ADDR_2);
|
||||
ProxySettings.STATIC, staticIpConfiguration1, proxyInfo);
|
||||
IpConfiguration expectedConfig2 = newIpConfiguration(IpAssignment.STATIC,
|
||||
ProxySettings.STATIC, staticIpConfiguration2, proxyInfo);
|
||||
|
||||
ArrayMap<String, IpConfiguration> expectedNetworks = new ArrayMap<>();
|
||||
expectedNetworks.put(IFACE_1, expectedConfig1);
|
||||
@@ -107,14 +114,24 @@ public class IpConfigStoreTest {
|
||||
assertEquals(expectedNetworks.get(IFACE_2), actualNetworks.get(IFACE_2));
|
||||
}
|
||||
|
||||
private IpConfiguration newIpConfiguration(IpAssignment ipAssignment,
|
||||
ProxySettings proxySettings, StaticIpConfiguration staticIpConfig, ProxyInfo info) {
|
||||
final IpConfiguration config = new IpConfiguration();
|
||||
config.setIpAssignment(ipAssignment);
|
||||
config.setProxySettings(proxySettings);
|
||||
config.setStaticIpConfiguration(staticIpConfig);
|
||||
config.setHttpProxy(info);
|
||||
return config;
|
||||
}
|
||||
|
||||
// This is simplified snapshot of code that was used to store values in V2 format (key as int).
|
||||
private static void writeDhcpConfigV2(DataOutputStream out, int configKey,
|
||||
IpConfiguration config) throws IOException {
|
||||
out.writeInt(2); // VERSION 2
|
||||
switch (config.ipAssignment) {
|
||||
switch (config.getIpAssignment()) {
|
||||
case DHCP:
|
||||
out.writeUTF("ipAssignment");
|
||||
out.writeUTF(config.ipAssignment.toString());
|
||||
out.writeUTF(config.getIpAssignment().toString());
|
||||
break;
|
||||
default:
|
||||
fail("Not supported in test environment");
|
||||
|
||||
Reference in New Issue
Block a user