Dont attempt to place a call if canCall returns false.
Bug: 15359464
Change-Id: Icca208b9704d5f1bf391aa576ddcce3d558f29d1
diff --git a/src/com/android/services/telephony/PstnConnectionService.java b/src/com/android/services/telephony/PstnConnectionService.java
index b692e73..cd3598e 100644
--- a/src/com/android/services/telephony/PstnConnectionService.java
+++ b/src/com/android/services/telephony/PstnConnectionService.java
@@ -49,6 +49,13 @@
public void onCreateConnections(
final ConnectionRequest request,
final Response<ConnectionRequest, Connection> response) {
+
+ if (!canCall(request.getHandle())) {
+ Log.d(this, "Cannot place the call with %s", this.getClass().getSimpleName());
+ respondWithError(request, response, "Cannot place call.");
+ return;
+ }
+
// TODO: Consider passing call emergency information as part of ConnectionRequest so
// that we do not have to make the check here once again.
String handle = request.getHandle().getSchemeSpecificPart();
@@ -64,7 +71,7 @@
if (isRadioReady) {
startCallWithPhone(phone, request, response);
} else {
- responseError(request, response, "Failed to turn on radio.");
+ respondWithError(request, response, "Failed to turn on radio.");
}
}
}
@@ -93,7 +100,7 @@
com.android.internal.telephony.Connection connection = call.getEarliestConnection();
if (isConnectionKnown(connection)) {
- responseError(
+ respondWithError(
request,
response,
"Cannot set incoming call ID, ringing connection already registered.");
@@ -110,17 +117,17 @@
try {
telephonyConnection = createTelephonyConnection(request, connection);
} catch (Exception e) {
- responseError(request, response, e.getMessage());
+ respondWithError(request, response, e.getMessage());
return;
}
- responseResult(
+ respondWithResult(
new ConnectionRequest(handle, request.getExtras()),
response,
telephonyConnection);
}
} else {
- responseError(
+ respondWithError(
request,
response,
String.format("Found no ringing call, call state: %s", call.getState()));
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index 24d11fb..185fa57 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -44,9 +44,9 @@
Uri handle,
Response<Uri, Subscription> response) {
try {
- responseResult(handle, response, canCall(handle) ? new Subscription() : null);
+ respondWithResult(handle, response, canCall(handle) ? new Subscription() : null);
} catch (Exception e) {
- responseError(handle, response, "onFindSubscriptions error: " + e.toString());
+ respondWithError(handle, response, "onFindSubscriptions error: " + e.toString());
}
}
@@ -64,18 +64,18 @@
Log.d(this, "startCallWithPhone: %s.", request);
if (phone == null) {
- responseError(request, response, "Phone is null");
+ respondWithError(request, response, "Phone is null");
return;
}
if (request.getHandle() == null) {
- responseError(request, response, "Handle is null");
+ respondWithError(request, response, "Handle is null");
return;
}
String number = request.getHandle().getSchemeSpecificPart();
if (TextUtils.isEmpty(number)) {
- responseError(request, response, "Unable to parse number");
+ respondWithError(request, response, "Unable to parse number");
return;
}
@@ -84,44 +84,44 @@
connection = phone.dial(number);
} catch (CallStateException e) {
Log.e(this, e, "Call to Phone.dial failed with exception");
- responseError(request, response, e.getMessage());
+ respondWithError(request, response, e.getMessage());
return;
}
if (connection == null) {
- responseError(request, response, "Call to phone.dial failed");
+ respondWithError(request, response, "Call to phone.dial failed");
return;
}
try {
- responseResult(request, response, createTelephonyConnection(request, connection));
+ respondWithResult(request, response, createTelephonyConnection(request, connection));
} catch (Exception e) {
Log.e(this, e, "Call to createConnection failed with exception");
- responseError(request, response, e.getMessage());
+ respondWithError(request, response, e.getMessage());
}
}
- protected <REQUEST, RESULT> void responseError(
+ protected <REQUEST, RESULT> void respondWithError(
REQUEST request,
Response<REQUEST, RESULT> response,
String reason) {
- Log.d(this, "responseError %s: %s", request, reason);
+ Log.d(this, "respondWithError %s: %s", request, reason);
response.onError(request, reason);
}
- protected void responseResult(
+ protected void respondWithResult(
Uri request,
Response<Uri, Subscription> response,
Subscription result) {
- Log.d(this, "responseResult %s -> %s", request, result);
+ Log.d(this, "respondWithResult %s -> %s", request, result);
response.onResult(request, result);
}
- protected void responseResult(
+ protected void respondWithResult(
ConnectionRequest request,
Response<ConnectionRequest, Connection> response,
Connection result) {
- Log.d(this, "responseResult %s -> %s", request, result);
+ Log.d(this, "respondWithResult %s -> %s", request, result);
response.onResult(request, result);
}