Merge "TIF: Handle possible memory leaks" into nyc-dev am: cea42f6353

am: 07b1cd430b

* commit '07b1cd430b46085042d3d753520d79a23640c7f2':
  TIF: Handle possible memory leaks

Change-Id: I8d6b25e4f69e387c9e345a517e3013ee862f142c
This commit is contained in:
Youngsang Cho
2016-05-10 01:42:12 +00:00
committed by android-build-merger

View File

@@ -78,6 +78,8 @@ public abstract class TvInputService extends Service {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final String TAG = "TvInputService"; private static final String TAG = "TvInputService";
private static final int DETACH_OVERLAY_VIEW_TIMEOUT_MS = 5000;
/** /**
* This is the interface name that a service implementing a TV input should say that it support * This is the interface name that a service implementing a TV input should say that it support
* -- that is, this is the action it uses for its intent filter. To be supported, the service * -- that is, this is the action it uses for its intent filter. To be supported, the service
@@ -268,7 +270,6 @@ public abstract class TvInputService extends Service {
* Base class for derived classes to implement to provide a TV input session. * Base class for derived classes to implement to provide a TV input session.
*/ */
public abstract static class Session implements KeyEvent.Callback { public abstract static class Session implements KeyEvent.Callback {
private static final int DETACH_OVERLAY_VIEW_TIMEOUT_MS = 5000;
private static final int POSITION_UPDATE_INTERVAL_MS = 1000; private static final int POSITION_UPDATE_INTERVAL_MS = 1000;
private final KeyEvent.DispatcherState mDispatcherState = new KeyEvent.DispatcherState(); private final KeyEvent.DispatcherState mDispatcherState = new KeyEvent.DispatcherState();
@@ -1256,7 +1257,7 @@ public abstract class TvInputService extends Service {
// Creates a container view to check hanging on the overlay view detaching. // Creates a container view to check hanging on the overlay view detaching.
// Adding/removing the overlay view to/from the container make the view attach/detach // Adding/removing the overlay view to/from the container make the view attach/detach
// logic run on the main thread. // logic run on the main thread.
mOverlayViewContainer = new FrameLayout(mContext); mOverlayViewContainer = new FrameLayout(mContext.getApplicationContext());
mOverlayViewContainer.addView(mOverlayView); mOverlayViewContainer.addView(mOverlayView);
// TvView's window type is TYPE_APPLICATION_MEDIA and we want to create // TvView's window type is TYPE_APPLICATION_MEDIA and we want to create
// an overlay window above the media window but below the application window. // an overlay window above the media window but below the application window.
@@ -1496,26 +1497,26 @@ public abstract class TvInputService extends Service {
POSITION_UPDATE_INTERVAL_MS); POSITION_UPDATE_INTERVAL_MS);
} }
} }
}
private final class OverlayViewCleanUpTask extends AsyncTask<View, Void, Void> { private static final class OverlayViewCleanUpTask extends AsyncTask<View, Void, Void> {
@Override @Override
protected Void doInBackground(View... views) { protected Void doInBackground(View... views) {
View overlayViewParent = views[0]; View overlayViewParent = views[0];
try { try {
Thread.sleep(DETACH_OVERLAY_VIEW_TIMEOUT_MS); Thread.sleep(DETACH_OVERLAY_VIEW_TIMEOUT_MS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
return null;
}
if (isCancelled()) {
return null;
}
if (overlayViewParent.isAttachedToWindow()) {
Log.e(TAG, "Time out on releasing overlay view. Killing "
+ overlayViewParent.getContext().getPackageName());
Process.killProcess(Process.myPid());
}
return null; return null;
} }
if (isCancelled()) {
return null;
}
if (overlayViewParent.isAttachedToWindow()) {
Log.e(TAG, "Time out on releasing overlay view. Killing "
+ overlayViewParent.getContext().getPackageName());
Process.killProcess(Process.myPid());
}
return null;
} }
} }