android P 默认开启wlan热点

时间:2024-02-29 20:07:22

vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigReceiver.java

+///mh.add
+import android.net.ConnectivityManager;
+import android.provider.Settings;
+///mh.end

     private static final String TAG = "AnomalyConfigReceiver";
+    private Context mContext;//mh.add


     @Override
     public void onReceive(Context context, Intent intent) {
         if (StatsManager.ACTION_STATSD_STARTED.equals(intent.getAction())
                 || Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {                           
+            mContext = context;//mh.add
             final StatsManager statsManager = context.getSystemService(StatsManager.class);
 
             // Check whether to update the config

             if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
+                wifiApControl();//mh.add
                 AnomalyCleanupJobService.scheduleCleanUp(context);
             }

+       //mh.add start
+       private void wifiApControl() {
+               Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 0);
+               ConnectivityManager  connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+               connectivityManager.startTethering(ConnectivityManager.TETHERING_WIFI,
+                                               true, new ConnectivityManager.OnStartTetheringCallback() {
+
+            @Override
+            public void onTetheringFailed() {
+                super.onTetheringFailed();
+                Log.d("menghua", "onTetheringFailed");
+            }
+
+            @Override
+            public void onTetheringStarted() {
+                super.onTetheringStarted();
+                Log.d("menghua", "onTetheringStarted");
+            }
+
+        });
+       }
+       //mh.end