@Override
 public void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   mAwContents.onDetachedFromWindow();
   if (mHardwareView != null) {
     mHardwareView.setReadyToRenderCallback(null);
   }
   mAttachedContents = false;
 }
 @Override
 public void onAttachedToWindow() {
   super.onAttachedToWindow();
   if (mHardwareView == null || mHardwareView.isReadyToRender()) {
     mAwContents.onAttachedToWindow();
     mAttachedContents = true;
   } else {
     mHardwareView.setReadyToRenderCallback(
         new Runnable() {
           @Override
           public void run() {
             assert !mAttachedContents;
             mAwContents.onAttachedToWindow();
             mAttachedContents = true;
           }
         });
   }
 }