diff --git a/CHANGELOG.md b/CHANGELOG.md index 8284866..dd70584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Version displayed within the app has now been changed to also reflect the exact Git commit when the app is built. - File Shuttle no longer appends ".null" or ".bin" suffixes unnecessarily. This should make it work much better with file managers such as Material Files. - File Shuttle now triggers media scanning much more robustly. Media files (pictures, videos, etc.) copied into the work profile should now show up much quicker in gallery apps. +- Added a fake NFC payment service to workaround a bug in Android that prevents payment apps inside the work profile from being used if none is present in the main profile. 1.8 === diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a4767f4..23f5253 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,7 @@ + @@ -156,6 +157,19 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/net/typeblog/shelter/services/PaymentStubService.java b/app/src/main/java/net/typeblog/shelter/services/PaymentStubService.java new file mode 100644 index 0000000..8b9c713 --- /dev/null +++ b/app/src/main/java/net/typeblog/shelter/services/PaymentStubService.java @@ -0,0 +1,18 @@ +package net.typeblog.shelter.services; + +import android.nfc.cardemulation.HostApduService; +import android.os.Bundle; + +public class PaymentStubService extends HostApduService { + @Override + public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) { + // We do not handle anything + notifyUnhandled(); + return null; + } + + @Override + public void onDeactivated(int reason) { + + } +} diff --git a/app/src/main/java/net/typeblog/shelter/ui/SettingsFragment.java b/app/src/main/java/net/typeblog/shelter/ui/SettingsFragment.java index 22fe946..85498b8 100644 --- a/app/src/main/java/net/typeblog/shelter/ui/SettingsFragment.java +++ b/app/src/main/java/net/typeblog/shelter/ui/SettingsFragment.java @@ -35,6 +35,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer private static final String SETTINGS_AUTO_FREEZE_SERVICE = "settings_auto_freeze_service"; private static final String SETTINGS_AUTO_FREEZE_DELAY = "settings_auto_freeze_delay"; private static final String SETTINGS_SKIP_FOREGROUND = "settings_dont_freeze_foreground"; + private static final String SETTINGS_PAYMENT_STUB = "settings_payment_stub"; private SettingsManager mManager = SettingsManager.getInstance(); private IShelterService mServiceWork = null; @@ -43,6 +44,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer private CheckBoxPreference mPrefBlockContactsSearching = null; private CheckBoxPreference mPrefAutoFreezeService = null; private CheckBoxPreference mPrefSkipForeground = null; + private CheckBoxPreference mPrefPaymentStub = null; private Preference mPrefAutoFreezeDelay = null; @@ -78,6 +80,9 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer mPrefBlockContactsSearching = (CheckBoxPreference) findPreference(SETTINGS_BLOCK_CONTACTS_SEARCHING); mPrefBlockContactsSearching.setChecked(mManager.getBlockContactsSearchingEnabled()); mPrefBlockContactsSearching.setOnPreferenceChangeListener(this); + mPrefPaymentStub = (CheckBoxPreference) findPreference(SETTINGS_PAYMENT_STUB); + mPrefPaymentStub.setChecked(mManager.getPaymentStubEnabled()); + mPrefPaymentStub.setOnPreferenceChangeListener(this); // === Services === mPrefAutoFreezeService = (CheckBoxPreference) findPreference(SETTINGS_AUTO_FREEZE_SERVICE); @@ -203,6 +208,9 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer mManager.setSkipForegroundEnabled(true); return true; + } else if (preference == mPrefPaymentStub) { + mManager.setPaymentStubEnabled((boolean) newState); + return true; } else { return false; } diff --git a/app/src/main/java/net/typeblog/shelter/util/LocalStorageManager.java b/app/src/main/java/net/typeblog/shelter/util/LocalStorageManager.java index aa45fb4..4292036 100644 --- a/app/src/main/java/net/typeblog/shelter/util/LocalStorageManager.java +++ b/app/src/main/java/net/typeblog/shelter/util/LocalStorageManager.java @@ -17,6 +17,7 @@ public class LocalStorageManager { public static final String PREF_DONT_FREEZE_FOREGROUND = "dont_freeze_foreground"; public static final String PREF_AUTO_FREEZE_DELAY = "auto_freeze_delay"; public static final String PREF_BLOCK_CONTACTS_SEARCHING = "block_contacts_searching"; + public static final String PREF_PAYMENT_STUB = "payment_stub"; private static final String LIST_DIVIDER = ","; diff --git a/app/src/main/java/net/typeblog/shelter/util/SettingsManager.java b/app/src/main/java/net/typeblog/shelter/util/SettingsManager.java index 2b4e3e7..03f79ec 100644 --- a/app/src/main/java/net/typeblog/shelter/util/SettingsManager.java +++ b/app/src/main/java/net/typeblog/shelter/util/SettingsManager.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import net.typeblog.shelter.services.PaymentStubService; import net.typeblog.shelter.ui.DummyActivity; public class SettingsManager { @@ -46,6 +47,7 @@ public class SettingsManager { // Enforce all settings public void applyAll() { applyCrossProfileFileChooser(); + applyPaymentStub(); } // Read and apply the enabled state of the cross profile file chooser @@ -117,4 +119,22 @@ public class SettingsManager { public boolean getSkipForegroundEnabled() { return mStorage.getBoolean(LocalStorageManager.PREF_DONT_FREEZE_FOREGROUND); } + + public boolean getPaymentStubEnabled() { + return mStorage.getBoolean(LocalStorageManager.PREF_PAYMENT_STUB); + } + + public void setPaymentStubEnabled(boolean enabled) { + mStorage.setBoolean(LocalStorageManager.PREF_PAYMENT_STUB, enabled); + applyPaymentStub(); + } + + // Enable / disable the payment stub component based on settings in local storage + public void applyPaymentStub() { + boolean enabled = mStorage.getBoolean(LocalStorageManager.PREF_PAYMENT_STUB); + mContext.getPackageManager().setComponentEnabledSetting( + new ComponentName(mContext, PaymentStubService.class), + enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9327590..573039d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ Shelter App Isolation Service Shelter needs to become Device Admin in order to perform its isolation tasks. + Payment Service Stub (DO NOT USE) Welcome to Shelter @@ -70,6 +71,8 @@ When enabled, you\'ll be able to browse / view / pick / copy files in Shelter from main profile and vice-versa, ONLY through Documents UI (named Files or Documents on your launcher) or apps with Documents UI support (they only gain temporary access to files you choose in Documents UI), while still pertaining the filesystem isolation. Block Contacts Searching Deny access from main profile to contacts inside work profile. + Payment Service Stub + Enable a fake NFC payment service in the main profile, so that the "contactless payments" option under Settings - NFC becomes enabled to allow you to choose a payment app inside the work profile. This works around an Android bug that makes it impossible to select a payment app inside the work profile if none is available in the main profile. Services Auto Freeze Service When the screen is locked, automatically freeze apps launched from \"Unfreeze & Launch Shortcut\". diff --git a/app/src/main/res/xml/payment_stub.xml b/app/src/main/res/xml/payment_stub.xml new file mode 100644 index 0000000..a6ac793 --- /dev/null +++ b/app/src/main/res/xml/payment_stub.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_settings.xml b/app/src/main/res/xml/preferences_settings.xml index 419cd18..2935234 100644 --- a/app/src/main/res/xml/preferences_settings.xml +++ b/app/src/main/res/xml/preferences_settings.xml @@ -15,6 +15,11 @@ android:title="@string/settings_block_contacts_searching" android:summary="@string/settings_block_contacts_searching_desc" /> + +