replaced copied AOSP code with own implementation