From ebb232a6a9b430e5ae4ea44bbe6c2c1c351d247f Mon Sep 17 00:00:00 2001 From: Ravi Date: Wed, 26 Oct 2022 17:54:45 +1100 Subject: [PATCH 01/17] Disable push notifications for WP If an instance of JP is detected then disable push notifications for WP to prevent double notifications --- .../android/ui/main/WPMainActivity.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index b785f121996d..f31b4b741611 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.app.Dialog; import android.content.Intent; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; @@ -459,6 +460,23 @@ && getIntent().getExtras().getBoolean(ARG_CONTINUE_JETPACK_CONNECT, false)) { initSelectedSite(); } mSharedLoginResolver.tryJetpackLogin(); + + if (!mBuildConfigWrapper.isJetpackApp() && isJetpackInstalled()) { + mGCMMessageHandler.removeAllNotifications(this); + } + } + + private boolean isJetpackInstalled() { + final PackageManager packageManager = getPackageManager(); + + // TODO - Remove these two lines before merge + List apps = getPackageManager().getInstalledPackages(0); + AppLog.i(T.MAIN, apps.toString()); + + Intent jetpackIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android"); + Intent jetpackBetaIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android.beta"); + + return jetpackIntent != null || jetpackBetaIntent != null; } private void showBloggingPromptsOnboarding() { From e7ebaed7dcdd0aba9db9df7c583c10c6520fad27 Mon Sep 17 00:00:00 2001 From: Ravi Date: Thu, 27 Oct 2022 12:05:08 +1100 Subject: [PATCH 02/17] Apply feature flag apply feature flag jetpack_powered_bottom_sheet_remote_field --- .../java/org/wordpress/android/ui/main/WPMainActivity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index f31b4b741611..59d580a318af 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -133,6 +133,7 @@ import org.wordpress.android.util.BuildConfigWrapper; import org.wordpress.android.util.DeviceUtils; import org.wordpress.android.util.FluxCUtils; +import org.wordpress.android.util.JetpackBrandingUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ProfilingUtils; import org.wordpress.android.util.QuickStartUtils; @@ -262,6 +263,7 @@ public class WPMainActivity extends LocaleAwareActivity implements @Inject BloggingRemindersResolver mBloggingRemindersResolver; @Inject BuildConfigWrapper mBuildConfigWrapper; + @Inject JetpackBrandingUtils mJetpackBrandingUtils; /* * fragments implement this if their contents can be scrolled, called when user @@ -461,7 +463,9 @@ && getIntent().getExtras().getBoolean(ARG_CONTINUE_JETPACK_CONNECT, false)) { } mSharedLoginResolver.tryJetpackLogin(); - if (!mBuildConfigWrapper.isJetpackApp() && isJetpackInstalled()) { + if (mJetpackBrandingUtils.shouldShowJetpackPoweredBottomSheet() + && !mBuildConfigWrapper.isJetpackApp() + && isJetpackInstalled()) { mGCMMessageHandler.removeAllNotifications(this); } } From 42a8a2ffa707cc31303628fecb213084285fe32f Mon Sep 17 00:00:00 2001 From: Ravi Date: Thu, 27 Oct 2022 12:28:43 +1100 Subject: [PATCH 03/17] Remove debug logging --- .../java/org/wordpress/android/ui/main/WPMainActivity.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 59d580a318af..27db0b42b0a6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -472,11 +472,6 @@ && isJetpackInstalled()) { private boolean isJetpackInstalled() { final PackageManager packageManager = getPackageManager(); - - // TODO - Remove these two lines before merge - List apps = getPackageManager().getInstalledPackages(0); - AppLog.i(T.MAIN, apps.toString()); - Intent jetpackIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android"); Intent jetpackBetaIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android.beta"); From e34a5b6df0bb4daea94dc479236fe8b64c077c90 Mon Sep 17 00:00:00 2001 From: Ravi Date: Thu, 27 Oct 2022 13:02:10 +1100 Subject: [PATCH 04/17] Remove unused import --- .../main/java/org/wordpress/android/ui/main/WPMainActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 27db0b42b0a6..b8d81d545d80 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -3,7 +3,6 @@ import android.app.Activity; import android.app.Dialog; import android.content.Intent; -import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; From 4cced645e5f360c30561333a0654d8659b70e732 Mon Sep 17 00:00:00 2001 From: Ravi Date: Fri, 28 Oct 2022 18:59:09 +1100 Subject: [PATCH 05/17] Turn off Notifications Settings switch Turn off switch on Notifications Settings screen --- .../org/wordpress/android/ui/main/WPMainActivity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index b8d81d545d80..96ec452a5104 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.app.Dialog; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; @@ -23,6 +24,7 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.lifecycle.ViewModelProvider; +import androidx.preference.PreferenceManager; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; @@ -465,6 +467,10 @@ && getIntent().getExtras().getBoolean(ARG_CONTINUE_JETPACK_CONNECT, false)) { if (mJetpackBrandingUtils.shouldShowJetpackPoweredBottomSheet() && !mBuildConfigWrapper.isJetpackApp() && isJetpackInstalled()) { + // Turn toggle off on Notifications Settings screen + SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + mSharedPreferences.edit().putBoolean(getString(R.string.wp_pref_notifications_main), false).apply(); + mGCMMessageHandler.removeAllNotifications(this); } } @@ -473,8 +479,9 @@ private boolean isJetpackInstalled() { final PackageManager packageManager = getPackageManager(); Intent jetpackIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android"); Intent jetpackBetaIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android.beta"); + Intent jetpackAlphaIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android.prealpha"); - return jetpackIntent != null || jetpackBetaIntent != null; + return jetpackIntent != null || jetpackBetaIntent != null || jetpackAlphaIntent != null; } private void showBloggingPromptsOnboarding() { From 2a1bac579ee37db22e93ef9d8fe2632d5c9ef1b4 Mon Sep 17 00:00:00 2001 From: Ravi Date: Mon, 31 Oct 2022 17:50:45 +1100 Subject: [PATCH 06/17] Add JetpackAppInstallReceiver Updating implementation to use BroadcastReceiver to disable notifications --- WordPress/src/main/AndroidManifest.xml | 5 +++ .../android/modules/AppComponent.java | 3 ++ .../jetpackbadge/JetpackAppInstallReceiver.kt | 39 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index 5c914e8219b8..cde7ec5e5e85 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -924,6 +924,11 @@ android:resource="@xml/stats_minified_widget_info"/> + diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index a684d9b74319..e6e183da84f4 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -76,6 +76,7 @@ import org.wordpress.android.ui.mlp.ModalLayoutPickerFragment; import org.wordpress.android.ui.mysite.MySiteFragment; import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardMenuFragment; +import org.wordpress.android.ui.mysite.jetpackbadge.JetpackAppInstallReceiver; import org.wordpress.android.ui.mysite.tabs.MySiteTabFragment; import org.wordpress.android.ui.notifications.DismissNotificationReceiver; import org.wordpress.android.ui.notifications.NotificationsDetailActivity; @@ -658,4 +659,6 @@ public interface AppComponent { void inject(BloggingRemindersProvider object); void inject(ReaderSavedPostsProvider object); + + void inject(JetpackAppInstallReceiver object); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt new file mode 100644 index 000000000000..971291bf6589 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt @@ -0,0 +1,39 @@ +package org.wordpress.android.ui.mysite.jetpackbadge + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import androidx.preference.PreferenceManager +import org.wordpress.android.R +import org.wordpress.android.WordPress +import org.wordpress.android.push.GCMMessageHandler +import org.wordpress.android.util.BuildConfigWrapper +import javax.inject.Inject + +class JetpackAppInstallReceiver : BroadcastReceiver() { + @Inject lateinit var mBuildConfigWrapper: BuildConfigWrapper + @Inject lateinit var gcmMessageHandler: GCMMessageHandler + + override fun onReceive(context: Context?, intent: Intent?) { + (context?.applicationContext as WordPress).component().inject(this) + + if (intent != null && !mBuildConfigWrapper.isJetpackApp) { + disableNotifications(context) + } + } + + private fun disableNotifications(context: Context) { + // Turn toggle off on Notifications Settings screen + val mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + mSharedPreferences + .edit() + .putBoolean(context.getString(R.string.wp_pref_notifications_main), false) + .apply() + + gcmMessageHandler.removeAllNotifications(context) + } + + companion object { + fun newIntent(context: Context): Intent = Intent(context, JetpackAppInstallReceiver::class.java) + } +} From 5484ff2ed0b9827e66cea7a70815f741c819025e Mon Sep 17 00:00:00 2001 From: Ravi Date: Mon, 31 Oct 2022 18:02:25 +1100 Subject: [PATCH 07/17] Update WPMainActivity.java Remove initial implementation in favour of BroadcastReceiver --- .../android/ui/main/WPMainActivity.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 96ec452a5104..1b440a3435c9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -3,7 +3,6 @@ import android.app.Activity; import android.app.Dialog; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; @@ -24,7 +23,6 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.lifecycle.ViewModelProvider; -import androidx.preference.PreferenceManager; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; @@ -463,25 +461,6 @@ && getIntent().getExtras().getBoolean(ARG_CONTINUE_JETPACK_CONNECT, false)) { initSelectedSite(); } mSharedLoginResolver.tryJetpackLogin(); - - if (mJetpackBrandingUtils.shouldShowJetpackPoweredBottomSheet() - && !mBuildConfigWrapper.isJetpackApp() - && isJetpackInstalled()) { - // Turn toggle off on Notifications Settings screen - SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - mSharedPreferences.edit().putBoolean(getString(R.string.wp_pref_notifications_main), false).apply(); - - mGCMMessageHandler.removeAllNotifications(this); - } - } - - private boolean isJetpackInstalled() { - final PackageManager packageManager = getPackageManager(); - Intent jetpackIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android"); - Intent jetpackBetaIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android.beta"); - Intent jetpackAlphaIntent = packageManager.getLaunchIntentForPackage("com.jetpack.android.prealpha"); - - return jetpackIntent != null || jetpackBetaIntent != null || jetpackAlphaIntent != null; } private void showBloggingPromptsOnboarding() { From e695cdb70b230021da32cde64876f55597708128 Mon Sep 17 00:00:00 2001 From: Ravi Date: Tue, 1 Nov 2022 15:00:37 +1100 Subject: [PATCH 08/17] Update WPMainActivity.java Remove unnecessary injected class --- .../main/java/org/wordpress/android/ui/main/WPMainActivity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 1b440a3435c9..b785f121996d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -132,7 +132,6 @@ import org.wordpress.android.util.BuildConfigWrapper; import org.wordpress.android.util.DeviceUtils; import org.wordpress.android.util.FluxCUtils; -import org.wordpress.android.util.JetpackBrandingUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ProfilingUtils; import org.wordpress.android.util.QuickStartUtils; @@ -262,7 +261,6 @@ public class WPMainActivity extends LocaleAwareActivity implements @Inject BloggingRemindersResolver mBloggingRemindersResolver; @Inject BuildConfigWrapper mBuildConfigWrapper; - @Inject JetpackBrandingUtils mJetpackBrandingUtils; /* * fragments implement this if their contents can be scrolled, called when user From 1d9dee07b7f2c2aae781ad4248eaf55839b5476d Mon Sep 17 00:00:00 2001 From: Ravi Date: Tue, 1 Nov 2022 15:22:08 +1100 Subject: [PATCH 09/17] Add intent filter to Receiver --- WordPress/src/main/AndroidManifest.xml | 8 ++++++-- .../jetpackbadge/JetpackAppInstallReceiver.kt | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index cde7ec5e5e85..2e9e294912b3 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -927,8 +927,12 @@ + android:exported="true" + tools:ignore="ManifestResource"> + + + + diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt index 971291bf6589..7b22d0ec2a73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt @@ -3,6 +3,8 @@ package org.wordpress.android.ui.mysite.jetpackbadge import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.util.Log +import android.widget.Toast import androidx.preference.PreferenceManager import org.wordpress.android.R import org.wordpress.android.WordPress @@ -17,6 +19,16 @@ class JetpackAppInstallReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { (context?.applicationContext as WordPress).component().inject(this) + // TODO: Remove this logging before merge + StringBuilder().apply { + append("Action: ${intent?.action}\n") + append("URI: ${intent?.toUri(Intent.URI_INTENT_SCHEME)}\n") + toString().also { log -> + Log.d(TAG, log) + Toast.makeText(context, log, Toast.LENGTH_LONG).show() + } + } + if (intent != null && !mBuildConfigWrapper.isJetpackApp) { disableNotifications(context) } @@ -34,6 +46,8 @@ class JetpackAppInstallReceiver : BroadcastReceiver() { } companion object { + private const val TAG = "JetpackAppInstallReceiver" + fun newIntent(context: Context): Intent = Intent(context, JetpackAppInstallReceiver::class.java) } } From 0772eaabef65b403b9856d768ae9dfd4440497f5 Mon Sep 17 00:00:00 2001 From: Ravi Date: Wed, 2 Nov 2022 09:23:22 +1100 Subject: [PATCH 10/17] Use AndroidEntryPoint --- .../jetpackbadge/JetpackAppInstallReceiver.kt | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt index 7b22d0ec2a73..43f3d078159e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt @@ -6,31 +6,29 @@ import android.content.Intent import android.util.Log import android.widget.Toast import androidx.preference.PreferenceManager +import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R -import org.wordpress.android.WordPress import org.wordpress.android.push.GCMMessageHandler import org.wordpress.android.util.BuildConfigWrapper import javax.inject.Inject +@AndroidEntryPoint class JetpackAppInstallReceiver : BroadcastReceiver() { @Inject lateinit var mBuildConfigWrapper: BuildConfigWrapper @Inject lateinit var gcmMessageHandler: GCMMessageHandler - override fun onReceive(context: Context?, intent: Intent?) { - (context?.applicationContext as WordPress).component().inject(this) - - // TODO: Remove this logging before merge - StringBuilder().apply { - append("Action: ${intent?.action}\n") - append("URI: ${intent?.toUri(Intent.URI_INTENT_SCHEME)}\n") - toString().also { log -> - Log.d(TAG, log) - Toast.makeText(context, log, Toast.LENGTH_LONG).show() - } + override fun onReceive(context: Context, intent: Intent) { + if (!mBuildConfigWrapper.isJetpackApp) { + disableNotifications(context) } - if (intent != null && !mBuildConfigWrapper.isJetpackApp) { - disableNotifications(context) + // TODO: Remove this logging before merge + buildString { + append("Action: ").append(intent.action).append("\n") + append("URI: ").append(intent.toUri(Intent.URI_INTENT_SCHEME)).append("\n") + }.also { log -> + Log.d(TAG, log) + Toast.makeText(context, log, Toast.LENGTH_LONG).show() } } From b81fd47f74a778ebea95d1626a281f1d0de36240 Mon Sep 17 00:00:00 2001 From: Ravi Date: Fri, 4 Nov 2022 15:10:51 +1100 Subject: [PATCH 11/17] ignore lint check for now --- WordPress/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index 2e9e294912b3..c5a1d2fea97f 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -928,7 +928,7 @@ android:name=".ui.mysite.jetpackbadge.JetpackAppInstallReceiver" android:enabled="true" android:exported="true" - tools:ignore="ManifestResource"> + tools:ignore="ExportedReceiver"> From 9d87d70dc330c7f12308cd26de83dbddd39fbdef Mon Sep 17 00:00:00 2001 From: Ravi Date: Fri, 4 Nov 2022 15:52:15 +1100 Subject: [PATCH 12/17] Update JetpackAppInstallReceiver.kt removed TODO for detekt --- .../android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt index 43f3d078159e..6a361228de2f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt @@ -22,7 +22,6 @@ class JetpackAppInstallReceiver : BroadcastReceiver() { disableNotifications(context) } - // TODO: Remove this logging before merge buildString { append("Action: ").append(intent.action).append("\n") append("URI: ").append(intent.toUri(Intent.URI_INTENT_SCHEME)).append("\n") From 2b0b09cd071ef6295e5208058248f31ee2a742e1 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 9 Nov 2022 13:51:49 +0300 Subject: [PATCH 13/17] Remove redundant inject in AppComponent --- .../main/java/org/wordpress/android/modules/AppComponent.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index e6e183da84f4..a684d9b74319 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -76,7 +76,6 @@ import org.wordpress.android.ui.mlp.ModalLayoutPickerFragment; import org.wordpress.android.ui.mysite.MySiteFragment; import org.wordpress.android.ui.mysite.dynamiccards.DynamicCardMenuFragment; -import org.wordpress.android.ui.mysite.jetpackbadge.JetpackAppInstallReceiver; import org.wordpress.android.ui.mysite.tabs.MySiteTabFragment; import org.wordpress.android.ui.notifications.DismissNotificationReceiver; import org.wordpress.android.ui.notifications.NotificationsDetailActivity; @@ -659,6 +658,4 @@ public interface AppComponent { void inject(BloggingRemindersProvider object); void inject(ReaderSavedPostsProvider object); - - void inject(JetpackAppInstallReceiver object); } From 0ab45a0c0e59f5ae00d46d3817078de4dada3cc5 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 9 Nov 2022 22:58:15 +0300 Subject: [PATCH 14/17] Move JetpackAppInstallReceiver to wordpress directory This receiver will be used only in WordPress app. --- WordPress/src/main/AndroidManifest.xml | 9 --------- WordPress/src/wordpress/AndroidManifest.xml | 8 ++++++++ .../ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt | 6 +----- 3 files changed, 9 insertions(+), 14 deletions(-) rename WordPress/src/{main => wordpress}/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt (87%) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index c5a1d2fea97f..5c914e8219b8 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -924,15 +924,6 @@ android:resource="@xml/stats_minified_widget_info"/> - - - - - diff --git a/WordPress/src/wordpress/AndroidManifest.xml b/WordPress/src/wordpress/AndroidManifest.xml index e2c1caf6b1d2..fe87882bbcbd 100644 --- a/WordPress/src/wordpress/AndroidManifest.xml +++ b/WordPress/src/wordpress/AndroidManifest.xml @@ -21,5 +21,13 @@ android:name=".reader.savedposts.provider.ReaderSavedPostsProvider" android:authorities="${applicationId}.ReaderSavedPostsProvider" android:exported="true" /> + + + + + + diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt b/WordPress/src/wordpress/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt similarity index 87% rename from WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt rename to WordPress/src/wordpress/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt index 6a361228de2f..bb67dc8149cc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt +++ b/WordPress/src/wordpress/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt @@ -9,18 +9,14 @@ import androidx.preference.PreferenceManager import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R import org.wordpress.android.push.GCMMessageHandler -import org.wordpress.android.util.BuildConfigWrapper import javax.inject.Inject @AndroidEntryPoint class JetpackAppInstallReceiver : BroadcastReceiver() { - @Inject lateinit var mBuildConfigWrapper: BuildConfigWrapper @Inject lateinit var gcmMessageHandler: GCMMessageHandler override fun onReceive(context: Context, intent: Intent) { - if (!mBuildConfigWrapper.isJetpackApp) { - disableNotifications(context) - } + disableNotifications(context) buildString { append("Action: ").append(intent.action).append("\n") From e0847bd5650887fed743f28ddc3f7ba45fed1d37 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 9 Nov 2022 22:59:24 +0300 Subject: [PATCH 15/17] Add DISABLE_NOTIFICATIONS permission for broadcast --- WordPress/src/main/AndroidManifest.xml | 6 ++++++ WordPress/src/wordpress/AndroidManifest.xml | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index 5c914e8219b8..6d14077ed982 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -23,6 +23,12 @@ + + + + android:exported="true" + android:permission="org.wordpress.android.permission.DISABLE_NOTIFICATIONS"> From 1f4fbcb660b8873d8cf8d44ec98a69742c5d1f1e Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 9 Nov 2022 23:01:10 +0300 Subject: [PATCH 16/17] Remove debug logging from JetpackAppInstallReceiver --- .../mysite/jetpackbadge/JetpackAppInstallReceiver.kt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/WordPress/src/wordpress/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt b/WordPress/src/wordpress/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt index bb67dc8149cc..86597032df53 100644 --- a/WordPress/src/wordpress/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt +++ b/WordPress/src/wordpress/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackAppInstallReceiver.kt @@ -3,8 +3,6 @@ package org.wordpress.android.ui.mysite.jetpackbadge import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import android.util.Log -import android.widget.Toast import androidx.preference.PreferenceManager import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R @@ -17,14 +15,6 @@ class JetpackAppInstallReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { disableNotifications(context) - - buildString { - append("Action: ").append(intent.action).append("\n") - append("URI: ").append(intent.toUri(Intent.URI_INTENT_SCHEME)).append("\n") - }.also { log -> - Log.d(TAG, log) - Toast.makeText(context, log, Toast.LENGTH_LONG).show() - } } private fun disableNotifications(context: Context) { @@ -39,8 +29,6 @@ class JetpackAppInstallReceiver : BroadcastReceiver() { } companion object { - private const val TAG = "JetpackAppInstallReceiver" - fun newIntent(context: Context): Intent = Intent(context, JetpackAppInstallReceiver::class.java) } } From 66b5d8154630a10a5d48acb631be13364306a261 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 9 Nov 2022 23:22:36 +0300 Subject: [PATCH 17/17] Update DISABLE_NOTIFICATIONS permission label and desc --- WordPress/src/main/AndroidManifest.xml | 4 ++-- WordPress/src/main/res/values/strings.xml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index 6d14077ed982..ad87e1ef7d5d 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -25,8 +25,8 @@ + android:description="@string/notification_disable_broadcast_permission_desc" + android:label="@string/notification_disable_broadcast_permission_label" /> diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 7f53560703bd..6bc3774d755e 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1522,6 +1522,8 @@ Search sites No sites matched \'%s\' The chosen sound has invalid path. Please choose another. + disable WordPress notifications + Allows the app to disable WordPress notifications. Email me new posts Receive notifications for new posts from this site