Enable BT OPP base activities in system service.
Bug: 242963176
Tag: #feature
Test: manual
Change-Id: I5954d22647dca07d5bfd55aea263a79d70ad0f7c
diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java
index 4ca7757..27bfe50 100644
--- a/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java
+++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java
@@ -86,14 +86,6 @@
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 @@
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 @@
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);
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
index 05f277b..a835174 100644
--- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
@@ -102,6 +102,7 @@
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.time.Duration;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -2982,8 +2983,18 @@
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)
@@ -3013,26 +3024,21 @@
}
for (var activity : packageInfo.activities) {
Log.v(TAG, "Checking activity " + activity.name);
- if (launcherActivity.equals(activity.name)) {
- 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),
- newState,
- PackageManager.DONT_KILL_APP
- );
+ if (baseBluetoothOppActivities.contains(activity.name)) {
+ for (String activityName : baseBluetoothOppActivities) {
+ userPackageManager.setComponentEnabledSetting(
+ 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);
}