Compare commits

...

2 commits

Author SHA1 Message Date
Peter Cai d5c5b71fc9 CHANGELOG: describe NFC payment service stub 2023-11-12 15:53:13 -05:00
Peter Cai 06b89a9534 feat: NFC payment service stub
This commits adds a NFC payment service stub in the main profile that
can be enabled on-demand. This is intended to work around a bug in AOSP
where if no payment app is present in the main profile, one cannot even
choose a payment app from the work profile. The stub simply shows up in
the main profile to enable the Settings menu for NFC payment services.
2023-11-12 15:51:03 -05:00
9 changed files with 81 additions and 0 deletions

View file

@ -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
===

View file

@ -20,6 +20,7 @@
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.NFC" />
<!-- For querying apps on Android R and later -->
<queries>
@ -156,6 +157,19 @@
<!-- Service to freeze apps on screen lock -->
<service android:name=".services.FreezeService"
android:foregroundServiceType="systemExempted" />
<!-- Payment stub service -->
<service android:name=".services.PaymentStubService"
android:exported="true"
android:enabled="false"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
</intent-filter>
<meta-data android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/payment_stub"/>
</service>
</application>
</manifest>

View file

@ -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) {
}
}

View file

@ -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;
}

View file

@ -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 = ",";

View file

@ -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);
}
}

View file

@ -5,6 +5,7 @@
<string name="device_admin_label" translatable="false">Shelter</string>
<string name="device_admin_desc">App Isolation Service</string>
<string name="device_admin_explanation">Shelter needs to become Device Admin in order to perform its isolation tasks.</string>
<string name="payment_stub_description">Payment Service Stub (DO NOT USE)</string>
<!-- Setup Wizard -->
<string name="setup_wizard_welcome">Welcome to Shelter</string>
@ -70,6 +71,8 @@
<string name="settings_cross_profile_file_chooser_desc">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.</string>
<string name="settings_block_contacts_searching">Block Contacts Searching</string>
<string name="settings_block_contacts_searching_desc">Deny access from main profile to contacts inside work profile.</string>
<string name="settings_payment_stub">Payment Service Stub</string>
<string name="settings_payment_stub_desc">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.</string>
<string name="settings_services">Services</string>
<string name="settings_auto_freeze_service">Auto Freeze Service</string>
<string name="settings_auto_freeze_service_desc">When the screen is locked, automatically freeze apps launched from \"Unfreeze &amp; Launch Shortcut\".</string>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<host-apdu-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/payment_stub_description"
android:requireDeviceUnlock="false">
<aid-group android:description="@string/payment_stub_description"
android:category="payment">
<!-- This is not a real AID -->
<aid-filter android:name="F0010203040506"/>
</aid-group>
</host-apdu-service>

View file

@ -15,6 +15,11 @@
android:title="@string/settings_block_contacts_searching"
android:summary="@string/settings_block_contacts_searching_desc" />
<androidx.preference.CheckBoxPreference
android:key="settings_payment_stub"
android:title="@string/settings_payment_stub"
android:summary="@string/settings_payment_stub_desc" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory