Revert "Revert "frameworks/base: Fix to avoid crash when the tab is not set from app""

This reverts commit 6aaea237ad2278c6c7aae9e933359865f81a099c.