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

Commit ba221ea5 authored by Kangping Dong's avatar Kangping Dong Committed by Gerrit Code Review
Browse files

Merge "[Thread] update Thread settings screen" into main

parents 1d591b26 ab7f48dc
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -12076,11 +12076,17 @@
    <!-- Title for Thread network preference [CHAR_LIMIT=60] -->
    <string name="thread_network_settings_title">Thread</string>
    <!-- Summary for Thread network preference. [CHAR_LIMIT=NONE]-->
    <string name="thread_network_settings_summary">Connect to compatible devices using Thread for a seamless smart home experience</string>
    <!-- Title for Thread network settings main switch [CHAR_LIMIT=60] -->
    <string name="thread_network_settings_main_switch_title">Use Thread</string>
    <!-- Summary for Thread network preference when airplane mode is enabled. [CHAR_LIMIT=NONE]-->
    <string name="thread_network_settings_summary_airplane_mode">Turn off airplane mode to use Thread</string>
    <!-- Title for Thread network settings footer [CHAR_LIMIT=NONE] -->
    <string name="thread_network_settings_footer_title">Thread helps connect your smart home devices, boosting efficiency, and performance.\n\nWhen enabled, this device is eligible to join a Thread network, allowing control of Matter supported devices through this phone.</string>
    <!-- Text for Thread network settings learn more link [CHAR_LIMIT=NONE] -->
    <string name="thread_network_settings_learn_more">Learn more about Thread</string>
    <!-- URL for Thread network settings learn more link [CHAR_LIMIT=NONE] -->
    <string name="thread_network_settings_learn_more_link" translatable="false">https://developers.home.google.com</string>
    <!-- Label for the camera use toggle [CHAR LIMIT=40] -->
    <string name="camera_toggle_title">Camera access</string>
+15 −13
Original line number Diff line number Diff line
@@ -54,12 +54,23 @@
        settings:keywords="@string/keywords_wifi_display_settings"/>

    <com.android.settingslib.RestrictedPreference
        android:fragment="com.android.settings.connecteddevice.threadnetwork.ThreadNetworkFragment"
        android:key="thread_network_settings"
        android:title="@string/thread_network_settings_title"
        android:icon="@*android:drawable/ic_thread_network"
        android:order="-5"
        settings:searchable="false"
        settings:controller="com.android.settings.connecteddevice.threadnetwork.ThreadNetworkFragmentController"
        settings:userRestriction="no_thread_network"
        settings:useAdminDisabledSummary="true"/>

    <com.android.settingslib.RestrictedPreference
        android:fragment="com.android.settings.print.PrintSettingsFragment"
        android:icon="@*android:drawable/ic_settings_print"
        android:key="connected_device_printing"
        android:title="@string/print_settings"
        android:order="-3"
        android:summary="@string/summary_placeholder"
        android:icon="@*android:drawable/ic_settings_print"
        android:fragment="com.android.settings.print.PrintSettingsFragment"
        android:order="-3"/>
        android:title="@string/print_settings" />

    <SwitchPreferenceCompat
        android:key="uwb_settings"
@@ -70,15 +81,6 @@
        settings:userRestriction="no_ultra_wideband_radio"
        settings:useAdminDisabledSummary="true"/>

    <com.android.settingslib.RestrictedSwitchPreference
        android:key="thread_network_settings"
        android:title="@string/thread_network_settings_title"
        android:order="110"
        android:summary="@string/summary_placeholder"
        settings:controller="com.android.settings.connecteddevice.threadnetwork.ThreadNetworkPreferenceController"
        settings:userRestriction="no_thread_network"
        settings:useAdminDisabledSummary="true"/>

    <PreferenceCategory
        android:key="dashboard_tile_placeholder"
        android:order="-8"/>
+33 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2024 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:title="@string/thread_network_settings_title">

    <com.android.settingslib.widget.MainSwitchPreference
        android:key="toggle_thread_network"
        android:title="@string/thread_network_settings_main_switch_title"
        settings:controller="com.android.settings.connecteddevice.threadnetwork.ThreadNetworkToggleController"/>

    <com.android.settingslib.widget.FooterPreference
        android:key="thread_network_settings_footer"
        android:title="@string/thread_network_settings_footer_title"
        android:selectable="false"
        settings:searchable="false"
        settings:controller="com.android.settings.connecteddevice.threadnetwork.ThreadNetworkFooterController"/>
</PreferenceScreen>
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.threadnetwork

import android.net.thread.ThreadNetworkController
import android.net.thread.ThreadNetworkController.StateCallback
import android.net.thread.ThreadNetworkException
import android.os.OutcomeReceiver
import androidx.annotation.VisibleForTesting
import java.util.concurrent.Executor

/**
 * A testable interface for [ThreadNetworkController] which is `final`.
 *
 * We are in a awkward situation that Android API guideline suggest `final` for API classes
 * while Robolectric test is being deprecated for platform testing (See
 * tests/robotests/new_tests_hook.sh). This force us to use "mockito-target-extended" but it's
 * conflicting with the default "mockito-target" which is somehow indirectly depended by the
 * `SettingsUnitTests` target.
 */
@VisibleForTesting
interface BaseThreadNetworkController {
    fun setEnabled(
        enabled: Boolean,
        executor: Executor,
        receiver: OutcomeReceiver<Void?, ThreadNetworkException>
    )

    fun registerStateCallback(executor: Executor, callback: StateCallback)

    fun unregisterStateCallback(callback: StateCallback)
}
 No newline at end of file
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.threadnetwork

import android.content.Context
import android.util.Log
import androidx.preference.PreferenceScreen
import com.android.settings.R
import com.android.settings.core.BasePreferenceController
import com.android.settingslib.HelpUtils
import com.android.settingslib.widget.FooterPreference

/**
 * The footer preference controller for Thread settings in
 * "Connected devices > Connection preferences > Thread".
 */
class ThreadNetworkFooterController(
    context: Context,
    preferenceKey: String
) : BasePreferenceController(context, preferenceKey) {
    override fun getAvailabilityStatus(): Int {
        // The thread_network_settings screen won't be displayed and it doesn't matter if this
        // controller always return AVAILABLE
        return AVAILABLE
    }

    override fun displayPreference(screen: PreferenceScreen) {
        val footer: FooterPreference? = screen.findPreference(KEY_PREFERENCE_FOOTER)
        if (footer != null) {
            footer.setLearnMoreAction { _ -> openLocaleLearnMoreLink() }
            footer.setLearnMoreText(mContext.getString(R.string.thread_network_settings_learn_more))
        }
    }

    private fun openLocaleLearnMoreLink() {
        val intent = HelpUtils.getHelpIntent(
            mContext,
            mContext.getString(R.string.thread_network_settings_learn_more_link),
            mContext::class.java.name
        )
        if (intent != null) {
            mContext.startActivity(intent)
        } else {
            Log.w(TAG, "HelpIntent is null")
        }
    }

    companion object {
        private const val TAG = "ThreadNetworkSettings"
        private const val KEY_PREFERENCE_FOOTER = "thread_network_settings_footer"
    }
}
Loading