Commit 5a5d9b93 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Make ApplicationStatus.getStateForActivity handle null input.

Holding a weak reference to activities is the preferred approach
in a lot of client code, so making this support null seems OK
to me.  I think it would be fine to update each client as well...
don't have a strong preference.

The gotcha (which I wasn't aware of) is that ConcurrentHashMap
does not handle null keys/calls of get(<key>).

BUG=792377

Change-Id: I34549aecf68c04f6140bbc4eaaa3405409347cba
Reviewed-on: https://chromium-review.googlesource.com/811431Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: David Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522315}
parent da07836f
...@@ -10,6 +10,7 @@ import android.app.Application; ...@@ -10,6 +10,7 @@ import android.app.Application;
import android.app.Application.ActivityLifecycleCallbacks; import android.app.Application.ActivityLifecycleCallbacks;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Window; import android.view.Window;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
...@@ -435,8 +436,9 @@ public class ApplicationStatus { ...@@ -435,8 +436,9 @@ public class ApplicationStatus {
* @return The state of the specified activity (see {@link ActivityState}). * @return The state of the specified activity (see {@link ActivityState}).
*/ */
@ActivityState @ActivityState
public static int getStateForActivity(Activity activity) { public static int getStateForActivity(@Nullable Activity activity) {
ApplicationStatus.assertInitialized(); ApplicationStatus.assertInitialized();
if (activity == null) return ActivityState.DESTROYED;
ActivityInfo info = sActivityInfo.get(activity); ActivityInfo info = sActivityInfo.get(activity);
return info != null ? info.getStatus() : ActivityState.DESTROYED; return info != null ? info.getStatus() : ActivityState.DESTROYED;
} }
......
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