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

Commit 6107007e authored by Etienne Ruffieux's avatar Etienne Ruffieux Committed by Android (Google) Code Review
Browse files

Merge "Enable BT OPP base activities in system service." into tm-qpr-dev

parents 4950e54a 44268145
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -86,14 +86,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
            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 =
@@ -252,8 +244,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti

        setComponentAvailable(OPP_PROVIDER, true);
        setComponentAvailable(OPP_FILE_PROVIDER, 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);
@@ -296,8 +286,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti

        setComponentAvailable(OPP_PROVIDER, false);
        setComponentAvailable(OPP_FILE_PROVIDER, 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);
+21 −16
Original line number Diff line number Diff line
@@ -3012,8 +3012,18 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                newState = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
            }

            String launcherActivity = "com.android.bluetooth.opp.BluetoothOppLauncherActivity";
            String btEnableActivity = "com.android.bluetooth.opp.BluetoothOppBtEnableActivity";
            // Bluetooth OPP activities that should always be enabled,
            // even when Bluetooth is turned OFF.
            ArrayList<String> baseBluetoothOppActivities = new ArrayList<String>() {
                {
                    // Base sharing activity
                    add("com.android.bluetooth.opp.BluetoothOppLauncherActivity");
                    // BT enable activities
                    add("com.android.bluetooth.opp.BluetoothOppBtEnableActivity");
                    add("com.android.bluetooth.opp.BluetoothOppBtEnablingActivity");
                    add("com.android.bluetooth.opp.BluetoothOppBtErrorActivity");
                }
            };

            PackageManager systemPackageManager = mContext.getPackageManager();
            PackageManager userPackageManager = mContext.createContextAsUser(userHandle, 0)
@@ -3043,26 +3053,21 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                }
                for (var activity : packageInfo.activities) {
                    Log.v(TAG, "Checking activity " + activity.name);
                    if (launcherActivity.equals(activity.name)) {
                    if (baseBluetoothOppActivities.contains(activity.name)) {
                        for (String activityName : baseBluetoothOppActivities) {
                            userPackageManager.setComponentEnabledSetting(
                                new ComponentName(candidatePackage, launcherActivity),
                                newState,
                                PackageManager.DONT_KILL_APP
                        );
                        // Bluetooth enable Activity should also be turned on here so
                        // when sharing with Bluetooth OFF, launcher Activity can turn it ON.
                        userPackageManager.setComponentEnabledSetting(
                                new ComponentName(candidatePackage, btEnableActivity),
                                    new ComponentName(candidatePackage, activityName),
                                    newState,
                                    PackageManager.DONT_KILL_APP
                            );
                        }
                        return;
                    }
                }
            }

            Log.e(TAG,
                    "Cannot toggle BluetoothOppLauncherActivity, could not find it in any package");
                    "Cannot toggle Bluetooth OPP activities, could not find them in any package");
        } catch (Exception e) {
            Log.e(TAG, "updateOppLauncherComponentState failed: " + e);
        }