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

Commit af686c85 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Opp: Replace "direction" usages with a constant

There are many places that uses a string value "direction" to get/set
an intent extra.

This CL makes the code more readable by defining a new constant for
intent extra key - but with a different value.

Bug: 318610752
Test: atest BluetoothOppReceiverTest BluetoothOppTransferHistoryTest
Flag: EXEMPT, string value change
Change-Id: Ic9bc8609240f0d09ad2b47186f3918b83c3c1f21
parent d5126d4b
Loading
Loading
Loading
Loading
+12 −28
Original line number Diff line number Diff line
/*
 * Copyright (c) 2008-2009, Motorola, Inc.
 * Copyright (C) 2024 The Android Open Source Project
 *
 * All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * - Neither the name of the Motorola, Inc. nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.opp;
@@ -161,7 +145,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {

            Intent in = new Intent(context, BluetoothOppTransferHistory.class);
            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            in.putExtra("direction", BluetoothShare.DIRECTION_OUTBOUND);
            in.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
            context.startActivity(in);
        } else if (action.equals(Constants.ACTION_OPEN_INBOUND_TRANSFER)) {
            if (V) {
@@ -170,7 +154,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {

            Intent in = new Intent(context, BluetoothOppTransferHistory.class);
            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            in.putExtra("direction", BluetoothShare.DIRECTION_INBOUND);
            in.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND);
            context.startActivity(in);
        } else if (action.equals(Constants.ACTION_HIDE)) {
            if (V) {
+11 −27
Original line number Diff line number Diff line
/*
 * Copyright (c) 2008-2009, Motorola, Inc.
 * Copyright (C) 2024 The Android Open Source Project
 *
 * All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * - Neither the name of the Motorola, Inc. nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.opp;
@@ -93,7 +77,7 @@ public class BluetoothOppTransferHistory extends Activity
        mShowAllIncoming = getIntent().getBooleanExtra(Constants.EXTRA_SHOW_ALL_FILES, false);

        String direction;
        int dir = getIntent().getIntExtra("direction", 0);
        int dir = getIntent().getIntExtra(Constants.EXTRA_DIRECTION, 0);
        if (dir == BluetoothShare.DIRECTION_OUTBOUND) {
            setTitle(getText(R.string.outbound_history_title));
            direction = "(" + BluetoothShare.DIRECTION + " == " + BluetoothShare.DIRECTION_OUTBOUND
+16 −26
Original line number Diff line number Diff line
/*
 * Copyright (c) 2008-2009, Motorola, Inc.
 * Copyright (C) 2024 The Android Open Source Project
 *
 * All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * - Neither the name of the Motorola, Inc. nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.opp;
@@ -76,6 +60,12 @@ public class Constants {
    /** the intent that can be sent by handover requesters to stop a BTOPP transfer */
    static final String ACTION_STOP_HANDOVER = "android.btopp.intent.action.STOP_HANDOVER_TRANSFER";

    /**
     * the intent extra to show the direction of a transfer. Value should be one of {@link
     * BluetoothShare#DIRECTION_INBOUND} or {@link BluetoothShare#DIRECTION_OUTBOUND}
     */
    static final String EXTRA_DIRECTION = "android.btopp.intent.extra.DIRECTION";

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

+2 −2
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public class BluetoothOppReceiverTest {

        mReceiver.onReceive(mContext, intent);
        intended(hasComponent(BluetoothOppTransferHistory.class.getName()));
        intended(hasExtra("direction", BluetoothShare.DIRECTION_OUTBOUND));
        intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND));
    }

    @Test
@@ -173,7 +173,7 @@ public class BluetoothOppReceiverTest {
                new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent()));
        mReceiver.onReceive(mContext, intent);
        intended(hasComponent(BluetoothOppTransferHistory.class.getName()));
        intended(hasExtra("direction", BluetoothShare.DIRECTION_INBOUND));
        intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND));
    }

    @Test
+4 −4
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ public class BluetoothOppTransferHistoryTest {

        BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList);
        mIntent.putExtra(Constants.EXTRA_SHOW_ALL_FILES, true);
        mIntent.putExtra("direction", BluetoothShare.DIRECTION_INBOUND);
        mIntent.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND);
        ActivityScenario<BluetoothOppTransferHistory> scenario = ActivityScenario.launch(mIntent);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();

@@ -159,7 +159,7 @@ public class BluetoothOppTransferHistoryTest {

        BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList);
        mIntent.putExtra(Constants.EXTRA_SHOW_ALL_FILES, false);
        mIntent.putExtra("direction", BluetoothShare.DIRECTION_INBOUND);
        mIntent.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND);

        ActivityScenario<BluetoothOppTransferHistory> scenario = ActivityScenario.launch(mIntent);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
@@ -178,7 +178,7 @@ public class BluetoothOppTransferHistoryTest {
                new BluetoothOppTestUtils.CursorMockData(BluetoothShare.DIRECTION, 2,
                        BluetoothShare.DIRECTION_OUTBOUND));
        mIntent.putExtra(Constants.EXTRA_SHOW_ALL_FILES, true);
        mIntent.putExtra("direction", BluetoothShare.DIRECTION_OUTBOUND);
        mIntent.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);

        ActivityScenario<BluetoothOppTransferHistory> scenario = ActivityScenario.launch(mIntent);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
@@ -193,7 +193,7 @@ public class BluetoothOppTransferHistoryTest {
    public void onOptionsItemSelected_clearAllSelected_promptWarning() {
        BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList);
        mIntent.putExtra(Constants.EXTRA_SHOW_ALL_FILES, false);
        mIntent.putExtra("direction", BluetoothShare.DIRECTION_INBOUND);
        mIntent.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND);

        ActivityScenario<BluetoothOppTransferHistory> scenario = ActivityScenario.launch(mIntent);