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

Commit e60845e0 authored by Sal Savage's avatar Sal Savage
Browse files

Refactor OPP logging to be unguarded

With the recent addition of a process minimum default log level, the
Android Log framework will now enforce the set log level against the
various log invocations we make in code. We no longer need to guard log
invocations on our own.

Tag: #refactor
Flag: EXEMPT, logging only change
Bug: 315046089
Test: atest BluetoothInstrumentationTests
Change-Id: Ia521b010984c05bc5adf031084acb470e103b256
parent 8bfc653f
Loading
Loading
Loading
Loading
+3 −10
Original line number Original line Diff line number Diff line
@@ -60,7 +60,6 @@ import java.util.ArrayList;


public class BluetoothOppBatch {
public class BluetoothOppBatch {
    private static final String TAG = "BtOppBatch";
    private static final String TAG = "BtOppBatch";
    private static final boolean V = Constants.VERBOSE;


    public int mId;
    public int mId;
    public int mStatus;
    public int mStatus;
@@ -111,10 +110,8 @@ public class BluetoothOppBatch {
        mStatus = Constants.BATCH_STATUS_PENDING;
        mStatus = Constants.BATCH_STATUS_PENDING;
        mShares.add(info);
        mShares.add(info);


        if (V) {
        Log.v(TAG, "New Batch created for info " + info.mId);
        Log.v(TAG, "New Batch created for info " + info.mId);
    }
    }
    }


    /**
    /**
     * Add one share into the batch.
     * Add one share into the batch.
@@ -137,9 +134,7 @@ public class BluetoothOppBatch {
     * 3) update ContentProvider for these canceled transfer
     * 3) update ContentProvider for these canceled transfer
     */
     */
    public void cancelBatch() {
    public void cancelBatch() {
        if (V) {
        Log.v(TAG, "batch " + this.mId + " is canceled");
        Log.v(TAG, "batch " + this.mId + " is canceled");
        }


        if (mListener != null) {
        if (mListener != null) {
            mListener.onBatchCanceled();
            mListener.onBatchCanceled();
@@ -154,9 +149,7 @@ public class BluetoothOppBatch {
                            mContext.getContentResolver(), info.mUri, null, null
                            mContext.getContentResolver(), info.mUri, null, null
                    );
                    );
                }
                }
                if (V) {
                Log.v(TAG, "Cancel batch for info " + info.mId);
                Log.v(TAG, "Cancel batch for info " + info.mId);
                }


                Constants.updateShareStatus(mContext, info.mId, BluetoothShare.STATUS_CANCELED);
                Constants.updateShareStatus(mContext, info.mId, BluetoothShare.STATUS_CANCELED);
            }
            }
+3 −11
Original line number Original line Diff line number Diff line
@@ -58,9 +58,7 @@ import com.android.internal.annotations.VisibleForTesting;
public class BluetoothOppBtEnablingActivity extends AlertActivity {
public class BluetoothOppBtEnablingActivity extends AlertActivity {
    private static final String TAG = "BluetoothOppEnablingActivity";
    private static final String TAG = "BluetoothOppEnablingActivity";


    private static final boolean D = Constants.DEBUG;


    private static final boolean V = Constants.VERBOSE;


    private static final int BT_ENABLING_TIMEOUT = 0;
    private static final int BT_ENABLING_TIMEOUT = 0;


@@ -106,9 +104,7 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {
    @Override
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (D) {
            Log.d(TAG, "onKeyDown() called; Key: back key");
            Log.d(TAG, "onKeyDown() called; Key: back key");
            }
            mTimeoutHandler.removeMessages(BT_ENABLING_TIMEOUT);
            mTimeoutHandler.removeMessages(BT_ENABLING_TIMEOUT);
            cancelSendingProgress();
            cancelSendingProgress();
        }
        }
@@ -129,9 +125,7 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {
        public void handleMessage(Message msg) {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            switch (msg.what) {
                case BT_ENABLING_TIMEOUT:
                case BT_ENABLING_TIMEOUT:
                    if (V) {
                    Log.v(TAG, "Received BT_ENABLING_TIMEOUT msg.");
                    Log.v(TAG, "Received BT_ENABLING_TIMEOUT msg.");
                    }
                    cancelSendingProgress();
                    cancelSendingProgress();
                    break;
                    break;
                default:
                default:
@@ -145,9 +139,7 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            String action = intent.getAction();
            if (V) {
            Log.v(TAG, "Received intent: " + action);
            Log.v(TAG, "Received intent: " + action);
            }
            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
                switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
                switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
                    case BluetoothAdapter.STATE_ON:
                    case BluetoothAdapter.STATE_ON:
+6 −17
Original line number Original line Diff line number Diff line
@@ -31,21 +31,18 @@ import java.util.ArrayList;


public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
    public static final String TAG = "BluetoothOppHandoverReceiver";
    public static final String TAG = "BluetoothOppHandoverReceiver";
    private static final boolean D = Constants.DEBUG;


    @Override
    @Override
    public void onReceive(Context context, Intent intent) {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        String action = intent.getAction();
        if (D) Log.d(TAG, "Action :" + action);
        Log.d(TAG, "Action :" + action);
        if (action == null) return;
        if (action == null) return;
        if (action.equals(Constants.ACTION_HANDOVER_SEND) || action.equals(
        if (action.equals(Constants.ACTION_HANDOVER_SEND) || action.equals(
                Constants.ACTION_HANDOVER_SEND_MULTIPLE)) {
                Constants.ACTION_HANDOVER_SEND_MULTIPLE)) {
            final BluetoothDevice device =
            final BluetoothDevice device =
                    (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if (device == null) {
            if (device == null) {
                if (D) {
                Log.d(TAG, "No device attached to handover intent.");
                Log.d(TAG, "No device attached to handover intent.");
                }
                return;
                return;
            }
            }


@@ -74,9 +71,7 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
                });
                });
                t.start();
                t.start();
            } else {
            } else {
                if (D) {
                Log.d(TAG, "No mimeType or stream attached to handover request");
                Log.d(TAG, "No mimeType or stream attached to handover request");
                }
                return;
                return;
            }
            }
        } else if (action.equals(Constants.ACTION_ACCEPTLIST_DEVICE)) {
        } else if (action.equals(Constants.ACTION_ACCEPTLIST_DEVICE)) {
@@ -89,26 +84,20 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
                    Flags.identityAddressNullIfUnknown()
                    Flags.identityAddressNullIfUnknown()
                            ? Utils.getBrEdrAddress(device)
                            ? Utils.getBrEdrAddress(device)
                            : device.getIdentityAddress();
                            : device.getIdentityAddress();
            if (D) {
            Log.d(TAG, "Adding " + brEdrAddress + " to acceptlist");
            Log.d(TAG, "Adding " + brEdrAddress + " to acceptlist");
            }
            BluetoothOppManager.getInstance(context).addToAcceptlist(brEdrAddress);
            BluetoothOppManager.getInstance(context).addToAcceptlist(brEdrAddress);
        } else if (action.equals(Constants.ACTION_STOP_HANDOVER)) {
        } else if (action.equals(Constants.ACTION_STOP_HANDOVER)) {
            int id = intent.getIntExtra(Constants.EXTRA_BT_OPP_TRANSFER_ID, -1);
            int id = intent.getIntExtra(Constants.EXTRA_BT_OPP_TRANSFER_ID, -1);
            if (id != -1) {
            if (id != -1) {
                Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);
                Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);


                if (D) {
                Log.d(TAG, "Stopping handover transfer with Uri " + contentUri);
                Log.d(TAG, "Stopping handover transfer with Uri " + contentUri);
                }
                BluetoothMethodProxy.getInstance().contentResolverDelete(
                BluetoothMethodProxy.getInstance().contentResolverDelete(
                        context.getContentResolver(), contentUri, null, null);
                        context.getContentResolver(), contentUri, null, null);
            }
            }
        } else {
        } else {
            if (D) {
            Log.d(TAG, "Unknown action: " + action);
            Log.d(TAG, "Unknown action: " + action);
        }
        }
    }
    }
    }


}
}
+8 −26
Original line number Original line Diff line number Diff line
@@ -64,8 +64,6 @@ import com.android.internal.annotations.VisibleForTesting;
// Next tag value for ContentProfileErrorReportUtils.report(): 1
// Next tag value for ContentProfileErrorReportUtils.report(): 1
public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
    private static final String TAG = "BluetoothIncomingFileConfirmActivity";
    private static final String TAG = "BluetoothIncomingFileConfirmActivity";
    private static final boolean D = Constants.DEBUG;
    private static final boolean V = Constants.VERBOSE;


    @VisibleForTesting
    @VisibleForTesting
    static final int DISMISS_TIMEOUT_DIALOG = 0;
    static final int DISMISS_TIMEOUT_DIALOG = 0;
@@ -88,9 +86,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
    @Override
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.Theme_Material_Settings_Floating);
        setTheme(R.style.Theme_Material_Settings_Floating);
        if (V) {
        Log.v(TAG, "onCreate(): action = " + getIntent().getAction());
            Log.d(TAG, "onCreate(): action = " + getIntent().getAction());
        }
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);


        getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
        getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
@@ -99,9 +95,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
        mTransInfo = new BluetoothOppTransferInfo();
        mTransInfo = new BluetoothOppTransferInfo();
        mTransInfo = BluetoothOppUtility.queryRecord(this, mUri);
        mTransInfo = BluetoothOppUtility.queryRecord(this, mUri);
        if (mTransInfo == null) {
        if (mTransInfo == null) {
            if (V) {
            Log.w(TAG, "Error: Can not get data from db");
                Log.e(TAG, "Error: Can not get data from db");
            }
            ContentProfileErrorReportUtils.report(
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.OPP,
                    BluetoothProfile.OPP,
                    BluetoothProtoEnums.BLUETOOTH_OPP_INCOMING_FILE_CONFIRM_ACTIVITY,
                    BluetoothProtoEnums.BLUETOOTH_OPP_INCOMING_FILE_CONFIRM_ACTIVITY,
@@ -119,16 +113,12 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
                (dialog, which) -> onIncomingFileConfirmCancel());
                (dialog, which) -> onIncomingFileConfirmCancel());


        setupAlert();
        setupAlert();
        if (V) {
        Log.v(TAG, "mTimeout: " + mTimeout);
        Log.v(TAG, "mTimeout: " + mTimeout);
        }
        if (mTimeout) {
        if (mTimeout) {
            onTimeout();
            onTimeout();
        }
        }


        if (V) {
        Log.v(TAG, "BluetoothIncomingFileConfirmActivity: Got uri:" + mUri);
        Log.v(TAG, "BluetoothIncomingFileConfirmActivity: Got uri:" + mUri);
        }


        mReceiver = new BroadcastReceiver() {
        mReceiver = new BroadcastReceiver() {
            @Override
            @Override
@@ -187,9 +177,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
    @Override
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (D) {
            Log.d(TAG, "onKeyDown() called; Key: back key");
            Log.d(TAG, "onKeyDown() called; Key: back key");
            }
            finish();
            finish();
            return true;
            return true;
        }
        }
@@ -208,9 +196,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        super.onRestoreInstanceState(savedInstanceState);
        mTimeout = savedInstanceState.getBoolean(PREFERENCE_USER_TIMEOUT);
        mTimeout = savedInstanceState.getBoolean(PREFERENCE_USER_TIMEOUT);
        if (V) {
        Log.v(TAG, "onRestoreInstanceState() mTimeout: " + mTimeout);
        Log.v(TAG, "onRestoreInstanceState() mTimeout: " + mTimeout);
        }
        if (mTimeout) {
        if (mTimeout) {
            onTimeout();
            onTimeout();
        }
        }
@@ -219,9 +205,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
    @Override
    @Override
    protected void onSaveInstanceState(Bundle outState) {
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        super.onSaveInstanceState(outState);
        if (V) {
        Log.v(TAG, "onSaveInstanceState() mTimeout: " + mTimeout);
        Log.v(TAG, "onSaveInstanceState() mTimeout: " + mTimeout);
        }
        outState.putBoolean(PREFERENCE_USER_TIMEOUT, mTimeout);
        outState.putBoolean(PREFERENCE_USER_TIMEOUT, mTimeout);
    }
    }


@@ -245,9 +229,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
        public void handleMessage(Message msg) {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            switch (msg.what) {
                case DISMISS_TIMEOUT_DIALOG:
                case DISMISS_TIMEOUT_DIALOG:
                    if (V) {
                    Log.v(TAG, "Received DISMISS_TIMEOUT_DIALOG msg.");
                    Log.v(TAG, "Received DISMISS_TIMEOUT_DIALOG msg.");
                    }
                    finish();
                    finish();
                    break;
                    break;
                default:
                default:
+12 −30
Original line number Original line Diff line number Diff line
@@ -71,8 +71,6 @@ import java.util.regex.Pattern;
// Next tag value for ContentProfileErrorReportUtils.report(): 11
// Next tag value for ContentProfileErrorReportUtils.report(): 11
public class BluetoothOppLauncherActivity extends Activity {
public class BluetoothOppLauncherActivity extends Activity {
    private static final String TAG = "BluetoothOppLauncherActivity";
    private static final String TAG = "BluetoothOppLauncherActivity";
    private static final boolean D = Constants.DEBUG;
    private static final boolean V = Constants.VERBOSE;


    // Regex that matches characters that have special meaning in HTML. '<', '>', '&' and
    // Regex that matches characters that have special meaning in HTML. '<', '>', '&' and
    // multiple continuous spaces.
    // multiple continuous spaces.
@@ -124,10 +122,8 @@ public class BluetoothOppLauncherActivity extends Activity {
                // EXTRA_TEXT, we will try send this TEXT out; Currently in
                // EXTRA_TEXT, we will try send this TEXT out; Currently in
                // Browser, share one link goes to this case;
                // Browser, share one link goes to this case;
                if (stream != null && type != null) {
                if (stream != null && type != null) {
                    if (V) {
                    Log.v(TAG,
                    Log.v(TAG,
                            "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = " + type);
                            "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = " + type);
                    }
                    // Save type/stream, will be used when adding transfer
                    // Save type/stream, will be used when adding transfer
                    // session to DB.
                    // session to DB.
                    Thread t = new Thread(new Runnable() {
                    Thread t = new Thread(new Runnable() {
@@ -140,11 +136,9 @@ public class BluetoothOppLauncherActivity extends Activity {
                    t.start();
                    t.start();
                    return;
                    return;
                } else if (extraText != null && type != null) {
                } else if (extraText != null && type != null) {
                    if (V) {
                    Log.v(TAG,
                    Log.v(TAG,
                            "Get ACTION_SEND intent with Extra_text = " + extraText.toString()
                            "Get ACTION_SEND intent with Extra_text = " + extraText.toString()
                                    + "; mimetype = " + type);
                                    + "; mimetype = " + type);
                    }
                    final Uri fileUri = createFileForSharedContent(
                    final Uri fileUri = createFileForSharedContent(
                            this.createCredentialProtectedStorageContext(), extraText);
                            this.createCredentialProtectedStorageContext(), extraText);
                    if (fileUri != null) {
                    if (fileUri != null) {
@@ -183,10 +177,8 @@ public class BluetoothOppLauncherActivity extends Activity {
                final String mimeType = intent.getType();
                final String mimeType = intent.getType();
                final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                if (mimeType != null && uris != null) {
                if (mimeType != null && uris != null) {
                    if (V) {
                    Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= "
                    Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= "
                            + mimeType);
                            + mimeType);
                    }
                    Thread t =
                    Thread t =
                            new Thread(
                            new Thread(
                                    new Runnable() {
                                    new Runnable() {
@@ -233,9 +225,7 @@ public class BluetoothOppLauncherActivity extends Activity {
            }
            }
        } else if (action.equals(Constants.ACTION_OPEN)) {
        } else if (action.equals(Constants.ACTION_OPEN)) {
            Uri uri = getIntent().getData();
            Uri uri = getIntent().getData();
            if (V) {
            Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri);
            Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri);
            }
            Intent intent1 = new Intent(Constants.ACTION_OPEN);
            Intent intent1 = new Intent(Constants.ACTION_OPEN);
            intent1.setClassName(this, BluetoothOppReceiver.class.getName());
            intent1.setClassName(this, BluetoothOppReceiver.class.getName());
            intent1.setDataAndNormalize(uri);
            intent1.setDataAndNormalize(uri);
@@ -265,16 +255,12 @@ public class BluetoothOppLauncherActivity extends Activity {
        // directly,
        // directly,
        // and let DevicePickerActivity to handle Bluetooth Enable.
        // and let DevicePickerActivity to handle Bluetooth Enable.
        if (!BluetoothOppManager.getInstance(this).isEnabled()) {
        if (!BluetoothOppManager.getInstance(this).isEnabled()) {
            if (V) {
            Log.v(TAG, "Prepare Enable BT!! ");
            Log.v(TAG, "Prepare Enable BT!! ");
            }
            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);
            startActivity(in);
            startActivity(in);
        } else {
        } else {
            if (V) {
            Log.v(TAG, "BT already enabled!! ");
            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);
            in1.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false);
            in1.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false);
@@ -283,9 +269,7 @@ public class BluetoothOppLauncherActivity extends Activity {
            in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE, getPackageName());
            in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE, getPackageName());
            in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS,
            in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS,
                    BluetoothOppReceiver.class.getName());
                    BluetoothOppReceiver.class.getName());
            if (V) {
            Log.v(TAG, "Launching " + BluetoothDevicePicker.ACTION_LAUNCH);
                Log.d(TAG, "Launching " + BluetoothDevicePicker.ACTION_LAUNCH);
            }
            startActivity(in1);
            startActivity(in1);
        }
        }
    }
    }
@@ -394,11 +378,9 @@ public class BluetoothOppLauncherActivity extends Activity {
                outStream.write(byteBuff, 0, byteBuff.length);
                outStream.write(byteBuff, 0, byteBuff.length);
                fileUri = Uri.fromFile(new File(context.getFilesDir(), fileName));
                fileUri = Uri.fromFile(new File(context.getFilesDir(), fileName));
                if (fileUri != null) {
                if (fileUri != null) {
                    if (D) {
                    Log.d(TAG, "Created one file for shared content: " + fileUri.toString());
                    Log.d(TAG, "Created one file for shared content: " + fileUri.toString());
                }
                }
            }
            }
            }
        } catch (FileNotFoundException e) {
        } catch (FileNotFoundException e) {
            ContentProfileErrorReportUtils.report(
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.OPP,
                    BluetoothProfile.OPP,
Loading