Change incoming call intent to a TelecommManager method. (2/3)
Also moves a few constants from TelecommConstants to TelecommManager.
Bug:16416927
Change-Id: I8e74feb228523ed1c186b2f06784d04cb9141f86
diff --git a/src/com/android/telecomm/TelecommServiceImpl.java b/src/com/android/telecomm/TelecommServiceImpl.java
index 3234aee..e08571a 100644
--- a/src/com/android/telecomm/TelecommServiceImpl.java
+++ b/src/com/android/telecomm/TelecommServiceImpl.java
@@ -19,9 +19,13 @@
import android.app.AppOpsManager;
import android.content.ComponentName;
import android.content.Context;
+
+import android.content.Intent;
import android.content.res.Resources;
import android.os.Binder;
+import android.os.Bundle;
import android.os.Handler;
+import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.ServiceManager;
@@ -40,7 +44,13 @@
* Implementation of the ITelecomm interface.
*/
public class TelecommServiceImpl extends ITelecommService.Stub {
- /**
+ /** ${inheritDoc} */
+ @Override
+ public IBinder asBinder() {
+ return super.asBinder();
+ }
+
+ /**
* A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
* request after sending. The main thread will notify the request when it is complete.
*/
@@ -321,6 +331,28 @@
return (int) sendRequest(MSG_GET_CURRENT_TTY_MODE);
}
+ /**
+ * @see TelecommManager#addNewIncomingCall
+ */
+ @Override
+ public void addNewIncomingCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
+ if (phoneAccountHandle != null && phoneAccountHandle.getComponentName() != null) {
+ mAppOpsManager.checkPackage(
+ Binder.getCallingUid(), phoneAccountHandle.getComponentName().getPackageName());
+
+ Intent intent = new Intent(TelecommManager.ACTION_INCOMING_CALL);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
+ if (extras != null) {
+ intent.putExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS, extras);
+ }
+
+ long token = Binder.clearCallingIdentity();
+ TelecommApp.getInstance().startActivity(intent);
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
//
// Supporting methods for the ITelecommService interface implementation.
//
diff --git a/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java b/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
index 8898a53..a8e3195 100644
--- a/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
+++ b/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
@@ -68,24 +68,15 @@
* @param isVideoCall {@code True} if this is a video call.
*/
private void sendIncomingCallIntent(Context context, boolean isVideoCall) {
- // Create intent for adding an incoming call.
- Intent intent = new Intent(TelecommManager.ACTION_INCOMING_CALL);
- // TODO(santoscordon): Use a private @hide permission to make sure this only goes to
- // Telecomm instead of setting the package explicitly.
- intent.setPackage("com.android.telecomm");
-
- PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(
+ PhoneAccountHandle phoneAccount = new PhoneAccountHandle(
new ComponentName(context, TestConnectionService.class),
- null /* id */);
- intent.putExtra(TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
+ CallServiceNotifier.PHONE_ACCOUNT_ID);
// For the purposes of testing, indicate whether the incoming call is a video call by
// stashing an indicator in the EXTRA_INCOMING_CALL_EXTRAS.
Bundle extras = new Bundle();
extras.putBoolean(TestConnectionService.IS_VIDEO_CALL, isVideoCall);
- intent.putExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS, extras);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(intent);
+ TelecommManager.from(context).addNewIncomingCall(phoneAccount, extras);
}
}
diff --git a/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java b/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
index d43f088..dfce7c7 100644
--- a/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
+++ b/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
@@ -38,6 +38,8 @@
public class CallServiceNotifier {
private static final CallServiceNotifier INSTANCE = new CallServiceNotifier();
+ static final String PHONE_ACCOUNT_ID = "testapps_TestConnectionService_Account_ID";
+
/**
* Static notification IDs.
*/
@@ -89,13 +91,13 @@
PhoneAccount account = new PhoneAccount(
new PhoneAccountHandle(
new ComponentName(context, TestConnectionService.class),
- "testapps_TestConnectionService_Account_ID"),
+ PHONE_ACCOUNT_ID),
Uri.parse("tel:555-TEST"),
"555-TEST",
PhoneAccount.CAPABILITY_CALL_PROVIDER,
0, // iconResId
- "a label",
- "a short description",
+ "Dummy Service",
+ "a short description for the dummy service",
false);
TelecommManager telecommManager =
(TelecommManager) context.getSystemService(Context.TELECOMM_SERVICE);