Skip to content

Commit

Permalink
fix: Show recent apps permission granted when installed as system app,
Browse files Browse the repository at this point in the history
…closes #89
  • Loading branch information
axel358 committed Feb 10, 2024
1 parent a520b61 commit c4e30c4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
20 changes: 10 additions & 10 deletions app/src/main/java/cu/axel/smartdock/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var notificationsBtn: MaterialButton
private lateinit var accessibilityBtn: MaterialButton
private lateinit var locationBtn: MaterialButton
private lateinit var usageBtn: MaterialButton
private lateinit var recentAppsBtn: MaterialButton
private lateinit var secureBtn: MaterialButton
private var canDrawOverOtherApps = false
private var hasStoragePermission = false
Expand Down Expand Up @@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() {
notificationsBtn = view.findViewById(R.id.btn_grant_notifications)
accessibilityBtn = view.findViewById(R.id.btn_manage_service)
locationBtn = view.findViewById(R.id.btn_grant_location)
usageBtn = view.findViewById(R.id.btn_manage_usage)
recentAppsBtn = view.findViewById(R.id.btn_manage_recent_apps)
secureBtn = view.findViewById(R.id.btn_manage_secure)
builder.setView(view)
permissionsDialog = builder.create()
Expand Down Expand Up @@ -122,11 +122,11 @@ class MainActivity : AppCompatActivity() {
::requestLocationPermissions, hasLocationPermission
)
}
usageBtn.setOnClickListener {
recentAppsBtn.setOnClickListener {
showPermissionInfoDialog(
R.string.usage_stats, R.string.usage_stats_desc,
::requestUsageStatsPermissions,
DeviceUtils.hasUsageStatsPermission(this)
R.string.recent_apps, R.string.recent_apps_desc,
::requestRecentAppsPermission,
DeviceUtils.hasRecentAppsPermission(this)
)
}
secureBtn.setOnClickListener {
Expand Down Expand Up @@ -159,7 +159,7 @@ class MainActivity : AppCompatActivity() {
DeviceUtils.requestDeviceAdminPermissions(this)
}

private fun requestUsageStatsPermissions() {
private fun requestRecentAppsPermission() {
startActivity(Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS))
}

Expand All @@ -179,9 +179,9 @@ class MainActivity : AppCompatActivity() {
accessibilityBtn.iconTint =
ColorStateList.valueOf(ColorUtils.getThemeColors(this, false)[2])
}
if (DeviceUtils.hasUsageStatsPermission(this)) {
usageBtn.setIconResource(R.drawable.ic_granted)
usageBtn.iconTint = ColorStateList.valueOf(ColorUtils.getThemeColors(this, false)[0])
if (DeviceUtils.hasRecentAppsPermission(this)) {
recentAppsBtn.setIconResource(R.drawable.ic_granted)
recentAppsBtn.iconTint = ColorStateList.valueOf(ColorUtils.getThemeColors(this, false)[0])
}
if (DeviceUtils.isServiceRunning(this, NotificationService::class.java)) {
notificationsBtn.setIconResource(R.drawable.ic_settings)
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/cu/axel/smartdock/utils/DeviceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import java.io.File
import java.io.IOException
import java.io.InputStreamReader
import android.os.UserManager
import kotlin.reflect.KClass

object DeviceUtils {
const val DISPLAY_SIZE = "display_density_forced"
Expand Down Expand Up @@ -333,8 +332,8 @@ object DeviceUtils {
return false
}

fun hasUsageStatsPermission(context: Context): Boolean {
return checkAppOpsPermission(context, AppOpsManager.OPSTR_GET_USAGE_STATS)
fun hasRecentAppsPermission(context: Context): Boolean {
return AppUtils.isSystemApp(context, context.packageName) || checkAppOpsPermission(context, AppOpsManager.OPSTR_GET_USAGE_STATS)
}

private fun checkAppOpsPermission(context: Context, permission: String): Boolean {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/permissions_required.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="1.0"
android:text="@string/usage_stats"
android:text="@string/recent_apps"
android:textAppearance="?attr/textAppearanceTitleMedium" />

<Button
app:iconTint="?attr/colorError"
android:id="@+id/btn_manage_usage"
android:id="@+id/btn_manage_recent_apps"
style="?attr/materialIconButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<string name="display_over_other_apps_desc">Requerido para mostrar el Dock, no puede iniciar el servicio sin esto</string>
<string name="accessibility_service">Servicio de accesibilidad</string>
<string name="accessibility_service_desc">Use esto para iniciar y detener el Dock. Requiere el permiso anterior. Si se muestra un error sobre <b>Ajuste restringido</b> haga click en el botón de Ayuda</string>
<string name="usage_stats">Estadísticas de uso</string>
<string name="usage_stats_desc">Permite mostrar aplicaciones recientes en dispositivos donde Smart Dock no se puede instalar como una aplicación de sistema</string>
<string name="recent_apps">Apps recientes</string>
<string name="recent_apps_desc">Permite mostrar aplicaciones recientes en el dock</string>
<string name="notification_access">Acceso a notificaciones</string>
<string name="notification_access_desc">Se utiliza para mostrar notificaciones. Si se muestra un error sobre <b>Ajuste restringido</b> haga click en el botón de Ayuda</string>
<string name="device_administrator">Administrador de dispositivo</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-pa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<string name="display_over_other_apps_desc">ਡੌਕ ਨੂੰ ਡਿਸਪਲੇ ਕਰਨ ਲਈ ਲੋੜੀਂਦਾ ਹੈ, ਤੁਸੀਂ ਇਸ ਤੋਂ ਬਿਨਾਂ ਸੇਵਾ ਸ਼ੁਰੂ ਨਹੀਂ ਕਰ ਸਕਦੇ ਹੋ</string>
<string name="accessibility_service">ਅਸੈਂਸੀਬਿਲਟੀ ਸੇਵਾ</string>
<string name="accessibility_service_desc">ਡੌਕ ਨੂੰ ਸ਼ੁਰੂ ਕਰਨ ਅਤੇ ਬੰਦ ਕਰਨ ਲਈ ਇਸਦੀ ਵਰਤੋਂ ਕਰੋ। ਉਪਰੋਕਤ ਇਜਾਜ਼ਤ ਦੀ ਲੋੜ ਹੈ</string>
<string name="usage_stats">ਵਰਤੋਂ ਦੇ ਅੰਕੜੇ</string>
<string name="usage_stats_desc">ਉਹਨਾਂ ਡੀਵਾਈਸਾਂ \'ਤੇ ਹਾਲੀਆ ਐਪਾਂ ਦਿਖਾਉਣ ਦੀ ਇਜਾਜ਼ਤ ਦਿੰਦਾ ਹੈ ਜਿੱਥੇ ਸਮਾਰਟ ਡੌਕ ਨੂੰ ਸਿਸਟਮ ਐਪ ਵਜੋਂ ਸਥਾਪਤ ਨਹੀਂ ਕੀਤਾ ਜਾ ਸਕਦਾ</string>
<string name="recent_apps">Recent apps</string>
<string name="recent_apps_desc">Allows to display recent apps on the dock</string>
<string name="notification_access">ਨੋਟੀਫੀਕੇਸਨ ਐਕਸੈਸ</string>
<string name="notification_access_desc">ਨੋਟੀਫੀਕੇਸਨ ਦਿਖਾਉਣ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ</string>
<string name="device_administrator">ਡਿਵਾਈਸ ਐਡਮਿਨਸਟਰੇਟਰ</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<string name="display_over_other_apps_desc">Required to display the Dock, you cannot start the service without this</string>
<string name="accessibility_service">Accessibility service</string>
<string name="accessibility_service_desc">Use this to start and stop the Dock. Requires the above permission. If you get an error about <b>Restricted setting</b> click the Help button below</string>
<string name="usage_stats">Usage stats</string>
<string name="usage_stats_desc">Allows to show recent apps on devices where Smart Dock can\'t be installed as a system app</string>
<string name="recent_apps">Recent apps</string>
<string name="recent_apps_desc">Allows to display recent apps on the dock</string>
<string name="notification_access">Notification access</string>
<string name="notification_access_desc">Used to display notifications. If you get an error about <b>Restricted setting</b> click the Help button below</string>
<string name="device_administrator">Device administrator</string>
Expand Down

0 comments on commit c4e30c4

Please sign in to comment.