2nd attempt to fix Slice strict mode.

1. Use real BluetoothAdapter instead of settingslib version. The
   settingslib version contains calls that violates strictmode rules.
2. Override StrictMode rules in SettingsSliceProvider when it's called
   in background thread. When in background, the enforcement from Slice
   framework (StrictMode#ThreadPolicy) is not useful and can be safely
   ignored.

Change-Id: I68523148f4c1dc88a54e207447d21ec439478cdf
Bug: 79985175
Test: robotests
This commit is contained in:
Fan Zhang
2018-05-24 10:10:02 -07:00
parent cf84bf0d6a
commit 934de22622
4 changed files with 116 additions and 52 deletions

View File

@@ -17,8 +17,6 @@ package com.android.settings.bluetooth;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static androidx.slice.builders.ListBuilder.ICON_IMAGE;
import android.annotation.ColorInt;
import android.app.PendingIntent;
import android.bluetooth.BluetoothAdapter;
@@ -83,7 +81,7 @@ public class BluetoothSliceBuilder {
* Bluetooth.
*/
public static Slice getSlice(Context context) {
final boolean isBluetoothEnabled = isBluetoothEnabled(context);
final boolean isBluetoothEnabled = isBluetoothEnabled();
final CharSequence title = context.getText(R.string.bluetooth_settings);
final IconCompat icon = IconCompat.createWithResource(context,
R.drawable.ic_settings_bluetooth);
@@ -119,9 +117,8 @@ public class BluetoothSliceBuilder {
// handle it.
}
private static boolean isBluetoothEnabled(Context context) {
final LocalBluetoothAdapter adapter = LocalBluetoothManager.getInstance(context,
null /* callback */).getBluetoothAdapter();
private static boolean isBluetoothEnabled() {
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
return adapter.isEnabled();
}