Replace Context @hide APIs
Connectivity service module is using some Context @hide APIs but
they are not able to call after CS becomes a mainline module.
Thus, replace them with similar System APIs.
Bug: 170593746
Test: atest FrameworksNetTests
Test: Manully check that receiving intent and starting activity
can work normally.
Change-Id: I0f5b53ce0da4e3fc0f927896e9a9e444048401bd
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user