diff options
author | Hemant Gupta <hemantg@codeaurora.org> | 2015-07-09 00:11:04 +0530 |
---|---|---|
committer | Hemant Gupta <hemantg@codeaurora.org> | 2015-07-20 17:01:05 +0530 |
commit | a0320ccb5d848d40611318705ec88e045bdbd5d7 (patch) | |
tree | 57637b8d4ad19a5619453668029b1a0b3183e91a /src/org/codeaurora | |
parent | e9a2fb8c4633b3a34080b219430c825f90fd13af (diff) | |
download | android_packages_apps_BluetoothExt-a0320ccb5d848d40611318705ec88e045bdbd5d7.tar.gz android_packages_apps_BluetoothExt-a0320ccb5d848d40611318705ec88e045bdbd5d7.tar.bz2 android_packages_apps_BluetoothExt-a0320ccb5d848d40611318705ec88e045bdbd5d7.zip |
Fix compilation issues in FTP and DUN code
This patch fixes compilation issues in DUN and FTP code due to
changes in SDP API's
Change-Id: Ie59c30c5135df4a0a81e6a316c4e758f6a121495
Diffstat (limited to 'src/org/codeaurora')
4 files changed, 127 insertions, 22 deletions
diff --git a/src/org/codeaurora/bluetooth/dun/BluetoothDunService.java b/src/org/codeaurora/bluetooth/dun/BluetoothDunService.java index 92ec785..ea98ebe 100644 --- a/src/org/codeaurora/bluetooth/dun/BluetoothDunService.java +++ b/src/org/codeaurora/bluetooth/dun/BluetoothDunService.java @@ -64,6 +64,7 @@ import android.text.TextUtils; import android.content.ComponentName; import android.os.RemoteException; import org.codeaurora.bluetooth.R; +import android.content.SharedPreferences; /** * Provides Bluetooth Dun profile, as a service in the BluetoothExt APK. @@ -274,12 +275,18 @@ public class BluetoothDunService extends Service { private static final String ACCESS_AUTHORITY_CLASS = "com.android.settings.bluetooth.BluetoothPermissionRequest"; + private static final String DUN_ACCESS_PERMISSION_PREFERENCE_FILE = + "dun_access_permission"; + private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; + private static final String BLUETOOTH_PRIVILEGED = + android.Manifest.permission.BLUETOOTH_PRIVILEGED;; + @Override public void onCreate() { @@ -494,10 +501,13 @@ public class BluetoothDunService extends Service { if (intent.getBooleanExtra(BluetoothDunService.DUN_EXTRA_ALWAYS_ALLOWED, false) == true) { if(mRemoteDevice != null) { - mRemoteDevice.setTrust(true); - Log.v(TAG, "setTrust() TRUE " + mRemoteDevice.getName()); + setDunAccessPermission(mRemoteDevice, + BluetoothDevice.ACCESS_ALLOWED); + Log.v(TAG, "setDunAccessPermission() ACCESS_ALLOWED " + + mRemoteDevice.getName()); } } + /* start the uplink thread */ startUplinkThread(); @@ -514,14 +524,12 @@ public class BluetoothDunService extends Service { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if(device != null) Log.d(TAG,"device: "+ device.getName()); - if(mRemoteDevice != null) - Log.d(TAG," Remtedevie: "+mRemoteDevice.getName()); - if ((device != null) && (mRemoteDevice != null) && (device.equals(mRemoteDevice)) && - (mRemoteDevice.getTrustState()) && (intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, - BluetoothDevice.BOND_NONE) == BluetoothDevice.BOND_NONE)) { - Log.d(TAG,"BOND_STATE_CHANGED REFRESH trustDevices"+ device.getName()); - mRemoteDevice.setTrust(false); + if ((device != null) && + (intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, + BluetoothDevice.BOND_NONE) == BluetoothDevice.BOND_NONE)) { + Log.d(TAG,"BOND_STATE_CHANGED REFRESH trustDevices "+ device.getName()); + setDunAccessPermission(device, BluetoothDevice.ACCESS_UNKNOWN); } } @@ -874,15 +882,16 @@ public class BluetoothDunService extends Service { Log.i(TAG, "getRemoteDevice() = null"); break; } - boolean trust = false; + int trust = BluetoothDevice.ACCESS_UNKNOWN; + if (mRemoteDevice != null) - trust = mRemoteDevice.getTrustState(); - if (VERBOSE) Log.v(TAG, "GetTrustState() = " + trust); + trust = getDunAccessPermission(mRemoteDevice); + if (VERBOSE) Log.v(TAG, "getDunAccessPermission() = " + trust); - if (trust) { + if (trust == BluetoothDevice.ACCESS_ALLOWED) { /* start the uplink thread */ startUplinkThread(); - } else { + } else if (trust == BluetoothDevice.ACCESS_UNKNOWN) { createDunNotification(mRemoteDevice); if (VERBOSE) Log.v(TAG, "incoming connection accepted from: "+ mRemoteDevice); @@ -1302,6 +1311,31 @@ public class BluetoothDunService extends Service { return true; } + int getDunAccessPermission(BluetoothDevice device) { + enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + SharedPreferences pref = getSharedPreferences(DUN_ACCESS_PERMISSION_PREFERENCE_FILE, + Context.MODE_PRIVATE); + if (!pref.contains(device.getAddress())) { + return BluetoothDevice.ACCESS_UNKNOWN; + } + return pref.getBoolean(device.getAddress(), false) + ? BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_REJECTED; + } + + boolean setDunAccessPermission(BluetoothDevice device, int value) { + enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, + "Need BLUETOOTH PRIVILEGED permission"); + SharedPreferences pref = getSharedPreferences(DUN_ACCESS_PERMISSION_PREFERENCE_FILE, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = pref.edit(); + if (value == BluetoothDevice.ACCESS_UNKNOWN) { + editor.remove(device.getAddress()); + } else { + editor.putBoolean(device.getAddress(), value == BluetoothDevice.ACCESS_ALLOWED); + } + return editor.commit(); + } + int getConnectionState(BluetoothDevice device) { BluetoothDunDevice dunDevice = mDunDevices.get(device); if (dunDevice == null) { diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpRfcommTransport.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpRfcommTransport.java index 82e1cb6..2046927 100644 --- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpRfcommTransport.java +++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpRfcommTransport.java @@ -83,4 +83,15 @@ public class BluetoothFtpRfcommTransport implements ObexTransport { return true; } + public int getMaxTransmitPacketSize() { + return -1; + } + + public int getMaxReceivePacketSize() { + return -1; + } + + public boolean isSrmSupported() { + return false; + } } diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java index cb78eca..5d16d65 100644 --- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java +++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java @@ -60,7 +60,7 @@ import android.os.RemoteException; import android.provider.MediaStore; import javax.obex.ObexHelper; import android.bluetooth.BluetoothUuid; - +import android.content.SharedPreferences; import java.util.ArrayList; import java.util.List; @@ -144,8 +144,13 @@ public class BluetoothFtpService extends Service { */ public static final String EXTRA_SESSION_KEY = "org.codeaurora.bluetooth.ftp.sessionkey"; + private static final String FTP_ACCESS_PERMISSION_PREFERENCE_FILE = + "ftp_access_permission"; + private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; + private static final String BLUETOOTH_PRIVILEGED = android.Manifest.permission.BLUETOOTH_PRIVILEGED;; + private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; public static final int MSG_SERVERSESSION_CLOSE = 5004; @@ -318,10 +323,11 @@ public class BluetoothFtpService extends Service { if (intent.getBooleanExtra(BluetoothFtpService.EXTRA_ALWAYS_ALLOWED, false)) { if(mRemoteDevice != null) { - mRemoteDevice.setTrust(true); - Log.v(TAG, "setTrust() TRUE " + mRemoteDevice.getName()); + setFtpAccessPermission(mRemoteDevice, BluetoothDevice.ACCESS_ALLOWED); + Log.v(TAG, "setFtpAccessPermission() ACCESS_ALLOWED " + mRemoteDevice.getName()); } } + try { if (mConnSocket != null) { startObexServerSession(); @@ -357,6 +363,20 @@ public class BluetoothFtpService extends Service { isWaitingAuthorization = false; stopObexServerSession(); } + } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) { + + if (intent.hasExtra(BluetoothDevice.EXTRA_DEVICE)) { + BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + if(device != null) + Log.d(TAG,"device: "+ device.getName()); + + if ((device != null) && + (intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, + BluetoothDevice.BOND_NONE) == BluetoothDevice.BOND_NONE)) { + Log.d(TAG,"BOND_STATE_CHANGED REFRESH trustDevices "+ device.getName()); + setFtpAccessPermission(device, BluetoothDevice.ACCESS_UNKNOWN); + } + } } else { removeTimeoutMsg = false; } @@ -648,13 +668,14 @@ public class BluetoothFtpService extends Service { } mSessionStatusHandler.sendMessage(mSessionStatusHandler .obtainMessage(MSG_INTERNAL_OBEX_RFCOMM_SESSION_UP)); - boolean trust = false; + int trust = BluetoothDevice.ACCESS_UNKNOWN; + if (mRemoteDevice != null) - trust = mRemoteDevice.getTrustState(); + trust = getFtpAccessPermission(mRemoteDevice); - Log.v(RTAG, "GetTrustState() = " + trust); + Log.v(RTAG, "getFtpAccessPermission() = " + trust); - if (trust) { + if (trust == BluetoothDevice.ACCESS_ALLOWED) { try { Log.i(RTAG, "incomming connection accepted from: " + sRemoteDeviceName + " automatically as trusted device"); @@ -663,7 +684,7 @@ public class BluetoothFtpService extends Service { Log.e(RTAG, "catch exception starting obex server session" + ex.toString()); } - } else { + } else if (trust == BluetoothDevice.ACCESS_UNKNOWN) { isWaitingAuthorization = true; createFtpNotification(ACCESS_REQUEST_ACTION); Log.i(RTAG, "waiting for authorization for connection from: " @@ -770,6 +791,32 @@ public class BluetoothFtpService extends Service { } } }; + + int getFtpAccessPermission(BluetoothDevice device) { + enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + SharedPreferences pref = getSharedPreferences(FTP_ACCESS_PERMISSION_PREFERENCE_FILE, + Context.MODE_PRIVATE); + if (!pref.contains(device.getAddress())) { + return BluetoothDevice.ACCESS_UNKNOWN; + } + return pref.getBoolean(device.getAddress(), false) + ? BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_REJECTED; + } + + boolean setFtpAccessPermission(BluetoothDevice device, int value) { + enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, + "Need BLUETOOTH PRIVILEGED permission"); + SharedPreferences pref = getSharedPreferences(FTP_ACCESS_PERMISSION_PREFERENCE_FILE, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = pref.edit(); + if (value == BluetoothDevice.ACCESS_UNKNOWN) { + editor.remove(device.getAddress()); + } else { + editor.putBoolean(device.getAddress(), value == BluetoothDevice.ACCESS_ALLOWED); + } + return editor.commit(); + } + private void createFtpNotification(String action) { NotificationManager nm = (NotificationManager) diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpTransport.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpTransport.java index f84b53d..8664495 100644 --- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpTransport.java +++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpTransport.java @@ -103,6 +103,19 @@ public class BluetoothFtpTransport implements ObexTransport { public boolean isSrmCapable() { return mType == TYPE_L2CAP; } + + public int getMaxTransmitPacketSize() { + return -1; + } + + public int getMaxReceivePacketSize() { + return -1; + } + + public boolean isSrmSupported() { + return false; + } + /* public boolean setDesiredAmpPolicy(int policy) { if (mSocket == null || mType != TYPE_L2CAP) |