diff --git a/app/src/main/java/com/smartpack/kernelmanager/activities/NavigationActivity.java b/app/src/main/java/com/smartpack/kernelmanager/activities/NavigationActivity.java index c6392f01..3d8e80e5 100644 --- a/app/src/main/java/com/smartpack/kernelmanager/activities/NavigationActivity.java +++ b/app/src/main/java/com/smartpack/kernelmanager/activities/NavigationActivity.java @@ -19,6 +19,7 @@ */ package com.smartpack.kernelmanager.activities; +import android.Manifest; import android.content.Intent; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; @@ -31,6 +32,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; +import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -41,6 +43,8 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; +import com.google.android.material.checkbox.MaterialCheckBox; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.navigation.NavigationView; import com.smartpack.kernelmanager.R; import com.smartpack.kernelmanager.fragments.BaseFragment; @@ -540,6 +544,32 @@ public NavigationFragment[] newArray(int size) { public void onStart() { super.onStart(); + // Request permission to post notification on Android 13 & above + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && Utils.isPermissionDenied(Manifest.permission.POST_NOTIFICATIONS, this) && + !Prefs.getBoolean("permission_notification", false, this)) { + View checkBoxView = View.inflate(this, R.layout.rv_checkbox, null); + MaterialCheckBox checkBox = checkBoxView.findViewById(R.id.checkbox); + checkBox.setChecked(!Prefs.getBoolean("permission_notification", false, this)); + checkBox.setText(getString(R.string.always_show)); + checkBox.setOnCheckedChangeListener((buttonView, isChecked) + -> Prefs.saveBoolean("permission_notification", !isChecked, this) + ); + + new MaterialAlertDialogBuilder(this) + .setView(checkBoxView) + .setIcon(R.mipmap.ic_launcher) + .setTitle(R.string.warning) + .setMessage(getString(R.string.permission_notification_message)) + .setCancelable(false) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + }) + .setPositiveButton(R.string.permission_request, (dialogInterface, i) -> Utils.requestPermission( + new String[] { + Manifest.permission.POST_NOTIFICATIONS + }, this) + ).show(); + } + // Initialize auto app update check if (Common.isUpdateCheckEnabled()) { new UpdateCheck().initialize(1, this); diff --git a/app/src/main/java/com/smartpack/kernelmanager/services/boot/ApplyOnBootService.java b/app/src/main/java/com/smartpack/kernelmanager/services/boot/ApplyOnBootService.java index 089628a1..dade2091 100644 --- a/app/src/main/java/com/smartpack/kernelmanager/services/boot/ApplyOnBootService.java +++ b/app/src/main/java/com/smartpack/kernelmanager/services/boot/ApplyOnBootService.java @@ -19,6 +19,7 @@ */ package com.smartpack.kernelmanager.services.boot; +import android.Manifest; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -66,6 +67,9 @@ public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && Utils.isPermissionDenied(Manifest.permission.POST_NOTIFICATIONS, this)) { + return; + } NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, diff --git a/app/src/main/java/com/smartpack/kernelmanager/utils/Utils.java b/app/src/main/java/com/smartpack/kernelmanager/utils/Utils.java index 8dfeddbd..f655387a 100644 --- a/app/src/main/java/com/smartpack/kernelmanager/utils/Utils.java +++ b/app/src/main/java/com/smartpack/kernelmanager/utils/Utils.java @@ -44,6 +44,7 @@ import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.app.AppCompatDelegate; +import androidx.core.app.ActivityCompat; import androidx.core.content.FileProvider; import androidx.core.hardware.fingerprint.FingerprintManagerCompat; import androidx.core.view.ViewCompat; @@ -103,6 +104,14 @@ public static boolean isPackageInstalled(String packageName) { return RootUtils.runAndGetOutput("pm list packages " + packageName).equals("package:" + packageName); } + public static boolean isPermissionDenied(String permission, Context context) { + return (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED); + } + + public static void requestPermission(String[] permissions, Activity activity) { + ActivityCompat.requestPermissions(activity, permissions, 0); + } + public static void initializeAppTheme(Context context) { if (Prefs.getBoolean("darktheme", true, context)) { AppCompatDelegate.setDefaultNightMode( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aa6c73b7..827886cd 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1001,6 +1001,8 @@ Disable %s? Sorry! You can\'t swipe out a %s. Sorry! You can\'t drag a %s into different position. + Inorder to work \'Apply on boot notifications\' on devices running android TIRAMISU and newer versions, it is necessary to have permission to post notifications granted by the user. If you like to have this feature working, please go ahead with requesting (and granting) the permission by clicking the button provided below. + Request Permission Acquiring update info