From 4bd37041c3ace75e4ac5bfbd87fe6d1cfad8038a Mon Sep 17 00:00:00 2001
From: TheScarastic <warabhishek@e.email>
Date: Mon, 11 Apr 2022 14:51:12 +0530
Subject: privacycentralapp: Add notification on 1st boot to tell us more about
 our app

---
 app/src/main/AndroidManifest.xml                   |  9 +++
 .../common/BootCompletedReceiver.kt                | 73 ++++++++++++++++++++++
 .../data/repositories/LocalStateRepository.kt      |  8 ++-
 app/src/main/res/drawable/ic_notification_logo.xml | 33 ++++++++++
 app/src/main/res/values/strings.xml                |  3 +
 5 files changed, 125 insertions(+), 1 deletion(-)
 create mode 100644 app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt
 create mode 100644 app/src/main/res/drawable/ic_notification_logo.xml

(limited to 'app')

diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index cbb4ccc..d285b6f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -31,6 +31,15 @@
         android:windowSoftInputMode="adjustResize"
         tools:replace="android:icon,android:label,android:theme"
         >
+        <receiver
+            android:name=".common.BootCompletedReceiver"
+            >
+            <intent-filter>
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </receiver>
+
         <receiver
             android:exported="true"
             android:name=".Widget"
diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt b/app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt
new file mode 100644
index 0000000..a26c06a
--- /dev/null
+++ b/app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2022 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 <https://www.gnu.org/licenses/>.
+ */
+
+package foundation.e.privacycentralapp.common
+
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import androidx.core.app.NotificationCompat
+import foundation.e.privacycentralapp.R
+import foundation.e.privacycentralapp.data.repositories.LocalStateRepository
+
+class BootCompletedReceiver : BroadcastReceiver() {
+    companion object {
+        const val FIRST_BOOT_NOTIFICATION_ID = 10
+    }
+
+    override fun onReceive(context: Context, intent: Intent?) {
+        if (intent?.action == Intent.ACTION_BOOT_COMPLETED) {
+            val localStateRepository = LocalStateRepository(context)
+            if (localStateRepository.firstBoot) {
+                showNotification(context)
+                localStateRepository.firstBoot = false
+            }
+        }
+    }
+
+    private fun showNotification(context: Context) {
+        val channelId = "first_boot_notification"
+        val pendingIntent =
+            PendingIntent.getActivity(
+                context,
+                0,
+                context.packageManager.getLaunchIntentForPackage(context.packageName),
+                PendingIntent.FLAG_IMMUTABLE
+            )
+        val notificationBuilder: NotificationCompat.Builder =
+            NotificationCompat.Builder(context, channelId)
+                .setSmallIcon(R.drawable.ic_notification_logo)
+                .setContentTitle(context.getString(R.string.first_notification_title))
+                .setAutoCancel(true)
+                .setContentIntent(pendingIntent)
+                .setStyle(
+                    NotificationCompat.BigTextStyle()
+                        .bigText(context.getString(R.string.first_notification_summary))
+                )
+        val notificationManager =
+            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+
+        val name: CharSequence = "First Boot"
+        val importance = NotificationManager.IMPORTANCE_HIGH
+        val mChannel = NotificationChannel(channelId, name, importance)
+        notificationManager.createNotificationChannel(mChannel)
+        notificationManager.notify(FIRST_BOOT_NOTIFICATION_ID, notificationBuilder.build())
+    }
+}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt
index 145ff32..9a7fd15 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt
@@ -28,11 +28,13 @@ class LocalStateRepository(context: Context) {
         private const val KEY_IP_SCRAMBLING = "ipScrambling"
         private const val KEY_FAKE_LATITUDE = "fakeLatitude"
         private const val KEY_FAKE_LONGITUDE = "fakeLongitude"
+        private const val KEY_FIRST_BOOT = "firstBoot"
     }
 
     private val sharedPref = context.getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE)
 
-    private val quickPrivacyEnabledMutableFlow = MutableStateFlow<Boolean>(sharedPref.getBoolean(KEY_QUICK_PRIVACY, false))
+    private val quickPrivacyEnabledMutableFlow =
+        MutableStateFlow<Boolean>(sharedPref.getBoolean(KEY_QUICK_PRIVACY, false))
     var isQuickPrivacyEnabled: Boolean
         get() = quickPrivacyEnabledMutableFlow.value
         set(value) {
@@ -70,6 +72,10 @@ class LocalStateRepository(context: Context) {
         get() = sharedPref.getBoolean(KEY_IP_SCRAMBLING, false)
         set(value) = set(KEY_IP_SCRAMBLING, value)
 
+    var firstBoot: Boolean
+        get() = sharedPref.getBoolean(KEY_FIRST_BOOT, true)
+        set(value) = set(KEY_FIRST_BOOT, value)
+
     private fun set(key: String, value: Boolean) {
         sharedPref.edit().putBoolean(key, value).commit()
     }
diff --git a/app/src/main/res/drawable/ic_notification_logo.xml b/app/src/main/res/drawable/ic_notification_logo.xml
new file mode 100644
index 0000000..a8ec9c2
--- /dev/null
+++ b/app/src/main/res/drawable/ic_notification_logo.xml
@@ -0,0 +1,33 @@
+<!--
+  ~ Copyright (C) 2022 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 <https://www.gnu.org/licenses/>.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:viewportHeight="32"
+    android:viewportWidth="32"
+    android:width="24dp"
+    >
+    <path
+        android:fillColor="#ffffff"
+        android:fillType="evenOdd"
+        android:pathData="M15.3988,3.72C15.6974,3.4573 16.1446,3.4573 16.4431,3.72L17.5715,4.7129C17.5717,4.7131 17.5719,4.7133 17.5721,4.7134C19.6392,6.5272 22.2985,7.5201 25.0671,7.5201C25.5036,7.5201 25.8575,7.874 25.8575,8.3105V16.4404C25.8575,19.8435 24.1451,23.0463 21.3097,24.9538C21.309,24.9543 21.3084,24.9547 21.3077,24.9552L16.3437,28.3397C16.0751,28.5229 15.7217,28.5229 15.4531,28.3397L10.4891,24.9552C10.4884,24.9547 10.4877,24.9542 10.487,24.9538C7.6476,23.0435 5.9619,19.8385 5.9619,16.4178V8.3105C5.9619,7.874 6.3158,7.5201 6.7523,7.5201C9.5196,7.5201 12.1801,6.528 14.2716,4.712L15.3988,3.72ZM15.921,5.3662L15.314,5.9004L15.3102,5.9037C13.1303,7.7973 10.4052,8.9045 7.5427,9.0771V16.4178C7.5427,19.3195 8.9726,22.0305 11.3712,23.6433L11.3754,23.6462L15.8984,26.73L20.4214,23.6462L20.4256,23.6433C22.8282,22.0278 24.2767,19.3146 24.2767,16.4404V9.0771C21.4147,8.9045 18.6897,7.7974 16.5288,5.9011L15.921,5.3662Z"
+        />
+    <path
+        android:fillColor="#ffffff"
+        android:pathData="M18.2019,13.8885C18.2019,12.6239 17.1857,11.6077 15.921,11.6077C14.6564,11.6077 13.6401,12.6239 13.6401,13.8885C13.6401,14.7693 14.137,15.5371 14.8822,15.921L13.9111,20.415H17.9309L16.9598,15.921C17.6825,15.5371 18.2019,14.7693 18.2019,13.8885Z"
+        />
+</vector>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 88bd473..199472d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -134,4 +134,7 @@
     <string name="widget_state_ipaddress_off">@string/dashboard_state_ipaddress_off</string>
     <string name="widget_state_ipaddress_on">@string/dashboard_state_ipaddress_on</string>
     <string name="widget_graph_trackers_legend">@string/dashboard_graph_trackers_legend</string>
+
+    <string name="first_notification_title">Discover Advanced Privacy</string>
+    <string name="first_notification_summary">Tap to find out how to easily block trackers, fake your location &amp; hide your IP address.</string>
 </resources>
\ No newline at end of file
-- 
cgit v1.2.1