Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3cac00d4 authored by Zhihai Xu's avatar Zhihai Xu Committed by Matthew Xie
Browse files

Bluetooth: Added Shared Preferences to restore tethering preference

Added a Shared Preferences to have the tethering preference persist,
The value is stored while changing the tethering preference by user
and tethering preference will be restored based on the value(last
saved tethering preference) while starting the PAN service.
from QCOM
Change-Id: I468564a51ff17dfdf1b95a532fa429477db0da15
parent 4b7ccfd3
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * Provides Bluetooth Pan Device profile, as a service in
@@ -76,6 +77,8 @@ public class PanService extends ProfileService {
    private static final int MESSAGE_DISCONNECT = 2;
    private static final int MESSAGE_CONNECT_STATE_CHANGED = 11;
    private boolean mTetherOn = false;
    private static final String PAN_PREFERENCE_FILE = "PANMGR";
    private static final String PAN_TETHER_SETTING = "TETHERSTATE";

    AsyncChannel mTetherAc;

@@ -108,6 +111,10 @@ public class PanService extends ProfileService {
                Context.CONNECTIVITY_SERVICE);
        cm.supplyMessenger(ConnectivityManager.TYPE_BLUETOOTH, new Messenger(mHandler));

        // Set mTetherOn based on the last saved tethering preference while starting the Pan service
        SharedPreferences tetherSetting = getSharedPreferences(PAN_PREFERENCE_FILE, 0);
        mTetherOn = tetherSetting.getBoolean(PAN_TETHER_SETTING, false);

        return true;
    }

@@ -259,7 +266,6 @@ public class PanService extends ProfileService {
            return service.isPanUOn();
        }
        public boolean isTetheringOn() {
            // TODO(BT) have a variable marking the on/off state
            PanService service = getService();
            if (service == null) return false;
            return service.isTetheringOn();
@@ -319,7 +325,6 @@ public class PanService extends ProfileService {
        return (getPanLocalRoleNative() & BluetoothPan.LOCAL_PANU_ROLE) != 0;
    }
     boolean isTetheringOn() {
        // TODO(BT) have a variable marking the on/off state
        return mTetherOn;
    }

@@ -327,6 +332,14 @@ public class PanService extends ProfileService {
        if(DBG) Log.d(TAG, "setBluetoothTethering: " + value +", mTetherOn: " + mTetherOn);
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if(mTetherOn != value) {

            SharedPreferences tetherSetting = getSharedPreferences(PAN_PREFERENCE_FILE, 0);
            SharedPreferences.Editor editor = tetherSetting.edit();

            editor.putBoolean(PAN_TETHER_SETTING, value);

            // Commit the edit!
            editor.commit();
            //drop any existing panu or pan-nap connection when changing the tethering state
            mTetherOn = value;
            List<BluetoothDevice> DevList = getConnectedDevices();