Android rom开发:修改Settings源码,支持蓝牙自动配对,无需输入PIN码

--- a/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
+++ b/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
@@ -34,6 +34,7 @@ public class BluetoothPairingDialog extends Activity {
     public static final String FRAGMENT_TAG = "bluetooth.pairing.fragment";
 
     private BluetoothPairingController mBluetoothPairingController;
+    private BluetoothPairingDialogFragment mBluetoothFragment;
     private boolean mReceiverRegistered = false;
 
     /**
@@ -68,24 +69,23 @@ public class BluetoothPairingDialog extends Activity {
         // build the dialog fragment
         boolean fragmentFound = true;
         // check if the fragment has been preloaded
-        BluetoothPairingDialogFragment bluetoothFragment =
-            (BluetoothPairingDialogFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
+        mBluetoothFragment =(BluetoothPairingDialogFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
         // dismiss the fragment if it is already used
-        if (bluetoothFragment != null && (bluetoothFragment.isPairingControllerSet()
-            || bluetoothFragment.isPairingDialogActivitySet())) {
-            bluetoothFragment.dismiss();
-            bluetoothFragment = null;
+        if (mBluetoothFragment != null && (mBluetoothFragment.isPairingControllerSet()
+            || mBluetoothFragment.isPairingDialogActivitySet())) {
+            mBluetoothFragment.dismiss();
+            mBluetoothFragment = null;
         }
         // build a new fragment if it is null
-        if (bluetoothFragment == null) {
+        if (mBluetoothFragment == null) {
             fragmentFound = false;
-            bluetoothFragment = new BluetoothPairingDialogFragment();
+            mBluetoothFragment = new BluetoothPairingDialogFragment();
         }
-        bluetoothFragment.setPairingController(mBluetoothPairingController);
-        bluetoothFragment.setPairingDialogActivity(this);
+        mBluetoothFragment.setPairingController(mBluetoothPairingController);
+        mBluetoothFragment.setPairingDialogActivity(this);
         // pass the fragment to the manager when it is created from scratch
         if (!fragmentFound) {
-            bluetoothFragment.show(getFragmentManager(), FRAGMENT_TAG);
+            mBluetoothFragment.show(getFragmentManager(), FRAGMENT_TAG);
         }
         /*
          * Leave this registered through pause/resume since we still want to
@@ -96,6 +96,16 @@ public class BluetoothPairingDialog extends Activity {
         mReceiverRegistered = true;
     }
 
+    @Override
+    protected void onResume() {
+        super.onResume();
+        if (mBluetoothFragment != null) {
+            mBluetoothFragment.autoClick();
+        }
+    }
+
     @Override
     protected void onDestroy() {
         super.onDestroy();
diff --git a/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java b/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
old mode 100644
new mode 100755
index eaf1231556..299a9dcde9
--- a/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
+++ b/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
@@ -129,6 +129,12 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
         mPairingDialogActivity.dismiss();
     }
 
+    //模拟点击配对按钮,直接同意
+    public void autoClick() {
+        mPairingController.onDialogPositiveClick(this);
+        mPairingDialogActivity.dismiss();
+    }
+
     @Override
     public int getMetricsCategory() {
         return MetricsEvent.BLUETOOTH_DIALOG_FRAGMENT;
diff --git a/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingRequest.java b/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
old mode 100644
new mode 100755
index 4d02fd50c3..855c821a18
--- a/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
+++ b/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
@@ -54,9 +54,11 @@ public final class BluetoothPairingRequest extends BroadcastReceiver {
       // just open the dialog
       context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
     } else {
+      //屏蔽状态栏通知,直接跳转配对对话框 wjz@2022.3.28
+      context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
       // Put up a notification that leads to the dialog
-      intent.setClass(context, BluetoothPairingService.class);
-      context.startServiceAsUser(intent, UserHandle.CURRENT);
+      //intent.setClass(context, BluetoothPairingService.class);
+      //context.startServiceAsUser(intent, UserHandle.CURRENT);
     }
   }
 }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值