Create a Satellite SOS entry

- This is a entry to start Satellite SOS pagein mobile network page.

Flag: com.android.settings.flags.satellite_oem_settings_ux_migration
Fix: b/370509415
Test: atest pass
Change-Id: I3978513b15ad498b9b8ea298060d89fd35efc7ed
This commit is contained in:
tomhsu
2024-11-29 07:10:21 +00:00
parent 01043fdf93
commit 90092e7da4
6 changed files with 210 additions and 1 deletions

View File

@@ -12273,7 +12273,7 @@
<!-- Summary for _satellite_setting_preference_layout. [CHAR LIMIT=NONE]-->
<string name="satellite_setting_disabled_summary">Send and receive text messages by satellite. Not included with your account.</string>
<!-- Search keywords for "_satellite_setting_preference_layout" [CHAR_LIMIT=NONE] -->
<string name="keywords_satellite_setting">Satellite messaging</string>
<string name="keywords_satellite_setting">Satellite messaging, satellite connectivity</string>
<!-- Category name "About satellite messaging" [CHAR_LIMIT=NONE] -->
<string name="category_name_about_satellite_messaging">About <xliff:g id="subject" example="satellite messaging">%1$s</xliff:g></string>
<!-- Summary for category "About satellite messaging" [CHAR_LIMIT=NONE] -->
@@ -12314,6 +12314,12 @@
<string name="description_satellite_setting_messaging">satellite messaging</string>
<!-- Title for notifying user's account be able to use data transmission of Satellite" [CHAR_LIMIT=NONE] -->
<string name="title_have_satellite_data_plan">Use of data is included with your account</string>
<!-- Title for the entry of Satellite SOS [CHAR_LIMIT=NONE] -->
<string name="title_for_satellite_sos_entry">Satellite SOS</string>
<!-- Summary for the entry of Satellite SOS [CHAR_LIMIT=NONE] -->
<string name="summary_for_satellite_sos_entry">Message with emergency services when you can\u2019t connect to a mobile or Wi\u2011Fi network</string>
<!-- Keywords for the entry of Satellite SOS [CHAR_LIMIT=NONE] -->
<string name="keywords_satellite_sos">satellite sos, sos</string>

View File

@@ -217,6 +217,16 @@
settings:controller=
"com.android.settings.network.telephony.SatelliteSettingPreferenceController"/>
<com.android.settingslib.RestrictedPreference
android:key="telephony_satellite_setting_sos_key"
android:persistent="false"
android:title="@string/title_for_satellite_sos_entry"
android:summary="@string/summary_for_satellite_sos_entry"
settings:keywords="@string/keywords_satellite_setting"
settings:fragment="com.android.settings.network.telephony.SatelliteSettingsSosFragment"
settings:controller=
"com.android.settings.network.telephony.SatelliteSettingSosPreferenceController"/>
</PreferenceCategory>
<PreferenceCategory

View File

@@ -288,6 +288,11 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
if (satelliteSettingPreferenceController != null) {
satelliteSettingPreferenceController.init(mSubId);
}
final SatelliteSettingSosPreferenceController satelliteSettingSosPreferenceController = use(
SatelliteSettingSosPreferenceController.class);
if (satelliteSettingSosPreferenceController != null) {
satelliteSettingSosPreferenceController.init(mSubId);
}
use(ApnPreferenceController.class).init(mSubId);
use(CarrierPreferenceController.class).init(mSubId);
use(DataUsagePreferenceController.class).init(mSubId);

View File

@@ -0,0 +1,54 @@
/*
* 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.telephony;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ESOS_SUPPORTED_BOOL;
import android.content.Context;
import android.os.PersistableBundle;
import com.android.settings.flags.Flags;
import com.android.settings.network.CarrierConfigCache;
/** A controller for Satellite SOS entry preference. */
public class SatelliteSettingSosPreferenceController extends TelephonyBasePreferenceController {
private static final String TAG = "SatelliteSettingSosPrefController";
public SatelliteSettingSosPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
}
/** Setup the subscription Id for the UI with specific UI group. */
public void init(int subId) {
mSubId = subId;
}
@Override
public int getAvailabilityStatus(int subId) {
if (Flags.satelliteOemSettingsUxMigration()) {
CarrierConfigCache carrierConfigCache = CarrierConfigCache.getInstance(mContext);
PersistableBundle bundle = carrierConfigCache.getConfigForSubId(subId);
if (bundle == null) {
return CONDITIONALLY_UNAVAILABLE;
}
boolean isCarrierSupport = bundle.getBoolean(KEY_SATELLITE_ESOS_SUPPORTED_BOOL);
return isCarrierSupport ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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.telephony;
import com.android.settings.SettingsPreferenceFragment;
public class SatelliteSettingsSosFragment extends SettingsPreferenceFragment {
@Override
public int getMetricsCategory() {
return 0;
}
}

View File

@@ -0,0 +1,108 @@
/*
* 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.telephony;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
import android.os.PersistableBundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.telephony.CarrierConfigManager;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.telephony.flags.Flags;
import com.android.settings.network.CarrierConfigCache;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class SatelliteSettingsSosPreferenceControllerTest {
private static final String KEY = "key";
private static final int TEST_SUB_ID = 0;
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Mock
private CarrierConfigCache mCarrierConfigCache;
private Context mContext = null;
private SatelliteSettingSosPreferenceController mController = null;
private PersistableBundle mCarrierConfig = new PersistableBundle();
@Before
public void setUp() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
mContext = spy(ApplicationProvider.getApplicationContext());
mController = new SatelliteSettingSosPreferenceController(mContext, KEY);
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
}
@Test
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public void getAvailabilityStatus_carrierNotSupport_returnUnAvailable() {
mCarrierConfig.putBoolean(
CarrierConfigManager.KEY_SATELLITE_ESOS_SUPPORTED_BOOL,
false);
when(mCarrierConfigCache.getConfigForSubId(TEST_SUB_ID)).thenReturn(mCarrierConfig);
mController.init(TEST_SUB_ID);
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
assertThat(result).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public void getAvailabilityStatus_carrierSupported_returnAvailable() {
mCarrierConfig.putBoolean(
CarrierConfigManager.KEY_SATELLITE_ESOS_SUPPORTED_BOOL,
true);
when(mCarrierConfigCache.getConfigForSubId(TEST_SUB_ID)).thenReturn(mCarrierConfig);
mController.init(TEST_SUB_ID);
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
assertThat(result).isEqualTo(AVAILABLE);
}
@Test
@DisableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public void getAvailabilityStatus_featureDisabled_returnAvailable() {
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
assertThat(result).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
}