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

Commit 4b13fb36 authored by Yiyi Shen's avatar Yiyi Shen
Browse files

[Audiosharing] Add activity skeleton to handle new connected sink

Test: atest
Flag: com.android.settingslib.flags.promote_audio_sharing_for_second_auto_connected_lea_device
Bug: 395786392
Change-Id: Iff1378af8d9a8aa50ccd02b92630541acb24a1ad
parent 29234e59
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 The Android Open Source Project
     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
          http://www.apache.org/licenses/LICENSE-2.0
     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.
-->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:key="audio_sharing_join_handler"
    settings:searchable="false"
    settings:controller="com.android.settings.connecteddevice.audiosharing.AudioSharingJoinHandlerController" />
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.settings.connecteddevice.audiosharing;

import com.android.settings.SettingsActivity;

public class AudioSharingJoinHandlerActivity extends SettingsActivity {
    private static final String TAG = "AudioSharingJoinHandlerActivity";

    @Override
    protected boolean isToolbarEnabled() {
        return false;
    }

    @Override
    protected boolean isValidFragment(String fragmentName) {
        return AudioSharingJoinHandlerDashboardFragment.class.getName().equals(fragmentName);
    }
}
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.settings.connecteddevice.audiosharing;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;

import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.flags.Flags;

public class AudioSharingJoinHandlerController extends BasePreferenceController
        implements DefaultLifecycleObserver {
    private static final String TAG = "AudioSharingJoinHandlerCtrl";
    private static final String KEY = "audio_sharing_join_handler";

    public AudioSharingJoinHandlerController(@NonNull Context context,
            @NonNull String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public int getAvailabilityStatus() {
        return (Flags.promoteAudioSharingForSecondAutoConnectedLeaDevice()
                && BluetoothUtils.isAudioSharingUIAvailable(mContext))
                ? AVAILABLE_UNSEARCHABLE
                : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    public String getPreferenceKey() {
        return KEY;
    }

    @Override
    public int getSliceHighlightMenuRes() {
        return 0;
    }
}
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.settings.connecteddevice.audiosharing;

import android.content.Context;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;

public class AudioSharingJoinHandlerDashboardFragment extends DashboardFragment {
    private static final String TAG = "AudioSharingJoinHandlerFrag";

    @Override
    public int getMetricsCategory() {
        // TODO: use real enum
        return 0;
    }

    @Override
    protected int getPreferenceScreenResId() {
        return R.xml.bluetooth_le_audio_sharing_join_handler;
    }

    @Override
    protected String getLogTag() {
        return TAG;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        use(AudioSharingJoinHandlerController.class);
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.settings.connecteddevice.audiosharing;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.spy;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class AudioSharingJoinHandlerActivityTest {
    @Rule
    public final MockitoRule mMockitoRule = MockitoJUnit.rule();

    private AudioSharingJoinHandlerActivity mActivity;

    @Before
    public void setUp() {
        mActivity = spy(Robolectric.buildActivity(AudioSharingJoinHandlerActivity.class).get());
    }

    @Test
    public void isValidFragment_returnsTrue() {
        assertThat(mActivity.isValidFragment(
                AudioSharingJoinHandlerDashboardFragment.class.getName())).isTrue();
    }

    @Test
    public void isValidFragment_returnsFalse() {
        assertThat(mActivity.isValidFragment("")).isFalse();
    }
}
Loading