Add support for reporting nuisance calls to CallScreeningService.

Add new API to report nuisance calls from the default dialer.
This API will relay the nuisance report on to the current
call screening service if it has previously provided call id
information for calls.

Test: Manual using test app
Test: Added CTS coverage
Test: Added unit tests
Bug: 63966743
Merged-In: I43c05ec9fa20f2df31da07c19090335c4d0154ca
Change-Id: I43c05ec9fa20f2df31da07c19090335c4d0154ca
diff --git a/testapps/AndroidManifest.xml b/testapps/AndroidManifest.xml
index 9cb1992..1373906 100644
--- a/testapps/AndroidManifest.xml
+++ b/testapps/AndroidManifest.xml
@@ -239,6 +239,13 @@
             android:process="com.android.server.telecom.testapps.SelfMangingCallingApp"
             android:name="com.android.server.telecom.testapps.SelfManagedCallNotificationReceiver" />
 
+        <receiver android:exported="true"
+                  android:name="com.android.server.telecom.testapps.NuisanceReportReceiver">
+            <intent-filter>
+                <action android:name="android.telecom.action.NUISANCE_CALL_STATUS_CHANGED" />
+            </intent-filter>
+        </receiver>
+
         <service
             android:name=".TestCallScreeningService"
             android:permission="android.permission.BIND_SCREENING_SERVICE">
diff --git a/testapps/res/layout/testdialer_main.xml b/testapps/res/layout/testdialer_main.xml
index e6c56b7..9da3789 100644
--- a/testapps/res/layout/testdialer_main.xml
+++ b/testapps/res/layout/testdialer_main.xml
@@ -30,6 +30,16 @@
         android:layout_height="wrap_content"
         android:text="@string/placeCallButton" />
     <Button
+        android:id="@+id/report_nuisance_button"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="Report Nuisance" />
+    <Button
+        android:id="@+id/report_not_nuisance_button"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="Report Not Nuisance" />
+    <Button
         android:id="@+id/set_default_button"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
diff --git a/testapps/src/com/android/server/telecom/testapps/NuisanceReportReceiver.java b/testapps/src/com/android/server/telecom/testapps/NuisanceReportReceiver.java
new file mode 100644
index 0000000..76fff66
--- /dev/null
+++ b/testapps/src/com/android/server/telecom/testapps/NuisanceReportReceiver.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2019 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.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.telecom.CallScreeningService;
+import android.widget.Toast;
+
+/**
+ * Example receiver for nuisance call reports from Telecom.
+ */
+public class NuisanceReportReceiver extends BroadcastReceiver {
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (intent.getAction().equals(CallScreeningService.ACTION_NUISANCE_CALL_STATUS_CHANGED)) {
+            Uri handle = intent.getParcelableExtra(CallScreeningService.EXTRA_CALL_HANDLE);
+            boolean isNuisance = intent.getBooleanExtra(CallScreeningService.EXTRA_IS_NUISANCE,
+                    false);
+            int durationBucket = intent.getIntExtra(CallScreeningService.EXTRA_CALL_DURATION, 0);
+            int callType = intent.getIntExtra(CallScreeningService.EXTRA_CALL_TYPE, 0);
+            handleNuisanceReport(context, handle, isNuisance, durationBucket, callType);
+        }
+    }
+
+    private void handleNuisanceReport(Context context, Uri handle, boolean isNuisance,
+            int durationBucket, int callType) {
+
+        String message = "Nuisance report for: " + handle + " isNuisance=" + isNuisance
+                + " duration=" + durationBucket + " callType=" + callType;
+        Toast.makeText(context,
+                (CharSequence) message,
+                Toast.LENGTH_LONG)
+                .show();
+    }
+}
diff --git a/testapps/src/com/android/server/telecom/testapps/TestDialerActivity.java b/testapps/src/com/android/server/telecom/testapps/TestDialerActivity.java
index c7eccf7..66a6944 100644
--- a/testapps/src/com/android/server/telecom/testapps/TestDialerActivity.java
+++ b/testapps/src/com/android/server/telecom/testapps/TestDialerActivity.java
@@ -54,6 +54,20 @@
             }
         });
 
+        findViewById(R.id.report_nuisance_button).setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                reportNuisance(true);
+            }
+        });
+
+        findViewById(R.id.report_not_nuisance_button).setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                reportNuisance(false);
+            }
+        });
+
         mNumberView = (EditText) findViewById(R.id.number);
         mRttCheckbox = (CheckBox) findViewById(R.id.call_with_rtt_checkbox);
         updateMutableUi();
@@ -140,4 +154,11 @@
         Log.i("Santos xtr", intentExtras.toString());
         return intentExtras;
     }
+
+    private void reportNuisance(boolean isNuisance) {
+        final TelecomManager telecomManager =
+                (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
+        telecomManager.reportNuisanceCallStatus(Uri.fromParts(PhoneAccount.SCHEME_TEL,
+                mNumberView.getText().toString(), null), isNuisance);
+    }
 }