[Catalyst] Migrate bluetooth screen to catalyst
Bug: 372774767 Flag: com.android.settings.flags.catalyst_bluetooth_switchbar_screen Test: devtool Change-Id: I08730e63f17b5fe57268e57f796f88f52ef5caa0
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="bluetooth_switchbar_screen"
|
||||
android:title="@string/bluetooth_settings_title">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
|
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.android.settings.connecteddevice;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -28,6 +30,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.bluetooth.AlwaysDiscoverable;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceRenamePreferenceController;
|
||||
import com.android.settings.bluetooth.BluetoothSwitchPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
@@ -47,7 +50,6 @@ import com.android.settingslib.widget.FooterPreference;
|
||||
public class BluetoothDashboardFragment extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "BluetoothDashboardFrag";
|
||||
private static final String KEY_BLUETOOTH_SCREEN_FOOTER = "bluetooth_screen_footer";
|
||||
private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
@@ -55,6 +57,8 @@ public class BluetoothDashboardFragment extends DashboardFragment {
|
||||
private SettingsMainSwitchBar mSwitchBar;
|
||||
private BluetoothSwitchPreferenceController mController;
|
||||
|
||||
private @Nullable AlwaysDiscoverable mAlwaysDiscoverable;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.BLUETOOTH_FRAGMENT;
|
||||
@@ -78,7 +82,9 @@ public class BluetoothDashboardFragment extends DashboardFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
mFooterPreference = findPreference(KEY_BLUETOOTH_SCREEN_FOOTER);
|
||||
if (!isCatalystEnabled()) {
|
||||
mFooterPreference = findPreference(BluetoothFooterPreference.KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,6 +96,9 @@ public class BluetoothDashboardFragment extends DashboardFragment {
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
if (isCatalystEnabled()) {
|
||||
return;
|
||||
}
|
||||
String callingAppPackageName = PasswordUtils.getCallingAppPackageName(
|
||||
getActivity().getActivityToken());
|
||||
String action = getIntent() != null ? getIntent().getAction() : "";
|
||||
@@ -110,8 +119,37 @@ public class BluetoothDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (isCatalystEnabled()) {
|
||||
Activity activity = requireActivity();
|
||||
String callingAppPackageName = PasswordUtils.getCallingAppPackageName(
|
||||
activity.getActivityToken());
|
||||
Intent intent = activity.getIntent();
|
||||
String action = intent != null ? intent.getAction() : "";
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onActivityCreated() calling package name is : " + callingAppPackageName
|
||||
+ ", action : " + action);
|
||||
}
|
||||
if (isAlwaysDiscoverable(callingAppPackageName, action)) {
|
||||
mAlwaysDiscoverable = new AlwaysDiscoverable(activity);
|
||||
mAlwaysDiscoverable.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (mAlwaysDiscoverable != null) {
|
||||
mAlwaysDiscoverable.stop();
|
||||
mAlwaysDiscoverable = null;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isAlwaysDiscoverable(String callingAppPackageName, String action) {
|
||||
boolean isAlwaysDiscoverable(@Nullable String callingAppPackageName, @Nullable String action) {
|
||||
return TextUtils.equals(SLICE_ACTION, action) ? false
|
||||
: TextUtils.equals(Utils.SETTINGS_PACKAGE_NAME, callingAppPackageName)
|
||||
|| TextUtils.equals(Utils.SYSTEMUI_PACKAGE_NAME, callingAppPackageName);
|
||||
|
@@ -17,7 +17,10 @@ package com.android.settings.connecteddevice
|
||||
|
||||
import android.content.Context
|
||||
import com.android.settings.R
|
||||
import com.android.settings.Settings.BluetoothDashboardActivity
|
||||
import com.android.settings.flags.Flags
|
||||
import com.android.settings.utils.makeLaunchIntent
|
||||
import com.android.settingslib.metadata.PreferenceMetadata
|
||||
import com.android.settingslib.metadata.ProvidePreferenceScreen
|
||||
import com.android.settingslib.metadata.preferenceHierarchy
|
||||
import com.android.settingslib.preference.PreferenceScreenCreator
|
||||
@@ -39,7 +42,15 @@ class BluetoothDashboardScreen : PreferenceScreenCreator {
|
||||
|
||||
override fun fragmentClass() = BluetoothDashboardFragment::class.java
|
||||
|
||||
override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) {}
|
||||
override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?) =
|
||||
makeLaunchIntent(context, BluetoothDashboardActivity::class.java, metadata?.key)
|
||||
|
||||
override fun getPreferenceHierarchy(context: Context) =
|
||||
preferenceHierarchy(this) {
|
||||
val bluetoothDataStore = BluetoothPreference.createDataStore(context)
|
||||
+BluetoothPreference(bluetoothDataStore)
|
||||
+BluetoothFooterPreference(bluetoothDataStore)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KEY = "bluetooth_switchbar_screen"
|
||||
|
Reference in New Issue
Block a user