class BindingManagerImpl implements BindingManager {
private static final String TAG = "BindingManager";
- // Delay of 1 second used when removing the initial oom binding of a process.
- private static final long REMOVE_INITIAL_BINDING_DELAY_MILLIS = 1 * 1000;
-
// Delay of 1 second used when removing temporary strong binding of a process (only on
// non-low-memory devices).
private static final long DETACH_AS_ACTIVE_HIGH_END_DELAY_MILLIS = 1 * 1000;
// These fields allow to override the parameters for testing - see
// createBindingManagerForTesting().
- private final long mRemoveInitialBindingDelay;
private final long mRemoveStrongBindingDelay;
private final boolean mIsLowMemoryDevice;
/** Removes the initial service binding. */
private void removeInitialBinding() {
- final ChildProcessConnection connection = mConnection;
- if (connection == null || !connection.isInitialBindingBound()) return;
-
- ThreadUtils.postOnUiThreadDelayed(new Runnable() {
- @Override
- public void run() {
- if (connection.isInitialBindingBound()) {
- connection.removeInitialBinding();
- }
- }
- }, mRemoveInitialBindingDelay);
+ if (mConnection == null || !mConnection.isInitialBindingBound()) return;
+ mConnection.removeInitialBinding();
}
/** Adds a strong service binding. */
}
/**
- * Sets the visibility of the service, adding or removing the strong binding as needed. This
- * also removes the initial binding, as the service visibility is now known.
+ * Sets the visibility of the service, adding or removing the strong binding as needed.
*/
void setInForeground(boolean nextInForeground) {
if (!mInForeground && nextInForeground) {
removeStrongBinding();
}
- removeInitialBinding();
mInForeground = nextInForeground;
}
/**
+ * Removes the initial binding.
+ */
+ void determinedVisibility() {
+ removeInitialBinding();
+ }
+
+ /**
* Sets or removes additional binding when the service is main service during the embedder
* background period.
*/
// When a process crashes, we can be queried about its oom status before or after the
// connection is cleared. For the latter case, the oom status is stashed in
// mWasOomProtected.
- return mConnection != null ?
- mConnection.isOomProtectedOrWasWhenDied() : mWasOomProtected;
+ return mConnection != null
+ ? mConnection.isOomProtectedOrWasWhenDied() : mWasOomProtected;
}
void clearConnection() {
* The constructor is private to hide parameters exposed for testing from the regular consumer.
* Use factory methods to create an instance.
*/
- private BindingManagerImpl(boolean isLowMemoryDevice, long removeInitialBindingDelay,
- long removeStrongBindingDelay) {
+ private BindingManagerImpl(boolean isLowMemoryDevice, long removeStrongBindingDelay) {
mIsLowMemoryDevice = isLowMemoryDevice;
- mRemoveInitialBindingDelay = removeInitialBindingDelay;
mRemoveStrongBindingDelay = removeStrongBindingDelay;
}
public static BindingManagerImpl createBindingManager() {
return new BindingManagerImpl(SysUtils.isLowEndDevice(),
- REMOVE_INITIAL_BINDING_DELAY_MILLIS, DETACH_AS_ACTIVE_HIGH_END_DELAY_MILLIS);
+ DETACH_AS_ACTIVE_HIGH_END_DELAY_MILLIS);
}
/**
* @param isLowEndDevice true iff the created instance should apply low-end binding policies
*/
public static BindingManagerImpl createBindingManagerForTesting(boolean isLowEndDevice) {
- return new BindingManagerImpl(isLowEndDevice, 0, 0);
+ return new BindingManagerImpl(isLowEndDevice, 0);
}
@Override
}
if (managedConnection == null) {
- Log.w(TAG, "Cannot setInForeground() - never saw a connection for the pid: " +
- Integer.toString(pid));
+ Log.w(TAG, "Cannot setInForeground() - never saw a connection for the pid: "
+ + Integer.toString(pid));
return;
}
}
@Override
+ public void determinedVisibility(int pid) {
+ ManagedConnection managedConnection;
+ synchronized (mManagedConnections) {
+ managedConnection = mManagedConnections.get(pid);
+ }
+
+ if (managedConnection == null) {
+ Log.w(TAG, "Cannot call determinedVisibility() - never saw a connection for the pid: "
+ + Integer.toString(pid));
+ return;
+ }
+
+ managedConnection.determinedVisibility();
+ }
+
+ @Override
public void onSentToBackground() {
assert mBoundForBackgroundPeriod == null;
synchronized (mLastInForegroundLock) {