Merge "VPN: Move package intent receiver to ConnectivityService."
am: aff267369c Change-Id: I3220f34afe7e56bcbde87a8de2b00ecddecbc97a
This commit is contained in:
@@ -902,6 +902,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// Listen to package add and removal events for all users.
|
// Listen to package add and removal events for all users.
|
||||||
intentFilter = new IntentFilter();
|
intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||||
|
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||||
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||||
intentFilter.addDataScheme("package");
|
intentFilter.addDataScheme("package");
|
||||||
mContext.registerReceiverAsUser(
|
mContext.registerReceiverAsUser(
|
||||||
@@ -4203,12 +4204,46 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mPermissionMonitor.onPackageAdded(packageName, uid);
|
mPermissionMonitor.onPackageAdded(packageName, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPackageRemoved(String packageName, int uid) {
|
private void onPackageReplaced(String packageName, int uid) {
|
||||||
|
if (TextUtils.isEmpty(packageName) || uid < 0) {
|
||||||
|
Slog.wtf(TAG, "Invalid package in onPackageReplaced: " + packageName + " | " + uid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int userId = UserHandle.getUserId(uid);
|
||||||
|
synchronized (mVpns) {
|
||||||
|
final Vpn vpn = mVpns.get(userId);
|
||||||
|
if (vpn == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Legacy always-on VPN won't be affected since the package name is not set.
|
||||||
|
if (TextUtils.equals(vpn.getAlwaysOnPackage(), packageName)) {
|
||||||
|
Slog.d(TAG, "Restarting always-on VPN package " + packageName + " for user "
|
||||||
|
+ userId);
|
||||||
|
vpn.startAlwaysOnVpn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onPackageRemoved(String packageName, int uid, boolean isReplacing) {
|
||||||
if (TextUtils.isEmpty(packageName) || uid < 0) {
|
if (TextUtils.isEmpty(packageName) || uid < 0) {
|
||||||
Slog.wtf(TAG, "Invalid package in onPackageRemoved: " + packageName + " | " + uid);
|
Slog.wtf(TAG, "Invalid package in onPackageRemoved: " + packageName + " | " + uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mPermissionMonitor.onPackageRemoved(uid);
|
mPermissionMonitor.onPackageRemoved(uid);
|
||||||
|
|
||||||
|
final int userId = UserHandle.getUserId(uid);
|
||||||
|
synchronized (mVpns) {
|
||||||
|
final Vpn vpn = mVpns.get(userId);
|
||||||
|
if (vpn == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Legacy always-on VPN won't be affected since the package name is not set.
|
||||||
|
if (TextUtils.equals(vpn.getAlwaysOnPackage(), packageName) && !isReplacing) {
|
||||||
|
Slog.d(TAG, "Removing always-on VPN package " + packageName + " for user "
|
||||||
|
+ userId);
|
||||||
|
vpn.setAlwaysOnPackage(null, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onUserUnlocked(int userId) {
|
private void onUserUnlocked(int userId) {
|
||||||
@@ -4245,8 +4280,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
onUserUnlocked(userId);
|
onUserUnlocked(userId);
|
||||||
} else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
|
} else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
|
||||||
onPackageAdded(packageName, uid);
|
onPackageAdded(packageName, uid);
|
||||||
|
} else if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
|
||||||
|
onPackageReplaced(packageName, uid);
|
||||||
} else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
|
} else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
|
||||||
onPackageRemoved(packageName, uid);
|
final boolean isReplacing = intent.getBooleanExtra(
|
||||||
|
Intent.EXTRA_REPLACING, false);
|
||||||
|
onPackageRemoved(packageName, uid, isReplacing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user