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
diff --git a/src/com/android/bluetooth/pan/PanService.java b/src/com/android/bluetooth/pan/PanService.java
index 682fe2d..0646f16 100755
--- a/src/com/android/bluetooth/pan/PanService.java
+++ b/src/com/android/bluetooth/pan/PanService.java
@@ -51,7 +51,8 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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();