Merge "Handle lockdown VPN reset intent in ConnectivityService" am: fc6fbde5df am: 8ea944d77a am: 1183f4a548
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1413614 Change-Id: I907b35a02c0957ae57f55ae960df1ff5fce0be8e
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.NETWORK_STACK;
|
||||||
import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
|
import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
|
||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport.KEY_NETWORK_PROBES_ATTEMPTED_BITMASK;
|
import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport.KEY_NETWORK_PROBES_ATTEMPTED_BITMASK;
|
||||||
@@ -1136,6 +1137,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
null /* broadcastPermission */,
|
null /* broadcastPermission */,
|
||||||
mHandler);
|
mHandler);
|
||||||
|
|
||||||
|
// Listen to lockdown VPN reset.
|
||||||
|
intentFilter = new IntentFilter();
|
||||||
|
intentFilter.addAction(LockdownVpnTracker.ACTION_LOCKDOWN_RESET);
|
||||||
|
mContext.registerReceiverAsUser(
|
||||||
|
mIntentReceiver, UserHandle.ALL, intentFilter, NETWORK_STACK, mHandler);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mNMS.registerObserver(mDataActivityObserver);
|
mNMS.registerObserver(mDataActivityObserver);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -5204,6 +5211,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onVpnLockdownReset() {
|
||||||
|
synchronized (mVpns) {
|
||||||
|
if (mLockdownTracker != null) mLockdownTracker.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -5214,6 +5227,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
final Uri packageData = intent.getData();
|
final Uri packageData = intent.getData();
|
||||||
final String packageName =
|
final String packageName =
|
||||||
packageData != null ? packageData.getSchemeSpecificPart() : null;
|
packageData != null ? packageData.getSchemeSpecificPart() : null;
|
||||||
|
|
||||||
|
if (LockdownVpnTracker.ACTION_LOCKDOWN_RESET.equals(action)) {
|
||||||
|
onVpnLockdownReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserId should be filled for below intents, check the existence.
|
||||||
if (userId == UserHandle.USER_NULL) return;
|
if (userId == UserHandle.USER_NULL) return;
|
||||||
|
|
||||||
if (Intent.ACTION_USER_STARTED.equals(action)) {
|
if (Intent.ACTION_USER_STARTED.equals(action)) {
|
||||||
@@ -5232,6 +5251,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
final boolean isReplacing = intent.getBooleanExtra(
|
final boolean isReplacing = intent.getBooleanExtra(
|
||||||
Intent.EXTRA_REPLACING, false);
|
Intent.EXTRA_REPLACING, false);
|
||||||
onPackageRemoved(packageName, uid, isReplacing);
|
onPackageRemoved(packageName, uid, isReplacing);
|
||||||
|
} else {
|
||||||
|
Log.wtf(TAG, "received unexpected intent: " + action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.server.net;
|
package com.android.server.net;
|
||||||
|
|
||||||
import static android.Manifest.permission.NETWORK_STACK;
|
|
||||||
import static android.provider.Settings.ACTION_VPN_SETTINGS;
|
import static android.provider.Settings.ACTION_VPN_SETTINGS;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
@@ -24,10 +23,8 @@ import android.annotation.Nullable;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
@@ -41,6 +38,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
|
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
|
||||||
import com.android.internal.net.VpnConfig;
|
import com.android.internal.net.VpnConfig;
|
||||||
import com.android.internal.net.VpnProfile;
|
import com.android.internal.net.VpnProfile;
|
||||||
@@ -63,7 +61,7 @@ public class LockdownVpnTracker {
|
|||||||
/** Number of VPN attempts before waiting for user intervention. */
|
/** Number of VPN attempts before waiting for user intervention. */
|
||||||
private static final int MAX_ERROR_COUNT = 4;
|
private static final int MAX_ERROR_COUNT = 4;
|
||||||
|
|
||||||
private static final String ACTION_LOCKDOWN_RESET = "com.android.server.action.LOCKDOWN_RESET";
|
public static final String ACTION_LOCKDOWN_RESET = "com.android.server.action.LOCKDOWN_RESET";
|
||||||
|
|
||||||
@NonNull private final Context mContext;
|
@NonNull private final Context mContext;
|
||||||
@NonNull private final ConnectivityService mConnService;
|
@NonNull private final ConnectivityService mConnService;
|
||||||
@@ -104,13 +102,6 @@ public class LockdownVpnTracker {
|
|||||||
mResetIntent = PendingIntent.getBroadcast(mContext, 0, resetIntent, 0);
|
mResetIntent = PendingIntent.getBroadcast(mContext, 0, resetIntent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BroadcastReceiver mResetReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch for state changes to both active egress network, kicking off a VPN
|
* Watch for state changes to both active egress network, kicking off a VPN
|
||||||
* connection when ready, or setting firewall rules once VPN is connected.
|
* connection when ready, or setting firewall rules once VPN is connected.
|
||||||
@@ -200,9 +191,6 @@ public class LockdownVpnTracker {
|
|||||||
|
|
||||||
mVpn.setEnableTeardown(false);
|
mVpn.setEnableTeardown(false);
|
||||||
mVpn.setLockdown(true);
|
mVpn.setLockdown(true);
|
||||||
|
|
||||||
final IntentFilter resetFilter = new IntentFilter(ACTION_LOCKDOWN_RESET);
|
|
||||||
mContext.registerReceiver(mResetReceiver, resetFilter, NETWORK_STACK, mHandler);
|
|
||||||
handleStateChangedLocked();
|
handleStateChangedLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,10 +210,14 @@ public class LockdownVpnTracker {
|
|||||||
mVpn.setLockdown(false);
|
mVpn.setLockdown(false);
|
||||||
hideNotification();
|
hideNotification();
|
||||||
|
|
||||||
mContext.unregisterReceiver(mResetReceiver);
|
|
||||||
mVpn.setEnableTeardown(true);
|
mVpn.setEnableTeardown(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset VPN lockdown tracker. Called by ConnectivityService when receiving
|
||||||
|
* {@link #ACTION_LOCKDOWN_RESET} pending intent.
|
||||||
|
*/
|
||||||
|
@GuardedBy("mConnService.mVpns")
|
||||||
public void reset() {
|
public void reset() {
|
||||||
Slog.d(TAG, "reset()");
|
Slog.d(TAG, "reset()");
|
||||||
synchronized (mStateLock) {
|
synchronized (mStateLock) {
|
||||||
|
|||||||
Reference in New Issue
Block a user