diff options
author | SongFerngWang <songferngwang@google.com> | 2018-08-21 18:04:29 +0800 |
---|---|---|
committer | SongFerngWang <songferngwang@google.com> | 2018-08-24 10:56:02 +0800 |
commit | 8cfb4d59a95ed4fd8ea8c25b34ee2eebf325842f (patch) | |
tree | 23ad087c71bfba27e667c2be37f5a7183248670c /packages/SettingsLib/src/com/android/settingslib/Utils.java | |
parent | ea1e4131cc84031c3631ccf01ec4500754366642 (diff) |
Refactor SystemUI and add function in settingslib for service state
To make behavior consistent in the long run and refactor the code
into settingslib and call it from both Settings and SystemUI.
Bug: 110973964
Test: run testcase as below:
1. frameworks/base/packages/SettingsLib: -> ALL PASS
make RunSettingsLibRoboTests -j40
2. frameworks/base/packages/SystemUI: -> ALL PASS
atest frameworks/base/packages/SystemUI/tests/src/com/android/systemui
/statusbar/policy/NetworkControllerSignalTest.java
Change-Id: Ie8899dd5398a503b861557c222bbd93bd2049d10
Diffstat (limited to 'packages/SettingsLib/src/com/android/settingslib/Utils.java')
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/Utils.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/Utils.java b/packages/SettingsLib/src/com/android/settingslib/Utils.java index c789c5d848c4..6abe76a1e753 100644 --- a/packages/SettingsLib/src/com/android/settingslib/Utils.java +++ b/packages/SettingsLib/src/com/android/settingslib/Utils.java @@ -23,6 +23,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.print.PrintManager; import android.provider.Settings; +import android.telephony.ServiceState; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.UserIcons; @@ -391,4 +392,52 @@ public class Utils { || audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION; } + + /** + * Return the service state is in-service or not. + * To make behavior consistent with SystemUI and Settings/AboutPhone/SIM status UI + * + * @param serviceState Service state. {@link ServiceState} + */ + public static boolean isInService(ServiceState serviceState) { + if (serviceState == null) { + return false; + } + int state = getCombinedServiceState(serviceState); + if (state == ServiceState.STATE_POWER_OFF + || state == ServiceState.STATE_OUT_OF_SERVICE + || state == ServiceState.STATE_EMERGENCY_ONLY) { + return false; + } else { + return true; + } + } + + /** + * Return the combined service state. + * To make behavior consistent with SystemUI and Settings/AboutPhone/SIM status UI + * + * @param serviceState Service state. {@link ServiceState} + */ + public static int getCombinedServiceState(ServiceState serviceState) { + if (serviceState == null) { + return ServiceState.STATE_OUT_OF_SERVICE; + } + + // Consider the device to be in service if either voice or data + // service is available. Some SIM cards are marketed as data-only + // and do not support voice service, and on these SIM cards, we + // want to show signal bars for data service as well as the "no + // service" or "emergency calls only" text that indicates that voice + // is not available. + int state = serviceState.getState(); + int dataState = serviceState.getDataRegState(); + if (state == ServiceState.STATE_OUT_OF_SERVICE + || state == ServiceState.STATE_EMERGENCY_ONLY) { + if (dataState == ServiceState.STATE_IN_SERVICE) { + return ServiceState.STATE_IN_SERVICE; + } + } + return state; + } } |