Merge "Factor out lookup code in DefaultVoicemailNotifier." into ub-contactsdialer-b-dev
diff --git a/res/layout/call_log_list_item_actions.xml b/res/layout/call_log_list_item_actions.xml
index ca00405..63385ee 100644
--- a/res/layout/call_log_list_item_actions.xml
+++ b/res/layout/call_log_list_item_actions.xml
@@ -129,6 +129,11 @@
</LinearLayout>
+ <ViewStub
+ android:id="@+id/spam_actions_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
<LinearLayout
android:id="@+id/details_action"
style="@style/CallLogActionStyle">
diff --git a/src-N/com/android/dialer/compat/UserManagerSdkCompat.java b/src-N/com/android/dialer/compat/UserManagerSdkCompat.java
new file mode 100644
index 0000000..9a08d4e
--- /dev/null
+++ b/src-N/com/android/dialer/compat/UserManagerSdkCompat.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2015 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.compat;
+
+import android.content.Context;
+
+/**
+ * UserManagerCompat respecting Sdk requirements
+ */
+public class UserManagerSdkCompat {
+
+ /**
+ * Return whether the calling user is running in an "unlocked" state. A user
+ * is unlocked only after they've entered their credentials (such as a lock
+ * pattern or PIN), and credential-encrypted private app data storage is
+ * available.
+ *
+ * @param context the current context
+ * @return {@code true} if the user is unlocked or context is null, {@code false} otherwise
+ * @throws NullPointerException if context is null
+ */
+ public static boolean isUserUnlocked(Context context) {
+ return android.support.v4.os.UserManagerCompat.isUserUnlocked(context);
+ }
+
+}
diff --git a/src-pre-N/com/android/dialer/compat/UserManagerSdkCompat.java b/src-pre-N/com/android/dialer/compat/UserManagerSdkCompat.java
new file mode 100644
index 0000000..c79ac2f
--- /dev/null
+++ b/src-pre-N/com/android/dialer/compat/UserManagerSdkCompat.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2015 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.compat;
+
+import android.content.Context;
+import android.util.Log;
+
+/**
+ * UserManagerCompat respecting Sdk requirements
+ */
+public class UserManagerSdkCompat {
+
+ /**
+ * @return {@code true}
+ */
+ public static boolean isUserUnlocked(Context context) {
+ Log.wtf("UserManagerSdkCompat", "Not implemented");
+ return true;
+ }
+
+}
diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
index 7e14719..f76312d 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
@@ -55,10 +55,16 @@
import com.android.dialer.filterednumber.FilteredNumbersUtil;
import com.android.dialer.logging.Logger;
import com.android.dialer.logging.ScreenEvent;
+import com.android.dialer.service.SpamButtonRenderer;
import com.android.dialer.util.DialerUtils;
import com.android.dialer.util.PhoneNumberUtil;
import com.android.dialer.voicemail.VoicemailPlaybackLayout;
import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
+import com.android.dialerbind.ObjectFactory;
+import com.google.common.collect.Lists;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* This is an object containing references to views contained by the call log list item. This
@@ -199,6 +205,9 @@
private final int mPhotoSize;
+ private ViewStub mSpamViewStub;
+ private SpamButtonRenderer mSpamButtonRenderer;
+
private View.OnClickListener mExpandCollapseListener;
private boolean mVoicemailPrimaryActionButtonClicked;
@@ -403,6 +412,9 @@
callWithNoteButtonView = actionsView.findViewById(R.id.call_with_note_action);
callWithNoteButtonView.setOnClickListener(this);
+
+ mSpamViewStub = (ViewStub) actionsView.findViewById(R.id.spam_actions_container);
+ mSpamButtonRenderer = ObjectFactory.newSpamButtonRenderer(mContext, mSpamViewStub);
}
bindActionButtons();
@@ -501,7 +513,7 @@
} else {
detailsButtonView.setVisibility(View.VISIBLE);
detailsButtonView.setTag(
- IntentProvider.getCallDetailIntentProvider(rowId, callIds, null));
+ IntentProvider.getCallDetailIntentProvider(rowId, callIds, null));
}
if (info != null && UriUtils.isEncodedContactUri(info.lookupUri)) {
@@ -532,6 +544,24 @@
mCallLogCache.isVoicemailNumber(accountHandle, number);
callWithNoteButtonView.setVisibility(
supportsCallSubject && !isVoicemailNumber ? View.VISIBLE : View.GONE);
+
+ if(mSpamButtonRenderer != null){
+ List<View> completeLogListItems = Lists.newArrayList(
+ createNewContactButtonView,
+ addToExistingContactButtonView,
+ sendMessageView,
+ callButtonView,
+ callWithNoteButtonView,
+ detailsButtonView,
+ voicemailPlaybackView);
+ List<View> blockedNumberVisibleViews = new ArrayList<>();
+ List<View> spamNumberVisibleViews = Lists.newArrayList(detailsButtonView);
+
+ mSpamButtonRenderer.setCompleteListItemViews(completeLogListItems);
+ mSpamButtonRenderer.setFilteredNumberViews(blockedNumberVisibleViews);
+ mSpamButtonRenderer.setSpamFilteredViews(spamNumberVisibleViews);
+ mSpamButtonRenderer.render(number, countryIso);
+ }
}
/**
diff --git a/src/com/android/dialer/compat/UserManagerCompat.java b/src/com/android/dialer/compat/UserManagerCompat.java
index a1fdcc6..5767033 100644
--- a/src/com/android/dialer/compat/UserManagerCompat.java
+++ b/src/com/android/dialer/compat/UserManagerCompat.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2015 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.compat;
import android.content.Context;
@@ -34,4 +49,23 @@
// Adapted from {@link UserManager} and {@link UserHandle}.
return (Process.myUid() / PER_USER_RANGE) == USER_SYSTEM;
}
+
+ /**
+ * Return whether the calling user is running in an "unlocked" state. A user
+ * is unlocked only after they've entered their credentials (such as a lock
+ * pattern or PIN), and credential-encrypted private app data storage is
+ * available.
+ *
+ * TODO b/26688153
+ *
+ * @param context the current context
+ * @return {@code true} if the user is unlocked, {@code false} otherwise
+ * @throws NullPointerException if context is null
+ */
+ public static boolean isUserUnlocked(Context context) {
+ if (CompatUtils.isNCompatible()) {
+ return UserManagerSdkCompat.isUserUnlocked(context);
+ }
+ return true;
+ }
}
diff --git a/src/com/android/dialer/service/SpamButtonRenderer.java b/src/com/android/dialer/service/SpamButtonRenderer.java
new file mode 100644
index 0000000..843bc55
--- /dev/null
+++ b/src/com/android/dialer/service/SpamButtonRenderer.java
@@ -0,0 +1,23 @@
+package com.android.dialer.service;
+
+import android.view.View;
+
+import java.util.List;
+
+/**
+ * Interface responsible for rendering spam buttons.
+ */
+public interface SpamButtonRenderer {
+
+ /**
+ * Renders buttons for a phone number.
+ */
+ void render(String number, String countryIso);
+
+ void setCompleteListItemViews(List<View> views);
+
+ void setSpamFilteredViews(List<View> views);
+
+ void setFilteredNumberViews(List<View> views);
+
+}
diff --git a/src/com/android/dialerbind/ObjectFactory.java b/src/com/android/dialerbind/ObjectFactory.java
index f346a7e..d06d55e 100644
--- a/src/com/android/dialerbind/ObjectFactory.java
+++ b/src/com/android/dialerbind/ObjectFactory.java
@@ -19,12 +19,16 @@
import static com.android.dialer.calllog.CallLogAdapter.CallFetcher;
import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewStub;
import com.android.dialer.calllog.CallLogAdapter;
import com.android.dialer.calllog.ContactInfoHelper;
import com.android.dialer.list.RegularSearchFragment;
import com.android.dialer.logging.Logger;
import com.android.dialer.service.CachedNumberLookupService;
+import com.android.dialer.service.SpamButtonRenderer;
import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
/**
@@ -41,6 +45,12 @@
return "com.android.dialer.database.filterednumberprovider";
}
+ public static SpamButtonRenderer newSpamButtonRenderer(
+ Context context,
+ ViewStub stub) {
+ return null;
+ }
+
/**
* Create a new instance of the call log adapter.
* @param context The context to use.
diff --git a/tests/src/com/android/dialer/compat/UserManagerCompatTest.java b/tests/src/com/android/dialer/compat/UserManagerCompatTest.java
new file mode 100644
index 0000000..ff734a1
--- /dev/null
+++ b/tests/src/com/android/dialer/compat/UserManagerCompatTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 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.compat;
+
+import android.test.AndroidTestCase;
+
+import com.android.contacts.common.compat.CompatUtils;
+
+public class UserManagerCompatTest extends AndroidTestCase {
+
+ public void testIsUserUnlocked_N_NullContext() {
+ if (!CompatUtils.isNCompatible()) {
+ return;
+ }
+ try {
+ UserManagerCompat.isUserUnlocked(null);
+ fail("Expected NullPointerException but none was thrown");
+ } catch (NullPointerException e) {}
+ }
+
+ public void testIsUserUnlocked_M_NullContext() {
+ if (CompatUtils.isNCompatible()) {
+ return;
+ }
+ assertTrue(UserManagerCompat.isUserUnlocked(null));
+ }
+
+ public void testIsUserUnlocked() {
+ assertTrue(UserManagerCompat.isUserUnlocked(getContext()));
+ }
+}