Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd040bcf authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I642a11d6,Ic4b69781

* changes:
  Fixed various speed dial issues.
  Use StorageComponent to get SharedPreference in SpamBlockingPromoHelper
parents d9d4b060 29b95403
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.app.Notification.Builder;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface.OnDismissListener;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.support.v4.os.BuildCompat;
import android.view.View;
@@ -35,6 +34,7 @@ import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.notification.NotificationChannelId;
import com.android.dialer.spam.SpamSettings;
import com.android.dialer.spam.promo.SpamBlockingPromoDialogFragment.OnEnableListener;
import com.android.dialer.storage.StorageComponent;

/** Helper class for showing spam blocking on-boarding promotions. */
public class SpamBlockingPromoHelper {
@@ -71,7 +71,8 @@ public class SpamBlockingPromoHelper {
    }

    long lastShowMillis =
        PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
        StorageComponent.get(context)
            .unencryptedSharedPrefs()
            .getLong(SPAM_BLOCKING_PROMO_LAST_SHOW_MILLIS, 0);
    long showPeriodMillis =
        ConfigProviderBindings.get(context)
@@ -103,10 +104,11 @@ public class SpamBlockingPromoHelper {
  }

  private void updateLastShowSpamTimestamp() {
    PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
    StorageComponent.get(context)
        .unencryptedSharedPrefs()
        .edit()
        .putLong(SPAM_BLOCKING_PROMO_LAST_SHOW_MILLIS, System.currentTimeMillis())
        .commit();
        .apply();
  }

  /**
+1 −0
Original line number Diff line number Diff line
@@ -183,6 +183,7 @@ public class SpeedDialFragment extends Fragment {
    super.onPause();
    favoritesListener.hideMenu();
    suggestedListener.onPause();
    onHidden();
  }

  @Override
+0 −36
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.dialer.speeddial;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.QuickContactBadge;

/** A square {@link android.widget.ImageView} constrained on width. */
public class SquareImageView extends QuickContactBadge {

  public SquareImageView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    setClickable(false);
  }

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, widthMeasureSpec);
  }
}
+7 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.dialer.speeddial.loader;

import android.content.res.Resources;
import android.database.Cursor;
import android.os.Trace;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
@@ -105,7 +106,9 @@ public abstract class SpeedDialUiItem {
   * <p>If the cursor started at row X, this method will advance to row Y s.t. rows X, X + 1, ... Y
   * - 1 all belong to the same contact (that is, share the same contact id and lookup key).
   */
  public static SpeedDialUiItem fromCursor(Resources resources, Cursor cursor) {
  public static SpeedDialUiItem fromCursor(
      Resources resources, Cursor cursor, boolean isImsEnabled) {
    Trace.beginSection("fromCursor");
    Assert.checkArgument(cursor != null);
    Assert.checkArgument(cursor.getCount() != 0);
    String lookupKey = cursor.getString(LOOKUP_KEY);
@@ -141,7 +144,8 @@ public abstract class SpeedDialUiItem {
              .build();
      channels.add(channel);

      if ((cursor.getInt(CARRIER_PRESENCE) & Data.CARRIER_PRESENCE_VT_CAPABLE) == 1) {
      if (isImsEnabled
          && (cursor.getInt(CARRIER_PRESENCE) & Data.CARRIER_PRESENCE_VT_CAPABLE) == 1) {
        // Add another channel if the number is ViLTE reachable
        channels.add(channel.toBuilder().setTechnology(Channel.IMS_VIDEO).build());
      }
@@ -149,6 +153,7 @@ public abstract class SpeedDialUiItem {
    } while (cursor.moveToNext() && Objects.equals(lookupKey, cursor.getString(LOOKUP_KEY)));

    builder.setChannels(ImmutableList.copyOf(channels));
    Trace.endSection();
    return builder.build();
  }

+30 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Build.VERSION_CODES;
import android.os.RemoteException;
import android.os.Trace;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
@@ -46,6 +47,7 @@ import com.android.dialer.speeddial.database.SpeedDialEntry;
import com.android.dialer.speeddial.database.SpeedDialEntry.Channel;
import com.android.dialer.speeddial.database.SpeedDialEntryDao;
import com.android.dialer.speeddial.database.SpeedDialEntryDatabaseHelper;
import com.android.dialer.util.CallUtil;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -205,7 +207,9 @@ public final class SpeedDialUiItemMutator {
        return loadSpeedDialUiItemsInternal();
      }
      Assert.checkArgument(cursor.moveToFirst(), "Cursor should never be empty");
      SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor);
      SpeedDialUiItem item =
          SpeedDialUiItem.fromCursor(
              appContext.getResources(), cursor, CallUtil.isVideoEnabled(appContext));

      // Star the contact if it isn't starred already, then return.
      if (!item.isStarred()) {
@@ -228,9 +232,12 @@ public final class SpeedDialUiItemMutator {

  @WorkerThread
  private ImmutableList<SpeedDialUiItem> loadSpeedDialUiItemsInternal() {
    Trace.beginSection("loadSpeedDialUiItemsInternal");
    Assert.isWorkerThread();
    contactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
    Trace.beginSection("getAllEntries");
    SpeedDialEntryDao db = getSpeedDialEntryDao();
    Trace.endSection(); // getAllEntries

    // This is the list of contacts that we will display to the user
    List<SpeedDialUiItem> speedDialUiItems = new ArrayList<>();
@@ -251,6 +258,7 @@ public final class SpeedDialUiItemMutator {
        "Updated entries are incomplete: " + entries.size() + " != " + entriesToUiItems.size());

    // Mark the SpeedDialEntries to be updated or deleted
    Trace.beginSection("updateOrDeleteEntries");
    for (SpeedDialEntry entry : entries) {
      SpeedDialUiItem contact = entriesToUiItems.get(entry);
      // Remove contacts that no longer exist or are no longer starred
@@ -271,12 +279,14 @@ public final class SpeedDialUiItemMutator {
      // These are our existing starred entries
      speedDialUiItems.add(contact);
    }
    Trace.endSection(); // updateOrDeleteEntries

    // Get all Strequent Contacts
    List<SpeedDialUiItem> strequentContacts = getStrequentContacts();

    // For each contact, if it isn't starred, add it as a suggestion.
    // If it is starred and not already accounted for above, then insert into the SpeedDialEntry DB.
    Trace.beginSection("addSuggestions");
    for (SpeedDialUiItem contact : strequentContacts) {
      if (!contact.isStarred()) {
        // Add this contact as a suggestion
@@ -291,12 +301,16 @@ public final class SpeedDialUiItemMutator {
        speedDialUiItems.add(contact);
      }
    }
    Trace.endSection(); // addSuggestions

    Trace.beginSection("insertUpdateAndDelete");
    ImmutableMap<SpeedDialEntry, Long> insertedEntriesToIdsMap =
        db.insertUpdateAndDelete(
            ImmutableList.copyOf(entriesToInsert),
            ImmutableList.copyOf(entriesToUpdate),
            ImmutableList.copyOf(entriesToDelete));
    Trace.endSection(); // insertUpdateAndDelete
    Trace.endSection(); // loadSpeedDialUiItemsInternal
    return speedDialUiItemsWithUpdatedIds(speedDialUiItems, insertedEntriesToIdsMap);
  }

@@ -388,11 +402,13 @@ public final class SpeedDialUiItemMutator {
  @WorkerThread
  private Map<SpeedDialEntry, SpeedDialUiItem> getSpeedDialUiItemsFromEntries(
      List<SpeedDialEntry> entries) {
    Trace.beginSection("getSpeedDialUiItemsFromEntries");
    Assert.isWorkerThread();
    // Fetch the contact ids from the SpeedDialEntries
    Set<String> contactIds = new ArraySet<>();
    entries.forEach(entry -> contactIds.add(Long.toString(entry.contactId())));
    if (contactIds.isEmpty()) {
      Trace.endSection();
      return new ArrayMap<>();
    }

@@ -410,7 +426,9 @@ public final class SpeedDialUiItemMutator {
                null)) {
      Map<SpeedDialEntry, SpeedDialUiItem> map = new ArrayMap<>();
      for (cursor.moveToFirst(); !cursor.isAfterLast(); /* Iterate in the loop */ ) {
        SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor);
        SpeedDialUiItem item =
            SpeedDialUiItem.fromCursor(
                appContext.getResources(), cursor, CallUtil.isVideoEnabled(appContext));
        for (SpeedDialEntry entry : entries) {
          if (entry.contactId() == item.contactId()) {
            // Update the id and pinned position to match it's corresponding SpeedDialEntry.
@@ -442,6 +460,7 @@ public final class SpeedDialUiItemMutator {
      for (SpeedDialEntry entry : entries) {
        map.putIfAbsent(entry, null);
      }
      Trace.endSection();
      return map;
    }
  }
@@ -467,6 +486,7 @@ public final class SpeedDialUiItemMutator {

  @WorkerThread
  private List<SpeedDialUiItem> getStrequentContacts() {
    Trace.beginSection("getStrequentContacts");
    Assert.isWorkerThread();
    Set<String> contactIds = new ArraySet<>();

@@ -482,9 +502,11 @@ public final class SpeedDialUiItemMutator {
            .query(strequentUri, new String[] {Phone.CONTACT_ID}, null, null, null)) {
      if (cursor == null) {
        LogUtil.e("SpeedDialUiItemMutator.getStrequentContacts", "null cursor");
        Trace.endSection();
        return new ArrayList<>();
      }
      if (cursor.getCount() == 0) {
        Trace.endSection();
        return new ArrayList<>();
      }
      for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
@@ -507,14 +529,19 @@ public final class SpeedDialUiItemMutator {
      List<SpeedDialUiItem> contacts = new ArrayList<>();
      if (cursor == null) {
        LogUtil.e("SpeedDialUiItemMutator.getStrequentContacts", "null cursor");
        Trace.endSection();
        return new ArrayList<>();
      }
      if (cursor.getCount() == 0) {
        Trace.endSection();
        return contacts;
      }
      for (cursor.moveToFirst(); !cursor.isAfterLast(); /* Iterate in the loop */ ) {
        contacts.add(SpeedDialUiItem.fromCursor(appContext.getResources(), cursor));
        contacts.add(
            SpeedDialUiItem.fromCursor(
                appContext.getResources(), cursor, CallUtil.isVideoEnabled(appContext)));
      }
      Trace.endSection();
      return contacts;
    }
  }
Loading