Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca5a3e54 authored by Sal Savage's avatar Sal Savage
Browse files

Migrate OPP profile enable/disable to sysprops

Tag: #refactor
Bug: 217448211
Test: atest BluetoothInstrumentationTests
Merged-In: Ia4364fbf9070f9163d2fcd8fe6849f4807a46743
Change-Id: Ia4364fbf9070f9163d2fcd8fe6849f4807a46743
parent a511f342
Loading
Loading
Loading
Loading
+118 −110
Original line number Diff line number Diff line
@@ -93,6 +93,15 @@
         android:defaultToDeviceProtectedStorage="true"
         android:memtagMode="async">

        <service android:process="@string/process"
             android:name="com.android.bluetooth.btservice.AdapterService"
             android:exported="true"
             android:permission="android.permission.ACCESS_BLUETOOTH_SHARE">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetooth"/>
            </intent-filter>
        </service>

        <!--  Advanced Audio Distribution Profile (A2DP) source Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.a2dp.A2dpService"
@@ -337,123 +346,41 @@
            </intent-filter>
        </service>

        <!--  Personal Area Network (PAN) Profile Service  -->
        <service
             android:process="@string/process"
             android:name="com.android.bluetooth.pan.PanService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPan"/>
            </intent-filter>
        </service>

        <!--  Phonebook Access Profile (PBAP) server Profile Service and owned Activiie  -->
        <service android:process="@string/process"
             android:permission="android.permission.BLUETOOTH_PRIVILEGED"
             android:name="com.android.bluetooth.pbap.BluetoothPbapService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbap"/>
            </intent-filter>
        </service>
        <activity android:name="com.android.bluetooth.pbap.BluetoothPbapActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="false">
        </activity>

        <!--  Phonebook Access Profile (PBAP) client Profile Service and owned Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.pbapclient.PbapClientService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbapClient"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name="com.android.bluetooth.pbapclient.AuthenticationService"
             android:enabled="false"
             android:exported="true">
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator"/>
            </intent-filter>
            <meta-data android:name="android.accounts.AccountAuthenticator"
                 android:resource="@xml/authenticator"/>
        </service>

        <!--  SIM Access Profile (SAP) server Profile Service -->
        <!--  Object Push Profile (OPP) Profile Service and owned Receives, Providers and Activiies  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.sap.SapService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothSap"/>
            </intent-filter>
        </service>

        <!--  Telephony Bearer Service (TBS) server Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.tbs.TbsService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothLeCallControl" />
            </intent-filter>
        </service>

        <!--  Volume Control Profile (VCP) server Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.vc.VolumeControlService"
             android:name="com.android.bluetooth.opp.BluetoothOppService"
             android:permission="android.permission.ACCESS_BLUETOOTH_SHARE"
             android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothVolumeControl" />
            </intent-filter>
        </service>

        <provider android:name=".opp.BluetoothOppProvider"
             android:exported="true"/>
        <provider android:name="com.android.bluetooth.opp.BluetoothOppProvider"
             android:authorities="com.android.bluetooth.opp"
             android:enabled="false"
             android:exported="true"
             android:process="@string/process">
            <path-permission android:pathPrefix="/btopp"
                 android:permission="android.permission.ACCESS_BLUETOOTH_SHARE"/>
        </provider>
        <provider android:name=".opp.BluetoothOppFileProvider"
        <provider android:name="com.android.bluetooth.opp.BluetoothOppFileProvider"
             android:authorities="com.android.bluetooth.opp.fileprovider"
             android:grantUriPermissions="true"
             android:enabled="false"
             android:exported="false">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
                 android:resource="@xml/file_paths"/>
        </provider>
        <service android:process="@string/process"
             android:name=".btservice.AdapterService"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetooth"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name=".opp.BluetoothOppService"
             android:permission="android.permission.ACCESS_BLUETOOTH_SHARE"
             android:enabled="@bool/profile_supported_opp"/>
        <receiver android:process="@string/process"
             android:name="com.android.bluetooth.opp.BluetoothOppReceiver"
             android:exported="true"
             android:name=".opp.BluetoothOppReceiver"
             android:enabled="@bool/profile_supported_opp">
             android:enabled="false">
            <intent-filter>
                <action android:name="android.btopp.intent.action.OPEN_RECEIVED_FILES"/>
            </intent-filter>
        </receiver>
        <receiver android:process="@string/process"
              android:name=".opp.BluetoothOppHandoverReceiver"
              android:name="com.android.bluetooth.opp.BluetoothOppHandoverReceiver"
              android:permission="com.android.permission.ALLOWLIST_BLUETOOTH_DEVICE"
              android:exported="true">
              android:exported="true"
              android:enabled="false">
            <intent-filter>
                <action android:name="android.btopp.intent.action.ACCEPTLIST_DEVICE"/>
                <action android:name="android.btopp.intent.action.STOP_HANDOVER_TRANSFER"/>
@@ -469,11 +396,11 @@
                <data android:mimeType="*/*"/>
            </intent-filter>
        </receiver>
        <activity android:name=".opp.BluetoothOppLauncherActivity"
        <activity android:name="com.android.bluetooth.opp.BluetoothOppLauncherActivity"
             android:process="@string/process"
             android:theme="@android:style/Theme.Material.Light.Dialog"
             android:label="@string/bt_share_picker_label"
             android:enabled="@bool/profile_supported_opp"
             android:enabled="false"
             android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
@@ -511,41 +438,42 @@
                <data android:mimeType="vnd.android.cursor.item/vnd.android.btopp"/>
            </intent-filter>
        </activity>
        <activity android:name=".opp.BluetoothOppBtEnableActivity"
        <activity android:name="com.android.bluetooth.opp.BluetoothOppBtEnableActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="@bool/profile_supported_opp">
             android:enabled="false">
        </activity>
        <activity android:name=".opp.BluetoothOppBtErrorActivity"
        <activity android:name="com.android.bluetooth.opp.BluetoothOppBtErrorActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog">
             android:theme="@style/dialog"
             android:enabled="false">>
        </activity>
        <activity android:name=".opp.BluetoothOppBtEnablingActivity"
        <activity android:name="com.android.bluetooth.opp.BluetoothOppBtEnablingActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="@bool/profile_supported_opp">
             android:enabled="false">
        </activity>
        <activity android:name=".opp.BluetoothOppIncomingFileConfirmActivity"
        <activity android:name="com.android.bluetooth.opp.BluetoothOppIncomingFileConfirmActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="@bool/profile_supported_opp">
             android:enabled="false">
        </activity>
        <activity android:name=".opp.BluetoothOppTransferActivity"
        <activity android:name="com.android.bluetooth.opp.BluetoothOppTransferActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="@bool/profile_supported_opp">
             android:enabled="false">
        </activity>
        <activity android:name=".opp.BluetoothOppTransferHistory"
        <activity android:name="com.android.bluetooth.opp.BluetoothOppTransferHistory"
             android:process="@string/process"
             android:label=""
             android:excludeFromRecents="true"
             android:configChanges="orientation|keyboardHidden"
             android:enabled="@bool/profile_supported_opp"
             android:enabled="false"
             android:theme="@android:style/Theme.DeviceDefault.Settings"
             android:exported="true">
            <intent-filter>
@@ -553,5 +481,85 @@
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <!--  Personal Area Network (PAN) Profile Service  -->
        <service
             android:process="@string/process"
             android:name="com.android.bluetooth.pan.PanService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPan"/>
            </intent-filter>
        </service>

        <!--  Phonebook Access Profile (PBAP) server Profile Service and owned Activiie  -->
        <service android:process="@string/process"
             android:permission="android.permission.BLUETOOTH_PRIVILEGED"
             android:name="com.android.bluetooth.pbap.BluetoothPbapService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbap"/>
            </intent-filter>
        </service>
        <activity android:name="com.android.bluetooth.pbap.BluetoothPbapActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="false">
        </activity>

        <!--  Phonebook Access Profile (PBAP) client Profile Service and owned Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.pbapclient.PbapClientService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbapClient"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name="com.android.bluetooth.pbapclient.AuthenticationService"
             android:enabled="false"
             android:exported="true">
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator"/>
            </intent-filter>
            <meta-data android:name="android.accounts.AccountAuthenticator"
                 android:resource="@xml/authenticator"/>
        </service>

        <!--  SIM Access Profile (SAP) server Profile Service -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.sap.SapService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothSap"/>
            </intent-filter>
        </service>

        <!--  Telephony Bearer Service (TBS) server Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.tbs.TbsService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothLeCallControl" />
            </intent-filter>
        </service>

        <!--  Volume Control Profile (VCP) server Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.vc.VolumeControlService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothVolumeControl" />
            </intent-filter>
        </service>
    </application>
</manifest>
+0 −1
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
   limitations under the License.
-->
<resources>
    <bool name="profile_supported_opp">true</bool>
    <bool name="pbap_include_photos_in_vcard">true</bool>
    <bool name="pbap_use_profile_for_owner_vcard">true</bool>

+68 −7
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevicePicker;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -52,6 +53,7 @@ import android.os.Binder;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.sysprop.BluetoothProperties;
import android.util.Log;

import com.android.bluetooth.BluetoothObexTransport;
@@ -78,6 +80,34 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
    private static final boolean D = Constants.DEBUG;
    private static final boolean V = Constants.VERBOSE;

    /**
     * Owned providers and activities
     */
    private static final String OPP_PROVIDER =
            BluetoothOppProvider.class.getCanonicalName();
    private static final String OPP_FILE_PROVIDER =
            BluetoothOppFileProvider.class.getCanonicalName();
    private static final String LAUNCHER_ACTIVITY =
            BluetoothOppLauncherActivity.class.getCanonicalName();
    private static final String BT_ENABLE_ACTIVITY =
            BluetoothOppBtEnableActivity.class.getCanonicalName();
    private static final String BT_ERROR_ACTIVITY =
            BluetoothOppBtErrorActivity.class.getCanonicalName();
    private static final String BT_ENABLING_ACTIVITY =
            BluetoothOppBtEnablingActivity.class.getCanonicalName();
    private static final String INCOMING_FILE_CONFIRM_ACTIVITY =
            BluetoothOppIncomingFileConfirmActivity.class.getCanonicalName();
    private static final String TRANSFER_ACTIVITY =
            BluetoothOppTransferActivity.class.getCanonicalName();
    private static final String TRANSFER_HISTORY_ACTIVITY =
            BluetoothOppTransferHistory.class.getCanonicalName();
    // Normally we would dynamically define and create these but they need to be manifest receivers
    // because they rely on explicit intents. Explicit intents don't work with dynamic receivers.
    private static final String OPP_RECEIVER =
            BluetoothOppReceiver.class.getCanonicalName();
    private static final String OPP_HANDOFF_RECEIVER =
            BluetoothOppHandoverReceiver.class.getCanonicalName();

    private static final byte[] SUPPORTED_OPP_FORMAT = {
            0x01 /* vCard 2.1 */,
            0x02 /* vCard 3.0 */,
@@ -174,6 +204,10 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
     */
    private BluetoothOppObexServerSession mServerSession;

    public static boolean isEnabled() {
        return BluetoothProperties.isProfileOppEnabled().orElse(false);
    }

    @Override
    protected IProfileServiceBinder initBinder() {
        return new OppBinder(this);
@@ -197,13 +231,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        mShares = new ArrayList();
        mBatches = new ArrayList();
        mBatchId = 1;
        final ContentResolver contentResolver = getContentResolver();
        new Thread("trimDatabase") {
            @Override
            public void run() {
                trimDatabase(contentResolver);
            }
        }.start();

        IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        registerReceiver(mBluetoothReceiver, filter);
@@ -223,6 +250,27 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        if (V) {
            Log.v(TAG, "start()");
        }

        setComponentAvailable(OPP_PROVIDER, true);
        setComponentAvailable(OPP_FILE_PROVIDER, true);
        setComponentAvailable(LAUNCHER_ACTIVITY, true);
        setComponentAvailable(BT_ENABLE_ACTIVITY, true);
        setComponentAvailable(BT_ERROR_ACTIVITY, true);
        setComponentAvailable(BT_ENABLING_ACTIVITY, true);
        setComponentAvailable(INCOMING_FILE_CONFIRM_ACTIVITY, true);
        setComponentAvailable(TRANSFER_ACTIVITY, true);
        setComponentAvailable(TRANSFER_HISTORY_ACTIVITY, true);
        setComponentAvailable(OPP_RECEIVER, true);
        setComponentAvailable(OPP_HANDOFF_RECEIVER, true);

        final ContentResolver contentResolver = getContentResolver();
        new Thread("trimDatabase") {
            @Override
            public void run() {
                trimDatabase(contentResolver);
            }
        }.start();

        mAdapterService = AdapterService.getAdapterService();
        mObserver = new BluetoothShareContentObserver();
        getContentResolver().registerContentObserver(BluetoothShare.CONTENT_URI, true, mObserver);
@@ -248,6 +296,19 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS);
        setBluetoothOppService(null);
        mHandler.sendMessage(mHandler.obtainMessage(STOP_LISTENER));

        setComponentAvailable(OPP_PROVIDER, false);
        setComponentAvailable(OPP_FILE_PROVIDER, false);
        setComponentAvailable(LAUNCHER_ACTIVITY, false);
        setComponentAvailable(BT_ENABLE_ACTIVITY, false);
        setComponentAvailable(BT_ERROR_ACTIVITY, false);
        setComponentAvailable(BT_ENABLING_ACTIVITY, false);
        setComponentAvailable(INCOMING_FILE_CONFIRM_ACTIVITY, false);
        setComponentAvailable(TRANSFER_ACTIVITY, false);
        setComponentAvailable(TRANSFER_HISTORY_ACTIVITY, false);
        setComponentAvailable(OPP_RECEIVER, false);
        setComponentAvailable(OPP_HANDOFF_RECEIVER, false);

        return true;
    }

+4 −0
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ public class Constants {
    /** Tag used for debugging/logging */
    public static final String TAG = "BluetoothOpp";

    /** the permission required for others to send us handover broadcasts */
    static final String PERMISSION_ALLOWLIST_BLUETOOTH_DEVICE =
                "com.android.permission.ALLOWLIST_BLUETOOTH_DEVICE";

    /**
     * The intent that gets sent when the service must wake up for a retry
     * Note: Only retry Outbound transfers
+2 −5
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static org.mockito.Mockito.doReturn;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.rule.ServiceTestRule;
import androidx.test.runner.AndroidJUnit4;
@@ -45,7 +44,6 @@ import org.mockito.MockitoAnnotations;
public class BluetoothOppServiceTest {
    private BluetoothOppService mService = null;
    private BluetoothAdapter mAdapter = null;
    private Context mTargetContext;

    @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();

@@ -53,9 +51,8 @@ public class BluetoothOppServiceTest {

    @Before
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getTargetContext();
        Assume.assumeTrue("Ignore test when BluetoothOppService is not enabled",
                mTargetContext.getResources().getBoolean(R.bool.profile_supported_opp));
                BluetoothOppService.isEnabled());
        MockitoAnnotations.initMocks(this);
        TestUtils.setAdapterService(mAdapterService);
        doReturn(true, false).when(mAdapterService).isStartedProfile(anyString());
@@ -69,7 +66,7 @@ public class BluetoothOppServiceTest {

    @After
    public void tearDown() throws Exception {
        if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_opp)) {
        if (!BluetoothOppService.isEnabled()) {
            return;
        }
        TestUtils.stopService(mServiceRule, BluetoothOppService.class);