Revert^2 "Replace Context#sendStickyBroadcastAsUser()"

ConnectivityService is using Context#sendStickyBroadcastAsUser
to send sticky broadcast but this API is not able to call after
it becomes part of Connectivity mainline module. Thus, replace it
with Context#sendStickyBroadcast.

The original commit was reverted because of a test failure. This
reverted commit is bound to the fix and will submit together.

Bug: 177223402
Change-Id: I75b8494e8ee30f484f33e9a9a660c7f9ad75f368
Test: atest FrameworksNetTests
Test: atest CtsNetTestCases
Test: atest CtsNetApi23TestCases
Test: atest FrameworksNetIntegrationTests
This commit is contained in:
Paul Hu
2021-01-26 02:53:06 +00:00
parent d930f01c14
commit 96f1cbbbe2

View File

@@ -314,6 +314,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
private boolean mRestrictBackground; private boolean mRestrictBackground;
private final Context mContext; private final Context mContext;
// The Context is created for UserHandle.ALL.
private final Context mUserAllContext;
private final Dependencies mDeps; private final Dependencies mDeps;
// 0 is full bad, 100 is full good // 0 is full bad, 100 is full good
private int mDefaultInetConditionPublished = 0; private int mDefaultInetConditionPublished = 0;
@@ -1088,8 +1090,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
intentFilter.addAction(Intent.ACTION_USER_REMOVED); intentFilter.addAction(Intent.ACTION_USER_REMOVED);
intentFilter.addAction(Intent.ACTION_USER_UNLOCKED); intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
final Context userAllContext = mContext.createContextAsUser(UserHandle.ALL, 0 /* flags */); mUserAllContext = mContext.createContextAsUser(UserHandle.ALL, 0 /* flags */);
userAllContext.registerReceiver( mUserAllContext.registerReceiver(
mIntentReceiver, mIntentReceiver,
intentFilter, intentFilter,
null /* broadcastPermission */, null /* broadcastPermission */,
@@ -1105,7 +1107,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
intentFilter.addDataScheme("package"); intentFilter.addDataScheme("package");
userAllContext.registerReceiver( mUserAllContext.registerReceiver(
mIntentReceiver, mIntentReceiver,
intentFilter, intentFilter,
null /* broadcastPermission */, null /* broadcastPermission */,
@@ -1114,7 +1116,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// Listen to lockdown VPN reset. // Listen to lockdown VPN reset.
intentFilter = new IntentFilter(); intentFilter = new IntentFilter();
intentFilter.addAction(LockdownVpnTracker.ACTION_LOCKDOWN_RESET); intentFilter.addAction(LockdownVpnTracker.ACTION_LOCKDOWN_RESET);
userAllContext.registerReceiver( mUserAllContext.registerReceiver(
mIntentReceiver, intentFilter, NETWORK_STACK, mHandler); mIntentReceiver, intentFilter, NETWORK_STACK, mHandler);
try { try {
@@ -2320,7 +2322,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
intent.addFlags(Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS); intent.addFlags(Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
} }
try { try {
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL, options); mUserAllContext.sendStickyBroadcast(intent, options);
} finally { } finally {
Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident);
} }