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.app.Activity; | 7 import android.app.Activity; |
8 import android.app.Application; | 8 import android.app.Application; |
9 import android.app.Application.ActivityLifecycleCallbacks; | 9 import android.app.Application.ActivityLifecycleCallbacks; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 386 |
387 /** | 387 /** |
388 * Unregisters the given listener from receiving state changes. | 388 * Unregisters the given listener from receiving state changes. |
389 * @param listener Listener that doesn't want to receive state changes. | 389 * @param listener Listener that doesn't want to receive state changes. |
390 */ | 390 */ |
391 public static void unregisterApplicationStateListener(ApplicationStateListen
er listener) { | 391 public static void unregisterApplicationStateListener(ApplicationStateListen
er listener) { |
392 sApplicationStateListeners.removeObserver(listener); | 392 sApplicationStateListeners.removeObserver(listener); |
393 } | 393 } |
394 | 394 |
395 /** | 395 /** |
| 396 * Robolectric JUnit tests create a new application between each test, while
all the context |
| 397 * in static classes isn't reset. This function allows to reset the applicat
ion status to avoid |
| 398 * being in a dirty state. |
| 399 */ |
| 400 public static void destroyForJUnitTests() { |
| 401 sApplicationStateListeners.clear(); |
| 402 sGeneralActivityStateListeners.clear(); |
| 403 sActivityInfo.clear(); |
| 404 synchronized (sCachedApplicationStateLock) { |
| 405 sCachedApplicationState = null; |
| 406 } |
| 407 sActivity = null; |
| 408 sApplication = null; |
| 409 sNativeApplicationStateListener = null; |
| 410 } |
| 411 |
| 412 /** |
396 * Registers the single thread-safe native activity status listener. | 413 * Registers the single thread-safe native activity status listener. |
397 * This handles the case where the caller is not on the main thread. | 414 * This handles the case where the caller is not on the main thread. |
398 * Note that this is used by a leaky singleton object from the native | 415 * Note that this is used by a leaky singleton object from the native |
399 * side, hence lifecycle management is greatly simplified. | 416 * side, hence lifecycle management is greatly simplified. |
400 */ | 417 */ |
401 @CalledByNative | 418 @CalledByNative |
402 private static void registerThreadSafeNativeApplicationStateListener() { | 419 private static void registerThreadSafeNativeApplicationStateListener() { |
403 ThreadUtils.runOnUiThread(new Runnable() { | 420 ThreadUtils.runOnUiThread(new Runnable() { |
404 @Override | 421 @Override |
405 public void run() { | 422 public void run() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 461 |
445 if (hasPausedActivity) return ApplicationState.HAS_PAUSED_ACTIVITIES; | 462 if (hasPausedActivity) return ApplicationState.HAS_PAUSED_ACTIVITIES; |
446 if (hasStoppedActivity) return ApplicationState.HAS_STOPPED_ACTIVITIES; | 463 if (hasStoppedActivity) return ApplicationState.HAS_STOPPED_ACTIVITIES; |
447 return ApplicationState.HAS_DESTROYED_ACTIVITIES; | 464 return ApplicationState.HAS_DESTROYED_ACTIVITIES; |
448 } | 465 } |
449 | 466 |
450 // Called to notify the native side of state changes. | 467 // Called to notify the native side of state changes. |
451 // IMPORTANT: This is always called on the main thread! | 468 // IMPORTANT: This is always called on the main thread! |
452 private static native void nativeOnApplicationStateChange(int newState); | 469 private static native void nativeOnApplicationStateChange(int newState); |
453 } | 470 } |
OLD | NEW |