Implemented the safe area logic on the Java side