[Android] Truy cập Internal API thông qua phương pháp reflection

Yêu cầu: Ngắt cuộc gọi theo yêu cầu nhất định như theo thời gian và nhiều điều kiện. Kể cả khi người dùng đã nhận cuộc gọi hay chưa.

Class ví dụ: Telephony Class

Code:

try {
String serviceManagerName = “android.os.ServiceManager”;
String serviceManagerNativeName = “android.os.ServiceManagerNative”;
String telephonyName = “com.android.internal.telephony.ITelephony”;
Class<?> telephonyClass;
Class<?> telephonyStubClass;
Class<?> serviceManagerClass;
Class<?> serviceManagerNativeClass;
Method telephonyEndCall;
Object telephonyObject;
Object serviceManagerObject;
telephonyClass = Class.forName(telephonyName);
telephonyStubClass = telephonyClass.getClasses()[0];
serviceManagerClass = Class.forName(serviceManagerName);
serviceManagerNativeClass = Class.forName(serviceManagerNativeName);
Method getService = // getDefaults[29];
serviceManagerClass.getMethod(“getService”, String.class);
Method tempInterfaceMethod = serviceManagerNativeClass.getMethod(“asInterface”, IBinder.class);
Binder tmpBinder = new Binder();
tmpBinder.attachInterface(null, “fake”);
serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder);
IBinder reBinder = (IBinder) getService.invoke(serviceManagerObject, “phone”);
Method serviceMethod = telephonyStubClass.getMethod(“asInterface”, IBinder.class);
telephonyObject = serviceMethod.invoke(null, reBinder);

//Call End Call method
telephonyEndCall = telephonyClass.getMethod(“endCall”);
telephonyEndCall.invoke(telephonyObject);
} catch (Exception ex) { }

Hạn chế

  • Với mỗi nhà cung cấp họ sẽ tùy biến Android theo cách riêng Vì vậy tên của Internal Class có thể khác nhau tùy theo nhà sản xuất.
  • Google hoặc nhà sản xuất có thể chặn quyền truy cập các API này mà không thông báo trước.
  • Mỗi lần thay đổi phiên bản Android có thể sẽ cần kiểm tra lại hoạt động của các API này.
Bài viết liên quan