Skip to content

Commit f665feb

Browse files
committed
Merge branch 'main' into gradle-versions-check
2 parents 04e31d2 + c8bba23 commit f665feb

File tree

11 files changed

+108
-54
lines changed

11 files changed

+108
-54
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog[^1]
22

3+
## [1.4.3][] (2024-08-12)
4+
5+
Redirected long-tap to NFC Settings when granted `WRITE_SECURE_SETTINGS` permission.
6+
37
## [1.4.2][] (2024-07-30)
48

59
Handle a rare exception when unregistering the broadcast listener.
@@ -42,7 +46,8 @@ Added translations for 86 languages.
4246

4347
Initial release.
4448

45-
[Unreleased]: https://github.com/pcolby/nfc-quick-settings/compare/v1.4.2...HEAD
49+
[Unreleased]: https://github.com/pcolby/nfc-quick-settings/compare/v1.4.3...HEAD
50+
[1.4.3]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.4.3
4651
[1.4.2]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.4.2
4752
[1.4.1]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.4.1
4853
[1.4.0]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.4.0

app/build.gradle

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ android {
3030
applicationId "au.id.colby.nfcquicksettings"
3131
minSdk 24
3232
targetSdk 34
33-
versionCode 13
34-
versionName "1.4.3-pre"
33+
versionCode 14
34+
versionName "1.4.4-pre"
3535
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3636
}
3737

@@ -51,6 +51,11 @@ android {
5151
kotlinOptions {
5252
jvmTarget = '1.8'
5353
}
54+
packaging {
55+
resources {
56+
excludes += '/META-INF/{AL2.0,LGPL2.1}'
57+
}
58+
}
5459
}
5560

5661
base {

app/src/main/AndroidManifest.xml

+13-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,19 @@
1414
android:label="@string/app_name"
1515
android:roundIcon="@mipmap/ic_launcher_round"
1616
android:supportsRtl="true"
17-
android:theme="@style/Theme.NFCQuickSettingsTile"
18-
tools:targetApi="31">
17+
tools:targetApi="34">
18+
19+
<activity
20+
android:name=".NfcTilePreferencesActivity"
21+
android:enabled="false"
22+
android:excludeFromRecents="true"
23+
android:exported="false"
24+
android:label="@string/tile_prefs_label"
25+
android:theme="@android:style/Theme.NoDisplay">
26+
<intent-filter>
27+
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
28+
</intent-filter>
29+
</activity>
1930

2031
<service
2132
android:name=".NfcTileService"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package au.id.colby.nfcquicksettings
2+
3+
import android.app.Activity
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import android.provider.Settings
7+
import android.util.Log
8+
9+
private const val TAG = "NfcTilePrefsActivity"
10+
11+
/**
12+
* A custom "preferences" activity for the NFC Quick Settings tile.
13+
*
14+
* The activity has no display, but simply starts the NFC Settings activity, then finishes. By
15+
* default, this activity is not enabled (ie via the AndroidManifest.xml) however, if the
16+
* `WRITE_SECURE_SETTINGS` permission has been granted, then the NfcTileService will enable this
17+
* activity. See NfcTileService::onCreate().
18+
*/
19+
class NfcTilePreferencesActivity : Activity() {
20+
21+
/**
22+
* Called when this activity is being created.
23+
*
24+
* This override simply starts the NFC Settings activity, then finishes this activity.
25+
*/
26+
override fun onCreate(savedInstanceState: Bundle?) {
27+
super.onCreate(savedInstanceState)
28+
Log.d(TAG, "onCreate")
29+
Log.i(TAG, "Starting the ACTION_NFC_SETTINGS activity")
30+
startActivity(
31+
Intent(Settings.ACTION_NFC_SETTINGS).setFlags(
32+
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
33+
)
34+
)
35+
finish()
36+
}
37+
}

app/src/main/java/au/id/colby/nfcquicksettings/NfcTileService.kt

+40-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import android.Manifest.permission.WRITE_SECURE_SETTINGS
77
import android.app.PendingIntent
88
import android.app.PendingIntent.FLAG_IMMUTABLE
99
import android.content.BroadcastReceiver
10+
import android.content.ComponentName
1011
import android.content.Context
1112
import android.content.Intent
1213
import android.content.IntentFilter
14+
import android.content.pm.PackageManager
1315
import android.content.pm.PackageManager.PERMISSION_GRANTED
1416
import android.nfc.NfcAdapter
1517
import android.os.Build.VERSION.SDK_INT
@@ -21,7 +23,6 @@ import android.service.quicksettings.TileService
2123
import android.util.Log
2224
import androidx.core.content.ContextCompat
2325
import au.id.colby.nfcquicksettings.R.string
24-
import java.lang.IllegalArgumentException
2526

2627
private const val TAG = "NfcTileService"
2728

@@ -34,6 +35,18 @@ private const val TAG = "NfcTileService"
3435
class NfcTileService : TileService() {
3536
private val nfcBroadcastReceiver = NfcBroadcastReceiver()
3637

38+
/**
39+
* Called when the tile service is created.
40+
*
41+
* This updates the associated NFC Tile Preferences activity (ie to enable or disable that
42+
* activity, based on whether or not the WRITE_SECURE_SETTINGS permission has been granted).
43+
*/
44+
override fun onCreate() {
45+
super.onCreate()
46+
Log.d(TAG, "onCreate")
47+
updatePreferencesActivity()
48+
}
49+
3750
/**
3851
* Called when this tile moves into a listening state.
3952
*
@@ -145,6 +158,28 @@ class NfcTileService : TileService() {
145158
else startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, FLAG_IMMUTABLE))
146159
}
147160

161+
/**
162+
* Enables or disables the NFC tile's preferences activity based on whether or not the
163+
* `WRITE_SECURE_SETTINGS` permission has been granted.
164+
*
165+
* Thus if the permission is granted, then NfcTilePreferencesActivity will be enabled to
166+
* redirect users to the NFC Settings activity (`ACTION_NFC_SETTINGS`) on long-tapping the tile
167+
* But if the the permissions is not granted, then NfcTilePreferencesActivity is disabled,
168+
* and long-tapping the tile will result in the default OS behaviour (ie starting the
169+
* Application Details activity (`ACTION_APPLICATION_DETAILS_SETTINGS`)).
170+
*/
171+
private fun updatePreferencesActivity() {
172+
val newState =
173+
if (permissionGranted(WRITE_SECURE_SETTINGS)) PackageManager.COMPONENT_ENABLED_STATE_ENABLED
174+
else PackageManager.COMPONENT_ENABLED_STATE_DISABLED
175+
Log.d(TAG, "Setting preferences activity enabled setting to $newState")
176+
applicationContext.packageManager.setComponentEnabledSetting(
177+
ComponentName(applicationContext, NfcTilePreferencesActivity::class.java),
178+
newState,
179+
PackageManager.DONT_KILL_APP
180+
)
181+
}
182+
148183
/**
149184
* Updates the Quick Settings tile with the [newState] and (if supported) [newSubTitleResId].
150185
*
@@ -178,8 +213,10 @@ class NfcTileService : TileService() {
178213
* @param adapter The adapter to reflect the state of.
179214
*/
180215
private fun updateTile(adapter: NfcAdapter? = NfcAdapter.getDefaultAdapter(this)) {
181-
adapter?.apply { updateTile(isEnabled) } ?:
182-
updateTile(Tile.STATE_INACTIVE, string.tile_subtitle_unavailable)
216+
adapter?.apply { updateTile(isEnabled) } ?: updateTile(
217+
Tile.STATE_UNAVAILABLE,
218+
string.tile_subtitle_unavailable
219+
)
183220
}
184221

185222
/**
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Handled a very rare, but possible, exception when removing the tile
1+
- Redirected long-tap to NFC Settings, when granted WRITE_SECURE_SETTINGS permission

app/src/main/res/values-night/themes.xml

-16
This file was deleted.

app/src/main/res/values/colors.xml

-10
This file was deleted.

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<resources>
22
<string name="app_name" translatable="false">NFC Quick Settings</string>
33
<string name="tile_label" translatable="false">NFC</string>
4+
<string name="tile_prefs_label" translatable="false">NFC Tile Preferences</string>
45
<string name="tile_subtitle_active">On</string>
56
<string name="tile_subtitle_inactive">Off</string>
67
<string name="tile_subtitle_turning_on">Turning on…</string>

app/src/main/res/values/themes.xml

-16
This file was deleted.

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '8.5.2' apply false
4-
id 'com.android.library' version '8.5.2' apply false
3+
id 'com.android.application' version '8.6.1' apply false
4+
id 'com.android.library' version '8.6.1' apply false
55
id 'com.github.ben-manes.versions' version '0.51.0'
66
id 'org.jetbrains.dokka' version '1.9.20' apply false
7-
id 'org.jetbrains.kotlin.android' version '2.0.10' apply false
7+
id 'org.jetbrains.kotlin.android' version '2.0.20' apply false
88
}

0 commit comments

Comments
 (0)