Whenever Android App needs a handle to system service(such as LAYOUT_INFLATER_SERVICE or TELEPHONY_SERVICE), the usual way is to make a call to getSystemService() API with appropriate service name, like below:
Context.getSystemService(Context.TELEPHONY_SERVICE)
In AOSP, in the source code of TelephonyManager class, it is clear that 1 Constructor is "private" but this class also has 1 "Public" constructor as well.
public TelephonyManager(Context context)
But when in code, when I try to create a class using this "public" constructor in below code:
TelephonyManager tm = new TelephonyManager(context);
During compilation only, Eclipse reports an error saying:
"The constructor TelephonyManager(context) is undefined"
So, somehow Android is ensuring that handle to system service can only be obtained using getSystemService() API, and not even through "public" constructor.
What is that code/technique used to achieve this?
There is @hide annotation which is associated with these constructors.
AFAIK, @hide attribute is just part of javadoc(droiddoc also), so the "hide" annotation just simply mean the method/class/field is excluded from the API docs.
I am not sure if this annotation is preventing "TelephonyManager " object creation.