Commit 7e2dc21a authored by Kevin F. Haggerty's avatar Kevin F. Haggerty

Merge tag 'android-8.1.0_r43' into staging/lineage-15.1_merge-android-8.1.0_r43

Android 8.1.0 release 43

* tag 'android-8.1.0_r43': (24 commits)
  Fix DynamicRefTable::load security bug
  ResStringPool: Prevenet boot loop from se fix
  Make safe label more safe
  WM: Prevent secondary display focus while keyguard is up
  DO NOT MERGE: Add unit tests to ensure VPN meteredness
  DO NOT MERGE: Fix ConnectivityController meteredness checks
  clearCallingIdentity before calling into getPackageUidAsUser
  Nullcheck to fix Autofill CTS
  Osu: fixed Mismatch between createFromParcel and writeToParcel
  DO NOT MERGE Truncate newline and tab characters in BluetoothDevice name
  Fix broken check for TelephonyManager#getForbiddenPlmns
  DO NOT MERGE (O) Revoke permision when group changed
  ResStringPool: Fix security vulnerability
  RESTRICT AUTOMERGE: Prevent reporting fake package name - framework (backport to oc-mr1-dev)
  Use concrete CREATOR instance for parceling lists
  Rework thumbnail cleanup
  DO NOT MERGE - fix AFM.getComponentNameFromContext()
  Proper autofill fix to let phone process autofill Settings activity.
  Make sure apps cannot forge package name on AssistStructure used for Autofill.
  Fixed Security Vulnerability of DcParamObject
  ...

Change-Id: I37be2836181595f928721968cb7ffa2df312eff1
parents b78e9ae6 9522ef33
......@@ -42,6 +42,9 @@ import java.util.Comparator;
*/
public class PackageItemInfo {
private static final float MAX_LABEL_SIZE_PX = 500f;
/** The maximum length of a safe label, in characters */
private static final int MAX_SAFE_LABEL_LENGTH = 50000;
/**
* Public name of this item. From the "android:name" attribute.
*/
......@@ -169,7 +172,8 @@ public class PackageItemInfo {
// If the label contains new line characters it may push the UI
// down to hide a part of it. Labels shouldn't have new line
// characters, so just truncate at the first time one is seen.
final int labelLength = labelStr.length();
final int labelLength = Math.min(labelStr.length(), MAX_SAFE_LABEL_LENGTH);
final StringBuffer sb = new StringBuffer(labelLength);
int offset = 0;
while (offset < labelLength) {
final int codePoint = labelStr.codePointAt(offset);
......@@ -181,14 +185,19 @@ public class PackageItemInfo {
break;
}
// replace all non-break space to " " in order to be trimmed
final int charCount = Character.charCount(codePoint);
if (type == Character.SPACE_SEPARATOR) {
labelStr = labelStr.substring(0, offset) + " " + labelStr.substring(offset +
Character.charCount(codePoint));
sb.append(' ');
} else {
sb.append(labelStr.charAt(offset));
if (charCount == 2) {
sb.append(labelStr.charAt(offset + 1));
}
}
offset += Character.charCount(codePoint);
offset += charCount;
}
labelStr = labelStr.trim();
labelStr = sb.toString().trim();
if (labelStr.isEmpty()) {
return packageName;
}
......
......@@ -2504,6 +2504,28 @@ public class ConnectivityManager {
}
}
/**
* Returns if the active data network for the given UID is metered. A network
* is classified as metered when the user is sensitive to heavy data usage on
* that connection due to monetary costs, data limitations or
* battery/performance issues. You should check this before doing large
* data transfers, and warn the user or delay the operation until another
* network is available.
*
* @return {@code true} if large transfers should be avoided, otherwise
* {@code false}.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL)
public boolean isActiveNetworkMeteredForUid(int uid) {
try {
return mService.isActiveNetworkMeteredForUid(uid);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* If the LockdownVpn mechanism is enabled, updates the vpn
* with a reload of its profile.
......
......@@ -66,6 +66,7 @@ interface IConnectivityManager
NetworkQuotaInfo getActiveNetworkQuotaInfo();
boolean isActiveNetworkMetered();
boolean isActiveNetworkMeteredForUid(int uid);
boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress);
......
......@@ -616,6 +616,11 @@ public interface WindowManagerPolicy {
*/
void notifyKeyguardTrustedChanged();
/**
* The keyguard showing state has changed
*/
void onKeyguardShowingAndNotOccludedChanged();
/**
* Notifies the window manager that screen is being turned off.
*
......
......@@ -460,7 +460,7 @@ status_t ResStringPool::setTo(const void* data, size_t size, bool copyData)
// The chunk must be at least the size of the string pool header.
if (size < sizeof(ResStringPool_header)) {
LOG_ALWAYS_FATAL("Bad string block: data size %zu is too small to be a string block", size);
ALOGW("Bad string block: data size %zu is too small to be a string block", size);
return (mError=BAD_TYPE);
}
......@@ -470,7 +470,7 @@ status_t ResStringPool::setTo(const void* data, size_t size, bool copyData)
if (validate_chunk(reinterpret_cast<const ResChunk_header*>(data), sizeof(ResStringPool_header),
reinterpret_cast<const uint8_t*>(data) + size,
"ResStringPool_header") != NO_ERROR) {
LOG_ALWAYS_FATAL("Bad string block: malformed block dimensions");
ALOGW("Bad string block: malformed block dimensions");
return (mError=BAD_TYPE);
}
......@@ -6581,8 +6581,16 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
}
} else if (ctype == RES_TABLE_LIBRARY_TYPE) {
if (group->dynamicRefTable.entries().size() == 0) {
status_t err = group->dynamicRefTable.load((const ResTable_lib_header*) chunk);
const ResTable_lib_header* lib = (const ResTable_lib_header*) chunk;
status_t err = validate_chunk(&lib->header, sizeof(*lib),
endPos, "ResTable_lib_header");
if (err != NO_ERROR) {
return (mError=err);
}
err = group->dynamicRefTable.load(lib);
if (err != NO_ERROR) {
return (mError=err);
}
......
......@@ -971,7 +971,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (!mLockdownEnabled) {
int user = UserHandle.getUserId(uid);
synchronized (mVpns) {
Vpn vpn = mVpns.get(user);
Vpn vpn = getVpn(user);
if (vpn != null && vpn.appliesToUid(uid)) {
return vpn.getUnderlyingNetworks();
}
......@@ -1019,7 +1019,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
return false;
}
synchronized (mVpns) {
final Vpn vpn = mVpns.get(UserHandle.getUserId(uid));
final Vpn vpn = getVpn(UserHandle.getUserId(uid));
if (vpn != null && vpn.isBlockingUid(uid)) {
return true;
}
......@@ -1096,7 +1096,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
final int user = UserHandle.getUserId(uid);
int vpnNetId = NETID_UNSET;
synchronized (mVpns) {
final Vpn vpn = mVpns.get(user);
final Vpn vpn = getVpn(user);
if (vpn != null && vpn.appliesToUid(uid)) vpnNetId = vpn.getNetId();
}
NetworkAgentInfo nai;
......@@ -1226,7 +1226,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (!mLockdownEnabled) {
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn != null) {
Network[] networks = vpn.getUnderlyingNetworks();
if (networks != null) {
......@@ -1341,7 +1341,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
public boolean isActiveNetworkMetered() {
enforceAccessPermission();
final int uid = Binder.getCallingUid();
return isActiveNetworkMeteredCommon(Binder.getCallingUid());
}
@Override
public boolean isActiveNetworkMeteredForUid(int uid) {
enforceConnectivityInternalPermission();
return isActiveNetworkMeteredCommon(uid);
}
private boolean isActiveNetworkMeteredCommon(int uid) {
final NetworkCapabilities caps = getUnfilteredActiveNetworkState(uid).networkCapabilities;
if (caps != null) {
return !caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
......@@ -3444,7 +3454,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
throwIfLockdownEnabled();
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn != null) {
return vpn.prepare(oldPackage, newPackage);
} else {
......@@ -3471,7 +3481,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
enforceCrossUserPermission(userId);
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn != null) {
vpn.setPackageAuthorization(packageName, authorized);
}
......@@ -3490,7 +3500,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
throwIfLockdownEnabled();
int user = UserHandle.getUserId(Binder.getCallingUid());
synchronized (mVpns) {
return mVpns.get(user).establish(config);
return getVpn(user).establish(config);
}
}
......@@ -3507,7 +3517,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
int user = UserHandle.getUserId(Binder.getCallingUid());
synchronized (mVpns) {
mVpns.get(user).startLegacyVpn(profile, mKeyStore, egress);
getVpn(user).startLegacyVpn(profile, mKeyStore, egress);
}
}
......@@ -3521,7 +3531,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
enforceCrossUserPermission(userId);
synchronized (mVpns) {
return mVpns.get(userId).getLegacyVpnInfo();
return getVpn(userId).getLegacyVpnInfo();
}
}
......@@ -3585,7 +3595,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
public VpnConfig getVpnConfig(int userId) {
enforceCrossUserPermission(userId);
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn != null) {
return vpn.getVpnConfig();
} else {
......@@ -3619,7 +3629,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
int user = UserHandle.getUserId(Binder.getCallingUid());
synchronized (mVpns) {
Vpn vpn = mVpns.get(user);
Vpn vpn = getVpn(user);
if (vpn == null) {
Slog.w(TAG, "VPN for user " + user + " not ready yet. Skipping lockdown");
return false;
......@@ -3666,7 +3676,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
*/
private boolean startAlwaysOnVpn(int userId) {
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn == null) {
// Shouldn't happen as all codepaths that point here should have checked the Vpn
// exists already.
......@@ -3684,7 +3694,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
enforceCrossUserPermission(userId);
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn == null) {
Slog.w(TAG, "User " + userId + " has no Vpn configuration");
return false;
......@@ -3704,7 +3714,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn == null) {
Slog.w(TAG, "User " + userId + " has no Vpn configuration");
return false;
......@@ -3726,7 +3736,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
enforceCrossUserPermission(userId);
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
Vpn vpn = getVpn(userId);
if (vpn == null) {
Slog.w(TAG, "User " + userId + " has no Vpn configuration");
return null;
......@@ -3872,22 +3882,38 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void onUserStart(int userId) {
synchronized (mVpns) {
Vpn userVpn = mVpns.get(userId);
Vpn userVpn = getVpn(userId);
if (userVpn != null) {
loge("Starting user already has a VPN");
return;
}
userVpn = new Vpn(mHandler.getLooper(), mContext, mNetd, userId);
mVpns.put(userId, userVpn);
setVpn(userId, userVpn);
}
if (mUserManager.getUserInfo(userId).isPrimary() && LockdownVpnTracker.isEnabled()) {
updateLockdownVpn();
}
}
/** @hide */
@VisibleForTesting
Vpn getVpn(int userId) {
synchronized (mVpns) {
return mVpns.get(userId);
}
}
/** @hide */
@VisibleForTesting
void setVpn(int userId, Vpn userVpn) {
synchronized (mVpns) {
mVpns.put(userId, userVpn);
}
}
private void onUserStop(int userId) {
synchronized (mVpns) {
Vpn userVpn = mVpns.get(userId);
Vpn userVpn = getVpn(userId);
if (userVpn == null) {
loge("Stopped user has no VPN");
return;
......@@ -5461,7 +5487,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
throwIfLockdownEnabled();
int user = UserHandle.getUserId(Binder.getCallingUid());
synchronized (mVpns) {
return mVpns.get(user).addAddress(address, prefixLength);
return getVpn(user).addAddress(address, prefixLength);
}
}
......@@ -5470,7 +5496,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
throwIfLockdownEnabled();
int user = UserHandle.getUserId(Binder.getCallingUid());
synchronized (mVpns) {
return mVpns.get(user).removeAddress(address, prefixLength);
return getVpn(user).removeAddress(address, prefixLength);
}
}
......@@ -5480,7 +5506,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
int user = UserHandle.getUserId(Binder.getCallingUid());
boolean success;
synchronized (mVpns) {
success = mVpns.get(user).setUnderlyingNetworks(networks);
success = getVpn(user).setUnderlyingNetworks(networks);
}
if (success) {
notifyIfacesChangedForNetworkStats();
......
......@@ -112,10 +112,8 @@ public final class ConnectivityController extends StateController implements
final boolean connected = (info != null) && info.isConnected();
final boolean connectionUsable = connected && validated;
final boolean metered = connected && (capabilities != null)
&& !capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
final boolean unmetered = connected && (capabilities != null)
&& capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
final boolean metered = connected && mConnManager.isActiveNetworkMeteredForUid(jobUid);
final boolean unmetered = connected && !mConnManager.isActiveNetworkMeteredForUid(jobUid);
final boolean notRoaming = connected && (info != null)
&& !info.isRoaming();
......
......@@ -2414,6 +2414,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
public void onTrustedChanged() {
mWindowManagerFuncs.notifyKeyguardTrustedChanged();
}
@Override
public void onShowingChanged() {
mWindowManagerFuncs.onKeyguardShowingAndNotOccludedChanged();
}
});
final Resources res = mContext.getResources();
......
......@@ -86,6 +86,8 @@ public class KeyguardStateMonitor extends IKeyguardStateCallback.Stub {
@Override // Binder interface
public void onShowingStateChanged(boolean showing) {
mIsShowing = showing;
mCallback.onShowingChanged();
}
@Override // Binder interface
......@@ -119,6 +121,7 @@ public class KeyguardStateMonitor extends IKeyguardStateCallback.Stub {
public interface StateCallback {
void onTrustedChanged();
void onShowingChanged();
}
public void dump(String prefix, PrintWriter pw) {
......
......@@ -167,10 +167,18 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
}
WindowState computeFocusedWindow() {
// While the keyguard is showing, we must focus anything besides the main display.
// Otherwise we risk input not going to the keyguard when the user expects it to.
final boolean forceDefaultDisplay = mService.mPolicy.isKeyguardShowingAndNotOccluded();
for (int i = mChildren.size() - 1; i >= 0; i--) {
final DisplayContent dc = mChildren.get(i);
final WindowState win = dc.findFocusedWindow();
if (win != null) {
if (forceDefaultDisplay && !dc.isDefaultDisplay) {
EventLog.writeEvent(0x534e4554, "71786287", win.mOwnerUid, "");
continue;
}
return win;
}
}
......
......@@ -2928,6 +2928,11 @@ public class WindowManagerService extends IWindowManager.Stub
mH.sendEmptyMessage(H.NOTIFY_KEYGUARD_TRUSTED_CHANGED);
}
@Override
public void onKeyguardShowingAndNotOccludedChanged() {
mH.sendEmptyMessage(H.RECOMPUTE_FOCUS);
}
@Override
public void screenTurningOff(ScreenOffListener listener) {
mTaskSnapshotController.screenTurningOff(listener);
......@@ -4910,6 +4915,7 @@ public class WindowManagerService extends IWindowManager.Stub
public static final int NOTIFY_KEYGUARD_FLAGS_CHANGED = 56;
public static final int NOTIFY_KEYGUARD_TRUSTED_CHANGED = 57;
public static final int SET_HAS_OVERLAY_UI = 58;
public static final int RECOMPUTE_FOCUS = 61;
/**
* Used to denote that an integer field in a message will not be used.
......@@ -5376,6 +5382,13 @@ public class WindowManagerService extends IWindowManager.Stub
mAmInternal.setHasOverlayUi(msg.arg1, msg.arg2 == 1);
}
break;
case RECOMPUTE_FOCUS: {
synchronized (mWindowMap) {
updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
true /* updateInputWindows */);
}
}
break;
}
if (DEBUG_WINDOW_TRACE) {
Slog.v(TAG_WM, "handleMessage: exit");
......
......@@ -313,6 +313,25 @@ public class DisplayContentTests extends WindowTestsBase {
assertEquals(window1, sWm.mRoot.computeFocusedWindow());
}
@Test
public void testKeyguard_preventsSecondaryDisplayFocus() throws Exception {
final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR,
sWm.getDefaultDisplayContentLocked(), "keyguard");
assertEquals(keyguard, sWm.mRoot.computeFocusedWindow());
// Add a window to a second display, and it should be focused
final DisplayContent dc = createNewDisplay();
final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win");
assertEquals(win, sWm.mRoot.computeFocusedWindow());
((TestWindowManagerPolicy)sWm.mPolicy).keyguardShowingAndNotOccluded = true;
try {
assertEquals(keyguard, sWm.mRoot.computeFocusedWindow());
} finally {
((TestWindowManagerPolicy)sWm.mPolicy).keyguardShowingAndNotOccluded = false;
}
}
/**
* This tests setting the maximum ui width on a display.
*/
......
......@@ -63,6 +63,7 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
private static WindowManagerService sWm = null;
int rotationToReport = 0;
boolean keyguardShowingAndNotOccluded = false;
private Runnable mRunnableWhenAddingSplashScreen;
......@@ -420,7 +421,7 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
@Override
public boolean isKeyguardLocked() {
return false;
return keyguardShowingAndNotOccluded;
}
@Override
......@@ -440,7 +441,7 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
@Override
public boolean isKeyguardShowingAndNotOccluded() {
return false;
return keyguardShowingAndNotOccluded;
}
@Override
......
......@@ -22,6 +22,7 @@ import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_MOBILE_FOTA;
import static android.net.ConnectivityManager.TYPE_MOBILE_MMS;
import static android.net.ConnectivityManager.TYPE_NONE;
import static android.net.ConnectivityManager.TYPE_VPN;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.getNetworkTypeName;
import static android.net.NetworkCapabilities.*;
......@@ -102,6 +103,7 @@ import com.android.server.connectivity.MockableSystemProperties;
import com.android.server.connectivity.NetworkAgentInfo;
import com.android.server.connectivity.NetworkMonitor;
import com.android.server.connectivity.NetworkMonitor.CaptivePortalProbeResult;
import com.android.server.connectivity.Vpn;
import com.android.server.net.NetworkPinner;
import com.android.server.net.NetworkPolicyManagerInternal;
......@@ -333,6 +335,9 @@ public class ConnectivityServiceTest extends AndroidTestCase {
case TRANSPORT_WIFI_AWARE:
mScore = 20;
break;
case TRANSPORT_VPN:
mScore = 0;
break;
default:
throw new UnsupportedOperationException("unimplemented network type");
}
......@@ -868,6 +873,8 @@ public class ConnectivityServiceTest extends AndroidTestCase {
return TYPE_WIFI;
case TRANSPORT_CELLULAR:
return TYPE_MOBILE;
case TRANSPORT_VPN:
return TYPE_VPN;
default:
return TYPE_NONE;
}
......@@ -3447,4 +3454,84 @@ public class ConnectivityServiceTest extends AndroidTestCase {
return;
}
}
@SmallTest
public void testVpnNetworkMetered() {
final TestNetworkCallback callback = new TestNetworkCallback();
mCm.registerDefaultNetworkCallback(callback);
final NetworkRequest cellRequest = new NetworkRequest.Builder()
.addTransportType(TRANSPORT_CELLULAR).build();
final TestNetworkCallback cellCallback = new TestNetworkCallback();
mCm.registerNetworkCallback(cellRequest, cellCallback);
// Setup cellular
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
mCellNetworkAgent.connect(true);
callback.expectAvailableAndValidatedCallbacks(mCellNetworkAgent);
cellCallback.expectAvailableAndValidatedCallbacks(mCellNetworkAgent);
verifyActiveNetwork(TRANSPORT_CELLULAR);
// Verify meteredness of cellular
assertTrue(mCm.isActiveNetworkMetered());
// Setup Wifi
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
mWiFiNetworkAgent.connect(true);
callback.expectAvailableAndValidatedCallbacks(mWiFiNetworkAgent);
cellCallback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
verifyActiveNetwork(TRANSPORT_WIFI);
// Verify meteredness of WiFi
assertTrue(mCm.isActiveNetworkMetered());
// Verify that setting unmetered on Wifi changes ActiveNetworkMetered
mWiFiNetworkAgent.addCapability(NET_CAPABILITY_NOT_METERED);
callback.expectCapabilitiesWith(NET_CAPABILITY_NOT_METERED, mWiFiNetworkAgent);
assertFalse(mCm.isActiveNetworkMetered());
// Setup VPN
final MockNetworkAgent vpnNetworkAgent = new MockNetworkAgent(TRANSPORT_VPN);
vpnNetworkAgent.connect(true);
Vpn mockVpn = mock(Vpn.class);
when(mockVpn.appliesToUid(anyInt())).thenReturn(true);
when(mockVpn.getNetId()).thenReturn(vpnNetworkAgent.getNetwork().netId);
Vpn oldVpn = mService.getVpn(UserHandle.myUserId());
mService.setVpn(UserHandle.myUserId(), mockVpn);
assertEquals(vpnNetworkAgent.getNetwork(), mCm.getActiveNetwork());
// Verify meteredness of VPN on default network
when(mockVpn.getUnderlyingNetworks()).thenReturn(null);
assertFalse(mCm.isActiveNetworkMetered());
assertFalse(mCm.isActiveNetworkMeteredForUid(Process.myUid()));
// Verify meteredness of VPN on unmetered wifi
when(mockVpn.getUnderlyingNetworks())
.thenReturn(new Network[] {mWiFiNetworkAgent.getNetwork()});
assertFalse(mCm.isActiveNetworkMetered());
assertFalse(mCm.isActiveNetworkMeteredForUid(Process.myUid()));
// Set WiFi as metered, then check to see that it has been updated on the VPN
mWiFiNetworkAgent.removeCapability(NET_CAPABILITY_NOT_METERED);
callback.expectCapabilitiesWithout(NET_CAPABILITY_NOT_METERED, mWiFiNetworkAgent);
assertTrue(mCm.isActiveNetworkMetered());
assertTrue(mCm.isActiveNetworkMeteredForUid(Process.myUid()));
// Switch to cellular
when(mockVpn.getUnderlyingNetworks())
.thenReturn(new Network[] {mCellNetworkAgent.getNetwork()});
assertTrue(mCm.isActiveNetworkMetered());
assertTrue(mCm.isActiveNetworkMeteredForUid(Process.myUid()));
// Test unmetered cellular
mCellNetworkAgent.addCapability(NET_CAPABILITY_NOT_METERED);
cellCallback.expectCapabilitiesWith(NET_CAPABILITY_NOT_METERED, mCellNetworkAgent);
assertFalse(mCm.isActiveNetworkMetered());
assertFalse(mCm.isActiveNetworkMeteredForUid(Process.myUid()));
mService.setVpn(UserHandle.myUserId(), oldVpn);
mCm.unregisterNetworkCallback(callback);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment