NFC payment receiver leaked


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);
         }
     }
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值