“
Description: BT tethering is getting disable after pressing the back button in setting screen.
Solution: Set the Bluetooth tethering to selected state when Bluetooth Profile callback and Tethering is open
”
具体修改的code位置:
packages/apps/Settings/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentController.java
diff --git a/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentController.java b/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentController.java
index 4b8c9bf..b9f766b 100644
--- a/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentController.java
+++ b/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentController.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2020 The Android Open Source Project
- * Copyright (C) 2022 Zebra Technologies Corporation and/or its affiliates. All rights reserved.
+ * Copyright (C) 2022-2023 Zebra Technologies Corporation and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,9 @@
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.os.UserManager;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@@ -34,36 +37,50 @@
/**
* Controller that used to show NFC and payment features
*/
-public class NfcAndPaymentFragmentController extends BasePreferenceController {
+public class NfcAndPaymentFragmentController extends BasePreferenceController
+ implements LifecycleObserver,OnStart,OnStop {
private final NfcAdapter mNfcAdapter;
private final PackageManager mPackageManager;
private final UserManager mUserManager;
private Preference mNFCPreference;
+ private final BroadcastReceiver mUpdateNfcStatusReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (NfcAdapter.ACTION_ADAPTER_STATE_CHANGED.equals(action)) {
+ if (mNfcAdapter != null && mNFCPreference != null) {
+ if (mNfcAdapter.isEnabled()) {
+ mNFCPreference.setSummary(R.string.switch_on_text);
+ } else {
+ mNFCPreference.setSummary(R.string.switch_off_text);
+ }
+ }
+ }
+ }
+ };
+
public NfcAndPaymentFragmentController(Context context, String preferenceKey) {
super(context, preferenceKey);
mPackageManager = context.getPackageManager();
mUserManager = context.getSystemService(UserManager.class);
mNfcAdapter = NfcAdapter.getDefaultAdapter(context);
+ }
+
+ @Override
+ public void onStart() {
if(ZebraUtils.isZebra().orElse(false)) {
- context.registerReceiver(
- new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (NfcAdapter.ACTION_ADAPTER_STATE_CHANGED.equals(action)) {
- if (mNfcAdapter != null && mNFCPreference != null) {
- if (mNfcAdapter.isEnabled()) {
- mNFCPreference.setSummary(R.string.switch_on_text);
- } else {
- mNFCPreference.setSummary(R.string.switch_off_text);
- }
- }
- }
- }
- },new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)
- );
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ mContext.registerReceiver(mUpdateNfcStatusReceiver, filter);
+ }
+ }
+
+ @Override
+ public void onStop() {
+ if(ZebraUtils.isZebra().orElse(false)) {
+ mContext.unregisterReceiver(mUpdateNfcStatusReceiver);
}
}