Skip to content

Commit 8280790

Browse files
committed
Merge branch 'main' into android-15
2 parents c5bb8f7 + 8a866f6 commit 8280790

File tree

10 files changed

+109
-12
lines changed

10 files changed

+109
-12
lines changed

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
distribution: 'temurin'
1717
java-version: '17'
1818
- name: Setup Gradle
19-
uses: gradle/actions/setup-gradle@v3
19+
uses: gradle/actions/setup-gradle@v4
2020
- name: Setup Build ID
2121
run: |
2222
[[ "$MATRIX_OS" == ubuntu* ]] && osName=linux || osName="${MATRIX_OS:0:3}"

.github/workflows/codeql.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
distribution: 'temurin'
2121
java-version: '17'
2222
- name: Setup Gradle
23-
uses: gradle/actions/setup-gradle@v3
23+
uses: gradle/actions/setup-gradle@v4
2424
- name: Initialize CodeQL
2525
uses: github/codeql-action/init@v3
2626
with:

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 35
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

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
android:theme="@style/Theme.NFCQuickSettingsTile"
1818
tools:targetApi="31">
1919

20+
<activity
21+
android:name=".NfcTilePreferencesActivity"
22+
android:enabled="false"
23+
android:excludeFromRecents="true"
24+
android:exported="false"
25+
android:label="@string/tile_prefs_label"
26+
android:theme="@android:style/Theme.NoDisplay">
27+
<intent-filter>
28+
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
29+
</intent-filter>
30+
</activity>
31+
2032
<service
2133
android:name=".NfcTileService"
2234
android:exported="true"
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_INACTIVE,
218+
string.tile_subtitle_unavailable
219+
)
183220
}
184221

185222
/**
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Added metadata for F-Droid
1+
- Redirected long-tap to NFC Settings, when granted WRITE_SECURE_SETTINGS permission

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>

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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.1' apply false
4-
id 'com.android.library' version '8.5.1' apply false
3+
id 'com.android.application' version '8.5.2' apply false
4+
id 'com.android.library' version '8.5.2' apply false
55
id 'org.jetbrains.dokka' version '1.9.20' apply false
6-
id 'org.jetbrains.kotlin.android' version '2.0.0' apply false
6+
id 'org.jetbrains.kotlin.android' version '2.0.10' apply false
77
}

0 commit comments

Comments
 (0)