OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.Application; | 9 import android.app.Application; |
10 import android.app.Application.ActivityLifecycleCallbacks; | 10 import android.app.Application.ActivityLifecycleCallbacks; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 public ObserverList<ActivityStateListener> getListeners() { | 54 public ObserverList<ActivityStateListener> getListeners() { |
55 return mListeners; | 55 return mListeners; |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 private static Object sCachedApplicationStateLock = new Object(); | 59 private static Object sCachedApplicationStateLock = new Object(); |
60 @ApplicationState | 60 @ApplicationState |
61 private static Integer sCachedApplicationState; | 61 private static Integer sCachedApplicationState; |
62 | 62 |
63 /** Last activity that was shown (or null if none or it was destroyed). */ | 63 /** Last activity that was shown (or null if none or it was destroyed). */ |
64 // TODO(crbug.com/635567): Fix this properly. | |
Ted C
2017/04/27 19:02:47
no fix needed, this is cleared when applicable alr
F
2017/04/28 18:25:14
Done.
| |
65 @SuppressLint("StaticFieldLeak") | |
64 private static Activity sActivity; | 66 private static Activity sActivity; |
65 | 67 |
66 /** A lazily initialized listener that forwards application state changes to native. */ | 68 /** A lazily initialized listener that forwards application state changes to native. */ |
67 private static ApplicationStateListener sNativeApplicationStateListener; | 69 private static ApplicationStateListener sNativeApplicationStateListener; |
68 | 70 |
69 /** | 71 /** |
70 * A map of which observers listen to state changes from which {@link Activi ty}. | 72 * A map of which observers listen to state changes from which {@link Activi ty}. |
71 */ | 73 */ |
72 private static final Map<Activity, ActivityInfo> sActivityInfo = | 74 private static final Map<Activity, ActivityInfo> sActivityInfo = |
73 new ConcurrentHashMap<Activity, ActivityInfo>(); | 75 new ConcurrentHashMap<Activity, ActivityInfo>(); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 } | 352 } |
351 | 353 |
352 /** | 354 /** |
353 * Registers the given listener to receive state changes for {@code activity }. After a call to | 355 * Registers the given listener to receive state changes for {@code activity }. After a call to |
354 * {@link ActivityStateListener#onActivityStateChange(Activity, int)} with | 356 * {@link ActivityStateListener#onActivityStateChange(Activity, int)} with |
355 * {@link ActivityState#DESTROYED} all listeners associated with that partic ular | 357 * {@link ActivityState#DESTROYED} all listeners associated with that partic ular |
356 * {@link Activity} are removed. | 358 * {@link Activity} are removed. |
357 * @param listener Listener to receive state changes. | 359 * @param listener Listener to receive state changes. |
358 * @param activity Activity to track or {@code null} to track all activities . | 360 * @param activity Activity to track or {@code null} to track all activities . |
359 */ | 361 */ |
362 // TODO(crbug.com/635567): Fix this properly. | |
Ted C
2017/04/27 19:02:47
fix what? activity.isDestroyed() is available in
F
2017/04/28 18:25:14
Done.
| |
360 @SuppressLint("NewApi") | 363 @SuppressLint("NewApi") |
361 public static void registerStateListenerForActivity(ActivityStateListener li stener, | 364 public static void registerStateListenerForActivity(ActivityStateListener li stener, |
362 Activity activity) { | 365 Activity activity) { |
363 assert activity != null; | 366 assert activity != null; |
364 | 367 |
365 ActivityInfo info = sActivityInfo.get(activity); | 368 ActivityInfo info = sActivityInfo.get(activity); |
366 // TODO(tedchoc): crbug/691100. The timing of application callback life cycles were changed | 369 // TODO(tedchoc): crbug/691100. The timing of application callback life cycles were changed |
367 // in O and the activity info may need to be lazily creat ed if the onCreate | 370 // in O and the activity info may need to be lazily creat ed if the onCreate |
368 // event has not yet been received. | 371 // event has not yet been received. |
369 if (BuildInfo.isAtLeastO() && info == null && !activity.isDestroyed()) { | 372 if (BuildInfo.isAtLeastO() && info == null && !activity.isDestroyed()) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 | 475 |
473 if (hasPausedActivity) return ApplicationState.HAS_PAUSED_ACTIVITIES; | 476 if (hasPausedActivity) return ApplicationState.HAS_PAUSED_ACTIVITIES; |
474 if (hasStoppedActivity) return ApplicationState.HAS_STOPPED_ACTIVITIES; | 477 if (hasStoppedActivity) return ApplicationState.HAS_STOPPED_ACTIVITIES; |
475 return ApplicationState.HAS_DESTROYED_ACTIVITIES; | 478 return ApplicationState.HAS_DESTROYED_ACTIVITIES; |
476 } | 479 } |
477 | 480 |
478 // Called to notify the native side of state changes. | 481 // Called to notify the native side of state changes. |
479 // IMPORTANT: This is always called on the main thread! | 482 // IMPORTANT: This is always called on the main thread! |
480 private static native void nativeOnApplicationStateChange(@ApplicationState int newState); | 483 private static native void nativeOnApplicationStateChange(@ApplicationState int newState); |
481 } | 484 } |
OLD | NEW |