Skip to content

Commit

Permalink
Explain basic and advanced modes in README.md
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit ccbb926
Author: Paul Colby <[email protected]>
Date:   Sat Jun 22 16:50:04 2024 +1000

    Some more README.md tweaks

commit 0f26aae
Author: Paul Colby <[email protected]>
Date:   Sat Jun 22 16:45:26 2024 +1000

    Multiple README.md tweaks

commit 57617ef
Author: Paul Colby <[email protected]>
Date:   Sat Jun 22 16:38:44 2024 +1000

    Explaing the basic/advanced modes in the README.md

commit fde6291
Author: Paul Colby <[email protected]>
Date:   Sat Jun 22 14:20:14 2024 +1000

    Add a 'Get it on Google Play' badge
  • Loading branch information
pcolby committed Jun 22, 2024
1 parent 7b9fac3 commit 6f4ed22
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
68 changes: 55 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,63 @@
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=pcolby_nfc-quick-settings&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=pcolby_nfc-quick-settings)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=pcolby_nfc-quick-settings&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=pcolby_nfc-quick-settings)

NFC Quick Settings is a really basic Android app with no GUI of it's own, that simply adds an NFC
tile to the tiles available to the [Quick Settings panel][].
NFC Quick Settings is a really basic Android app with no GUI of it's own, that simply adds an NFC tile to the tiles
available to the [Quick Settings panel][].

*Screenshots go here...*
The Quick Settings tile indicates the current NFC status (enabled, or disabled), but the action it takes when tapped
varies a little depending on the permissions available. See [Basic](#basic-mode) and [Advanced](#advanced-mode) modes
below.

## Internal Details
[![Get it on Google Play](assets/GetItOnGooglePlay_Badge_Web_color_English.png)](https://play.google.com/store/apps/details?id=au.id.colby.nfcquicksettings)

Just for the curious, the application implements a basic [TileService][], that overrides:
## Basic Mode

* [onStartListening()][] to check the default NFC adapter's current status, and update the tile state
accordingly; and
* [onClick()][] to show the device's NFC Settings by starting the [NFC Settings][] activity.
In the _basic_ mode, which requires no special permissions, tapping the tile will simply open the device's NFC Settings
page (assuming the device has one). This is actually the best that can be done using official Android APIs.

[NFC Settings]: https://developer.android.com/reference/android/provider/Settings#ACTION_NFC_SETTINGS
[onClick()]: https://developer.android.com/reference/android/service/quicksettings/TileService#onClick()
[onStartListening()]: https://developer.android.com/reference/android/service/quicksettings/TileService#onStartListening()
[Quick Settings panel]: https://support.google.com/android/answer/9083864
[TileService]: https://developer.android.com/reference/android/service/quicksettings/TileService
## Advanced Mode

The advanced mode requires special permissions (see below), but once enabled, tapping the NFC Quick Settings tile will
turn the NFC service on or off directly, without having to open the NFC settings page at all. Unfortunately, to acheive
this _advanced_ mode, NFC Quick Settings needs to use APIs not intended for third-party applications (specifically
[`NfcAdapter::enable()`][] and [`NfcAdapter::disable()`][]), and to use those methods the tile needs the special
[`WRITE_SECURE_SETTINGS`][] permission.

### Granting `WRITE_SECURE_SETTINGS` Permission

As the [`WRITE_SECURE_SETTINGS`][] permission is not intended to be used by third-party applications, it needs to be
granted via the [Android Debug Bridge (adb)][] tool.

1. Install [Android Debug Bridge (adb)][]:

> `adb` is included in the Android SDK Platform Tools package. Download this package with the [SDK Manager][], which
> installs it at `android_sdk/platform-tools/`. If you want the standalone Android SDK Platform Tools package,
> [download it here](https://developer.android.com/tools/releases/platform-tools).
2. Install NFC Quick Settings, via [Google Play] or [GitHub Releases].

3. [Enable adb debugging on your device](https://developer.android.com/tools/adb#Enabling).

4. [Connect your device via Wi-Fi](https://developer.android.com/tools/adb#connect-to-a-device-over-wi-fi).

5. Grant the permission to NFC Quick Settings via `adb`:

```sh
adb shell pm grant au.id.colby.nfcquicksettings android.permission.WRITE_SECURE_SETTINGS
```

If for some reason you want to revoke the [`WRITE_SECURE_SETTINGS`][] permission, and restore the _basic_ mode, then
simply follow the same steps as above, but replace `grant` with `revoke`. That is, run:

```sh
adb shell pm revoke au.id.colby.nfcquicksettings android.permission.WRITE_SECURE_SETTINGS
```

[`NfcAdapter::disable()`]: https://cs.android.com/android/platform/superproject/+/main:frameworks/base/core/java/android/nfc/NfcAdapter.java;l=986?q=NfcAdapter "android.nfc.NfcAdapter::disable()"
[`NfcAdapter::enable()`]: https://cs.android.com/android/platform/superproject/+/main:frameworks/base/core/java/android/nfc/NfcAdapter.java;l=947?q=NfcAdapter "android.nfc.NfcAdapter::enable()"
[`WRITE_SECURE_SETTINGS`]: https://developer.android.com/reference/android/Manifest.permission#WRITE_SECURE_SETTINGS "android.permission.WRITE_SECURE_SETTINGS"
[Android Debug Bridge (adb)]: https://developer.android.com/tools/adb "Android Debug Bridge (adb)"
[GitHub Releases]: https://github.com/pcolby/nfc-quick-settings/releases "NFC Quick Settings releases"
[Google Play]: https://play.google.com/store/apps/details?id=au.id.colby.nfcquicksettings "NFC Quick Settings on Google Play"
[SDK Manager]: https://developer.android.com/studio/intro/update#sdk-manager "Update your tools with the SDK Manager"
[Quick Settings panel]: https://support.google.com/android/answer/9083864 "Change settings quickly on your Android phone"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6f4ed22

Please sign in to comment.