Merge "[MS31] Fix several hidden API usages"
This commit is contained in:
commit
0892c27c57
@ -18,8 +18,6 @@ package com.android.server.net;
|
|||||||
|
|
||||||
import static android.app.usage.NetworkStatsManager.MIN_THRESHOLD_BYTES;
|
import static android.app.usage.NetworkStatsManager.MIN_THRESHOLD_BYTES;
|
||||||
|
|
||||||
import static com.android.internal.util.Preconditions.checkArgument;
|
|
||||||
|
|
||||||
import android.app.usage.NetworkStatsManager;
|
import android.app.usage.NetworkStatsManager;
|
||||||
import android.net.DataUsageRequest;
|
import android.net.DataUsageRequest;
|
||||||
import android.net.NetworkIdentitySet;
|
import android.net.NetworkIdentitySet;
|
||||||
@ -216,7 +214,10 @@ class NetworkStatsObservers {
|
|||||||
accessLevel);
|
accessLevel);
|
||||||
} else {
|
} else {
|
||||||
// Safety check in case a new access level is added and we forgot to update this
|
// Safety check in case a new access level is added and we forgot to update this
|
||||||
checkArgument(accessLevel >= NetworkStatsAccess.Level.DEVICESUMMARY);
|
if (accessLevel < NetworkStatsAccess.Level.DEVICESUMMARY) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"accessLevel " + accessLevel + " is less than DEVICESUMMARY.");
|
||||||
|
}
|
||||||
return new NetworkUsageRequestInfo(this, request, messenger, binder, callingUid,
|
return new NetworkUsageRequestInfo(this, request, messenger, binder, callingUid,
|
||||||
accessLevel);
|
accessLevel);
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,10 @@ import android.os.DropBoxManager;
|
|||||||
import android.service.NetworkStatsRecorderProto;
|
import android.service.NetworkStatsRecorderProto;
|
||||||
import android.util.IndentingPrintWriter;
|
import android.util.IndentingPrintWriter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.MathUtils;
|
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
|
|
||||||
import com.android.internal.util.FileRotator;
|
import com.android.internal.util.FileRotator;
|
||||||
|
import com.android.net.module.util.NetworkStatsUtils;
|
||||||
import com.google.android.collect.Sets;
|
|
||||||
|
|
||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
@ -132,7 +130,7 @@ public class NetworkStatsRecorder {
|
|||||||
|
|
||||||
public void setPersistThreshold(long thresholdBytes) {
|
public void setPersistThreshold(long thresholdBytes) {
|
||||||
if (LOGV) Log.v(TAG, "setPersistThreshold() with " + thresholdBytes);
|
if (LOGV) Log.v(TAG, "setPersistThreshold() with " + thresholdBytes);
|
||||||
mPersistThresholdBytes = MathUtils.constrain(
|
mPersistThresholdBytes = NetworkStatsUtils.constrain(
|
||||||
thresholdBytes, 1 * KB_IN_BYTES, 100 * MB_IN_BYTES);
|
thresholdBytes, 1 * KB_IN_BYTES, 100 * MB_IN_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +204,7 @@ public class NetworkStatsRecorder {
|
|||||||
*/
|
*/
|
||||||
public void recordSnapshotLocked(NetworkStats snapshot,
|
public void recordSnapshotLocked(NetworkStats snapshot,
|
||||||
Map<String, NetworkIdentitySet> ifaceIdent, long currentTimeMillis) {
|
Map<String, NetworkIdentitySet> ifaceIdent, long currentTimeMillis) {
|
||||||
final HashSet<String> unknownIfaces = Sets.newHashSet();
|
final HashSet<String> unknownIfaces = new HashSet<>();
|
||||||
|
|
||||||
// skip recording when snapshot missing
|
// skip recording when snapshot missing
|
||||||
if (snapshot == null) return;
|
if (snapshot == null) return;
|
||||||
|
@ -25,7 +25,6 @@ import static android.content.Intent.ACTION_USER_REMOVED;
|
|||||||
import static android.content.Intent.EXTRA_UID;
|
import static android.content.Intent.EXTRA_UID;
|
||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
import static android.net.NetworkIdentity.SUBTYPE_COMBINED;
|
import static android.net.NetworkIdentity.SUBTYPE_COMBINED;
|
||||||
import static android.net.NetworkStack.checkNetworkStackPermission;
|
|
||||||
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
|
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
|
||||||
import static android.net.NetworkStats.IFACE_ALL;
|
import static android.net.NetworkStats.IFACE_ALL;
|
||||||
import static android.net.NetworkStats.IFACE_VT;
|
import static android.net.NetworkStats.IFACE_VT;
|
||||||
@ -158,6 +157,7 @@ import com.android.server.LocalServices;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
@ -981,7 +981,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
@NonNull NetworkStateSnapshot[] networkStates,
|
@NonNull NetworkStateSnapshot[] networkStates,
|
||||||
@Nullable String activeIface,
|
@Nullable String activeIface,
|
||||||
@NonNull UnderlyingNetworkInfo[] underlyingNetworkInfos) {
|
@NonNull UnderlyingNetworkInfo[] underlyingNetworkInfos) {
|
||||||
checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@ -1197,13 +1197,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// On background handler thread, and USER_REMOVED is protected
|
// On background handler thread, and USER_REMOVED is protected
|
||||||
// broadcast.
|
// broadcast.
|
||||||
|
|
||||||
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
|
final UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
|
||||||
if (userId == -1) return;
|
if (userHandle == null) return;
|
||||||
|
|
||||||
synchronized (mStatsLock) {
|
synchronized (mStatsLock) {
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
try {
|
try {
|
||||||
removeUserLocked(userId);
|
removeUserLocked(userHandle);
|
||||||
} finally {
|
} finally {
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
}
|
}
|
||||||
@ -1228,7 +1228,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void limitReached(String limitName, String iface) {
|
public void limitReached(String limitName, String iface) {
|
||||||
// only someone like NMS should be calling us
|
// only someone like NMS should be calling us
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
if (LIMIT_GLOBAL_ALERT.equals(limitName)) {
|
if (LIMIT_GLOBAL_ALERT.equals(limitName)) {
|
||||||
// kick off background poll to collect network stats unless there is already
|
// kick off background poll to collect network stats unless there is already
|
||||||
@ -1648,8 +1648,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
* Clean up {@link #mUidRecorder} after user is removed.
|
* Clean up {@link #mUidRecorder} after user is removed.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mStatsLock")
|
@GuardedBy("mStatsLock")
|
||||||
private void removeUserLocked(int userId) {
|
private void removeUserLocked(@NonNull UserHandle userHandle) {
|
||||||
if (LOGV) Log.v(TAG, "removeUserLocked() for userId=" + userId);
|
if (LOGV) Log.v(TAG, "removeUserLocked() for UserHandle=" + userHandle);
|
||||||
|
|
||||||
// Build list of UIDs that we should clean up
|
// Build list of UIDs that we should clean up
|
||||||
final ArrayList<Integer> uids = new ArrayList<>();
|
final ArrayList<Integer> uids = new ArrayList<>();
|
||||||
@ -1657,7 +1657,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
PackageManager.MATCH_ANY_USER
|
PackageManager.MATCH_ANY_USER
|
||||||
| PackageManager.MATCH_DISABLED_COMPONENTS);
|
| PackageManager.MATCH_DISABLED_COMPONENTS);
|
||||||
for (ApplicationInfo app : apps) {
|
for (ApplicationInfo app : apps) {
|
||||||
final int uid = UserHandle.getUid(userId, app.uid);
|
final int uid = userHandle.getUid(app.uid);
|
||||||
uids.add(uid);
|
uids.add(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1865,7 +1865,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
@GuardedBy("mStatsLock")
|
@GuardedBy("mStatsLock")
|
||||||
private void dumpProtoLocked(FileDescriptor fd) {
|
private void dumpProtoLocked(FileDescriptor fd) {
|
||||||
final ProtoOutputStream proto = new ProtoOutputStream(fd);
|
final ProtoOutputStream proto = new ProtoOutputStream(new FileOutputStream(fd));
|
||||||
|
|
||||||
// TODO Right now it writes all history. Should it limit to the "since-boot" log?
|
// TODO Right now it writes all history. Should it limit to the "since-boot" log?
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ import android.util.Log;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.util.CollectionUtils;
|
import com.android.net.module.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -99,18 +99,19 @@ public class NetworkStatsSubscriptionsMonitor extends
|
|||||||
// prevent binder call to telephony when querying RAT. Keep listener registration with empty
|
// prevent binder call to telephony when querying RAT. Keep listener registration with empty
|
||||||
// IMSI is meaningless since the RAT type changed is ambiguous for multi-SIM if reported
|
// IMSI is meaningless since the RAT type changed is ambiguous for multi-SIM if reported
|
||||||
// with empty IMSI. So filter the subs w/o a valid IMSI to prevent such registration.
|
// with empty IMSI. So filter the subs w/o a valid IMSI to prevent such registration.
|
||||||
final List<Pair<Integer, String>> filteredNewSubs =
|
final List<Pair<Integer, String>> filteredNewSubs = new ArrayList<>();
|
||||||
CollectionUtils.mapNotNull(newSubs, subId -> {
|
for (final int subId : newSubs) {
|
||||||
final String subscriberId = mTeleManager.getSubscriberId(subId);
|
final String subscriberId = mTeleManager.getSubscriberId(subId);
|
||||||
return TextUtils.isEmpty(subscriberId) ? null : new Pair(subId, subscriberId);
|
if (!TextUtils.isEmpty(subscriberId)) {
|
||||||
});
|
filteredNewSubs.add(new Pair(subId, subscriberId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (final Pair<Integer, String> sub : filteredNewSubs) {
|
for (final Pair<Integer, String> sub : filteredNewSubs) {
|
||||||
// Fully match listener with subId and IMSI, since in some rare cases, IMSI might be
|
// Fully match listener with subId and IMSI, since in some rare cases, IMSI might be
|
||||||
// suddenly change regardless of subId, such as switch IMSI feature in modem side.
|
// suddenly change regardless of subId, such as switch IMSI feature in modem side.
|
||||||
// If that happens, register new listener with new IMSI and remove old one later.
|
// If that happens, register new listener with new IMSI and remove old one later.
|
||||||
if (CollectionUtils.find(mRatListeners,
|
if (CollectionUtils.any(mRatListeners, it -> it.equalsKey(sub.first, sub.second))) {
|
||||||
it -> it.equalsKey(sub.first, sub.second)) != null) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +127,8 @@ public class NetworkStatsSubscriptionsMonitor extends
|
|||||||
|
|
||||||
for (final RatTypeListener listener : new ArrayList<>(mRatListeners)) {
|
for (final RatTypeListener listener : new ArrayList<>(mRatListeners)) {
|
||||||
// If there is no subId and IMSI matched the listener, removes it.
|
// If there is no subId and IMSI matched the listener, removes it.
|
||||||
if (CollectionUtils.find(filteredNewSubs,
|
if (!CollectionUtils.any(filteredNewSubs,
|
||||||
it -> listener.equalsKey(it.first, it.second)) == null) {
|
it -> listener.equalsKey(it.first, it.second))) {
|
||||||
handleRemoveRatTypeListener(listener);
|
handleRemoveRatTypeListener(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,9 +149,10 @@ public class NetworkStatsSubscriptionsMonitor extends
|
|||||||
* @return collapsed RatType for the given subscriberId
|
* @return collapsed RatType for the given subscriberId
|
||||||
*/
|
*/
|
||||||
public int getRatTypeForSubscriberId(@NonNull String subscriberId) {
|
public int getRatTypeForSubscriberId(@NonNull String subscriberId) {
|
||||||
final RatTypeListener match = CollectionUtils.find(mRatListeners,
|
final int index = CollectionUtils.indexOf(mRatListeners,
|
||||||
it -> TextUtils.equals(subscriberId, it.mSubscriberId));
|
it -> TextUtils.equals(subscriberId, it.mSubscriberId));
|
||||||
return match != null ? match.mLastCollapsedRatType : TelephonyManager.NETWORK_TYPE_UNKNOWN;
|
return index != -1 ? mRatListeners.get(index).mLastCollapsedRatType
|
||||||
|
: TelephonyManager.NETWORK_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user