summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/promotion/impl
diff options
context:
space:
mode:
authorwangqi <wangqi@google.com>2018-05-21 12:29:32 -0700
committerCopybara-Service <copybara-piper@google.com>2018-05-21 13:18:02 -0700
commit71a22dc081e458706f07beb1684087dc4a6aedf5 (patch)
treed43592dc0b93433f7b7aa8c82888c9ad69ed8d40 /java/com/android/dialer/promotion/impl
parent929539eb864822d669265b142bdcc49b6cf8ea6b (diff)
Add promotion module.
Refactor Duo disclosure card to general promotion card. Bug: 78905507 Test: unit tests PiperOrigin-RevId: 197436677 Change-Id: I511c39308cadfb96ee4519b71ca29b75d0e6750b
Diffstat (limited to 'java/com/android/dialer/promotion/impl')
-rw-r--r--java/com/android/dialer/promotion/impl/AndroidManifest.xml23
-rw-r--r--java/com/android/dialer/promotion/impl/DuoPromotion.java132
-rw-r--r--java/com/android/dialer/promotion/impl/PromotionModule.java36
-rw-r--r--java/com/android/dialer/promotion/impl/RttPromotion.java94
-rw-r--r--java/com/android/dialer/promotion/impl/res/values/strings.xml35
5 files changed, 320 insertions, 0 deletions
diff --git a/java/com/android/dialer/promotion/impl/AndroidManifest.xml b/java/com/android/dialer/promotion/impl/AndroidManifest.xml
new file mode 100644
index 000000000..c938b9a37
--- /dev/null
+++ b/java/com/android/dialer/promotion/impl/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<!--
+ ~ Copyright (C) 2018 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
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.dialer.promotion">
+
+ <uses-sdk
+ android:minSdkVersion="24"
+ android:targetSdkVersion="28"/>
+
+</manifest>
diff --git a/java/com/android/dialer/promotion/impl/DuoPromotion.java b/java/com/android/dialer/promotion/impl/DuoPromotion.java
new file mode 100644
index 000000000..750e4a196
--- /dev/null
+++ b/java/com/android/dialer/promotion/impl/DuoPromotion.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2018 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.promotion.impl;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.support.annotation.VisibleForTesting;
+import com.android.dialer.configprovider.ConfigProvider;
+import com.android.dialer.duo.Duo;
+import com.android.dialer.inject.ApplicationContext;
+import com.android.dialer.promotion.Promotion;
+import com.android.dialer.spannable.ContentWithLearnMoreSpanner;
+import com.android.dialer.storage.Unencrypted;
+import java.util.concurrent.TimeUnit;
+import javax.inject.Inject;
+
+/** Duo promotion. */
+final class DuoPromotion implements Promotion {
+ private static final String SHARED_PREF_KEY_DUO_DISCLOSURE_DISMISSED = "duo_disclosure_dismissed";
+
+ private static final String SHARED_PREF_KEY_DUO_DISCLOSURE_FIRST_VIEW_TIME_MILLIS =
+ "duo_disclosure_first_viewed_time_ms";
+ @VisibleForTesting static final String FLAG_SHOW_DUO_DISCLOSURE = "show_duo_disclosure";
+
+ @VisibleForTesting
+ static final String FLAG_DUO_DISCLOSURE_AUTO_DISMISS_AFTER_VIEWED_TIME_MILLIS =
+ "show_duo_disclosure_auto_dismiss_after_viewed_time_millis";
+
+ private final Context appContext;
+ private final ConfigProvider configProvider;
+ private final Duo duo;
+ private final SharedPreferences sharedPreferences;
+
+ @Inject
+ DuoPromotion(
+ @ApplicationContext Context context,
+ ConfigProvider configProvider,
+ Duo duo,
+ @Unencrypted SharedPreferences sharedPreferences) {
+ this.appContext = context;
+ this.configProvider = configProvider;
+ this.duo = duo;
+ this.sharedPreferences = sharedPreferences;
+ }
+
+ @Override
+ public int getType() {
+ return PromotionType.CARD;
+ }
+
+ @Override
+ public boolean isEligibleToBeShown() {
+ if (!configProvider.getBoolean(FLAG_SHOW_DUO_DISCLOSURE, false)) {
+ return false;
+ }
+ // Don't show the Duo disclosure card if
+ // (1) Duo integration is not enabled on the device, or
+ // (2) Duo is not activated.
+ if (!duo.isEnabled(appContext) || !duo.isActivated(appContext)) {
+ return false;
+ }
+
+ // Don't show the Duo disclosure card if it has been dismissed.
+ if (sharedPreferences.getBoolean(SHARED_PREF_KEY_DUO_DISCLOSURE_DISMISSED, false)) {
+ return false;
+ }
+
+ // At this point, Duo is activated and the disclosure card hasn't been dismissed.
+ // We should show the card if it has never been viewed by the user.
+ if (!sharedPreferences.contains(SHARED_PREF_KEY_DUO_DISCLOSURE_FIRST_VIEW_TIME_MILLIS)) {
+ return true;
+ }
+
+ // At this point, the card has been viewed but not dismissed.
+ // We should not show the card if it has been viewed for more than 1 day.
+ long duoDisclosureFirstViewTimeMillis =
+ sharedPreferences.getLong(SHARED_PREF_KEY_DUO_DISCLOSURE_FIRST_VIEW_TIME_MILLIS, 0);
+ return System.currentTimeMillis() - duoDisclosureFirstViewTimeMillis
+ <= configProvider.getLong(
+ FLAG_DUO_DISCLOSURE_AUTO_DISMISS_AFTER_VIEWED_TIME_MILLIS, TimeUnit.DAYS.toMillis(1));
+ }
+
+ @Override
+ public void onViewed() {
+ if (!sharedPreferences.contains(SHARED_PREF_KEY_DUO_DISCLOSURE_FIRST_VIEW_TIME_MILLIS)) {
+ sharedPreferences
+ .edit()
+ .putLong(
+ SHARED_PREF_KEY_DUO_DISCLOSURE_FIRST_VIEW_TIME_MILLIS, System.currentTimeMillis())
+ .apply();
+ }
+ }
+
+ @Override
+ public void dismiss() {
+ sharedPreferences.edit().putBoolean(SHARED_PREF_KEY_DUO_DISCLOSURE_DISMISSED, true).apply();
+ }
+
+ @Override
+ public CharSequence getTitle() {
+ return appContext.getString(R.string.duo_disclosure_title);
+ }
+
+ @Override
+ public CharSequence getDetails() {
+ return new ContentWithLearnMoreSpanner(appContext)
+ .create(
+ appContext.getString(R.string.duo_disclosure_details),
+ configProvider.getString(
+ "duo_disclosure_link_full_url",
+ "http://support.google.com/pixelphone/?p=dialer_duo"));
+ }
+
+ @Override
+ public int getIconRes() {
+ return duo.getLogo();
+ }
+}
diff --git a/java/com/android/dialer/promotion/impl/PromotionModule.java b/java/com/android/dialer/promotion/impl/PromotionModule.java
new file mode 100644
index 000000000..f0908780c
--- /dev/null
+++ b/java/com/android/dialer/promotion/impl/PromotionModule.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018 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.promotion.impl;
+
+import com.android.dialer.inject.DialerVariant;
+import com.android.dialer.inject.InstallIn;
+import com.android.dialer.promotion.Promotion;
+import com.google.common.collect.ImmutableList;
+import dagger.Module;
+import dagger.Provides;
+
+/** Module for Promotion. */
+@InstallIn(variants = {DialerVariant.DIALER_TEST})
+@Module
+public abstract class PromotionModule {
+
+ @Provides
+ static ImmutableList<Promotion> providePriorityPromotionList(
+ RttPromotion rttPromotion, DuoPromotion duoPromotion) {
+ return ImmutableList.of(rttPromotion, duoPromotion);
+ }
+}
diff --git a/java/com/android/dialer/promotion/impl/RttPromotion.java b/java/com/android/dialer/promotion/impl/RttPromotion.java
new file mode 100644
index 000000000..f0f7f546b
--- /dev/null
+++ b/java/com/android/dialer/promotion/impl/RttPromotion.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2018 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.promotion.impl;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.support.annotation.DrawableRes;
+import com.android.dialer.common.LogUtil;
+import com.android.dialer.configprovider.ConfigProvider;
+import com.android.dialer.inject.ApplicationContext;
+import com.android.dialer.promotion.Promotion;
+import com.android.dialer.spannable.ContentWithLearnMoreSpanner;
+import com.android.dialer.storage.StorageComponent;
+import com.android.dialer.storage.Unencrypted;
+import javax.inject.Inject;
+
+/** RTT promotion. */
+public final class RttPromotion implements Promotion {
+ private static final String SHARED_PREFERENCE_KEY_ENABLED = "rtt_promotion_enabled";
+ private static final String SHARED_PREFERENCE_KEY_DISMISSED = "rtt_promotion_dismissed";
+ private final Context appContext;
+ private final SharedPreferences sharedPreferences;
+ private final ConfigProvider configProvider;
+
+ @Override
+ public int getType() {
+ return PromotionType.BOTTOM_SHEET;
+ }
+
+ @Inject
+ RttPromotion(
+ @ApplicationContext Context context,
+ @Unencrypted SharedPreferences sharedPreferences,
+ ConfigProvider configProvider) {
+ appContext = context;
+ this.sharedPreferences = sharedPreferences;
+ this.configProvider = configProvider;
+ }
+
+ @Override
+ public boolean isEligibleToBeShown() {
+ return sharedPreferences.getBoolean(SHARED_PREFERENCE_KEY_ENABLED, false)
+ && !sharedPreferences.getBoolean(SHARED_PREFERENCE_KEY_DISMISSED, false);
+ }
+
+ @Override
+ public CharSequence getTitle() {
+ return appContext.getString(R.string.rtt_promotion_title);
+ }
+
+ @Override
+ public CharSequence getDetails() {
+ return new ContentWithLearnMoreSpanner(appContext)
+ .create(
+ appContext.getString(R.string.rtt_promotion_details),
+ configProvider.getString(
+ "rtt_promo_learn_more_link_full_url",
+ "http://support.google.com/pixelphone/?p=dialer_rtt"));
+ }
+
+ @Override
+ @DrawableRes
+ public int getIconRes() {
+ return R.drawable.quantum_ic_rtt_vd_theme_24;
+ }
+
+ public static void setEnabled(Context context) {
+ LogUtil.enterBlock("RttPromotion.setEnabled");
+ StorageComponent.get(context)
+ .unencryptedSharedPrefs()
+ .edit()
+ .putBoolean(SHARED_PREFERENCE_KEY_ENABLED, true)
+ .apply();
+ }
+
+ @Override
+ public void dismiss() {
+ sharedPreferences.edit().putBoolean(SHARED_PREFERENCE_KEY_DISMISSED, true).apply();
+ }
+}
diff --git a/java/com/android/dialer/promotion/impl/res/values/strings.xml b/java/com/android/dialer/promotion/impl/res/values/strings.xml
new file mode 100644
index 000000000..899074932
--- /dev/null
+++ b/java/com/android/dialer/promotion/impl/res/values/strings.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2018 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
+ -->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Title for RTT promotion dialog. [CHAR LIMIT=NONE] -->
+ <string name="rtt_promotion_title">Real-time text messaging within a call</string>
+
+ <!-- Details for RTT promotion dialog. [CHAR LIMIT=NONE] -->
+ <string name="rtt_promotion_details">RTT assists callers who are deaf, hard of hearing, have a speech
+ disability, or need more than voice alone. RTT messaging transcripts are stored on your device
+ in the call history. <xliff:g exmaple="Learn More">%1$s</xliff:g></string>
+
+ <!-- Header on the Duo disclosure card. [CHAR_LIMIT=60] -->
+ <string name="duo_disclosure_title">
+ Make video calls with Duo
+ </string>
+
+ <!-- Details on the Duo disclosure card. [CHAR_LIMIT=200] -->
+ <string name="duo_disclosure_details">
+ Google Duo video calling lets you chat with friends and family face-to-face. Data charges may apply. <xliff:g example="Learn More">%1$s</xliff:g>
+ </string>
+</resources>