Skip to content

SystemUI: Enable NFC tile#17

Open
Enprytna wants to merge 3 commits intoxdroid-CAF:elevenfrom
xdCAF-ginkgo:eleven
Open

SystemUI: Enable NFC tile#17
Enprytna wants to merge 3 commits intoxdroid-CAF:elevenfrom
xdCAF-ginkgo:eleven

Conversation

@Enprytna
Copy link

@Enprytna Enprytna commented Oct 5, 2021

Author: Thecrazyskull anaskarbila@gmail.com
Date: Tue Jan 17 10:56:39 2017 -0600

SystemUI: Enable NFC tile

Change-Id: Ib21f927d336fcb5e460552786828b79551b235fa

Author: Luca Stefani luca.stefani.ge1@gmail.com
Date: Tue Sep 4 10:07:17 2018 +0200

SystemUI: Update NFCTile to match P style

Change-Id: I8309eda6b2dbb28156dd463e667ff60545b37b7d

Author: inthewaves inthewaves@pm.me
Date: Sun Sep 20 14:59:10 2020 -0700

have NfcTile get an NfcAdapter directly

This changes the NfcTile to not be dependent on an NfcManager giving the
NfcTile an NfcAdapter.

The problem with NfcTile is that the NfcService doesn't start until the
device is unlocked after a reboot, but NfcTile can be created and have
its state updated before the device is unlocked.

The state of NfcTile depends on an NfcAdapter. The tile gets an
NfcAdapter from a call to NfcAdapter#getDefaultAdapter, which gets an
adapter from an NfcManager via Context#getSystemService, and NfcManager
tries to get an adapter in its constructor via NfcAdapter#getNfcAdapter.

If this is done before unlock, NfcService isn't started, so the
constructor of NfcManager fails to get an adapter, opting to just store
null. This means that the NfcManager that's _cached_ by the NfcTile's
application context holds a null NfcAdapter, so subsequent calls in
NfcTile to get the NfcAdapter will keep returning null.

We can just have NfcTile get the NfcAdapter directly via
NfcAdapter#getNfcAdapter instead of relying on an NfcManager to call the
same method for us to get its default adapter. We just have to make sure
we use the application context for NfcAdapter#getNfcAdapter, as per the
doc comments for getNfcAdapter. This means that there's no longer an
NfcManager associated with the NfcTile's application context.

It doesn't look like NfcManager does anything special with the
NfcAdapter anyway. It seems to just be some middle man for NfcAdapters:
* The NfcAdapter field in NfcManager is final, and it doesn't do
anything else with it besides have a getter method for returning it. The
NfcManager seems to be a way to force third-party apps that want to get
an NfcAdapter to use the application context.
* NfcAdapter#getNfcAdapter manages the caching of NfcAdapters by
application context in a static HashMap. NfcManager doesn't manage
caching; it just calls NfcAdapter#getNfcAdapter.

Change-Id: Ifafc666568a001a60baf7c8c16782dca1ee4d011

Change-Id: Ia06b923ee15e91a9c84a806d4c69755478df2063
Signed-off-by: SahilSonar sss.sonar2003@gmail.com
Signed-off-by: HeroBuxx me@herobuxx.xyz
Signed-off-by: HeroBuxx herobuxx@conqueros.co
Signed-off-by: Dreadwyrm enprytna@gmail.com

timschumi and others added 3 commits October 5, 2021 15:01
Author: Thecrazyskull <anaskarbila@gmail.com>
Date:   Tue Jan 17 10:56:39 2017 -0600

    SystemUI: Enable NFC tile

    Change-Id: Ib21f927d336fcb5e460552786828b79551b235fa

Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date:   Tue Sep 4 10:07:17 2018 +0200

    SystemUI: Update NFCTile to match P style

    Change-Id: I8309eda6b2dbb28156dd463e667ff60545b37b7d

Author: inthewaves <inthewaves@pm.me>
Date:   Sun Sep 20 14:59:10 2020 -0700

    have NfcTile get an NfcAdapter directly

    This changes the NfcTile to not be dependent on an NfcManager giving the
    NfcTile an NfcAdapter.

    The problem with NfcTile is that the NfcService doesn't start until the
    device is unlocked after a reboot, but NfcTile can be created and have
    its state updated before the device is unlocked.

    The state of NfcTile depends on an NfcAdapter. The tile gets an
    NfcAdapter from a call to NfcAdapter#getDefaultAdapter, which gets an
    adapter from an NfcManager via Context#getSystemService, and NfcManager
    tries to get an adapter in its constructor via NfcAdapter#getNfcAdapter.

    If this is done before unlock, NfcService isn't started, so the
    constructor of NfcManager fails to get an adapter, opting to just store
    null. This means that the NfcManager that's _cached_ by the NfcTile's
    application context holds a null NfcAdapter, so subsequent calls in
    NfcTile to get the NfcAdapter will keep returning null.

    We can just have NfcTile get the NfcAdapter directly via
    NfcAdapter#getNfcAdapter instead of relying on an NfcManager to call the
    same method for us to get its default adapter. We just have to make sure
    we use the application context for NfcAdapter#getNfcAdapter, as per the
    doc comments for getNfcAdapter. This means that there's no longer an
    NfcManager associated with the NfcTile's application context.

    It doesn't look like NfcManager does anything special with the
    NfcAdapter anyway. It seems to just be some middle man for NfcAdapters:
    * The NfcAdapter field in NfcManager is final, and it doesn't do
    anything else with it besides have a getter method for returning it. The
    NfcManager seems to be a way to force third-party apps that want to get
    an NfcAdapter to use the application context.
    * NfcAdapter#getNfcAdapter manages the caching of NfcAdapters by
    application context in a static HashMap. NfcManager doesn't manage
    caching; it just calls NfcAdapter#getNfcAdapter.

    Change-Id: Ifafc666568a001a60baf7c8c16782dca1ee4d011

Change-Id: Ia06b923ee15e91a9c84a806d4c69755478df2063
Signed-off-by: SahilSonar <sss.sonar2003@gmail.com>
Signed-off-by: HeroBuxx <me@herobuxx.xyz>
Signed-off-by: HeroBuxx <herobuxx@conqueros.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants