hwsecurity / de.cotech.hw.util

Package de.cotech.hw.util

Types

Name Summary
Arrays

class Arrays

General array utilities.

HashUtil open class HashUtil
Hex

open class Hex

Converts hexadecimal Strings. This class is thread-safe.

NfcStatusObserver

open class NfcStatusObserver : LifecycleObserver

A helper class to monitor whether NFC hardware is available and enabled.

Note that this class does not communicate with the NFC device on its own - its only purpose is to tell when NFC functionality is available, and has been enabled or disabled!

Example:

public class NfcActionActivity extends AppCompatActivity {
      private NfcStatusObserver nfcStatusObserver;
 
      
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
 
          if (!SecurityKeyManager.getInstance().isNfcHardwareAvailable(this)) {
              startActivityToNicelyTellUserThatNfcHardwareIsUnavailable();
              finish();
              return;
          }
 
          this.nfcStatusObserver = new NfcStatusObserver((Context) this, (LifecycleOwner) this,
                  isEnabled -> showOrHideNfcDisabledView(!isEnabled));
 
          // this button should be part of the "nfc disabled view"
          View buttonPleaseEnableNfc = findViewById(R.id.buttonPleaseEnableNfc);
          buttonPleaseEnableNfc.setOnClickListener(view -> startAndroidNfcConfigActivityWithHint());
      }
 
      private void startAndroidNfcConfigActivityWithHint() {
          Toast.makeText(getApplicationContext(),
                  "Please activate NFC and press Back to return to MyApplication", Toast.LENGTH_SHORT).show();
          startActivity(new Intent(android.provider.Settings.ACTION_NFC_SETTINGS));
      }
 
      
      protected void onResume() {
          super.onResume();
          // In case we missed a change while the activity was in the background
          showOrHideNfcDisabledView(!nfcStatusObserver.isNfcEnabled());
      }
  }