Move attach/detach PiP menu calls to onTaskAppear/Vanish.

In an ideal case, onActivityPinned should always be followed by
an onActivityUpinned call in a PiP session. However, there are
possible times where it doesn't happen; PIP can crash suddenly,
or some other calls force closes PiP without it
getting a chance to call on Unpinned. In that case, menu isn't properly
cleaned up, so let's just make sure it is before trying to re-attach.
At the same time, move the call to onTaskAppear/Vanish, which is
guaranteed to be called.

Bug: 172268911
Bug: 172258041
Bug: 170315895
Test: Manual; Pause PiP, unpause PiP, menu still showing
Test: Locally hack so that detach doesn't get called the first time
(simulate crash), start PiP again - doesn't crash

Change-Id: I76984de59515f4178561ba92ae692fcc3c5edcb9
3 files changed