Loading android/app/AndroidManifest.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> <!--action android:name="android.intent.action.BOOT_COMPLETED" /--> <!--action android:name="android.intent.action.BOOT_COMPLETED" /--> <action android:name="android.btopp.intent.action.OPEN_RECEIVED_FILES" /> <action android:name="android.btopp.intent.action.OPEN_RECEIVED_FILES" /> <action android:name="todo-whitelist" /> </intent-filter> </intent-filter> </receiver> </receiver> <activity android:name=".opp.BluetoothOppLauncherActivity" <activity android:name=".opp.BluetoothOppLauncherActivity" Loading android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.ArrayList; import android.app.Activity; import android.app.Activity; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevicePicker; import android.bluetooth.BluetoothDevicePicker; import android.content.Intent; import android.content.Intent; import android.content.ContentResolver; import android.content.ContentResolver; Loading @@ -66,6 +67,7 @@ public class BluetoothOppLauncherActivity extends Activity { Intent intent = getIntent(); Intent intent = getIntent(); String action = intent.getAction(); String action = intent.getAction(); BluetoothDevice device = null; if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { /* /* Loading @@ -78,6 +80,9 @@ public class BluetoothOppLauncherActivity extends Activity { String type = intent.getType(); String type = intent.getType(); Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); //TODO: consider only checking EXTRA_DEVICE if it came from NFC device = (BluetoothDevice)intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the // If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the // uri data; // uri data; // If we get ACTION_SEND intent without EXTRA_STREAM, but with // If we get ACTION_SEND intent without EXTRA_STREAM, but with Loading Loading @@ -138,7 +143,7 @@ public class BluetoothOppLauncherActivity extends Activity { Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(in); this.startActivity(in); } else { } else if (device == null) { if (V) Log.v(TAG, "BT already enabled!! "); if (V) Log.v(TAG, "BT already enabled!! "); Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); in1.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); in1.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); Loading @@ -151,6 +156,9 @@ public class BluetoothOppLauncherActivity extends Activity { BluetoothOppReceiver.class.getName()); BluetoothOppReceiver.class.getName()); this.startActivity(in1); this.startActivity(in1); } else { // we already know where to send to BluetoothOppManager.getInstance(this).startTransfer(device); } } } else if (action.equals(Constants.ACTION_OPEN)) { } else if (action.equals(Constants.ACTION_OPEN)) { Uri uri = getIntent().getData(); Uri uri = getIntent().getData(); Loading android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java +12 −0 Original line number Original line Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.text.TextUtils; import android.util.Log; import android.util.Log; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; /** /** * This class provides a simplified interface on top of other Bluetooth service * This class provides a simplified interface on top of other Bluetooth service Loading Loading @@ -139,6 +140,17 @@ public class BluetoothOppManager { return true; return true; } } List<String> mWhitelist = new ArrayList<String>(); public void addToWhitelist(String address) { //TODO: timeout whitelist mWhitelist.add(address); } public boolean isWhitelisted(String address) { return mWhitelist.contains(address); } /** /** * Restore data from preference * Restore data from preference */ */ Loading android/app/src/com/android/bluetooth/opp/BluetoothOppProvider.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -46,7 +46,9 @@ import android.net.Uri; import android.provider.LiveFolders; import android.provider.LiveFolders; import android.util.Log; import android.util.Log; import java.util.ArrayList; import java.util.HashMap; import java.util.HashMap; import java.util.List; /** /** * This provider allows application to interact with Bluetooth OPP manager * This provider allows application to interact with Bluetooth OPP manager Loading Loading @@ -250,6 +252,7 @@ public final class BluetoothOppProvider extends ContentProvider { } } Integer dir = values.getAsInteger(BluetoothShare.DIRECTION); Integer dir = values.getAsInteger(BluetoothShare.DIRECTION); Integer con = values.getAsInteger(BluetoothShare.USER_CONFIRMATION); Integer con = values.getAsInteger(BluetoothShare.USER_CONFIRMATION); String address = values.getAsString(BluetoothShare.DESTINATION); if (values.getAsInteger(BluetoothShare.DIRECTION) == null) { if (values.getAsInteger(BluetoothShare.DIRECTION) == null) { dir = BluetoothShare.DIRECTION_OUTBOUND; dir = BluetoothShare.DIRECTION_OUTBOUND; Loading @@ -258,8 +261,13 @@ public final class BluetoothOppProvider extends ContentProvider { con = BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED; con = BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED; } } if (dir == BluetoothShare.DIRECTION_INBOUND && con == null) { if (dir == BluetoothShare.DIRECTION_INBOUND && con == null) { if (BluetoothOppManager.getInstance(getContext()).isWhitelisted(address)) { if (D) Log.d(TAG, address + " is in whitelist, auto confirming"); con = BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED; } else { con = BluetoothShare.USER_CONFIRMATION_PENDING; con = BluetoothShare.USER_CONFIRMATION_PENDING; } } } filteredValues.put(BluetoothShare.USER_CONFIRMATION, con); filteredValues.put(BluetoothShare.USER_CONFIRMATION, con); filteredValues.put(BluetoothShare.DIRECTION, dir); filteredValues.put(BluetoothShare.DIRECTION, dir); Loading android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,7 @@ import android.widget.Toast; */ */ public class BluetoothOppReceiver extends BroadcastReceiver { public class BluetoothOppReceiver extends BroadcastReceiver { private static final String TAG = "BluetoothOppReceiver"; private static final String TAG = "BluetoothOppReceiver"; private static final boolean D = Constants.DEBUG; private static final boolean V = Constants.VERBOSE; private static final boolean V = Constants.VERBOSE; @Override @Override Loading Loading @@ -248,6 +249,13 @@ public class BluetoothOppReceiver extends BroadcastReceiver { if (toastMsg != null) { if (toastMsg != null) { Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show(); Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show(); } } } else if (action.equals("todo-whitelist")) { //TODO: Verify sender of intent BluetoothDevice device = (BluetoothDevice)intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (D) Log.d(TAG, "Adding " + device + " to whitelist"); if (device == null) return; BluetoothOppManager.getInstance(context).addToWhitelist(device.getAddress()); } } } } } } Loading
android/app/AndroidManifest.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> <!--action android:name="android.intent.action.BOOT_COMPLETED" /--> <!--action android:name="android.intent.action.BOOT_COMPLETED" /--> <action android:name="android.btopp.intent.action.OPEN_RECEIVED_FILES" /> <action android:name="android.btopp.intent.action.OPEN_RECEIVED_FILES" /> <action android:name="todo-whitelist" /> </intent-filter> </intent-filter> </receiver> </receiver> <activity android:name=".opp.BluetoothOppLauncherActivity" <activity android:name=".opp.BluetoothOppLauncherActivity" Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.ArrayList; import android.app.Activity; import android.app.Activity; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevicePicker; import android.bluetooth.BluetoothDevicePicker; import android.content.Intent; import android.content.Intent; import android.content.ContentResolver; import android.content.ContentResolver; Loading @@ -66,6 +67,7 @@ public class BluetoothOppLauncherActivity extends Activity { Intent intent = getIntent(); Intent intent = getIntent(); String action = intent.getAction(); String action = intent.getAction(); BluetoothDevice device = null; if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { /* /* Loading @@ -78,6 +80,9 @@ public class BluetoothOppLauncherActivity extends Activity { String type = intent.getType(); String type = intent.getType(); Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); //TODO: consider only checking EXTRA_DEVICE if it came from NFC device = (BluetoothDevice)intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the // If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the // uri data; // uri data; // If we get ACTION_SEND intent without EXTRA_STREAM, but with // If we get ACTION_SEND intent without EXTRA_STREAM, but with Loading Loading @@ -138,7 +143,7 @@ public class BluetoothOppLauncherActivity extends Activity { Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(in); this.startActivity(in); } else { } else if (device == null) { if (V) Log.v(TAG, "BT already enabled!! "); if (V) Log.v(TAG, "BT already enabled!! "); Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); in1.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); in1.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); Loading @@ -151,6 +156,9 @@ public class BluetoothOppLauncherActivity extends Activity { BluetoothOppReceiver.class.getName()); BluetoothOppReceiver.class.getName()); this.startActivity(in1); this.startActivity(in1); } else { // we already know where to send to BluetoothOppManager.getInstance(this).startTransfer(device); } } } else if (action.equals(Constants.ACTION_OPEN)) { } else if (action.equals(Constants.ACTION_OPEN)) { Uri uri = getIntent().getData(); Uri uri = getIntent().getData(); Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java +12 −0 Original line number Original line Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.text.TextUtils; import android.util.Log; import android.util.Log; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; /** /** * This class provides a simplified interface on top of other Bluetooth service * This class provides a simplified interface on top of other Bluetooth service Loading Loading @@ -139,6 +140,17 @@ public class BluetoothOppManager { return true; return true; } } List<String> mWhitelist = new ArrayList<String>(); public void addToWhitelist(String address) { //TODO: timeout whitelist mWhitelist.add(address); } public boolean isWhitelisted(String address) { return mWhitelist.contains(address); } /** /** * Restore data from preference * Restore data from preference */ */ Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppProvider.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -46,7 +46,9 @@ import android.net.Uri; import android.provider.LiveFolders; import android.provider.LiveFolders; import android.util.Log; import android.util.Log; import java.util.ArrayList; import java.util.HashMap; import java.util.HashMap; import java.util.List; /** /** * This provider allows application to interact with Bluetooth OPP manager * This provider allows application to interact with Bluetooth OPP manager Loading Loading @@ -250,6 +252,7 @@ public final class BluetoothOppProvider extends ContentProvider { } } Integer dir = values.getAsInteger(BluetoothShare.DIRECTION); Integer dir = values.getAsInteger(BluetoothShare.DIRECTION); Integer con = values.getAsInteger(BluetoothShare.USER_CONFIRMATION); Integer con = values.getAsInteger(BluetoothShare.USER_CONFIRMATION); String address = values.getAsString(BluetoothShare.DESTINATION); if (values.getAsInteger(BluetoothShare.DIRECTION) == null) { if (values.getAsInteger(BluetoothShare.DIRECTION) == null) { dir = BluetoothShare.DIRECTION_OUTBOUND; dir = BluetoothShare.DIRECTION_OUTBOUND; Loading @@ -258,8 +261,13 @@ public final class BluetoothOppProvider extends ContentProvider { con = BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED; con = BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED; } } if (dir == BluetoothShare.DIRECTION_INBOUND && con == null) { if (dir == BluetoothShare.DIRECTION_INBOUND && con == null) { if (BluetoothOppManager.getInstance(getContext()).isWhitelisted(address)) { if (D) Log.d(TAG, address + " is in whitelist, auto confirming"); con = BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED; } else { con = BluetoothShare.USER_CONFIRMATION_PENDING; con = BluetoothShare.USER_CONFIRMATION_PENDING; } } } filteredValues.put(BluetoothShare.USER_CONFIRMATION, con); filteredValues.put(BluetoothShare.USER_CONFIRMATION, con); filteredValues.put(BluetoothShare.DIRECTION, dir); filteredValues.put(BluetoothShare.DIRECTION, dir); Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,7 @@ import android.widget.Toast; */ */ public class BluetoothOppReceiver extends BroadcastReceiver { public class BluetoothOppReceiver extends BroadcastReceiver { private static final String TAG = "BluetoothOppReceiver"; private static final String TAG = "BluetoothOppReceiver"; private static final boolean D = Constants.DEBUG; private static final boolean V = Constants.VERBOSE; private static final boolean V = Constants.VERBOSE; @Override @Override Loading Loading @@ -248,6 +249,13 @@ public class BluetoothOppReceiver extends BroadcastReceiver { if (toastMsg != null) { if (toastMsg != null) { Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show(); Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show(); } } } else if (action.equals("todo-whitelist")) { //TODO: Verify sender of intent BluetoothDevice device = (BluetoothDevice)intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (D) Log.d(TAG, "Adding " + device + " to whitelist"); if (device == null) return; BluetoothOppManager.getInstance(context).addToWhitelist(device.getAddress()); } } } } } }