[Catalyst] Create airplane mode preference
Bug: 375925972 Flag: com.android.settings.flags.catalyst_network_provider_and_internet_screen Test: Manual testing atest -c AirplaneModePreferenceTest atest -c VpnPreferenceControllerTest Change-Id: Icf0bb9dfc1a8bda7a001f2ad3c6d6b835c489c0d
This commit is contained in:
@@ -56,7 +56,7 @@
|
||||
settings:controller="com.android.settings.network.MobileNetworkSummaryController" />
|
||||
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="airplane_mode"
|
||||
android:key="airplane_mode_on"
|
||||
android:title="@string/airplane_mode"
|
||||
android:icon="@drawable/ic_airplanemode_active"
|
||||
android:order="-5"
|
||||
|
42
src/com/android/settings/network/AirplaneModePreference.kt
Normal file
42
src/com/android/settings/network/AirplaneModePreference.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.network
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.provider.Settings.Global.AIRPLANE_MODE_ON
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.android.settings.R
|
||||
import com.android.settingslib.datastore.SettingsGlobalStore
|
||||
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
|
||||
import com.android.settingslib.metadata.SwitchPreference
|
||||
|
||||
// LINT.IfChange
|
||||
class AirplaneModePreference :
|
||||
SwitchPreference(AIRPLANE_MODE_ON, R.string.airplane_mode),
|
||||
PreferenceAvailabilityProvider {
|
||||
|
||||
override val icon: Int
|
||||
@DrawableRes get() = R.drawable.ic_airplanemode_active
|
||||
|
||||
override fun storage(context: Context) = SettingsGlobalStore.get(context)
|
||||
|
||||
override fun isAvailable(context: Context) =
|
||||
(context.resources.getBoolean(R.bool.config_show_toggle_airplane)
|
||||
&& !context.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK))
|
||||
}
|
||||
// LINT.ThenChange(AirplaneModePreferenceController.java)
|
@@ -52,6 +52,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
// LINT.IfChange
|
||||
public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnResume, OnStop, OnDestroy,
|
||||
AirplaneModeEnabler.OnAirplaneModeChangedListener {
|
||||
@@ -217,3 +218,4 @@ public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
}
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(AirplaneModePreference.kt)
|
||||
|
@@ -26,7 +26,6 @@ import android.net.VpnManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.security.Credentials;
|
||||
import android.security.LegacyVpnProfileStore;
|
||||
import android.util.Log;
|
||||
@@ -39,7 +38,6 @@ import com.android.internal.net.LegacyVpnInfo;
|
||||
import com.android.internal.net.VpnConfig;
|
||||
import com.android.internal.net.VpnProfile;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.vpn2.VpnInfoPreference;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
@@ -50,7 +48,6 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class VpnPreferenceController extends AbstractPreferenceController
|
||||
@@ -87,7 +84,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
||||
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
// Manually set dependencies for Wifi when not toggleable.
|
||||
if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
|
||||
preference.setDependency(SettingsSlicesContract.KEY_AIRPLANE_MODE);
|
||||
preference.setDependency(Settings.Global.AIRPLANE_MODE_ON);
|
||||
}
|
||||
return preference;
|
||||
}
|
||||
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.network
|
||||
|
||||
import android.content.ContextWrapper
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.FEATURE_LEANBACK
|
||||
import android.content.res.Resources
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.stub
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AirplaneModePreferenceTest {
|
||||
|
||||
private val mockPackageManager = mock<PackageManager>()
|
||||
private val mockResources = mock<Resources>()
|
||||
|
||||
private val context =
|
||||
object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
|
||||
override fun getPackageManager(): PackageManager = mockPackageManager
|
||||
|
||||
override fun getResources(): Resources = mockResources
|
||||
}
|
||||
|
||||
private val airplaneModePreference = AirplaneModePreference()
|
||||
|
||||
@Test
|
||||
fun isAvailable_hasConfigAndNoFeatureLeanback_shouldReturnTrue() {
|
||||
mockResources.stub { on { getBoolean(anyInt()) } doReturn true }
|
||||
mockPackageManager.stub { on { hasSystemFeature(FEATURE_LEANBACK) } doReturn false }
|
||||
|
||||
assertThat(airplaneModePreference.isAvailable(context)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isAvailable_noConfig_shouldReturnFalse() {
|
||||
mockResources.stub { on { getBoolean(anyInt()) } doReturn false }
|
||||
mockPackageManager.stub { on { hasSystemFeature(FEATURE_LEANBACK) } doReturn false }
|
||||
|
||||
assertThat(airplaneModePreference.isAvailable(context)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isAvailable_hasFeatureLeanback_shouldReturnFalse() {
|
||||
mockResources.stub { on { getBoolean(anyInt()) } doReturn true }
|
||||
mockPackageManager.stub { on { hasSystemFeature(FEATURE_LEANBACK) } doReturn true }
|
||||
|
||||
assertThat(airplaneModePreference.isAvailable(context)).isFalse()
|
||||
}
|
||||
}
|
@@ -34,7 +34,6 @@ import android.net.VpnManager;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
@@ -102,7 +101,7 @@ public class VpnPreferenceControllerTest {
|
||||
|
||||
controller.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setDependency(SettingsSlicesContract.KEY_AIRPLANE_MODE);
|
||||
verify(mPreference).setDependency(Settings.Global.AIRPLANE_MODE_ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user