Merge "Replace Context @hide APIs"
This commit is contained in:
@@ -1105,23 +1105,26 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
intentFilter.addAction(Intent.ACTION_USER_ADDED);
|
||||
intentFilter.addAction(Intent.ACTION_USER_REMOVED);
|
||||
intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||
mContext.registerReceiverAsUser(
|
||||
|
||||
final Context userAllContext = mContext.createContextAsUser(UserHandle.ALL, 0 /* flags */);
|
||||
userAllContext.registerReceiver(
|
||||
mIntentReceiver,
|
||||
UserHandle.ALL,
|
||||
intentFilter,
|
||||
null /* broadcastPermission */,
|
||||
mHandler);
|
||||
mContext.registerReceiverAsUser(mUserPresentReceiver, UserHandle.SYSTEM,
|
||||
new IntentFilter(Intent.ACTION_USER_PRESENT), null, null);
|
||||
mContext.createContextAsUser(UserHandle.SYSTEM, 0 /* flags */).registerReceiver(
|
||||
mUserPresentReceiver,
|
||||
new IntentFilter(Intent.ACTION_USER_PRESENT),
|
||||
null /* broadcastPermission */,
|
||||
null /* scheduler */);
|
||||
|
||||
// Listen to package add and removal events for all users.
|
||||
intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
intentFilter.addDataScheme("package");
|
||||
mContext.registerReceiverAsUser(
|
||||
userAllContext.registerReceiver(
|
||||
mIntentReceiver,
|
||||
UserHandle.ALL,
|
||||
intentFilter,
|
||||
null /* broadcastPermission */,
|
||||
mHandler);
|
||||
@@ -1129,8 +1132,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// Listen to lockdown VPN reset.
|
||||
intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(LockdownVpnTracker.ACTION_LOCKDOWN_RESET);
|
||||
mContext.registerReceiverAsUser(
|
||||
mIntentReceiver, UserHandle.ALL, intentFilter, NETWORK_STACK, mHandler);
|
||||
userAllContext.registerReceiver(
|
||||
mIntentReceiver, intentFilter, NETWORK_STACK, mHandler);
|
||||
|
||||
try {
|
||||
mNMS.registerObserver(mDataActivityObserver);
|
||||
@@ -5259,7 +5262,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// Try creating lockdown tracker, since user present usually means
|
||||
// unlocked keystore.
|
||||
updateLockdownVpn();
|
||||
mContext.unregisterReceiver(this);
|
||||
// Use the same context that registered receiver before to unregister it. Because use
|
||||
// different context to unregister receiver will cause exception.
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -53,6 +54,7 @@ import android.net.NetworkTemplate;
|
||||
import android.net.StringNetworkSpecifier;
|
||||
import android.net.TelephonyNetworkSpecifier;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.test.mock.MockContentResolver;
|
||||
@@ -91,6 +93,7 @@ public class MultipathPolicyTrackerTest {
|
||||
private static final int POLICY_SNOOZED = -100;
|
||||
|
||||
@Mock private Context mContext;
|
||||
@Mock private Context mUserAllContext;
|
||||
@Mock private Resources mResources;
|
||||
@Mock private Handler mHandler;
|
||||
@Mock private MultipathPolicyTracker.Dependencies mDeps;
|
||||
@@ -127,8 +130,11 @@ public class MultipathPolicyTrackerTest {
|
||||
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mContext.getApplicationInfo()).thenReturn(new ApplicationInfo());
|
||||
when(mContext.registerReceiverAsUser(mConfigChangeReceiverCaptor.capture(),
|
||||
any(), argThat(f -> f.hasAction(ACTION_CONFIGURATION_CHANGED)), any(), any()))
|
||||
doReturn(UserHandle.ALL.getIdentifier()).when(mUserAllContext).getUserId();
|
||||
when(mContext.createContextAsUser(eq(UserHandle.ALL), anyInt()))
|
||||
.thenReturn(mUserAllContext);
|
||||
when(mUserAllContext.registerReceiver(mConfigChangeReceiverCaptor.capture(),
|
||||
argThat(f -> f.hasAction(ACTION_CONFIGURATION_CHANGED)), any(), any()))
|
||||
.thenReturn(null);
|
||||
|
||||
when(mDeps.getClock()).thenReturn(mClock);
|
||||
|
||||
Reference in New Issue
Block a user