public class TelephonyController
extends java.lang.Object
ITelephony
interface as discovered in the Android open source repository. However, in
this class, several of those methods are marked as deprecated. For each of
these deprecated methods, there is a static alternative that does not require
the reflexive workarounds of this class, and which will likely be more
efficient. Though marked as deprecated, there is no plan to remove them from
this library; the deprecation is merely an encouragement to choose
alternatives.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LOG_TAG |
protected java.lang.Class<?> |
m_clsITelephony
A persistent reflection into the Android internal telephony controller.
|
protected android.content.Context |
m_ctx
The context in which the controller operates.
|
protected java.lang.Object |
m_mgrServices
A persistent reference to the Android internal service manager.
|
protected java.lang.Object |
m_mgrTelephony
A persistent reference to the Android internal telephony controller.
|
static java.lang.String |
SERVICE_MANAGER_CLASS |
static java.lang.String |
SERVICE_MANAGER_NATIVE_CLASS |
static java.lang.String |
TELEPHONY_INTERFACE |
Constructor and Description |
---|
TelephonyController(android.content.Context ctx)
Initializes the controller in the given context.
|
Modifier and Type | Method and Description |
---|---|
void |
answerRingingCall()
Answers an incoming call.
|
void |
answerRingingCallForSubscriber(int id)
Answers an incoming call on behalf of a subscriber.
|
void |
call(java.lang.String pkgCaller,
java.lang.String sNumber)
Deprecated.
Use
placeCall(android.content.Context, java.lang.String) instead. |
void |
dial(java.lang.String sNumber)
Dials the specified number, but does not call it.
|
boolean |
disableDataConnectivity()
Disables the data connection over the cell radio.
|
protected java.lang.String |
dumpDiscoveredMethods()
Used to discover the actual definition of the
ITelephony
interface as visible to the current app. |
boolean |
enableDataConnectivity()
Enables the data connection over the cell radio.
|
boolean |
endCall()
Terminates a call in progress.
|
boolean |
endCallForSubscriber(int id)
Terminates a call in progress on behalf of a subscriber.
|
static int |
getCallState(android.content.Context ctx)
Indicates the current call state.
|
int |
getDataState()
Deprecated.
Use
getDataState(Context) instead. |
static int |
getDataState(android.content.Context ctx)
Indicates the current call state.
|
static android.telephony.TelephonyManager |
getManager(android.content.Context ctx)
Fetches an instance of the device's telephony manager.
|
protected TelephonyController |
init()
Initializes the member object that represents the Android telephony
controller.
|
protected java.lang.Object |
invoke(java.lang.String sMethod,
java.lang.Class<?>[] aclsTypes,
java.lang.Object[] aoParams)
Standard method of reflectively invoking a method of the telephony
manager.
|
boolean |
isDataConnectivityPossible()
Indicates whether the cell radio supports data connectivity.
|
static boolean |
isIdle(android.content.Context ctx)
Indicates whether the phone is in "idle" state — that is, no
outbound or inbound calls are in progress.
|
boolean |
isIdle(java.lang.String pkgCaller)
Deprecated.
Use
getCallState(android.content.Context) or isIdle(Context)
instead. |
boolean |
isIdleForSubscriber(int id,
java.lang.String pkgCaller)
Deprecated.
Use
getCallState(android.content.Context) or isIdle(Context)
instead. |
static boolean |
isOffhook(android.content.Context ctx)
Indicates whether the phone is "off-hook" — that is, waiting for a
call to complete, or fully engaged with an active call.
|
boolean |
isOffhook(java.lang.String pkgCaller)
Deprecated.
Use
getCallState(android.content.Context) or isOffhook(Context)
instead. |
boolean |
isOffhookForSubscriber(int id,
java.lang.String pkgCaller)
Deprecated.
Use
getCallState(android.content.Context) or isOffhook(Context)
instead. |
boolean |
isRadioOn(java.lang.String pkgCaller)
Indicates whether the cell radio is active.
|
boolean |
isRadioOnForSubscriber(int id,
java.lang.String pkgCaller)
Indicates whether the cell radio is active.
|
static boolean |
isRinging(android.content.Context ctx)
Indicates whether there is currently an incoming call that is causing
either a ring tone or a call waiting tone.
|
boolean |
isRinging(java.lang.String pkgCaller)
Deprecated.
Use
getCallState(android.content.Context) or isRinging(Context)
instead. |
boolean |
isRingingForSubscriber(int id,
java.lang.String pkgCaller)
Deprecated.
Use
getCallState(android.content.Context) or isRinging(Context)
instead. |
static void |
placeCall(android.content.Context ctx,
java.lang.String sNumber)
Places an outbound call to the specified telephone number.
|
boolean |
setRadio(boolean bEnabled)
Sets the cell radio on or off.
|
void |
silenceRinger()
Silences the ringer if an incoming call is ringing.
|
boolean |
supplyPin(java.lang.String sPIN)
Supply a PIN to unlock the phone's SIM card.
|
boolean |
supplyPinForSubscriber(int id,
java.lang.String sPIN)
Supply a PIN to unlock the phone's SIM card.
|
boolean |
supplyPuk(java.lang.String sPUK,
java.lang.String sPIN)
Supply a PUK (Personal Unlocking Key) to unlock the SIM and set its PIN
to a new value.
|
boolean |
supplyPukForSubscriber(int id,
java.lang.String sPUK,
java.lang.String sPIN)
Supply a PUK (Personal Unlocking Key) to unlock the SIM and set its PIN
to a new value.
|
void |
toggleRadio()
Toggles the state of the cell radio.
|
public static final java.lang.String LOG_TAG
public static final java.lang.String SERVICE_MANAGER_CLASS
public static final java.lang.String SERVICE_MANAGER_NATIVE_CLASS
public static final java.lang.String TELEPHONY_INTERFACE
protected android.content.Context m_ctx
protected java.lang.Object m_mgrServices
protected java.lang.Class<?> m_clsITelephony
protected java.lang.Object m_mgrTelephony
public TelephonyController(android.content.Context ctx) throws ControllerConstructionException
ctx
- the context in which the controller will operateControllerConstructionException
- if any failures occur under the
hoodinit()
public static android.telephony.TelephonyManager getManager(android.content.Context ctx)
Managers.get(android.content.Context, java.lang.Class<MGR>)
with the
appropriate class selected.ctx
- the context in which services are availablepublic static int getCallState(android.content.Context ctx) throws java.lang.SecurityException
TelephonyManager.getCallState()
on an
existing instance of the manager.
This method requires the
android.permission.READ_PHONE_STATE
permission, and will throw a
SecurityException
if the permission is not granted at runtime.ctx
- the context in which to check call stateTelephonyManager
:
CALL_STATE_RINGING
,
CALL_STATE_OFFHOOK
, or
CALL_STATE_IDLE
java.lang.SecurityException
- if the
android.permission.READ_PHONE_STATE
permission is not granted to
the app at runtimepublic static boolean isIdle(android.content.Context ctx) throws java.lang.SecurityException
ctx
- the context in which to check call statetrue
if the call state is "idle"java.lang.SecurityException
- if the
android.permission.READ_PHONE_STATE
permission is not granted to
the app at runtimepublic static boolean isOffhook(android.content.Context ctx) throws java.lang.SecurityException
ctx
- the context in which to check call statetrue
if the call state is "off-hook"java.lang.SecurityException
- if the
android.permission.READ_PHONE_STATE
permission is not granted to
the app at runtimepublic static boolean isRinging(android.content.Context ctx) throws java.lang.SecurityException
ctx
- the context in which to check call statetrue
if the call state is "ringing"java.lang.SecurityException
- if the
android.permission.READ_PHONE_STATE
permission is not granted to
the app at runtimepublic static int getDataState(android.content.Context ctx)
TelephonyManager.getDataState()
on an
existing instance of the manager.ctx
- the context in which to check data stateTelephonyManager
:
TelephonyManager.DATA_DISCONNECTED
,
TelephonyManager.DATA_CONNECTING
,
TelephonyManager.DATA_CONNECTED
, or
TelephonyManager.DATA_SUSPENDED
public static void placeCall(android.content.Context ctx, java.lang.String sNumber) throws java.lang.SecurityException
android.permission.CALL_PHONE
permission, and will throw a SecurityException
if the permission
is not granted at runtime.ctx
- the context in which to initiate the callsNumber
- a telephone numberjava.lang.SecurityException
- if the android.permission.CALL_PHONE
permission is not granted to the app at runtimePermissionCheckpoint.checkPermission(android.content.Context, java.lang.String)
protected TelephonyController init() throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundException
- if any of the various classes cannot be
found via reflectionjava.lang.NoSuchMethodException
- if any of the various methods cannot be
found via reflectionjava.lang.IllegalAccessException
- if a method invocation is forbiddenjava.lang.reflect.InvocationTargetException
- if a method cannot be invokedprotected java.lang.String dumpDiscoveredMethods()
ITelephony
interface as visible to the current app.protected java.lang.Object invoke(java.lang.String sMethod, java.lang.Class<?>[] aclsTypes, java.lang.Object[] aoParams) throws ControllerInvocationException
sMethod
- the name of the underlying method being invokedaclsTypes
- an array of parameter types, corresponding to the
parameters given in aoParams
(since zer0bandwidth-net/android 0.0.6 (#17))aoParams
- any parameters that would be passed to the underlying
method, corresponding to the types given in
aclsTypes
(since zer0bandwidth-net/android 0.0.6 (#17))ControllerInvocationException
- if the invocation failspublic void answerRingingCall() throws ControllerInvocationException
ControllerInvocationException
- if the invocation failspublic void answerRingingCallForSubscriber(int id)
id
- the subscriber IDControllerInvocationException
- if the invocation failspublic void call(java.lang.String pkgCaller, java.lang.String sNumber) throws ControllerInvocationException
placeCall(android.content.Context, java.lang.String)
instead.pkgCaller
- the code package that is requesting the callsNumber
- the target phone numberControllerInvocationException
- if the invocation failspublic void dial(java.lang.String sNumber) throws ControllerInvocationException
sNumber
- the target phone numberControllerInvocationException
- if the invocation failspublic boolean disableDataConnectivity() throws ControllerInvocationException
ControllerInvocationException
- if the invocation failspublic boolean enableDataConnectivity() throws ControllerInvocationException
ControllerInvocationException
- if the invocation failspublic boolean endCall() throws ControllerInvocationException
ControllerInvocationException
- if the invocation failspublic boolean endCallForSubscriber(int id) throws ControllerInvocationException
id
- the subscriber IDControllerInvocationException
- if the invocation failspublic int getDataState() throws ControllerInvocationException
getDataState(Context)
instead.ControllerInvocationException
- if the invocation failspublic boolean isDataConnectivityPossible() throws ControllerInvocationException
ControllerInvocationException
- if the invocation failspublic boolean isIdle(java.lang.String pkgCaller) throws ControllerInvocationException
getCallState(android.content.Context)
or isIdle(Context)
instead.pkgCaller
- the code package making the inquirytrue
if the phone state is "idle"ControllerInvocationException
- if the invocation failspublic boolean isIdleForSubscriber(int id, java.lang.String pkgCaller) throws ControllerInvocationException
getCallState(android.content.Context)
or isIdle(Context)
instead.id
- the subscriber IDpkgCaller
- the code package making the inquirytrue
if the phone state is "idle"ControllerInvocationException
- if the invocation failspublic boolean isOffhook(java.lang.String pkgCaller) throws ControllerInvocationException
getCallState(android.content.Context)
or isOffhook(Context)
instead.pkgCaller
- the code package that is requesting the functiontrue
if the phone state is "off-hook"ControllerInvocationException
- if the invocation failspublic boolean isOffhookForSubscriber(int id, java.lang.String pkgCaller) throws ControllerInvocationException
getCallState(android.content.Context)
or isOffhook(Context)
instead.id
- the subscriber IDpkgCaller
- the code package making the inquirytrue
if the phone state is "off-hook"ControllerInvocationException
- if the invocation failspublic boolean isRadioOn(java.lang.String pkgCaller) throws ControllerInvocationException
pkgCaller
- the code package making the inquirytrue
if the cell radio is activeControllerInvocationException
- if the invocation failspublic boolean isRadioOnForSubscriber(int id, java.lang.String pkgCaller) throws ControllerInvocationException
id
- the subscriber IDpkgCaller
- the code package making the inquirytrue
if the cell radio is activeControllerInvocationException
- if the invocation failspublic boolean isRinging(java.lang.String pkgCaller) throws ControllerInvocationException
getCallState(android.content.Context)
or isRinging(Context)
instead.pkgCaller
- the code package making the inquirytrue
if the phone state is "ringing"ControllerInvocationException
- if the invocation failspublic boolean isRingingForSubscriber(int id, java.lang.String pkgCaller) throws ControllerInvocationException
getCallState(android.content.Context)
or isRinging(Context)
instead.id
- the subscriber IDpkgCaller
- the code package making the inquirytrue
if the phone state is "ringing"ControllerInvocationException
- if the invocation failspublic boolean setRadio(boolean bEnabled) throws ControllerInvocationException
bEnabled
- true
to enable; false
to disableControllerInvocationException
- if the invocation failspublic void silenceRinger() throws ControllerInvocationException
ControllerInvocationException
- if the invocation failspublic boolean supplyPin(java.lang.String sPIN) throws ControllerInvocationException
sPIN
- the PIN to be checkedControllerInvocationException
- if the invocation failspublic boolean supplyPinForSubscriber(int id, java.lang.String sPIN) throws ControllerInvocationException
id
- the subscriber IDsPIN
- the PIN to be checkedControllerInvocationException
- if the invocation failspublic boolean supplyPuk(java.lang.String sPUK, java.lang.String sPIN) throws ControllerInvocationException
sPUK
- the unlock keysPIN
- the new PIN to setControllerInvocationException
- if the invocation failspublic boolean supplyPukForSubscriber(int id, java.lang.String sPUK, java.lang.String sPIN) throws ControllerInvocationException
id
- the subscriber IDsPUK
- the unlock keysPIN
- the new PIN to setControllerInvocationException
- if the invocation failspublic void toggleRadio() throws ControllerInvocationException
ControllerInvocationException
- if the invocation fails