Commit 014ef33b authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Fix crash in NetworkActivationRequest

We try to unregister NetworkCallback in cases where one was never
registered due to an earlier failure. This fixes that.

Fixed: 1121933
Change-Id: If0a3a9db5d64197e8bad11df8bc53d8433692d21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392742
Commit-Queue: Ken Rockot <rockot@google.com>
Commit-Queue: Zhongyi Shi <zhongyi@chromium.org>
Reviewed-by: default avatarZhongyi Shi <zhongyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804356}
parent 471340e7
...@@ -44,7 +44,6 @@ public class NetworkActivationRequest extends NetworkCallback { ...@@ -44,7 +44,6 @@ public class NetworkActivationRequest extends NetworkCallback {
mConnectivityManager = mConnectivityManager =
(ConnectivityManager) ContextUtils.getApplicationContext().getSystemService( (ConnectivityManager) ContextUtils.getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE); Context.CONNECTIVITY_SERVICE);
mNativePtr = nativePtr;
if (mConnectivityManager == null) return; if (mConnectivityManager == null) return;
try { try {
...@@ -54,6 +53,10 @@ public class NetworkActivationRequest extends NetworkCallback { ...@@ -54,6 +53,10 @@ public class NetworkActivationRequest extends NetworkCallback {
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build(), .build(),
this); this);
// Only track the native pointer (and thus allow future unregistration) if the above
// call succeeds.
mNativePtr = nativePtr;
} catch (SecurityException e) { } catch (SecurityException e) {
// On some older devices the CHANGE_NETWORK_STATE permission is not sufficient to allow // On some older devices the CHANGE_NETWORK_STATE permission is not sufficient to allow
// use of {@code requestNetwork} above and it will throw a SecurityException. Do nothing // use of {@code requestNetwork} above and it will throw a SecurityException. Do nothing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment