summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-01-25 00:47:22 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-01-25 00:47:22 +0000
commit3bee9a13ea767987623d422457fc4fbe8daa81e5 (patch)
tree0503b23642f1e4aaba3aa4d94769c6289e571215 /java
parent418a818639a2dad7ed9f06b0785ed4f55966f56e (diff)
parent9e04310a9902a4dbf593060baaf41c37919fd7fe (diff)
Merge changes I647568c3,I73d3349f,I0889ea61,I981e944d,Ica75164c
* changes: Define methods in Spam interface to be used later in the PhoneLookup for spam features. Link to the correct Assisted Dialing settings depending on platform version. Add foreground service permission Fixed a regression where we incorrectly reported that the dialpad was visible. Add support for yesterday header in NUI Voicemail Tab
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/calldetails/CallDetailsActivity.java12
-rw-r--r--java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java4
-rw-r--r--java/com/android/dialer/spam/Spam.java25
-rw-r--r--java/com/android/dialer/spam/SpamStub.java32
-rw-r--r--java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java90
-rw-r--r--java/com/android/dialer/voicemail/listui/res/values/strings.xml5
-rw-r--r--java/com/android/incallui/AndroidManifest.xml3
-rw-r--r--java/com/android/incallui/InCallActivity.java6
8 files changed, 140 insertions, 37 deletions
diff --git a/java/com/android/dialer/calldetails/CallDetailsActivity.java b/java/com/android/dialer/calldetails/CallDetailsActivity.java
index b15dc456d..bf978ecf3 100644
--- a/java/com/android/dialer/calldetails/CallDetailsActivity.java
+++ b/java/com/android/dialer/calldetails/CallDetailsActivity.java
@@ -32,6 +32,7 @@ import android.provider.CallLog.Calls;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
+import android.support.v4.os.BuildCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -52,6 +53,7 @@ import com.android.dialer.common.concurrent.DialerExecutor.FailureListener;
import com.android.dialer.common.concurrent.DialerExecutor.SuccessListener;
import com.android.dialer.common.concurrent.DialerExecutor.Worker;
import com.android.dialer.common.concurrent.DialerExecutorComponent;
+import com.android.dialer.compat.telephony.TelephonyManagerCompat;
import com.android.dialer.constants.ActivityRequestCodes;
import com.android.dialer.dialercontact.DialerContact;
import com.android.dialer.duo.Duo;
@@ -407,8 +409,14 @@ public class CallDetailsActivity extends AppCompatActivity {
@Override
public void openAssistedDialingSettings(View unused) {
- Intent intent = new Intent(getActivity(), AssistedDialingSettingActivity.class);
- getActivity().startActivity(intent);
+ if (BuildCompat.isAtLeastP()) {
+ Intent callSettingsIntent =
+ new Intent(TelephonyManagerCompat.ACTION_SHOW_ASSISTED_DIALING_SETTINGS);
+ getActivity().startActivity(callSettingsIntent);
+ } else {
+ Intent intent = new Intent(getActivity(), AssistedDialingSettingActivity.class);
+ getActivity().startActivity(intent);
+ }
}
@Override
diff --git a/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java b/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java
index 86f344f4e..669cba7a9 100644
--- a/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java
+++ b/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java
@@ -80,6 +80,10 @@ public class TelephonyManagerCompat {
*/
public static final Integer FEATURES_ASSISTED_DIALING = 1 << 4;
+ /** The {@link android.content.Intent} action used to show the assisted dialing settings. */
+ public static final String ACTION_SHOW_ASSISTED_DIALING_SETTINGS =
+ "android.telecom.action.SHOW_ASSISTED_DIALING_SETTINGS";
+
/**
* Returns the number of phones available. Returns 1 for Single standby mode (Single SIM
* functionality) Returns 2 for Dual standby mode.(Dual SIM functionality)
diff --git a/java/com/android/dialer/spam/Spam.java b/java/com/android/dialer/spam/Spam.java
index b1240c69a..ea1ea138e 100644
--- a/java/com/android/dialer/spam/Spam.java
+++ b/java/com/android/dialer/spam/Spam.java
@@ -18,9 +18,13 @@ package com.android.dialer.spam;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.logging.ContactLookupResult;
import com.android.dialer.logging.ContactSource;
import com.android.dialer.logging.ReportingLocation;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.ListenableFuture;
/** Allows the container application to mark calls as spam. */
public interface Spam {
@@ -39,7 +43,17 @@ public interface Spam {
int percentOfNonSpamNotificationsToShow();
/**
- * Checks if the given number is suspected of being a spamer.
+ * Checks if each of numbers in the given list is suspected of being a spam.
+ *
+ * @param dialerPhoneNumbers A list of {@link DialerPhoneNumber}.
+ * @return A {@link ListenableFuture} of a map that maps each number to its spam status
+ * (true/false).
+ */
+ ListenableFuture<ImmutableMap<DialerPhoneNumber, Boolean>> batchCheckSpamStatus(
+ ImmutableList<DialerPhoneNumber> dialerPhoneNumbers);
+
+ /**
+ * Checks if the given number is suspected of being a spam.
*
* @param number The phone number of the call.
* @param countryIso The country ISO of the call.
@@ -81,6 +95,15 @@ public interface Spam {
boolean checkSpamStatusSynchronous(String number, String countryIso);
/**
+ * Returns a {@link ListenableFuture} indicating whether the spam data have been updated since
+ * {@code timestampMillis}.
+ *
+ * <p>It is the caller's responsibility to ensure the timestamp is in milliseconds. Failure to do
+ * so will result in undefined behavior.
+ */
+ ListenableFuture<Boolean> dataUpdatedSince(long timestampMillis);
+
+ /**
* Reports number as spam.
*
* @param number The number to be reported.
diff --git a/java/com/android/dialer/spam/SpamStub.java b/java/com/android/dialer/spam/SpamStub.java
index daa475c4a..ac2e94359 100644
--- a/java/com/android/dialer/spam/SpamStub.java
+++ b/java/com/android/dialer/spam/SpamStub.java
@@ -16,16 +16,27 @@
package com.android.dialer.spam;
+import com.android.dialer.DialerPhoneNumber;
+import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor;
import com.android.dialer.logging.ContactLookupResult;
import com.android.dialer.logging.ContactSource;
import com.android.dialer.logging.ReportingLocation;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
import javax.inject.Inject;
/** Default implementation of Spam. */
public class SpamStub implements Spam {
+ private final ListeningExecutorService backgroundExecutorService;
+
@Inject
- public SpamStub() {}
+ public SpamStub(@BackgroundExecutor ListeningExecutorService backgroundExecutorService) {
+ this.backgroundExecutorService = backgroundExecutorService;
+ }
@Override
public boolean isSpamEnabled() {
@@ -58,6 +69,20 @@ public class SpamStub implements Spam {
}
@Override
+ public ListenableFuture<ImmutableMap<DialerPhoneNumber, Boolean>> batchCheckSpamStatus(
+ ImmutableList<DialerPhoneNumber> dialerPhoneNumbers) {
+ return backgroundExecutorService.submit(
+ () -> {
+ ImmutableMap.Builder<DialerPhoneNumber, Boolean> resultBuilder =
+ new ImmutableMap.Builder<>();
+ for (DialerPhoneNumber dialerPhoneNumber : dialerPhoneNumbers) {
+ resultBuilder.put(dialerPhoneNumber, false);
+ }
+ return resultBuilder.build();
+ });
+ }
+
+ @Override
public void checkSpamStatus(String number, String countryIso, Listener listener) {
listener.onComplete(false);
}
@@ -83,6 +108,11 @@ public class SpamStub implements Spam {
}
@Override
+ public ListenableFuture<Boolean> dataUpdatedSince(long timestampMillis) {
+ return Futures.immediateFuture(false);
+ }
+
+ @Override
public void reportSpamFromAfterCallNotification(
String number,
String countryIso,
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
index c9bf6e1a8..5519aa486 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
@@ -59,7 +59,7 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
@interface RowType {
/** A row representing a voicemail alert. */
int VOICEMAIL_ALERT = 1;
- /** Header that displays "Today" or "Older". */
+ /** Header that displays "Today", "Yesterday" or "Older". */
int HEADER = 2;
/** A row representing a voicemail entry. */
int VOICEMAIL_ENTRY = 3;
@@ -70,6 +70,8 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
/** {@link Integer#MAX_VALUE} when the "Today" header should not be displayed. */
private int todayHeaderPosition = Integer.MAX_VALUE;
+ /** {@link Integer#MAX_VALUE} when the "Yesterday" header should not be displayed. */
+ private int yesterdayHeaderPosition = Integer.MAX_VALUE;
/** {@link Integer#MAX_VALUE} when the "Older" header should not be displayed. */
private int olderHeaderPosition = Integer.MAX_VALUE;
/** {@link Integer#MAX_VALUE} when the voicemail alert message should not be displayed. */
@@ -117,11 +119,44 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
private void updateHeaderPositions() {
LogUtil.i(
"NewVoicemailAdapter.updateHeaderPositions",
- "before updating todayPos:%d, olderPos:%d, alertPos:%d",
+ "before updating todayPos:%d, yestPos:%d, olderPos:%d, alertPos:%d",
todayHeaderPosition,
+ yesterdayHeaderPosition,
olderHeaderPosition,
voicemailAlertPosition);
+ // If there are no rows to display, set all header positions to MAX_VALUE.
+ if (!cursor.moveToFirst()) {
+ todayHeaderPosition = Integer.MAX_VALUE;
+ yesterdayHeaderPosition = Integer.MAX_VALUE;
+ olderHeaderPosition = Integer.MAX_VALUE;
+ return;
+ }
+
+ long currentTimeMillis = clock.currentTimeMillis();
+
+ int numItemsInToday = 0;
+ int numItemsInYesterday = 0;
+
+ do {
+ long timestamp = VoicemailCursorLoader.getTimestamp(cursor);
+ long dayDifference = CallLogDates.getDayDifference(currentTimeMillis, timestamp);
+ if (dayDifference == 0) {
+ numItemsInToday++;
+ } else if (dayDifference == 1) {
+ numItemsInYesterday++;
+ } else {
+ break;
+ }
+ } while (cursor.moveToNext());
+
+ if (numItemsInToday > 0) {
+ numItemsInToday++; // including the "Today" header;
+ }
+ if (numItemsInYesterday > 0) {
+ numItemsInYesterday++; // including the "Yesterday" header;
+ }
+
int alertOffSet = 0;
if (voicemailAlertPosition != Integer.MAX_VALUE) {
Assert.checkArgument(
@@ -129,37 +164,21 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
alertOffSet = 1;
}
- // Calculate header adapter positions by reading cursor.
- long currentTimeMillis = clock.currentTimeMillis();
- if (cursor.moveToNext()) {
- long firstTimestamp = VoicemailCursorLoader.getTimestamp(cursor);
- if (CallLogDates.getDayDifference(currentTimeMillis, firstTimestamp) == 0) {
- this.todayHeaderPosition = 0 + alertOffSet;
- int adapterPosition =
- 2 + alertOffSet; // Accounted for the "Alert", "Today" header and first row.
- while (cursor.moveToNext()) {
- long timestamp = VoicemailCursorLoader.getTimestamp(cursor);
-
- if (CallLogDates.getDayDifference(currentTimeMillis, timestamp) == 0) {
- adapterPosition++;
- } else {
- this.olderHeaderPosition = adapterPosition;
- return;
- }
- }
- this.olderHeaderPosition = Integer.MAX_VALUE; // Didn't find any "Older" rows.
- } else {
- this.todayHeaderPosition = Integer.MAX_VALUE; // Didn't find any "Today" rows.
- this.olderHeaderPosition = 0 + alertOffSet;
- }
- } else { // There are no rows, just need to set these because they are final.
- this.todayHeaderPosition = Integer.MAX_VALUE;
- this.olderHeaderPosition = Integer.MAX_VALUE;
- }
+ // Set all header positions.
+ // A header position will be MAX_VALUE if there is no item to be displayed under that header.
+ todayHeaderPosition = numItemsInToday > 0 ? alertOffSet : Integer.MAX_VALUE;
+ yesterdayHeaderPosition =
+ numItemsInYesterday > 0 ? numItemsInToday + alertOffSet : Integer.MAX_VALUE;
+ olderHeaderPosition =
+ !cursor.isAfterLast()
+ ? numItemsInToday + numItemsInYesterday + alertOffSet
+ : Integer.MAX_VALUE;
+
LogUtil.i(
"NewVoicemailAdapter.updateHeaderPositions",
- "after updating todayPos:%d, olderPos:%d, alertOffSet:%d, alertPos:%d",
+ "after updating todayPos:%d, yestPos:%d, olderPos:%d, alertOffSet:%d, alertPos:%d",
todayHeaderPosition,
+ yesterdayHeaderPosition,
olderHeaderPosition,
alertOffSet,
voicemailAlertPosition);
@@ -233,6 +252,8 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
@RowType int viewType = getItemViewType(position);
if (position == todayHeaderPosition) {
headerViewHolder.setHeader(R.string.new_voicemail_header_today);
+ } else if (position == yesterdayHeaderPosition) {
+ headerViewHolder.setHeader(R.string.new_voicemail_header_yesterday);
} else if (position == olderHeaderPosition) {
headerViewHolder.setHeader(R.string.new_voicemail_header_older);
} else {
@@ -272,6 +293,9 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
if (todayHeaderPosition != Integer.MAX_VALUE && position > todayHeaderPosition) {
previousHeaders++;
}
+ if (yesterdayHeaderPosition != Integer.MAX_VALUE && position > yesterdayHeaderPosition) {
+ previousHeaders++;
+ }
if (olderHeaderPosition != Integer.MAX_VALUE && position > olderHeaderPosition) {
previousHeaders++;
}
@@ -870,6 +894,9 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
if (todayHeaderPosition != Integer.MAX_VALUE) {
numberOfHeaders++;
}
+ if (yesterdayHeaderPosition != Integer.MAX_VALUE) {
+ numberOfHeaders++;
+ }
if (olderHeaderPosition != Integer.MAX_VALUE) {
numberOfHeaders++;
}
@@ -893,6 +920,9 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
if (todayHeaderPosition != Integer.MAX_VALUE && position == todayHeaderPosition) {
return RowType.HEADER;
}
+ if (yesterdayHeaderPosition != Integer.MAX_VALUE && position == yesterdayHeaderPosition) {
+ return RowType.HEADER;
+ }
if (olderHeaderPosition != Integer.MAX_VALUE && position == olderHeaderPosition) {
return RowType.HEADER;
}
diff --git a/java/com/android/dialer/voicemail/listui/res/values/strings.xml b/java/com/android/dialer/voicemail/listui/res/values/strings.xml
index 70a5d03df..e7373d69f 100644
--- a/java/com/android/dialer/voicemail/listui/res/values/strings.xml
+++ b/java/com/android/dialer/voicemail/listui/res/values/strings.xml
@@ -30,8 +30,9 @@
<!-- Header in voicemail tab to group calls from the current day. [CHAR LIMIT=30] -->
<string name="new_voicemail_header_today">Today</string>
-
- <!-- Header in voicemail tab to group calls from before the current day. [CHAR LIMIT=30] -->
+ <!-- Header in voicemail tab to group calls from yesterday. [CHAR LIMIT=30] -->
+ <string name="new_voicemail_header_yesterday">Yesterday</string>
+ <!-- Header in voicemail tab to group calls from before yesterday. [CHAR LIMIT=30] -->
<string name="new_voicemail_header_older">Older</string>
<string name="verizon_terms_and_conditions_title" translatable="false">Turn on visual voicemail</string>
diff --git a/java/com/android/incallui/AndroidManifest.xml b/java/com/android/incallui/AndroidManifest.xml
index a98cc91d2..3d5aa1ceb 100644
--- a/java/com/android/incallui/AndroidManifest.xml
+++ b/java/com/android/incallui/AndroidManifest.xml
@@ -28,6 +28,9 @@
reset state of the app. -->
<uses-permission android:name="android.permission.STATUS_BAR"/>
<uses-permission android:name="android.permission.CAMERA"/>
+
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
+
<!-- Warning: setting the required boolean to true would prevent installation of Dialer on
devices which do not support a camera. -->
<uses-feature
diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java
index 990560674..535b894f6 100644
--- a/java/com/android/incallui/InCallActivity.java
+++ b/java/com/android/incallui/InCallActivity.java
@@ -822,7 +822,11 @@ public class InCallActivity extends TransactionSafeFragmentActivity
public boolean isDialpadVisible() {
DialpadFragment dialpadFragment = getDialpadFragment();
- return dialpadFragment != null && dialpadFragment.getUserVisibleHint();
+ return dialpadFragment != null
+ && dialpadFragment.isAdded()
+ && !dialpadFragment.isHidden()
+ && dialpadFragment.getView() != null
+ && dialpadFragment.getUserVisibleHint();
}
/** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */