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

Commit 1a4d5488 authored by Myles Watson's avatar Myles Watson
Browse files

OPP: Remove dead code and update Constants.java

Remove unused debugging options.

Test: Use Bluetooth to transfer an image between two phones
Change-Id: I0ff0e6632955787f4e259fcf5f38784583263d80
parent 7d7753ce
Loading
Loading
Loading
Loading
+0 −16
Original line number Original line Diff line number Diff line
@@ -363,9 +363,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                            } catch (IOException e) {
                            } catch (IOException e) {
                                Log.e(TAG, "close tranport error");
                                Log.e(TAG, "close tranport error");
                            }
                            }
                        } else if (Constants.USE_TCP_DEBUG && !Constants.USE_TCP_SIMPLE_SERVER) {
                            Log.i(TAG, "Start Obex Server in TCP DEBUG mode");
                            createServerSession(transport);
                        } else {
                        } else {
                            Log.i(TAG, "OPP busy! Retry after 1 second");
                            Log.i(TAG, "OPP busy! Retry after 1 second");
                            mIncomingRetries = mIncomingRetries + 1;
                            mIncomingRetries = mIncomingRetries + 1;
@@ -790,19 +787,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                        Log.v(TAG,
                        Log.v(TAG,
                                "Service add new Batch " + newBatch.mId + " for info " + info.mId);
                                "Service add new Batch " + newBatch.mId + " for info " + info.mId);
                    }
                    }
                    if (Constants.USE_TCP_DEBUG && !Constants.USE_TCP_SIMPLE_SERVER) {
                        // only allow  concurrent serverTransfer in debug mode
                        if (info.mDirection == BluetoothShare.DIRECTION_INBOUND) {
                            if (V) {
                                Log.v(TAG,
                                        "TCP_DEBUG start server transfer new Batch " + newBatch.mId
                                                + " for info " + info.mId);
                            }
                            mServerTransfer =
                                    new BluetoothOppTransfer(this, newBatch, mServerSession);
                            mServerTransfer.start();
                        }
                    }
                }
                }
            }
            }
        }
        }
+69 −127
Original line number Original line Diff line number Diff line
@@ -44,164 +44,138 @@ import java.util.regex.Pattern;
import javax.obex.HeaderSet;
import javax.obex.HeaderSet;


/**
/**
 * Bluetooth OPP internal constants definition
 * Bluetooth OPP internal constant definitions
 */
 */
public class Constants {
public class Constants {
    /** Tag used for debugging/logging */
    /** Tag used for debugging/logging */
    public static final String TAG = "BluetoothOpp";
    public static final String TAG = "BluetoothOpp";


    /**
    /**
     * The intent that gets sent when the service must wake up for a retry Note:
     * The intent that gets sent when the service must wake up for a retry
     * only retry Outbound transfer
     * Note: Only retry Outbound transfers
     */
     */
    public static final String ACTION_RETRY = "android.btopp.intent.action.RETRY";
    static final String ACTION_RETRY = "android.btopp.intent.action.RETRY";


    /** the intent that gets sent when clicking a successful transfer */
    /** the intent that gets sent when clicking a successful transfer */
    public static final String ACTION_OPEN = "android.btopp.intent.action.OPEN";
    static final String ACTION_OPEN = "android.btopp.intent.action.OPEN";


    /** the intent that gets sent when clicking outbound transfer notification */
    /** the intent that gets sent when clicking outbound transfer notification */
    public static final String ACTION_OPEN_OUTBOUND_TRANSFER =
    static final String ACTION_OPEN_OUTBOUND_TRANSFER = "android.btopp.intent.action.OPEN_OUTBOUND";
            "android.btopp.intent.action.OPEN_OUTBOUND";


    /** the intent that gets sent when clicking a inbound transfer notification */
    /** the intent that gets sent when clicking a inbound transfer notification */
    public static final String ACTION_OPEN_INBOUND_TRANSFER =
    static final String ACTION_OPEN_INBOUND_TRANSFER = "android.btopp.intent.action.OPEN_INBOUND";
            "android.btopp.intent.action.OPEN_INBOUND";


    /** the intent that gets sent from the Settings app to show the received files */
    /** the intent that gets sent from the Settings app to show the received files */
    public static final String ACTION_OPEN_RECEIVED_FILES =
    static final String ACTION_OPEN_RECEIVED_FILES =
            "android.btopp.intent.action.OPEN_RECEIVED_FILES";
            "android.btopp.intent.action.OPEN_RECEIVED_FILES";


    /** the intent that whitelists a remote bluetooth device for auto-receive confirmation (NFC) */
    /** the intent that whitelists a remote bluetooth device for auto-receive confirmation (NFC) */
    public static final String ACTION_WHITELIST_DEVICE =
    static final String ACTION_WHITELIST_DEVICE = "android.btopp.intent.action.WHITELIST_DEVICE";
            "android.btopp.intent.action.WHITELIST_DEVICE";


    /** the intent that can be sent by handover requesters to stop a BTOPP transfer */
    /** the intent that can be sent by handover requesters to stop a BTOPP transfer */
    public static final String ACTION_STOP_HANDOVER =
    static final String ACTION_STOP_HANDOVER = "android.btopp.intent.action.STOP_HANDOVER_TRANSFER";
            "android.btopp.intent.action.STOP_HANDOVER_TRANSFER";


    /** the intent extra to show all received files in the transfer history */
    /** the intent extra to show all received files in the transfer history */
    public static final String EXTRA_SHOW_ALL_FILES = "android.btopp.intent.extra.SHOW_ALL";
    static final String EXTRA_SHOW_ALL_FILES = "android.btopp.intent.extra.SHOW_ALL";


    /** the intent that gets sent when clicking an incomplete/failed transfer */
    /** the intent that gets sent when clicking an incomplete/failed transfer */
    public static final String ACTION_LIST = "android.btopp.intent.action.LIST";
    static final String ACTION_LIST = "android.btopp.intent.action.LIST";


    /** the intent that is used for initiating a handover transfer */
    /** the intent that is used for initiating a handover transfer */
    public static final String ACTION_HANDOVER_SEND =
    static final String ACTION_HANDOVER_SEND = "android.nfc.handover.intent.action.HANDOVER_SEND";
            "android.nfc.handover.intent.action.HANDOVER_SEND";


    /** the intent that is used for initiating a multi-uri handover transfer */
    /** the intent that is used for initiating a multi-uri handover transfer */
    public static final String ACTION_HANDOVER_SEND_MULTIPLE =
    static final String ACTION_HANDOVER_SEND_MULTIPLE =
            "android.nfc.handover.intent.action.HANDOVER_SEND_MULTIPLE";
            "android.nfc.handover.intent.action.HANDOVER_SEND_MULTIPLE";


    /** the intent that is used for indicating an incoming transfer*/
    /** the intent that is used for indicating an incoming transfer*/
    public static final String ACTION_HANDOVER_STARTED =
    static final String ACTION_HANDOVER_STARTED =
            "android.nfc.handover.intent.action.HANDOVER_STARTED";
            "android.nfc.handover.intent.action.HANDOVER_STARTED";


    /** intent action used to indicate the progress of a handover transfer */
    /** intent action used to indicate the progress of a handover transfer */
    public static final String ACTION_BT_OPP_TRANSFER_PROGRESS =
    static final String ACTION_BT_OPP_TRANSFER_PROGRESS =
            "android.nfc.handover.intent.action.TRANSFER_PROGRESS";
            "android.nfc.handover.intent.action.TRANSFER_PROGRESS";


    /** intent action used to indicate the completion of a handover transfer */
    /** intent action used to indicate the completion of a handover transfer */
    public static final String ACTION_BT_OPP_TRANSFER_DONE =
    static final String ACTION_BT_OPP_TRANSFER_DONE =
            "android.nfc.handover.intent.action.TRANSFER_DONE";
            "android.nfc.handover.intent.action.TRANSFER_DONE";


    /** intent extra used to indicate the success of a handover transfer */
    /** intent extra used to indicate the success of a handover transfer */
    public static final String EXTRA_BT_OPP_TRANSFER_STATUS =
    static final String EXTRA_BT_OPP_TRANSFER_STATUS =
            "android.nfc.handover.intent.extra.TRANSFER_STATUS";
            "android.nfc.handover.intent.extra.TRANSFER_STATUS";


    /** intent extra used to indicate the address associated with the transfer */
    /** intent extra used to indicate the address associated with the transfer */
    public static final String EXTRA_BT_OPP_ADDRESS = "android.nfc.handover.intent.extra.ADDRESS";
    static final String EXTRA_BT_OPP_ADDRESS = "android.nfc.handover.intent.extra.ADDRESS";


    public static final String EXTRA_BT_OPP_OBJECT_COUNT =
    static final String EXTRA_BT_OPP_OBJECT_COUNT =
            "android.nfc.handover.intent.extra.OBJECT_COUNT";
            "android.nfc.handover.intent.extra.OBJECT_COUNT";


    public static final int COUNT_HEADER_UNAVAILABLE = -1;
    static final int COUNT_HEADER_UNAVAILABLE = -1;
    public static final int HANDOVER_TRANSFER_STATUS_SUCCESS = 0;
    static final int HANDOVER_TRANSFER_STATUS_SUCCESS = 0;


    public static final int HANDOVER_TRANSFER_STATUS_FAILURE = 1;
    static final int HANDOVER_TRANSFER_STATUS_FAILURE = 1;


    /** intent extra used to indicate the direction of a handover transfer */
    /** intent extra used to indicate the direction of a handover transfer */
    public static final String EXTRA_BT_OPP_TRANSFER_DIRECTION =
    static final String EXTRA_BT_OPP_TRANSFER_DIRECTION =
            "android.nfc.handover.intent.extra.TRANSFER_DIRECTION";
            "android.nfc.handover.intent.extra.TRANSFER_DIRECTION";


    public static final int DIRECTION_BLUETOOTH_INCOMING = 0;
    static final int DIRECTION_BLUETOOTH_INCOMING = 0;


    public static final int DIRECTION_BLUETOOTH_OUTGOING = 1;
    static final int DIRECTION_BLUETOOTH_OUTGOING = 1;


    /** intent extra used to provide a unique ID for the transfer */
    /** intent extra used to provide a unique ID for the transfer */
    public static final String EXTRA_BT_OPP_TRANSFER_ID =
    static final String EXTRA_BT_OPP_TRANSFER_ID = "android.nfc.handover.intent.extra.TRANSFER_ID";
            "android.nfc.handover.intent.extra.TRANSFER_ID";


    /** intent extra used to provide progress of the transfer */
    /** intent extra used to provide progress of the transfer */
    public static final String EXTRA_BT_OPP_TRANSFER_PROGRESS =
    static final String EXTRA_BT_OPP_TRANSFER_PROGRESS =
            "android.nfc.handover.intent.extra.TRANSFER_PROGRESS";
            "android.nfc.handover.intent.extra.TRANSFER_PROGRESS";


    /** intent extra used to provide the Uri where the data was stored
    /** intent extra used to provide the Uri where the data was stored by the handover transfer */
     * by the handover transfer */
    static final String EXTRA_BT_OPP_TRANSFER_URI =
    public static final String EXTRA_BT_OPP_TRANSFER_URI =
            "android.nfc.handover.intent.extra.TRANSFER_URI";
            "android.nfc.handover.intent.extra.TRANSFER_URI";


    /** intent extra used to provide the mime-type of the data in
    /** intent extra used to provide the mime-type of the data in the handover transfer */
     *  the handover transfer */
    static final String EXTRA_BT_OPP_TRANSFER_MIMETYPE =
    public static final String EXTRA_BT_OPP_TRANSFER_MIMETYPE =
            "android.nfc.handover.intent.extra.TRANSFER_MIME_TYPE";
            "android.nfc.handover.intent.extra.TRANSFER_MIME_TYPE";


    /** permission needed to be able to receive handover status requests */
    /** permission needed to be able to receive handover status requests */
    public static final String HANDOVER_STATUS_PERMISSION =
    static final String HANDOVER_STATUS_PERMISSION = "android.permission.NFC_HANDOVER_STATUS";
            "android.permission.NFC_HANDOVER_STATUS";


    /** intent extra that indicates this transfer is a handover from another
    /** the intent that gets sent when deleting the incoming file confirmation notification */
     * transport (NFC, WIFI)
    static final String ACTION_HIDE = "android.btopp.intent.action.HIDE";
     */
    public static final String EXTRA_CONNECTION_HANDOVER =
            "com.android.intent.extra.CONNECTION_HANDOVER";


    /**
    /** the intent that gets sent when accepting the incoming file confirmation notification */
     * the intent that gets sent when deleting the incoming file confirmation notification
    static final String ACTION_ACCEPT = "android.btopp.intent.action.ACCEPT";
     */
    public static final String ACTION_HIDE = "android.btopp.intent.action.HIDE";


    /**
    /** the intent that gets sent when declining the incoming file confirmation notification */
     * the intent that gets sent when accepting the incoming file confirmation notification
    static final String ACTION_DECLINE = "android.btopp.intent.action.DECLINE";
     */
    public static final String ACTION_ACCEPT = "android.btopp.intent.action.ACCEPT";

    /**
     * the intent that gets sent when declining the incoming file confirmation notification
     */
    public static final String ACTION_DECLINE = "android.btopp.intent.action.DECLINE";


    /**
    /**
     * the intent that gets sent when deleting the notifications of outbound and
     * the intent that gets sent when deleting the notifications of outbound and
     * inbound completed transfer
     * inbound completed transfer
     */
     */
    public static final String ACTION_COMPLETE_HIDE = "android.btopp.intent.action.HIDE_COMPLETE";
    static final String ACTION_COMPLETE_HIDE = "android.btopp.intent.action.HIDE_COMPLETE";


    /**
    /** the intent that gets sent when clicking a incoming file confirm notification */
     * the intent that gets sent when clicking a incoming file confirm
    static final String ACTION_INCOMING_FILE_CONFIRM = "android.btopp.intent.action.CONFIRM";
     * notification
     */
    public static final String ACTION_INCOMING_FILE_CONFIRM = "android.btopp.intent.action.CONFIRM";


    public static final String THIS_PACKAGE_NAME = "com.android.bluetooth";
    static final String THIS_PACKAGE_NAME = "com.android.bluetooth";


    /**
    /** The column that is used to remember whether the media scanner was invoked */
     * The column that is used to remember whether the media scanner was invoked
    static final String MEDIA_SCANNED = "scanned";
     */
    public static final String MEDIA_SCANNED = "scanned";


    public static final int MEDIA_SCANNED_NOT_SCANNED = 0;
    static final int MEDIA_SCANNED_NOT_SCANNED = 0;


    public static final int MEDIA_SCANNED_SCANNED_OK = 1;
    static final int MEDIA_SCANNED_SCANNED_OK = 1;


    public static final int MEDIA_SCANNED_SCANNED_FAILED = 2;
    static final int MEDIA_SCANNED_SCANNED_FAILED = 2;


    /**
    /**
     * The MIME type(s) of we could accept from other device.
     * The MIME type(s) of we could accept from other device.
     * This is in essence a "white list" of acceptable types.
     * This is in essence a "white list" of acceptable types.
     * Today, restricted to images, audio, video and certain text types.
     * Today, restricted to images, audio, video and certain text types.
     */
     */
    public static final String[] ACCEPTABLE_SHARE_INBOUND_TYPES = new String[]{
    static final String[] ACCEPTABLE_SHARE_INBOUND_TYPES = new String[]{
            "image/*",
            "image/*",
            "video/*",
            "video/*",
            "audio/*",
            "audio/*",
@@ -222,61 +196,33 @@ public class Constants {
            "application/x-hwp",
            "application/x-hwp",
    };
    };


    /**
    /** Where we store received files */
     * The MIME type(s) of we could not accept from other device. TODO: define
    static final String DEFAULT_STORE_SUBDIR = "/bluetooth";
     * correct type list
     */
    public static final String[] UNACCEPTABLE_SHARE_INBOUND_TYPES = new String[]{};

    /** Where we store Bluetooth received files on the external storage */
    public static final String DEFAULT_STORE_SUBDIR = "/bluetooth";

    /**
     * Notify NFC of the transfer progress per this period
     * to NFC Handover still consider this transfer to be "alive"
     * This value is taken into account the timeout value 20sec in NFC and delaying broadcast
     */
    public static final int NFC_ALIVE_CHECK_MS = 10000;

    /**
     * Debug level logging
     */
    public static final boolean DEBUG = true;

    /**
     * Verbose level logging
     */
    public static final boolean VERBOSE = false;

    /** use TCP socket instead of Rfcomm Socket to develop */
    public static final boolean USE_TCP_DEBUG = false;


    /** use simple TCP server started from TestActivity */
    /** Notify NFC of the transfer progress periodically, or it will timeout after 20sec. */
    public static final boolean USE_TCP_SIMPLE_SERVER = false;
    static final int NFC_ALIVE_CHECK_MS = 10000;


    /** Test TCP socket port */
    static final boolean DEBUG = true;
    public static final int TCP_DEBUG_PORT = 6500;


    /** use emulator to debug */
    static final boolean VERBOSE = false;
    public static final boolean USE_EMULATOR_DEBUG = false;


    public static final int MAX_RECORDS_IN_DATABASE = 50;
    static final int MAX_RECORDS_IN_DATABASE = 50;


    public static final int BATCH_STATUS_PENDING = 0;
    static final int BATCH_STATUS_PENDING = 0;


    public static final int BATCH_STATUS_RUNNING = 1;
    static final int BATCH_STATUS_RUNNING = 1;


    public static final int BATCH_STATUS_FINISHED = 2;
    static final int BATCH_STATUS_FINISHED = 2;


    public static final int BATCH_STATUS_FAILED = 3;
    static final int BATCH_STATUS_FAILED = 3;


    public static final String BLUETOOTHOPP_NAME_PREFERENCE = "btopp_names";
    static final String BLUETOOTHOPP_NAME_PREFERENCE = "btopp_names";


    public static final String BLUETOOTHOPP_CHANNEL_PREFERENCE = "btopp_channels";
    static final String BLUETOOTHOPP_CHANNEL_PREFERENCE = "btopp_channels";


    public static final String FILENAME_SEQUENCE_SEPARATOR = "-";
    static final String FILENAME_SEQUENCE_SEPARATOR = "-";


    public static void updateShareStatus(Context context, int id, int status) {
    static void updateShareStatus(Context context, int id, int status) {
        Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);
        Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);
        ContentValues updateValues = new ContentValues();
        ContentValues updateValues = new ContentValues();
        updateValues.put(BluetoothShare.STATUS, status);
        updateValues.put(BluetoothShare.STATUS, status);
@@ -284,11 +230,8 @@ public class Constants {
        Constants.sendIntentIfCompleted(context, contentUri, status);
        Constants.sendIntentIfCompleted(context, contentUri, status);
    }
    }


    /*
    /** This function should be called whenever the transfer status changes to completed. */
     * This function should be called whenever transfer status change to
    static void sendIntentIfCompleted(Context context, Uri contentUri, int status) {
     * completed.
     */
    public static void sendIntentIfCompleted(Context context, Uri contentUri, int status) {
        if (BluetoothShare.isStatusCompleted(status)) {
        if (BluetoothShare.isStatusCompleted(status)) {
            Intent intent = new Intent(BluetoothShare.TRANSFER_COMPLETED_ACTION);
            Intent intent = new Intent(BluetoothShare.TRANSFER_COMPLETED_ACTION);
            intent.setClassName(THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
            intent.setClassName(THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
@@ -297,7 +240,7 @@ public class Constants {
        }
        }
    }
    }


    public static boolean mimeTypeMatches(String mimeType, String[] matchAgainst) {
    static boolean mimeTypeMatches(String mimeType, String[] matchAgainst) {
        for (String matchType : matchAgainst) {
        for (String matchType : matchAgainst) {
            if (mimeTypeMatches(mimeType, matchType)) {
            if (mimeTypeMatches(mimeType, matchType)) {
                return true;
                return true;
@@ -306,16 +249,15 @@ public class Constants {
        return false;
        return false;
    }
    }


    public static boolean mimeTypeMatches(String mimeType, String matchAgainst) {
    private static boolean mimeTypeMatches(String mimeType, String matchAgainst) {
        Pattern p =
        Pattern p =
                Pattern.compile(matchAgainst.replaceAll("\\*", "\\.\\*"), Pattern.CASE_INSENSITIVE);
                Pattern.compile(matchAgainst.replaceAll("\\*", "\\.\\*"), Pattern.CASE_INSENSITIVE);
        return p.matcher(mimeType).matches();
        return p.matcher(mimeType).matches();
    }
    }


    public static void logHeader(HeaderSet hs) {
    static void logHeader(HeaderSet hs) {
        Log.v(TAG, "Dumping HeaderSet " + hs.toString());
        Log.v(TAG, "Dumping HeaderSet " + hs.toString());
        try {
        try {

            Log.v(TAG, "COUNT : " + hs.getHeader(HeaderSet.COUNT));
            Log.v(TAG, "COUNT : " + hs.getHeader(HeaderSet.COUNT));
            Log.v(TAG, "NAME : " + hs.getHeader(HeaderSet.NAME));
            Log.v(TAG, "NAME : " + hs.getHeader(HeaderSet.NAME));
            Log.v(TAG, "TYPE : " + hs.getHeader(HeaderSet.TYPE));
            Log.v(TAG, "TYPE : " + hs.getHeader(HeaderSet.TYPE));