CallScreeningService behavior changes and improvements.
1. When sending information about a call to the CallScreeningService,
using a new parceling method which passes the bare minimum amount of info
about a call necessary to screen the call.
2. Fix bug where the app name was being logged as the package name for
screened calls. Adding an AppLabelProxy in the
CallScreeningServiceController to perform lookup of the app name for
logging purposes.
3. Change lookup of user-defined call screening app to make use of the
role manager proxy instead.
Bug: 63966743
Test: Created call screening service test app.
Test: Manually tested operation of user selected CS app using test app and
test override commands.
Merged-In: I51c816f36ad1e5dcd229271c608982113f97b751
Change-Id: I51c816f36ad1e5dcd229271c608982113f97b751
diff --git a/testapps/AndroidManifest.xml b/testapps/AndroidManifest.xml
index 02443ba..9cb1992 100644
--- a/testapps/AndroidManifest.xml
+++ b/testapps/AndroidManifest.xml
@@ -238,5 +238,19 @@
<receiver android:exported="false"
android:process="com.android.server.telecom.testapps.SelfMangingCallingApp"
android:name="com.android.server.telecom.testapps.SelfManagedCallNotificationReceiver" />
+
+ <service
+ android:name=".TestCallScreeningService"
+ android:permission="android.permission.BIND_SCREENING_SERVICE">
+ <intent-filter>
+ <action android:name="android.telecom.CallScreeningService"/>
+ </intent-filter>
+ </service>
+
+ <activity android:name=".CallScreeningActivity"
+ android:configChanges="orientation|screenSize|keyboardHidden"
+ android:excludeFromRecents="true"
+ android:launchMode="singleInstance">
+ </activity>
</application>
</manifest>
diff --git a/testapps/src/com/android/server/telecom/testapps/CallScreeningActivity.java b/testapps/src/com/android/server/telecom/testapps/CallScreeningActivity.java
new file mode 100644
index 0000000..05ba500
--- /dev/null
+++ b/testapps/src/com/android/server/telecom/testapps/CallScreeningActivity.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.server.telecom.testapps;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.telecom.CallScreeningService;
+import android.view.WindowManager;
+
+public class CallScreeningActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ AlertDialog alertDialog = new AlertDialog.Builder(this)
+ .setTitle("Test Call Screening")
+ .setMessage("Allow the call?")
+ .setNegativeButton("Block", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (TestCallScreeningService.getInstance() != null) {
+ TestCallScreeningService.getInstance().blockCall();
+ }
+ finish();
+ }
+ })
+ .setPositiveButton("Allow", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (TestCallScreeningService.getInstance() != null) {
+ TestCallScreeningService.getInstance().allowCall();
+ }
+ finish();
+ }
+ }).create();
+ alertDialog.show();
+ }
+}
diff --git a/testapps/src/com/android/server/telecom/testapps/TestCallScreeningService.java b/testapps/src/com/android/server/telecom/testapps/TestCallScreeningService.java
new file mode 100644
index 0000000..81a469e
--- /dev/null
+++ b/testapps/src/com/android/server/telecom/testapps/TestCallScreeningService.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.server.telecom.testapps;
+
+import android.content.Intent;
+import android.telecom.Call;
+import android.telecom.CallScreeningService;
+import android.telecom.Log;
+
+public class TestCallScreeningService extends CallScreeningService {
+ private Call.Details mDetails;
+ private static TestCallScreeningService sTestCallScreeningService;
+
+ public static TestCallScreeningService getInstance() {
+ return sTestCallScreeningService;
+ }
+
+ /**
+ * Handles request from the system to screen an incoming call.
+ * @param callDetails Information about a new incoming call, see {@link Call.Details}.
+ */
+ @Override
+ public void onScreenCall(Call.Details callDetails) {
+ Log.i(this, "onScreenCall: received call %s", callDetails);
+ sTestCallScreeningService = this;
+
+ mDetails = callDetails;
+ Intent errorIntent = new Intent(this, CallScreeningActivity.class);
+ errorIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(errorIntent);
+ }
+
+ public void blockCall() {
+ CallScreeningService.CallResponse
+ response = new CallScreeningService.CallResponse.Builder()
+ .setDisallowCall(true)
+ .setRejectCall(true)
+ .setSkipCallLog(false)
+ .setSkipNotification(true)
+ .build();
+ respondToCall(mDetails, response);
+ }
+
+ public void allowCall() {
+ CallScreeningService.CallResponse
+ response = new CallScreeningService.CallResponse.Builder()
+ .setDisallowCall(false)
+ .setRejectCall(false)
+ .setSkipCallLog(false)
+ .setSkipNotification(false)
+ .build();
+ respondToCall(mDetails, response);
+ }
+}