diff options
author | Eric Erfanian <erfanian@google.com> | 2017-02-22 16:32:36 -0800 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-03-01 09:56:52 -0800 |
commit | ccca31529c07970e89419fb85a9e8153a5396838 (patch) | |
tree | a7034c0a01672b97728c13282a2672771cd28baa /java/com/android/incallui/spam/SpamNotificationActivity.java | |
parent | e7ae4624ba6f25cb8e648db74e0d64c0113a16ba (diff) |
Update dialer sources.
Test: Built package and system image.
This change clobbers the old source, and is an export
from an internal Google repository.
The internal repository was forked form Android in March,
and this change includes modifications since then, to
near the v8 release.
Since the fork, we've moved code from monolithic to independent modules. In addition,
we've switched to Blaze/Bazel as the build sysetm. This export, however, still uses make.
New dependencies have been added:
- Dagger
- Auto-Value
- Glide
- Libshortcutbadger
Going forward, development will still be in Google3, and the Gerrit release
will become an automated export, with the next drop happening in ~ two weeks.
Android.mk includes local modifications from ToT.
Abridged changelog:
Bug fixes
● Not able to mute, add a call when using Phone app in multiwindow mode
● Double tap on keypad triggering multiple key and tones
● Reported spam numbers not showing as spam in the call log
● Crash when user tries to block number while Phone app is not set as default
● Crash when user picks a number from search auto-complete list
Visual Voicemail (VVM) improvements
● Share Voicemail audio via standard exporting mechanisms that support file attachment
(email, MMS, etc.)
● Make phone number, email and web sites in VVM transcript clickable
● Set PIN before declining VVM Terms of Service {Carrier}
● Set client type for outbound visual voicemail SMS {Carrier}
New incoming call and incall UI on older devices
(Android M)
● Updated Phone app icon
● New incall UI (large buttons, button labels)
● New and animated Answer/Reject gestures
Accessibility
● Add custom answer/decline call buttons on answer screen for touch exploration
accessibility services
● Increase size of touch target
● Add verbal feedback when a Voicemail fails to load
● Fix pressing of Phone buttons while in a phone call using Switch Access
● Fix selecting and opening contacts in talkback mode
● Split focus for ‘Learn More’ link in caller id & spam to help distinguish similar text
Other
● Backup & Restore for App Preferences
● Prompt user to enable Wi-Fi calling if the call ends due to out of service and Wi-Fi is
connected
● Rename “Dialpad” to “Keypad”
● Show "Private number" for restricted calls
● Delete unused items (vcard, add contact, call history) from Phone menu
Change-Id: I2a7e53532a24c21bf308bf0a6d178d7ddbca4958
Diffstat (limited to 'java/com/android/incallui/spam/SpamNotificationActivity.java')
-rw-r--r-- | java/com/android/incallui/spam/SpamNotificationActivity.java | 483 |
1 files changed, 483 insertions, 0 deletions
diff --git a/java/com/android/incallui/spam/SpamNotificationActivity.java b/java/com/android/incallui/spam/SpamNotificationActivity.java new file mode 100644 index 000000000..88d6bdfda --- /dev/null +++ b/java/com/android/incallui/spam/SpamNotificationActivity.java @@ -0,0 +1,483 @@ +/* + * Copyright (C) 2016 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.incallui.spam; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.NotificationManager; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.provider.CallLog; +import android.provider.ContactsContract; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; +import com.android.contacts.common.GeoUtil; +import com.android.contacts.common.compat.PhoneNumberUtilsCompat; +import com.android.dialer.blocking.BlockReportSpamDialogs; +import com.android.dialer.blocking.BlockedNumbersMigrator; +import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; +import com.android.dialer.blocking.FilteredNumberCompat; +import com.android.dialer.common.LogUtil; +import com.android.dialer.logging.Logger; +import com.android.dialer.logging.nano.DialerImpression; +import com.android.dialer.logging.nano.ReportingLocation; +import com.android.dialer.spam.Spam; +import com.android.incallui.R; +import com.android.incallui.call.DialerCall; + +/** Creates the after call notification dialogs. */ +public class SpamNotificationActivity extends FragmentActivity { + + /** Action to add number to contacts. */ + static final String ACTION_ADD_TO_CONTACTS = "com.android.incallui.spam.ACTION_ADD_TO_CONTACTS"; + /** Action to show dialog. */ + static final String ACTION_SHOW_DIALOG = "com.android.incallui.spam.ACTION_SHOW_DIALOG"; + /** Action to mark a number as spam. */ + static final String ACTION_MARK_NUMBER_AS_SPAM = + "com.android.incallui.spam.ACTION_MARK_NUMBER_AS_SPAM"; + /** Action to mark a number as not spam. */ + static final String ACTION_MARK_NUMBER_AS_NOT_SPAM = + "com.android.incallui.spam.ACTION_MARK_NUMBER_AS_NOT_SPAM"; + + private static final String TAG = "SpamNotifications"; + private static final String EXTRA_NOTIFICATION_ID = "notification_id"; + private static final String EXTRA_CALL_INFO = "call_info"; + + private static final String CALL_INFO_KEY_PHONE_NUMBER = "phone_number"; + private static final String CALL_INFO_KEY_IS_SPAM = "is_spam"; + private static final String CALL_INFO_KEY_CALL_ID = "call_id"; + private static final String CALL_INFO_KEY_START_TIME_MILLIS = "call_start_time_millis"; + private static final String CALL_INFO_CONTACT_LOOKUP_RESULT_TYPE = "contact_lookup_result_type"; + private final DialogInterface.OnDismissListener dismissListener = + new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + if (!isFinishing()) { + finish(); + } + } + }; + private FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler; + + /** + * Creates an intent to start this activity. + * + * @return Intent intent that starts this activity. + */ + public static Intent createActivityIntent( + Context context, DialerCall call, String action, int notificationId) { + Intent intent = new Intent(context, SpamNotificationActivity.class); + intent.setAction(action); + // This ensures only one activity of this kind exists at a time. + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(EXTRA_NOTIFICATION_ID, notificationId); + intent.putExtra(EXTRA_CALL_INFO, newCallInfoBundle(call)); + return intent; + } + + /** Creates the intent to insert a contact. */ + private static Intent createInsertContactsIntent(String number) { + Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION); + // This ensures that the edit contact number field gets updated if called more than once. + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.setType(ContactsContract.RawContacts.CONTENT_TYPE); + intent.putExtra(ContactsContract.Intents.Insert.PHONE, number); + return intent; + } + + /** Returns the formatted version of the given number. */ + private static String getFormattedNumber(String number) { + return PhoneNumberUtilsCompat.createTtsSpannable(number).toString(); + } + + private static void logCallImpression(Context context, Bundle bundle, int impression) { + Logger.get(context) + .logCallImpression( + impression, + bundle.getString(CALL_INFO_KEY_CALL_ID), + bundle.getLong(CALL_INFO_KEY_START_TIME_MILLIS, 0)); + } + + private static Bundle newCallInfoBundle(DialerCall call) { + Bundle bundle = new Bundle(); + bundle.putString(CALL_INFO_KEY_PHONE_NUMBER, call.getNumber()); + bundle.putBoolean(CALL_INFO_KEY_IS_SPAM, call.isSpam()); + bundle.putString(CALL_INFO_KEY_CALL_ID, call.getUniqueCallId()); + bundle.putLong(CALL_INFO_KEY_START_TIME_MILLIS, call.getTimeAddedMs()); + bundle.putInt(CALL_INFO_CONTACT_LOOKUP_RESULT_TYPE, call.getLogState().contactLookupResult); + return bundle; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + LogUtil.i(TAG, "onCreate"); + super.onCreate(savedInstanceState); + setFinishOnTouchOutside(true); + filteredNumberAsyncQueryHandler = new FilteredNumberAsyncQueryHandler(this); + cancelNotification(); + } + + @Override + protected void onResume() { + LogUtil.i(TAG, "onResume"); + super.onResume(); + Intent intent = getIntent(); + String number = getCallInfo().getString(CALL_INFO_KEY_PHONE_NUMBER); + boolean isSpam = getCallInfo().getBoolean(CALL_INFO_KEY_IS_SPAM); + int contactLookupResultType = getCallInfo().getInt(CALL_INFO_CONTACT_LOOKUP_RESULT_TYPE, 0); + switch (intent.getAction()) { + case ACTION_ADD_TO_CONTACTS: + logCallImpression(DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_ADD_TO_CONTACTS); + startActivity(createInsertContactsIntent(number)); + finish(); + break; + case ACTION_MARK_NUMBER_AS_SPAM: + assertDialogsEnabled(); + maybeShowBlockReportSpamDialog(number, contactLookupResultType); + break; + case ACTION_MARK_NUMBER_AS_NOT_SPAM: + assertDialogsEnabled(); + maybeShowNotSpamDialog(number, contactLookupResultType); + break; + case ACTION_SHOW_DIALOG: + if (isSpam) { + showSpamFullDialog(); + } else { + showNonSpamDialog(); + } + break; + } + } + + @Override + protected void onPause() { + LogUtil.d(TAG, "onPause"); + // Finish activity on pause (e.g: orientation change or back button pressed) + filteredNumberAsyncQueryHandler = null; + if (!isFinishing()) { + finish(); + } + super.onPause(); + } + + /** Creates and displays the dialog for whitelisting a number. */ + private void maybeShowNotSpamDialog(final String number, final int contactLookupResultType) { + if (Spam.get(this).isDialogEnabledForSpamNotification()) { + BlockReportSpamDialogs.ReportNotSpamDialogFragment.newInstance( + getFormattedNumber(number), + new BlockReportSpamDialogs.OnConfirmListener() { + @Override + public void onClick() { + reportNotSpamAndFinish(number, contactLookupResultType); + } + }, + dismissListener) + .show(getFragmentManager(), BlockReportSpamDialogs.NOT_SPAM_DIALOG_TAG); + } else { + reportNotSpamAndFinish(number, contactLookupResultType); + } + } + + /** Creates and displays the dialog for blocking/reporting a number as spam. */ + private void maybeShowBlockReportSpamDialog( + final String number, final int contactLookupResultType) { + if (Spam.get(this).isDialogEnabledForSpamNotification()) { + maybeShowBlockNumberMigrationDialog( + new BlockedNumbersMigrator.Listener() { + @Override + public void onComplete() { + BlockReportSpamDialogs.BlockReportSpamDialogFragment.newInstance( + getFormattedNumber(number), + Spam.get(SpamNotificationActivity.this).isDialogReportSpamCheckedByDefault(), + new BlockReportSpamDialogs.OnSpamDialogClickListener() { + @Override + public void onClick(boolean isSpamChecked) { + blockReportNumberAndFinish( + number, isSpamChecked, contactLookupResultType); + } + }, + dismissListener) + .show(getFragmentManager(), BlockReportSpamDialogs.BLOCK_REPORT_SPAM_DIALOG_TAG); + } + }); + } else { + blockReportNumberAndFinish(number, true, contactLookupResultType); + } + } + + /** + * Displays the dialog for the first time unknown calls with actions "Add contact", "Block/report + * spam", and "Dismiss". + */ + private void showNonSpamDialog() { + logCallImpression(DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_SHOW_NON_SPAM_DIALOG); + FirstTimeNonSpamCallDialogFragment.newInstance(getCallInfo()) + .show(getSupportFragmentManager(), FirstTimeNonSpamCallDialogFragment.TAG); + } + + /** + * Displays the dialog for first time spam calls with actions "Not spam", "Block", and "Dismiss". + */ + private void showSpamFullDialog() { + logCallImpression(DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_SHOW_SPAM_DIALOG); + FirstTimeSpamCallDialogFragment.newInstance(getCallInfo()) + .show(getSupportFragmentManager(), FirstTimeSpamCallDialogFragment.TAG); + } + + /** Checks if the user has migrated to the new blocking and display a dialog if necessary. */ + private void maybeShowBlockNumberMigrationDialog(BlockedNumbersMigrator.Listener listener) { + if (!FilteredNumberCompat.maybeShowBlockNumberMigrationDialog( + this, getFragmentManager(), listener)) { + listener.onComplete(); + } + } + + /** Block and report the number as spam. */ + private void blockReportNumberAndFinish( + String number, boolean reportAsSpam, int contactLookupResultType) { + if (reportAsSpam) { + logCallImpression(DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_MARKED_NUMBER_AS_SPAM); + Spam.get(this) + .reportSpamFromAfterCallNotification( + number, + getCountryIso(), + CallLog.Calls.INCOMING_TYPE, + ReportingLocation.Type.FEEDBACK_PROMPT, + contactLookupResultType); + } + + logCallImpression(DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_BLOCK_NUMBER); + filteredNumberAsyncQueryHandler.blockNumber(null, number, getCountryIso()); + // TODO: DialerCall finish() after block/reporting async tasks complete (b/28441936) + finish(); + } + + /** Report the number as not spam. */ + private void reportNotSpamAndFinish(String number, int contactLookupResultType) { + logCallImpression(DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_REPORT_NUMBER_AS_NOT_SPAM); + Spam.get(this) + .reportNotSpamFromAfterCallNotification( + number, + getCountryIso(), + CallLog.Calls.INCOMING_TYPE, + ReportingLocation.Type.FEEDBACK_PROMPT, + contactLookupResultType); + // TODO: DialerCall finish() after async task completes (b/28441936) + finish(); + } + + /** Cancels the notification associated with the number. */ + private void cancelNotification() { + int notificationId = getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 1); + String number = getCallInfo().getString(CALL_INFO_KEY_PHONE_NUMBER); + ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) + .cancel(number, notificationId); + } + + private String getCountryIso() { + return GeoUtil.getCurrentCountryIso(this); + } + + private void assertDialogsEnabled() { + if (!Spam.get(this).isDialogEnabledForSpamNotification()) { + throw new IllegalStateException( + "Cannot start this activity with given action because dialogs are not enabled."); + } + } + + private Bundle getCallInfo() { + return getIntent().getBundleExtra(EXTRA_CALL_INFO); + } + + private void logCallImpression(int impression) { + logCallImpression(this, getCallInfo(), impression); + } + + /** Dialog that displays "Not spam", "Block/report spam" and "Dismiss". */ + public static class FirstTimeSpamCallDialogFragment extends DialogFragment { + + public static final String TAG = "FirstTimeSpamDialog"; + + private boolean dismissed; + private Context applicationContext; + + private static DialogFragment newInstance(Bundle bundle) { + FirstTimeSpamCallDialogFragment fragment = new FirstTimeSpamCallDialogFragment(); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public void onPause() { + dismiss(); + super.onPause(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + logCallImpression( + applicationContext, + getArguments(), + DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_ON_DISMISS_SPAM_DIALOG); + super.onDismiss(dialog); + // If dialog was not dismissed by user pressing one of the buttons, finish activity + if (!dismissed && getActivity() != null && !getActivity().isFinishing()) { + getActivity().finish(); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + applicationContext = context.getApplicationContext(); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + super.onCreateDialog(savedInstanceState); + final SpamNotificationActivity spamNotificationActivity = + (SpamNotificationActivity) getActivity(); + final String number = getArguments().getString(CALL_INFO_KEY_PHONE_NUMBER); + final int contactLookupResultType = + getArguments().getInt(CALL_INFO_CONTACT_LOOKUP_RESULT_TYPE, 0); + + return new AlertDialog.Builder(getActivity()) + .setCancelable(false) + .setTitle(getString(R.string.spam_notification_title, getFormattedNumber(number))) + .setMessage(getString(R.string.spam_notification_spam_call_expanded_text)) + .setNeutralButton( + getString(R.string.notification_action_dismiss), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dismiss(); + } + }) + .setPositiveButton( + getString(R.string.spam_notification_dialog_was_not_spam_action_text), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dismissed = true; + dismiss(); + spamNotificationActivity.maybeShowNotSpamDialog(number, contactLookupResultType); + } + }) + .setNegativeButton( + getString(R.string.spam_notification_block_spam_action_text), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dismissed = true; + dismiss(); + spamNotificationActivity.maybeShowBlockReportSpamDialog( + number, contactLookupResultType); + } + }) + .create(); + } + } + + /** Dialog that displays "Add contact", "Block/report spam" and "Dismiss". */ + public static class FirstTimeNonSpamCallDialogFragment extends DialogFragment { + + public static final String TAG = "FirstTimeNonSpamDialog"; + + private boolean dismissed; + private Context context; + + private static DialogFragment newInstance(Bundle bundle) { + FirstTimeNonSpamCallDialogFragment fragment = new FirstTimeNonSpamCallDialogFragment(); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public void onPause() { + // Dismiss on pause e.g: orientation change + dismiss(); + super.onPause(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + logCallImpression( + context, + getArguments(), + DialerImpression.Type.SPAM_AFTER_CALL_NOTIFICATION_ON_DISMISS_NON_SPAM_DIALOG); + // If dialog was not dismissed by user pressing one of the buttons, finish activity + if (!dismissed && getActivity() != null && !getActivity().isFinishing()) { + getActivity().finish(); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + this.context = context.getApplicationContext(); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + super.onCreateDialog(savedInstanceState); + final SpamNotificationActivity spamNotificationActivity = + (SpamNotificationActivity) getActivity(); + final String number = getArguments().getString(CALL_INFO_KEY_PHONE_NUMBER); + final int contactLookupResultType = + getArguments().getInt(CALL_INFO_CONTACT_LOOKUP_RESULT_TYPE, 0); + return new AlertDialog.Builder(getActivity()) + .setTitle(getString(R.string.non_spam_notification_title, getFormattedNumber(number))) + .setCancelable(false) + .setMessage(getString(R.string.spam_notification_non_spam_call_expanded_text)) + .setNeutralButton( + getString(R.string.notification_action_dismiss), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dismiss(); + } + }) + .setPositiveButton( + getString(R.string.spam_notification_dialog_add_contact_action_text), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dismissed = true; + dismiss(); + startActivity(createInsertContactsIntent(number)); + } + }) + .setNegativeButton( + getString(R.string.spam_notification_dialog_block_report_spam_action_text), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dismissed = true; + dismiss(); + spamNotificationActivity.maybeShowBlockReportSpamDialog( + number, contactLookupResultType); + } + }) + .create(); + } + } +} |