Merge changes I623e2983,I8b95e020 am: ec1966e372 am: bf84b9239b

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1479476

Change-Id: I8fa040d1156b88de203e6e6f1ddb776faf0ba82c
This commit is contained in:
Chalard Jean
2020-10-29 10:32:30 +00:00
committed by Automerger Merge Worker
2 changed files with 8 additions and 5 deletions

View File

@@ -83,8 +83,8 @@ public class LegacyVpnInfo implements Parcelable {
* Return best matching {@link LegacyVpnInfo} state based on given
* {@link NetworkInfo}.
*/
public static int stateFromNetworkInfo(NetworkInfo info) {
switch (info.getDetailedState()) {
public static int stateFromNetworkInfo(NetworkInfo.DetailedState state) {
switch (state) {
case CONNECTING:
return STATE_CONNECTING;
case CONNECTED:
@@ -94,8 +94,7 @@ public class LegacyVpnInfo implements Parcelable {
case FAILED:
return STATE_FAILED;
default:
Log.w(TAG, "Unhandled state " + info.getDetailedState()
+ " ; treating as disconnected");
Log.w(TAG, "Unhandled state " + state + " ; treating as disconnected");
return STATE_DISCONNECTED;
}
}

View File

@@ -201,6 +201,7 @@ public class Vpn {
private final Context mContext;
@VisibleForTesting final Dependencies mDeps;
private final NetworkInfo mNetworkInfo;
private int mLegacyState;
@VisibleForTesting protected String mPackage;
private int mOwnerUID;
private boolean mIsPackageTargetingAtLeastQ;
@@ -415,6 +416,7 @@ public class Vpn {
Log.wtf(TAG, "Problem registering observer", e);
}
mLegacyState = LegacyVpnInfo.STATE_DISCONNECTED;
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_VPN, 0 /* subtype */, NETWORKTYPE,
"" /* subtypeName */);
mNetworkCapabilities = new NetworkCapabilities();
@@ -440,6 +442,7 @@ public class Vpn {
@VisibleForTesting
protected void updateState(DetailedState detailedState, String reason) {
if (LOGD) Log.d(TAG, "setting state=" + detailedState + ", reason=" + reason);
mLegacyState = LegacyVpnInfo.stateFromNetworkInfo(detailedState);
mNetworkInfo.setDetailedState(detailedState, reason, null);
if (mNetworkAgent != null) {
mNetworkAgent.sendNetworkInfo(mNetworkInfo);
@@ -1243,6 +1246,7 @@ public class Vpn {
// behaves the same as when it uses the default network.
mNetworkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
mLegacyState = LegacyVpnInfo.STATE_CONNECTING;
mNetworkInfo.setDetailedState(DetailedState.CONNECTING, null, null);
NetworkAgentConfig networkAgentConfig = new NetworkAgentConfig();
@@ -2265,7 +2269,7 @@ public class Vpn {
final LegacyVpnInfo info = new LegacyVpnInfo();
info.key = mConfig.user;
info.state = LegacyVpnInfo.stateFromNetworkInfo(mNetworkInfo);
info.state = mLegacyState;
if (mNetworkInfo.isConnected()) {
info.intent = mStatusIntent;
}