From 5261efbf521cd92985ae7e184cfb7d3d9fc734da Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 6 Apr 2022 20:26:42 +0530 Subject: [PATCH 1/8] PWA Player: (issue 4945) Create class to broadcast PWA status to all eligible receivers. --- .../pwaplayer/broadcast/PWAStatusBroadcast.kt | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt diff --git a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt new file mode 100644 index 0000000..e41c504 --- /dev/null +++ b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt @@ -0,0 +1,54 @@ +package foundation.e.pwaplayer.broadcast + +import android.app.Application +import android.content.Context +import android.content.Intent + +/** + * This class is responsible for sending PWA install / removal status to all apps. + * An app should declare a broadcast receiver in the manifest as below: + * ``` + * + * + * + * + * + * + * + * + * + * + * + * ``` + * This class will be able to manually resolve the eligible broadcast receivers in all apps + * and send them the broadcast. + */ +object PWAStatusBroadcast { + + private fun broadcast(application: Application, action: String) { + try { + val pm = application.packageManager + val intent = Intent(action) + pm.queryBroadcastReceivers(intent, 0).forEach { + val receiverPackage = it.activityInfo.packageName + application.sendBroadcast(intent.setPackage(receiverPackage)) + } + } + catch (e: Exception) { + e.printStackTrace() + } + } + + fun broadcastPwaAdded(context: Context) { + broadcast(context.applicationContext as Application, "foundation.e.pwaplayer.PWA_ADDED") + } + + fun broadcastPwaChanged(context: Context) { + broadcast(context.applicationContext as Application, "foundation.e.pwaplayer.PWA_CHANGED") + } + + fun broadcastPwaRemoved(context: Context) { + broadcast(context.applicationContext as Application, "foundation.e.pwaplayer.PWA_REMOVED") + } +} \ No newline at end of file -- GitLab From c16c586b55930c9ad64989e01de15689950ea0ca Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 6 Apr 2022 20:28:00 +0530 Subject: [PATCH 2/8] PWA Player: (issue 4945) Implement PWAStatusBroadcast class from PwaProvider to send broadcasts. --- .../main/java/foundation/e/pwaplayer/provider/PwaProvider.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt b/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt index 54dc564..04fd6d4 100644 --- a/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt +++ b/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt @@ -7,6 +7,7 @@ import android.content.UriMatcher import android.database.Cursor import android.net.Uri import android.util.Log +import foundation.e.pwaplayer.broadcast.PWAStatusBroadcast import foundation.e.pwaplayer.database.PwaDatabase import foundation.e.pwaplayer.database.mapToPwa import foundation.e.pwaplayer.provider.PwaConstants.Companion.TABLE_NAME @@ -51,6 +52,7 @@ class PwaProvider : ContentProvider() { } val uri = ContentUris.withAppendedId(uri, id) notifyListeners(uri) + PWAStatusBroadcast.broadcastPwaAdded(context) return uri } else -> throw IllegalArgumentException("Invalid URI: Insert failed $uri") @@ -118,6 +120,7 @@ class PwaProvider : ContentProvider() { val count = pwas.update(pwa) if (count > 0) { notifyListeners(uri) + PWAStatusBroadcast.broadcastPwaChanged(context) } return count } @@ -139,6 +142,7 @@ class PwaProvider : ContentProvider() { val count = pwas.delete(ContentUris.parseId(uri)) if (count > 0) { notifyListeners(uri) + PWAStatusBroadcast.broadcastPwaRemoved(context) } return count } @@ -150,6 +154,7 @@ class PwaProvider : ContentProvider() { val count = pwas.delete(selectionArgs[0]) if (count > 0) { notifyListeners(uri) + PWAStatusBroadcast.broadcastPwaRemoved(context) } return count } -- GitLab From 0f1fc0c094a82e03be9cbae9a1796f6ea2632e1b Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 7 Apr 2022 21:05:38 +0530 Subject: [PATCH 3/8] PWA Player: (issue 4945) Send pwa shortcut id as intent extra in pwa status broadcast. --- .../pwaplayer/broadcast/PWAStatusBroadcast.kt | 24 ++++++++++++------- .../e/pwaplayer/provider/PwaProvider.kt | 22 +++++++++++++---- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt index e41c504..fb9ef50 100644 --- a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt +++ b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt @@ -6,6 +6,9 @@ import android.content.Intent /** * This class is responsible for sending PWA install / removal status to all apps. + * The sent intent contains following extras: + * 1. SHORTCUT_ID - string shortcut id. + * * An app should declare a broadcast receiver in the manifest as below: * ``` * throw IllegalArgumentException("Invalid URI: Insert failed $uri") @@ -120,7 +120,7 @@ class PwaProvider : ContentProvider() { val count = pwas.update(pwa) if (count > 0) { notifyListeners(uri) - PWAStatusBroadcast.broadcastPwaChanged(context) + PWAStatusBroadcast.broadcastPwaChanged(context, pwa.shortcutId) } return count } @@ -139,10 +139,22 @@ class PwaProvider : ContentProvider() { val pwas = PwaDatabase.getInstance(context).pwaDao() when (uriMatcher.match(uri)) { CODE_PWA_ITEM -> { - val count = pwas.delete(ContentUris.parseId(uri)) + val id = ContentUris.parseId(uri) + /* + * TODO : VERIFY IF THIS WORKS + * This is an attempt to get the string shortcutId. Not sure if this works. + */ + val shortcutId: String = try { + pwas.getById(ContentUris.parseId(uri)).mapToPwa().shortcutId + } + catch (e: Exception) { + e.printStackTrace() + "" + } + val count = pwas.delete(id) if (count > 0) { notifyListeners(uri) - PWAStatusBroadcast.broadcastPwaRemoved(context) + PWAStatusBroadcast.broadcastPwaRemoved(context, shortcutId) } return count } @@ -154,7 +166,7 @@ class PwaProvider : ContentProvider() { val count = pwas.delete(selectionArgs[0]) if (count > 0) { notifyListeners(uri) - PWAStatusBroadcast.broadcastPwaRemoved(context) + PWAStatusBroadcast.broadcastPwaRemoved(context, selectionArgs[0]) } return count } -- GitLab From 8c360f3a31cd00aabb6cb3bb55c977cae9bd718a Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 17:23:51 +0530 Subject: [PATCH 4/8] PWA Player: (issue 4945) Add getById() taking shortcutId --- app/src/main/java/foundation/e/pwaplayer/database/PwaDao.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/foundation/e/pwaplayer/database/PwaDao.kt b/app/src/main/java/foundation/e/pwaplayer/database/PwaDao.kt index 5730d52..cce12bd 100644 --- a/app/src/main/java/foundation/e/pwaplayer/database/PwaDao.kt +++ b/app/src/main/java/foundation/e/pwaplayer/database/PwaDao.kt @@ -11,6 +11,9 @@ interface PwaDao { @Query("SELECT * FROM pwa WHERE _id = :id") fun getById(id: Long): Cursor + @Query("SELECT * FROM pwa WHERE shortcutId = :shortcutId") + fun getById(shortcutId: String): Cursor + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(pwa: Pwa): Long -- GitLab From ab0edf56e8dc166c46b9cbc06b244f542a659875 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 18:54:25 +0530 Subject: [PATCH 5/8] PWA Player: (issue 4945) Send pwa shortcutId and pwa url via broadcasts --- .../pwaplayer/broadcast/PWAStatusBroadcast.kt | 16 ++++++---- .../e/pwaplayer/provider/PwaProvider.kt | 32 +++++++++++++------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt index fb9ef50..7fc0c9d 100644 --- a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt +++ b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt @@ -8,6 +8,7 @@ import android.content.Intent * This class is responsible for sending PWA install / removal status to all apps. * The sent intent contains following extras: * 1. SHORTCUT_ID - string shortcut id. + * 2. URL - string url of the pwa. * * An app should declare a broadcast receiver in the manifest as below: * ``` @@ -29,11 +30,12 @@ import android.content.Intent */ object PWAStatusBroadcast { - private fun broadcast(application: Application, action: String, shortcutId: String) { + private fun broadcast(application: Application, action: String, shortcutId: String, url: String) { try { val pm = application.packageManager val intent = Intent(action).apply { putExtra("SHORTCUT_ID", shortcutId) + putExtra("URL", url) } pm.queryBroadcastReceivers(intent, 0).forEach { val receiverPackage = it.activityInfo.packageName @@ -45,18 +47,18 @@ object PWAStatusBroadcast { } } - fun broadcastPwaAdded(context: Context, shortcutId: String) { + fun broadcastPwaAdded(context: Context, shortcutId: String, url: String) { broadcast(context.applicationContext as Application, - "foundation.e.pwaplayer.PWA_ADDED", shortcutId) + "foundation.e.pwaplayer.PWA_ADDED", shortcutId, url) } - fun broadcastPwaChanged(context: Context, shortcutId: String) { + fun broadcastPwaChanged(context: Context, shortcutId: String, url: String) { broadcast(context.applicationContext as Application, - "foundation.e.pwaplayer.PWA_CHANGED", shortcutId) + "foundation.e.pwaplayer.PWA_CHANGED", shortcutId, url) } - fun broadcastPwaRemoved(context: Context, shortcutId: String) { + fun broadcastPwaRemoved(context: Context, shortcutId: String, url: String) { broadcast(context.applicationContext as Application, - "foundation.e.pwaplayer.PWA_REMOVED", shortcutId) + "foundation.e.pwaplayer.PWA_REMOVED", shortcutId, url) } } \ No newline at end of file diff --git a/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt b/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt index 67ec1da..8b28792 100644 --- a/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt +++ b/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt @@ -52,7 +52,7 @@ class PwaProvider : ContentProvider() { } val uri = ContentUris.withAppendedId(uri, id) notifyListeners(uri) - PWAStatusBroadcast.broadcastPwaAdded(context, pwa.shortcutId) + PWAStatusBroadcast.broadcastPwaAdded(context, pwa.shortcutId, pwa.url) return uri } else -> throw IllegalArgumentException("Invalid URI: Insert failed $uri") @@ -120,7 +120,7 @@ class PwaProvider : ContentProvider() { val count = pwas.update(pwa) if (count > 0) { notifyListeners(uri) - PWAStatusBroadcast.broadcastPwaChanged(context, pwa.shortcutId) + PWAStatusBroadcast.broadcastPwaChanged(context, pwa.shortcutId, pwa.url) } return count } @@ -141,20 +141,23 @@ class PwaProvider : ContentProvider() { CODE_PWA_ITEM -> { val id = ContentUris.parseId(uri) /* + * Attempt to get PWA info to send via broadcast before deleting it. * TODO : VERIFY IF THIS WORKS * This is an attempt to get the string shortcutId. Not sure if this works. */ - val shortcutId: String = try { - pwas.getById(ContentUris.parseId(uri)).mapToPwa().shortcutId - } - catch (e: Exception) { + val (shortcutId: String, url: String) = try { + val cursor = pwas.getById(ContentUris.parseId(uri)) + cursor.moveToFirst() + val pwa = cursor.mapToPwa() + Pair(pwa.shortcutId, pwa.url) + } catch (e: Exception) { e.printStackTrace() - "" + Pair("", "") } val count = pwas.delete(id) if (count > 0) { notifyListeners(uri) - PWAStatusBroadcast.broadcastPwaRemoved(context, shortcutId) + PWAStatusBroadcast.broadcastPwaRemoved(context, shortcutId, url) } return count } @@ -163,10 +166,21 @@ class PwaProvider : ContentProvider() { throw IllegalArgumentException("Invalid URI: cannot delete without ID $uri") else { Log.d(TAG, "delete: ${selectionArgs[0]}") + /* + * Attempt to get PWA info to send via broadcast before deleting it. + */ + val url: String = try { + val cursor = pwas.getById(selectionArgs[0]) + cursor.moveToFirst() + cursor.mapToPwa().url + } catch (e: Exception) { + e.printStackTrace() + "" + } val count = pwas.delete(selectionArgs[0]) if (count > 0) { notifyListeners(uri) - PWAStatusBroadcast.broadcastPwaRemoved(context, selectionArgs[0]) + PWAStatusBroadcast.broadcastPwaRemoved(context, selectionArgs[0], url) } return count } -- GitLab From 660c05c7f8706044044a8de77c09217af01fe68e Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 19:07:45 +0530 Subject: [PATCH 6/8] PWA Player: (issue 4945) Send broadcast to individual components of a package, and not the whole package --- .../foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt index 7fc0c9d..a818a27 100644 --- a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt +++ b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt @@ -1,6 +1,7 @@ package foundation.e.pwaplayer.broadcast import android.app.Application +import android.content.ComponentName import android.content.Context import android.content.Intent @@ -38,8 +39,8 @@ object PWAStatusBroadcast { putExtra("URL", url) } pm.queryBroadcastReceivers(intent, 0).forEach { - val receiverPackage = it.activityInfo.packageName - application.sendBroadcast(intent.setPackage(receiverPackage)) + val component = ComponentName(it.activityInfo.packageName, it.activityInfo.name) + application.sendBroadcast(intent.setComponent(component)) } } catch (e: Exception) { -- GitLab From 5e0fc13f7018270e7de5f06fea0dd2b91311fa96 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 12 Apr 2022 12:32:09 +0530 Subject: [PATCH 7/8] PWA Player: (issue 4945) Add license --- .../pwaplayer/broadcast/PWAStatusBroadcast.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt index a818a27..7705b8b 100644 --- a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt +++ b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt @@ -1,3 +1,21 @@ +/* + * Apps Quickly and easily install Android apps onto your device! + * Copyright (C) 2021 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package foundation.e.pwaplayer.broadcast import android.app.Application -- GitLab From e70eb15ead317c09db4822aafaf1611c13421f30 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 12 Apr 2022 16:56:41 +0530 Subject: [PATCH 8/8] PWA Player: (issue 4945) update license --- .../foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt index 7705b8b..950f290 100644 --- a/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt +++ b/app/src/main/java/foundation/e/pwaplayer/broadcast/PWAStatusBroadcast.kt @@ -1,6 +1,5 @@ /* - * Apps Quickly and easily install Android apps onto your device! - * Copyright (C) 2021 E FOUNDATION + * Copyright (C) 2022 ECORP * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by -- GitLab