Snap for 9905984 from 8930e6ea87
to udc-release
Change-Id: I1050fedbfeca093a8cf098f66520a66c7c95e880
This commit is contained in:
@@ -14,11 +14,11 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layoutDirection="locale"
|
android:layoutDirection="locale"
|
||||||
android:textDirection="locale">
|
android:textDirection="locale">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -48,4 +48,4 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</FrameLayout>
|
||||||
|
@@ -871,9 +871,9 @@
|
|||||||
<string name="biometric_settings_use_face_or_fingerprint_preference_summary">Using face or fingerprint</string>
|
<string name="biometric_settings_use_face_or_fingerprint_preference_summary">Using face or fingerprint</string>
|
||||||
<!-- Button text shown during enrollment to proceed after a child user has handed the device to a parent or guardian. [CHAR LIMIT=22] -->
|
<!-- Button text shown during enrollment to proceed after a child user has handed the device to a parent or guardian. [CHAR LIMIT=22] -->
|
||||||
<string name="biometric_settings_hand_back_to_guardian_ok">OK</string>
|
<string name="biometric_settings_hand_back_to_guardian_ok">OK</string>
|
||||||
<!-- Dialog title for dialog which shows when trying to add fingerprint in split mode. [CHAR LIMIT=45] -->
|
<!-- Dialog title for dialog which shows when trying to add fingerprint in split mode. [CHAR LIMIT=80] -->
|
||||||
<string name="biometric_settings_add_fingerprint_in_split_mode_title">Can\u2019t set up fingerprint</string>
|
<string name="biometric_settings_add_fingerprint_in_split_mode_title">Can\u2019t set up fingerprint</string>
|
||||||
<!-- Dialog message for dialog which shows when trying to add fingerprint in split mode. [CHAR LIMIT=45] -->
|
<!-- Dialog message for dialog which shows when trying to add fingerprint in split mode. [CHAR LIMIT=NONE] -->
|
||||||
<string name="biometric_settings_add_fingerprint_in_split_mode_message">Exit split screen to set up Fingerprint Unlock</string>
|
<string name="biometric_settings_add_fingerprint_in_split_mode_message">Exit split screen to set up Fingerprint Unlock</string>
|
||||||
<!-- Button text shown in adding fingerprint dialog that allows the user to go back to the settings page [CHAR LIMIT=22] -->
|
<!-- Button text shown in adding fingerprint dialog that allows the user to go back to the settings page [CHAR LIMIT=22] -->
|
||||||
<string name="biometric_settings_add_fingerprint_in_split_mode_ok">OK</string>
|
<string name="biometric_settings_add_fingerprint_in_split_mode_ok">OK</string>
|
||||||
@@ -11524,9 +11524,12 @@
|
|||||||
<!-- Summary for UWB preference. [CHAR_LIMIT=NONE]-->
|
<!-- Summary for UWB preference. [CHAR_LIMIT=NONE]-->
|
||||||
<string name="uwb_settings_summary">Helps identify the relative position of nearby devices that have UWB</string>
|
<string name="uwb_settings_summary">Helps identify the relative position of nearby devices that have UWB</string>
|
||||||
|
|
||||||
<!-- Summary for UWB preference when airplane mode is disabled. [CHAR_LIMIT=NONE]-->
|
<!-- Summary for UWB preference when airplane mode is enabled. [CHAR_LIMIT=NONE]-->
|
||||||
<string name="uwb_settings_summary_airplane_mode">Turn off airplane mode to use UWB </string>
|
<string name="uwb_settings_summary_airplane_mode">Turn off airplane mode to use UWB </string>
|
||||||
|
|
||||||
|
<!-- Summary for UWB preference when UWB is unavailable due to regulatory requirements. [CHAR_LIMIT=NONE]-->
|
||||||
|
<string name="uwb_settings_summary_no_uwb_regulatory">UWB is unavailable in the current location</string>
|
||||||
|
|
||||||
<!-- Label for the camera use toggle [CHAR LIMIT=40] -->
|
<!-- Label for the camera use toggle [CHAR LIMIT=40] -->
|
||||||
<string name="camera_toggle_title">Camera access</string>
|
<string name="camera_toggle_title">Camera access</string>
|
||||||
<!-- Label for the camera use toggle [CHAR LIMIT=40] -->
|
<!-- Label for the camera use toggle [CHAR LIMIT=40] -->
|
||||||
|
@@ -1446,31 +1446,39 @@ public final class DataProcessor {
|
|||||||
final int workProfileUserId =
|
final int workProfileUserId =
|
||||||
userHandle != null ? userHandle.getIdentifier() : Integer.MIN_VALUE;
|
userHandle != null ? userHandle.getIdentifier() : Integer.MIN_VALUE;
|
||||||
// Each time slot usage diff data =
|
// Each time slot usage diff data =
|
||||||
// Math.abs(timestamp[i+2] data - timestamp[i+1] data) +
|
// sum(Math.abs(timestamp[i+1] data - timestamp[i] data));
|
||||||
// Math.abs(timestamp[i+1] data - timestamp[i] data);
|
// since we want to aggregate every hour usage diff data into a single time slot.
|
||||||
// since we want to aggregate every two hours data into a single time slot.
|
|
||||||
for (int dailyIndex = 0; dailyIndex < hourlyBatteryLevelsPerDay.size(); dailyIndex++) {
|
for (int dailyIndex = 0; dailyIndex < hourlyBatteryLevelsPerDay.size(); dailyIndex++) {
|
||||||
final Map<Integer, BatteryDiffData> dailyDiffMap = new ArrayMap<>();
|
final Map<Integer, BatteryDiffData> dailyDiffMap = new ArrayMap<>();
|
||||||
resultMap.put(dailyIndex, dailyDiffMap);
|
resultMap.put(dailyIndex, dailyDiffMap);
|
||||||
if (hourlyBatteryLevelsPerDay.get(dailyIndex) == null) {
|
if (hourlyBatteryLevelsPerDay.get(dailyIndex) == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final List<Long> timestamps = hourlyBatteryLevelsPerDay.get(dailyIndex).getTimestamps();
|
final List<Long> hourlyTimestamps =
|
||||||
for (int hourlyIndex = 0; hourlyIndex < timestamps.size() - 1; hourlyIndex++) {
|
hourlyBatteryLevelsPerDay.get(dailyIndex).getTimestamps();
|
||||||
|
for (int hourlyIndex = 0; hourlyIndex < hourlyTimestamps.size() - 1; hourlyIndex++) {
|
||||||
|
final Long startTimestamp = hourlyTimestamps.get(hourlyIndex);
|
||||||
|
final Long endTimestamp = hourlyTimestamps.get(hourlyIndex + 1);
|
||||||
|
final long slotDuration = endTimestamp - startTimestamp;
|
||||||
|
List<Map<String, BatteryHistEntry>> slotBatteryHistoryList = new ArrayList<>();
|
||||||
|
for (Long timestamp = startTimestamp; timestamp <= endTimestamp;
|
||||||
|
timestamp += DateUtils.HOUR_IN_MILLIS) {
|
||||||
|
slotBatteryHistoryList.add(
|
||||||
|
batteryHistoryMap.getOrDefault(timestamp, EMPTY_BATTERY_MAP));
|
||||||
|
}
|
||||||
final BatteryDiffData hourlyBatteryDiffData =
|
final BatteryDiffData hourlyBatteryDiffData =
|
||||||
insertHourlyUsageDiffDataPerSlot(
|
insertHourlyUsageDiffDataPerSlot(
|
||||||
context,
|
context,
|
||||||
currentUserId,
|
currentUserId,
|
||||||
workProfileUserId,
|
workProfileUserId,
|
||||||
hourlyIndex,
|
slotDuration,
|
||||||
timestamps,
|
|
||||||
systemAppsPackageNames,
|
systemAppsPackageNames,
|
||||||
systemAppsUids,
|
systemAppsUids,
|
||||||
appUsagePeriodMap == null
|
appUsagePeriodMap == null
|
||||||
|| appUsagePeriodMap.get(dailyIndex) == null
|
|| appUsagePeriodMap.get(dailyIndex) == null
|
||||||
? null
|
? null
|
||||||
: appUsagePeriodMap.get(dailyIndex).get(hourlyIndex),
|
: appUsagePeriodMap.get(dailyIndex).get(hourlyIndex),
|
||||||
batteryHistoryMap);
|
slotBatteryHistoryList);
|
||||||
dailyDiffMap.put(hourlyIndex, hourlyBatteryDiffData);
|
dailyDiffMap.put(hourlyIndex, hourlyBatteryDiffData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1508,54 +1516,42 @@ public final class DataProcessor {
|
|||||||
final Context context,
|
final Context context,
|
||||||
final int currentUserId,
|
final int currentUserId,
|
||||||
final int workProfileUserId,
|
final int workProfileUserId,
|
||||||
final int currentIndex,
|
final long slotDuration,
|
||||||
final List<Long> timestamps,
|
|
||||||
final Set<String> systemAppsPackageNames,
|
final Set<String> systemAppsPackageNames,
|
||||||
final Set<Integer> systemAppsUids,
|
final Set<Integer> systemAppsUids,
|
||||||
final Map<Long, Map<String, List<AppUsagePeriod>>> appUsageMap,
|
final Map<Long, Map<String, List<AppUsagePeriod>>> appUsageMap,
|
||||||
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
|
final List<Map<String, BatteryHistEntry>> slotBatteryHistoryList) {
|
||||||
final List<BatteryDiffEntry> appEntries = new ArrayList<>();
|
final List<BatteryDiffEntry> appEntries = new ArrayList<>();
|
||||||
final List<BatteryDiffEntry> systemEntries = new ArrayList<>();
|
final List<BatteryDiffEntry> systemEntries = new ArrayList<>();
|
||||||
|
|
||||||
final Long currentTimestamp = timestamps.get(currentIndex);
|
|
||||||
final Long nextTimestamp = currentTimestamp + DateUtils.HOUR_IN_MILLIS;
|
|
||||||
final Long nextTwoTimestamp = nextTimestamp + DateUtils.HOUR_IN_MILLIS;
|
|
||||||
// Fetches BatteryHistEntry data from corresponding time slot.
|
|
||||||
final Map<String, BatteryHistEntry> currentBatteryHistMap =
|
|
||||||
batteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
|
|
||||||
final Map<String, BatteryHistEntry> nextBatteryHistMap =
|
|
||||||
batteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
|
|
||||||
final Map<String, BatteryHistEntry> nextTwoBatteryHistMap =
|
|
||||||
batteryHistoryMap.getOrDefault(nextTwoTimestamp, EMPTY_BATTERY_MAP);
|
|
||||||
// We should not get the empty list since we have at least one fake data to record
|
|
||||||
// the battery level and status in each time slot, the empty list is used to
|
|
||||||
// represent there is no enough data to apply interpolation arithmetic.
|
|
||||||
if (currentBatteryHistMap.isEmpty()
|
|
||||||
|| nextBatteryHistMap.isEmpty()
|
|
||||||
|| nextTwoBatteryHistMap.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collects all keys in these three time slot records as all populations.
|
// Collects all keys in these three time slot records as all populations.
|
||||||
final Set<String> allBatteryHistEntryKeys = new ArraySet<>();
|
final Set<String> allBatteryHistEntryKeys = new ArraySet<>();
|
||||||
allBatteryHistEntryKeys.addAll(currentBatteryHistMap.keySet());
|
for (Map<String, BatteryHistEntry> slotBatteryHistMap : slotBatteryHistoryList) {
|
||||||
allBatteryHistEntryKeys.addAll(nextBatteryHistMap.keySet());
|
if (slotBatteryHistMap.isEmpty()) {
|
||||||
allBatteryHistEntryKeys.addAll(nextTwoBatteryHistMap.keySet());
|
// We should not get the empty list since we have at least one fake data to record
|
||||||
|
// the battery level and status in each time slot, the empty list is used to
|
||||||
|
// represent there is no enough data to apply interpolation arithmetic.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
allBatteryHistEntryKeys.addAll(slotBatteryHistMap.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
// Calculates all packages diff usage data in a specific time slot.
|
// Calculates all packages diff usage data in a specific time slot.
|
||||||
for (String key : allBatteryHistEntryKeys) {
|
for (String key : allBatteryHistEntryKeys) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final BatteryHistEntry currentEntry =
|
|
||||||
currentBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
|
|
||||||
final BatteryHistEntry nextEntry =
|
|
||||||
nextBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
|
|
||||||
final BatteryHistEntry nextTwoEntry =
|
|
||||||
nextTwoBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
|
|
||||||
|
|
||||||
final BatteryHistEntry selectedBatteryEntry =
|
BatteryHistEntry selectedBatteryEntry = null;
|
||||||
selectBatteryHistEntry(currentEntry, nextEntry, nextTwoEntry);
|
final List<BatteryHistEntry> batteryHistEntries = new ArrayList<>();
|
||||||
|
for (Map<String, BatteryHistEntry> slotBatteryHistMap : slotBatteryHistoryList) {
|
||||||
|
BatteryHistEntry entry =
|
||||||
|
slotBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
|
||||||
|
batteryHistEntries.add(entry);
|
||||||
|
if (selectedBatteryEntry == null && entry != EMPTY_BATTERY_HIST_ENTRY) {
|
||||||
|
selectedBatteryEntry = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (selectedBatteryEntry == null) {
|
if (selectedBatteryEntry == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1568,41 +1564,45 @@ public final class DataProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cumulative values is a specific time slot for a specific app.
|
// Cumulative values is a specific time slot for a specific app.
|
||||||
long foregroundUsageTimeInMs =
|
long foregroundUsageTimeInMs = 0;
|
||||||
getDiffValue(
|
long backgroundUsageTimeInMs = 0;
|
||||||
currentEntry.mForegroundUsageTimeInMs,
|
double consumePower = 0;
|
||||||
nextEntry.mForegroundUsageTimeInMs,
|
double foregroundUsageConsumePower = 0;
|
||||||
nextTwoEntry.mForegroundUsageTimeInMs);
|
double foregroundServiceUsageConsumePower = 0;
|
||||||
long backgroundUsageTimeInMs =
|
double backgroundUsageConsumePower = 0;
|
||||||
getDiffValue(
|
double cachedUsageConsumePower = 0;
|
||||||
currentEntry.mBackgroundUsageTimeInMs,
|
for (int i = 0; i < batteryHistEntries.size() - 1; i++) {
|
||||||
nextEntry.mBackgroundUsageTimeInMs,
|
final BatteryHistEntry currentEntry = batteryHistEntries.get(i);
|
||||||
nextTwoEntry.mBackgroundUsageTimeInMs);
|
final BatteryHistEntry nextEntry = batteryHistEntries.get(i + 1);
|
||||||
double consumePower =
|
foregroundUsageTimeInMs +=
|
||||||
getDiffValue(
|
getDiffValue(
|
||||||
currentEntry.mConsumePower,
|
currentEntry.mForegroundUsageTimeInMs,
|
||||||
nextEntry.mConsumePower,
|
nextEntry.mForegroundUsageTimeInMs);
|
||||||
nextTwoEntry.mConsumePower);
|
backgroundUsageTimeInMs +=
|
||||||
double foregroundUsageConsumePower =
|
getDiffValue(
|
||||||
getDiffValue(
|
currentEntry.mBackgroundUsageTimeInMs,
|
||||||
currentEntry.mForegroundUsageConsumePower,
|
nextEntry.mBackgroundUsageTimeInMs);
|
||||||
nextEntry.mForegroundUsageConsumePower,
|
consumePower +=
|
||||||
nextTwoEntry.mForegroundUsageConsumePower);
|
getDiffValue(
|
||||||
double foregroundServiceUsageConsumePower =
|
currentEntry.mConsumePower,
|
||||||
getDiffValue(
|
nextEntry.mConsumePower);
|
||||||
currentEntry.mForegroundServiceUsageConsumePower,
|
foregroundUsageConsumePower +=
|
||||||
nextEntry.mForegroundServiceUsageConsumePower,
|
getDiffValue(
|
||||||
nextTwoEntry.mForegroundServiceUsageConsumePower);
|
currentEntry.mForegroundUsageConsumePower,
|
||||||
double backgroundUsageConsumePower =
|
nextEntry.mForegroundUsageConsumePower);
|
||||||
getDiffValue(
|
foregroundServiceUsageConsumePower +=
|
||||||
currentEntry.mBackgroundUsageConsumePower,
|
getDiffValue(
|
||||||
nextEntry.mBackgroundUsageConsumePower,
|
currentEntry.mForegroundServiceUsageConsumePower,
|
||||||
nextTwoEntry.mBackgroundUsageConsumePower);
|
nextEntry.mForegroundServiceUsageConsumePower);
|
||||||
double cachedUsageConsumePower =
|
backgroundUsageConsumePower +=
|
||||||
getDiffValue(
|
getDiffValue(
|
||||||
currentEntry.mCachedUsageConsumePower,
|
currentEntry.mBackgroundUsageConsumePower,
|
||||||
nextEntry.mCachedUsageConsumePower,
|
nextEntry.mBackgroundUsageConsumePower);
|
||||||
nextTwoEntry.mCachedUsageConsumePower);
|
cachedUsageConsumePower +=
|
||||||
|
getDiffValue(
|
||||||
|
currentEntry.mCachedUsageConsumePower,
|
||||||
|
nextEntry.mCachedUsageConsumePower);
|
||||||
|
}
|
||||||
// Excludes entry since we don't have enough data to calculate.
|
// Excludes entry since we don't have enough data to calculate.
|
||||||
if (foregroundUsageTimeInMs == 0
|
if (foregroundUsageTimeInMs == 0
|
||||||
&& backgroundUsageTimeInMs == 0
|
&& backgroundUsageTimeInMs == 0
|
||||||
@@ -1613,13 +1613,13 @@ public final class DataProcessor {
|
|||||||
// will apply the interpolation arithmetic.
|
// will apply the interpolation arithmetic.
|
||||||
final float totalUsageTimeInMs =
|
final float totalUsageTimeInMs =
|
||||||
foregroundUsageTimeInMs + backgroundUsageTimeInMs;
|
foregroundUsageTimeInMs + backgroundUsageTimeInMs;
|
||||||
if (totalUsageTimeInMs > TOTAL_HOURLY_TIME_THRESHOLD) {
|
if (totalUsageTimeInMs > slotDuration) {
|
||||||
final float ratio = TOTAL_HOURLY_TIME_THRESHOLD / totalUsageTimeInMs;
|
final float ratio = slotDuration / totalUsageTimeInMs;
|
||||||
if (sDebug) {
|
if (sDebug) {
|
||||||
Log.w(TAG, String.format("abnormal usage time %d|%d for:\n%s",
|
Log.w(TAG, String.format("abnormal usage time %d|%d for:\n%s",
|
||||||
Duration.ofMillis(foregroundUsageTimeInMs).getSeconds(),
|
Duration.ofMillis(foregroundUsageTimeInMs).getSeconds(),
|
||||||
Duration.ofMillis(backgroundUsageTimeInMs).getSeconds(),
|
Duration.ofMillis(backgroundUsageTimeInMs).getSeconds(),
|
||||||
currentEntry));
|
selectedBatteryEntry));
|
||||||
}
|
}
|
||||||
foregroundUsageTimeInMs =
|
foregroundUsageTimeInMs =
|
||||||
Math.round(foregroundUsageTimeInMs * ratio);
|
Math.round(foregroundUsageTimeInMs * ratio);
|
||||||
@@ -1634,14 +1634,14 @@ public final class DataProcessor {
|
|||||||
|
|
||||||
// Compute the screen on time and make sure it won't exceed the threshold.
|
// Compute the screen on time and make sure it won't exceed the threshold.
|
||||||
final long screenOnTime = Math.min(
|
final long screenOnTime = Math.min(
|
||||||
(long) TOTAL_HOURLY_TIME_THRESHOLD,
|
(long) slotDuration,
|
||||||
getScreenOnTime(
|
getScreenOnTime(
|
||||||
appUsageMap,
|
appUsageMap,
|
||||||
selectedBatteryEntry.mUserId,
|
selectedBatteryEntry.mUserId,
|
||||||
selectedBatteryEntry.mPackageName));
|
selectedBatteryEntry.mPackageName));
|
||||||
// Make sure the background + screen-on time will not exceed the threshold.
|
// Make sure the background + screen-on time will not exceed the threshold.
|
||||||
backgroundUsageTimeInMs = Math.min(
|
backgroundUsageTimeInMs = Math.min(
|
||||||
backgroundUsageTimeInMs, (long) TOTAL_HOURLY_TIME_THRESHOLD - screenOnTime);
|
backgroundUsageTimeInMs, (long) slotDuration - screenOnTime);
|
||||||
final BatteryDiffEntry currentBatteryDiffEntry = new BatteryDiffEntry(
|
final BatteryDiffEntry currentBatteryDiffEntry = new BatteryDiffEntry(
|
||||||
context,
|
context,
|
||||||
foregroundUsageTimeInMs,
|
foregroundUsageTimeInMs,
|
||||||
@@ -1948,23 +1948,12 @@ public final class DataProcessor {
|
|||||||
return calendar.getTimeInMillis();
|
return calendar.getTimeInMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long getDiffValue(long v1, long v2, long v3) {
|
private static long getDiffValue(long v1, long v2) {
|
||||||
return (v2 > v1 ? v2 - v1 : 0) + (v3 > v2 ? v3 - v2 : 0);
|
return v2 > v1 ? v2 - v1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double getDiffValue(double v1, double v2, double v3) {
|
private static double getDiffValue(double v1, double v2) {
|
||||||
return (v2 > v1 ? v2 - v1 : 0) + (v3 > v2 ? v3 - v2 : 0);
|
return v2 > v1 ? v2 - v1 : 0;
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static BatteryHistEntry selectBatteryHistEntry(
|
|
||||||
final BatteryHistEntry... batteryHistEntries) {
|
|
||||||
for (BatteryHistEntry entry : batteryHistEntries) {
|
|
||||||
if (entry != null && entry != EMPTY_BATTERY_HIST_ENTRY) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> getSystemAppsPackageNames(Context context) {
|
private static Set<String> getSystemAppsPackageNames(Context context) {
|
||||||
|
@@ -329,6 +329,7 @@ public class LocaleListEditor extends RestrictedSettingsFragment {
|
|||||||
list.setLayoutManager(llm);
|
list.setLayoutManager(llm);
|
||||||
|
|
||||||
list.setHasFixedSize(true);
|
list.setHasFixedSize(true);
|
||||||
|
list.setNestedScrollingEnabled(false);
|
||||||
mAdapter.setRecyclerView(list);
|
mAdapter.setRecyclerView(list);
|
||||||
list.setAdapter(mAdapter);
|
list.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.security;
|
package com.android.settings.security;
|
||||||
|
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.internal.os.Zygote;
|
import com.android.internal.os.Zygote;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -25,18 +26,15 @@ import com.android.settings.core.BasePreferenceController;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class MemtagHelper {
|
public class MemtagHelper {
|
||||||
|
public static final String DEVICE_CONFIG_PROP =
|
||||||
|
"persist.device_config.runtime_native_boot.bootloader_override";
|
||||||
|
|
||||||
public static boolean isForcedOff() {
|
public static boolean isForcedOff() {
|
||||||
return "force_off"
|
return TextUtils.equals("force_on", SystemProperties.get(DEVICE_CONFIG_PROP));
|
||||||
.equals(
|
|
||||||
SystemProperties.get(
|
|
||||||
"persist.device_config.memory_safety_native_boot.bootloader_override"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isForcedOn() {
|
public static boolean isForcedOn() {
|
||||||
return "force_on"
|
return TextUtils.equals("force_on", SystemProperties.get(DEVICE_CONFIG_PROP));
|
||||||
.equals(
|
|
||||||
SystemProperties.get(
|
|
||||||
"persist.device_config.memory_safety_native_boot.bootloader_override"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isChecked() {
|
public static boolean isChecked() {
|
||||||
|
@@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.uwb;
|
package com.android.settings.uwb;
|
||||||
|
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_CHANGED_REASON_SYSTEM_REGULATION;
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_DISABLED;
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_ENABLED_ACTIVE;
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_ENABLED_INACTIVE;
|
||||||
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||||
|
|
||||||
@@ -25,7 +30,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.os.HandlerExecutor;
|
||||||
import android.uwb.UwbManager;
|
import android.uwb.UwbManager;
|
||||||
import android.uwb.UwbManager.AdapterStateCallback;
|
import android.uwb.UwbManager.AdapterStateCallback;
|
||||||
|
|
||||||
@@ -39,52 +44,68 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
/** Controller for "UWB" toggle. */
|
/** Controller for "UWB" toggle. */
|
||||||
public class UwbPreferenceController extends TogglePreferenceController implements
|
public class UwbPreferenceController extends TogglePreferenceController implements
|
||||||
AdapterStateCallback, LifecycleObserver {
|
LifecycleObserver {
|
||||||
@VisibleForTesting
|
private final UwbManager mUwbManager;
|
||||||
static final String KEY_UWB_SETTINGS = "uwb_settings";
|
private final UwbUtils mUwbUtils;
|
||||||
@VisibleForTesting
|
private boolean mAirplaneModeOn;
|
||||||
UwbManager mUwbManager;
|
private /* @AdapterStateCallback.State */ int mState;
|
||||||
@VisibleForTesting
|
private /* @AdapterStateCallback.StateChangedReason */ int mStateReason;
|
||||||
boolean mAirplaneModeOn;
|
|
||||||
@VisibleForTesting
|
|
||||||
private final BroadcastReceiver mAirplaneModeChangedReceiver;
|
private final BroadcastReceiver mAirplaneModeChangedReceiver;
|
||||||
|
private final AdapterStateCallback mAdapterStateCallback;
|
||||||
private final Executor mExecutor;
|
private final Executor mExecutor;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
public UwbPreferenceController(Context context, String key) {
|
@VisibleForTesting
|
||||||
|
public UwbPreferenceController(Context context, String key, UwbUtils uwbUtils) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mExecutor = Executors.newSingleThreadExecutor();
|
|
||||||
mHandler = new Handler(context.getMainLooper());
|
mHandler = new Handler(context.getMainLooper());
|
||||||
|
mExecutor = new HandlerExecutor(mHandler);
|
||||||
|
mUwbUtils = uwbUtils;
|
||||||
if (isUwbSupportedOnDevice()) {
|
if (isUwbSupportedOnDevice()) {
|
||||||
mUwbManager = context.getSystemService(UwbManager.class);
|
mUwbManager = context.getSystemService(UwbManager.class);
|
||||||
}
|
mAirplaneModeChangedReceiver = new BroadcastReceiver() {
|
||||||
mAirplaneModeOn = Settings.Global.getInt(mContext.getContentResolver(),
|
@Override
|
||||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
|
public void onReceive(Context context, Intent intent) {
|
||||||
mAirplaneModeChangedReceiver = new BroadcastReceiver() {
|
mAirplaneModeOn = mUwbUtils.isAirplaneModeOn(mContext);
|
||||||
@Override
|
updateState(mPreference);
|
||||||
public void onReceive(Context context, Intent intent) {
|
}
|
||||||
mAirplaneModeOn = Settings.Global.getInt(mContext.getContentResolver(),
|
};
|
||||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
|
mAdapterStateCallback = (state, reason) -> {
|
||||||
|
mState = state;
|
||||||
|
mStateReason = reason;
|
||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
};
|
||||||
};
|
} else {
|
||||||
|
mUwbManager = null;
|
||||||
|
mAirplaneModeChangedReceiver = null;
|
||||||
|
mAdapterStateCallback = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UwbPreferenceController(Context context, String key) {
|
||||||
|
this(context, key, new UwbUtils());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUwbSupportedOnDevice() {
|
public boolean isUwbSupportedOnDevice() {
|
||||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_UWB);
|
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_UWB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isUwbDisabledDueToRegulatory() {
|
||||||
|
return mState == STATE_DISABLED && mStateReason == STATE_CHANGED_REASON_SYSTEM_REGULATION;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (!isUwbSupportedOnDevice()) {
|
if (!isUwbSupportedOnDevice()) {
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
} else if (mAirplaneModeOn) {
|
} else if (mAirplaneModeOn) {
|
||||||
return DISABLED_DEPENDENT_SETTING;
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
|
} else if (isUwbDisabledDueToRegulatory()) {
|
||||||
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
} else {
|
} else {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
@@ -101,14 +122,11 @@ public class UwbPreferenceController extends TogglePreferenceController implemen
|
|||||||
if (!isUwbSupportedOnDevice()) {
|
if (!isUwbSupportedOnDevice()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int state = mUwbManager.getAdapterState();
|
return mState == STATE_ENABLED_ACTIVE || mState == STATE_ENABLED_INACTIVE;
|
||||||
return state == STATE_ENABLED_ACTIVE || state == STATE_ENABLED_INACTIVE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
mAirplaneModeOn = Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
|
|
||||||
if (isUwbSupportedOnDevice()) {
|
if (isUwbSupportedOnDevice()) {
|
||||||
if (mAirplaneModeOn) {
|
if (mAirplaneModeOn) {
|
||||||
mUwbManager.setUwbEnabled(false);
|
mUwbManager.setUwbEnabled(false);
|
||||||
@@ -119,32 +137,25 @@ public class UwbPreferenceController extends TogglePreferenceController implemen
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStateChanged(int state, int reason) {
|
|
||||||
Runnable runnable = () -> updateState(mPreference);
|
|
||||||
mHandler.post(runnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called when activity starts being displayed to user. */
|
/** Called when activity starts being displayed to user. */
|
||||||
@OnLifecycleEvent(ON_START)
|
@OnLifecycleEvent(ON_START)
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (isUwbSupportedOnDevice()) {
|
if (isUwbSupportedOnDevice()) {
|
||||||
mUwbManager.registerAdapterStateCallback(mExecutor, this);
|
mState = mUwbManager.getAdapterState();
|
||||||
}
|
mStateReason = AdapterStateCallback.STATE_CHANGED_REASON_ERROR_UNKNOWN;
|
||||||
if (mAirplaneModeChangedReceiver != null) {
|
mAirplaneModeOn = mUwbUtils.isAirplaneModeOn(mContext);
|
||||||
|
mUwbManager.registerAdapterStateCallback(mExecutor, mAdapterStateCallback);
|
||||||
mContext.registerReceiver(mAirplaneModeChangedReceiver,
|
mContext.registerReceiver(mAirplaneModeChangedReceiver,
|
||||||
new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
|
new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED), null, mHandler);
|
||||||
|
refreshSummary(mPreference);
|
||||||
}
|
}
|
||||||
refreshSummary(mPreference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when activity stops being displayed to user. */
|
/** Called when activity stops being displayed to user. */
|
||||||
@OnLifecycleEvent(ON_STOP)
|
@OnLifecycleEvent(ON_STOP)
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
if (isUwbSupportedOnDevice()) {
|
if (isUwbSupportedOnDevice()) {
|
||||||
mUwbManager.unregisterAdapterStateCallback(this);
|
mUwbManager.unregisterAdapterStateCallback(mAdapterStateCallback);
|
||||||
}
|
|
||||||
if (mAirplaneModeChangedReceiver != null) {
|
|
||||||
mContext.unregisterReceiver(mAirplaneModeChangedReceiver);
|
mContext.unregisterReceiver(mAirplaneModeChangedReceiver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,13 +164,16 @@ public class UwbPreferenceController extends TogglePreferenceController implemen
|
|||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
preference.setEnabled(!mAirplaneModeOn);
|
preference.setEnabled(!mAirplaneModeOn);
|
||||||
refreshSummary(preference);
|
refreshSummary(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
if (mAirplaneModeOn) {
|
if (mAirplaneModeOn) {
|
||||||
return mContext.getResources().getString(R.string.uwb_settings_summary_airplane_mode);
|
return mContext.getResources().getString(R.string.uwb_settings_summary_airplane_mode);
|
||||||
|
} else if (isUwbDisabledDueToRegulatory()) {
|
||||||
|
return mContext.getResources().getString(
|
||||||
|
R.string.uwb_settings_summary_no_uwb_regulatory);
|
||||||
} else {
|
} else {
|
||||||
return mContext.getResources().getString(R.string.uwb_settings_summary);
|
return mContext.getResources().getString(R.string.uwb_settings_summary);
|
||||||
}
|
}
|
||||||
|
34
src/com/android/settings/uwb/UwbUtils.java
Normal file
34
src/com/android/settings/uwb/UwbUtils.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.uwb;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utils to help mock static methods in {@link UwbPreferenceController}.
|
||||||
|
*/
|
||||||
|
public class UwbUtils {
|
||||||
|
/**
|
||||||
|
* Returns whether airplane mode is on or off.
|
||||||
|
*/
|
||||||
|
public boolean isAirplaneModeOn(Context context) {
|
||||||
|
return Settings.Global.getInt(context.getContentResolver(),
|
||||||
|
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -42,6 +42,7 @@ android_app {
|
|||||||
"androidx.test.core",
|
"androidx.test.core",
|
||||||
"androidx.test.runner",
|
"androidx.test.runner",
|
||||||
"androidx.test.ext.junit",
|
"androidx.test.ext.junit",
|
||||||
|
"frameworks-base-testutils",
|
||||||
"guava",
|
"guava",
|
||||||
"jsr305",
|
"jsr305",
|
||||||
"settings-contextual-card-protos-lite",
|
"settings-contextual-card-protos-lite",
|
||||||
|
@@ -33,8 +33,6 @@ import org.robolectric.shadows.ShadowSystemProperties;
|
|||||||
public class MemtagHelperTest {
|
public class MemtagHelperTest {
|
||||||
private final String mMemtagProperty = "arm64.memtag.bootctl";
|
private final String mMemtagProperty = "arm64.memtag.bootctl";
|
||||||
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_settings_toggle";
|
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_settings_toggle";
|
||||||
private final String mDeviceConfigOverride =
|
|
||||||
"persist.device_config.memory_safety_native_boot.bootloader_override";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_empty_isFalse() {
|
public void isChecked_empty_isFalse() {
|
||||||
@@ -80,7 +78,7 @@ public class MemtagHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_isForcedOff_isDISABLED_DEPENDENT_SETTING() {
|
public void getAvailabilityStatus_isForcedOff_isDISABLED_DEPENDENT_SETTING() {
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "force_off");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "force_off");
|
||||||
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
||||||
assertThat(MemtagHelper.getAvailabilityStatus())
|
assertThat(MemtagHelper.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||||
@@ -88,7 +86,7 @@ public class MemtagHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_isForcedOn_isDISABLED_DEPENDENT_SETTING() {
|
public void getAvailabilityStatus_isForcedOn_isDISABLED_DEPENDENT_SETTING() {
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "force_on");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "force_on");
|
||||||
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
||||||
assertThat(MemtagHelper.getAvailabilityStatus())
|
assertThat(MemtagHelper.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||||
@@ -96,7 +94,7 @@ public class MemtagHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_isUnsupported_isUNSUPPORTED_ON_DEVICE() {
|
public void getAvailabilityStatus_isUnsupported_isUNSUPPORTED_ON_DEVICE() {
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "");
|
||||||
ShadowSystemProperties.override(mMemtagSupportedProperty, "false");
|
ShadowSystemProperties.override(mMemtagSupportedProperty, "false");
|
||||||
assertThat(MemtagHelper.getAvailabilityStatus())
|
assertThat(MemtagHelper.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
@@ -127,7 +125,7 @@ public class MemtagHelperTest {
|
|||||||
@Config(shadows = {ZygoteShadow.class})
|
@Config(shadows = {ZygoteShadow.class})
|
||||||
public void getSummary_memtagAndZygoteSupportsMemoryTagging_memtag_on() {
|
public void getSummary_memtagAndZygoteSupportsMemoryTagging_memtag_on() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(true);
|
ZygoteShadow.setSupportsMemoryTagging(true);
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "");
|
||||||
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
||||||
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_on);
|
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_on);
|
||||||
}
|
}
|
||||||
@@ -136,7 +134,7 @@ public class MemtagHelperTest {
|
|||||||
@Config(shadows = {ZygoteShadow.class})
|
@Config(shadows = {ZygoteShadow.class})
|
||||||
public void getSummary_noMemtagAndZygoteSupportsMemoryTagging_memtag_off_pending() {
|
public void getSummary_noMemtagAndZygoteSupportsMemoryTagging_memtag_off_pending() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(true);
|
ZygoteShadow.setSupportsMemoryTagging(true);
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "");
|
||||||
ShadowSystemProperties.override(mMemtagProperty, "");
|
ShadowSystemProperties.override(mMemtagProperty, "");
|
||||||
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_off_pending);
|
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_off_pending);
|
||||||
}
|
}
|
||||||
@@ -145,7 +143,7 @@ public class MemtagHelperTest {
|
|||||||
@Config(shadows = {ZygoteShadow.class})
|
@Config(shadows = {ZygoteShadow.class})
|
||||||
public void getSummary_noMemtagAndNoZygoteSupportsMemoryTagging_memtag_off() {
|
public void getSummary_noMemtagAndNoZygoteSupportsMemoryTagging_memtag_off() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "");
|
||||||
ShadowSystemProperties.override(mMemtagProperty, "");
|
ShadowSystemProperties.override(mMemtagProperty, "");
|
||||||
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_off);
|
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_off);
|
||||||
}
|
}
|
||||||
@@ -154,7 +152,7 @@ public class MemtagHelperTest {
|
|||||||
@Config(shadows = {ZygoteShadow.class})
|
@Config(shadows = {ZygoteShadow.class})
|
||||||
public void getSummary_memtagAndNoZygoteSupportsMemoryTagging_memtag_on_pending() {
|
public void getSummary_memtagAndNoZygoteSupportsMemoryTagging_memtag_on_pending() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "");
|
||||||
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
||||||
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_on_pending);
|
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_on_pending);
|
||||||
}
|
}
|
||||||
@@ -163,7 +161,7 @@ public class MemtagHelperTest {
|
|||||||
@Config(shadows = {ZygoteShadow.class})
|
@Config(shadows = {ZygoteShadow.class})
|
||||||
public void getSummary_forceOffOverride_memtag_force_off() {
|
public void getSummary_forceOffOverride_memtag_force_off() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "force_off");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "force_off");
|
||||||
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
||||||
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_force_off);
|
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_force_off);
|
||||||
}
|
}
|
||||||
@@ -172,20 +170,20 @@ public class MemtagHelperTest {
|
|||||||
@Config(shadows = {ZygoteShadow.class})
|
@Config(shadows = {ZygoteShadow.class})
|
||||||
public void getSummary_forceOffOverride_memtag_force_on() {
|
public void getSummary_forceOffOverride_memtag_force_on() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "force_on");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "force_on");
|
||||||
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
ShadowSystemProperties.override(mMemtagProperty, "memtag");
|
||||||
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_force_on);
|
assertThat(MemtagHelper.getSummary()).isEqualTo(R.string.memtag_force_on);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isForcedOn_forceOnOverride_isTrue() {
|
public void isForcedOn_forceOnOverride_isTrue() {
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "force_on");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "force_on");
|
||||||
assertThat(MemtagHelper.isForcedOn()).isTrue();
|
assertThat(MemtagHelper.isForcedOn()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isForcedOff_forceOffOverride_isTrue() {
|
public void isForcedOff_forceOffOverride_isTrue() {
|
||||||
ShadowSystemProperties.override(mDeviceConfigOverride, "force_off");
|
ShadowSystemProperties.override(MemtagHelper.DEVICE_CONFIG_PROP, "force_off");
|
||||||
assertThat(MemtagHelper.isForcedOff()).isTrue();
|
assertThat(MemtagHelper.isForcedOff()).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,110 +16,157 @@
|
|||||||
|
|
||||||
package com.android.settings.uwb;
|
package com.android.settings.uwb;
|
||||||
|
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_CHANGED_REASON_SYSTEM_POLICY;
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_CHANGED_REASON_SYSTEM_REGULATION;
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_DISABLED;
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_ENABLED_ACTIVE;
|
||||||
|
import static android.uwb.UwbManager.AdapterStateCallback.STATE_ENABLED_INACTIVE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.any;
|
||||||
|
import static org.mockito.Mockito.anyString;
|
||||||
import static org.mockito.Mockito.clearInvocations;
|
import static org.mockito.Mockito.clearInvocations;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.os.test.TestLooper;
|
||||||
import android.uwb.UwbManager;
|
import android.uwb.UwbManager;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
/** Unit tests for UWB preference toggle. */
|
/** Unit tests for UWB preference toggle. */
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class UwbPreferenceControllerTest {
|
public class UwbPreferenceControllerTest {
|
||||||
|
private static final String TEST_SUMMARY = "uwb";
|
||||||
|
private static final String TEST_AIRPLANE_SUMMARY = "apm_uwb";
|
||||||
|
private static final String TEST_NO_UWB_REGULATORY_SUMMARY = "regulatory_uwb";
|
||||||
@Rule
|
@Rule
|
||||||
public MockitoRule rule = MockitoJUnit.rule();
|
public MockitoRule rule = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
private UwbPreferenceController mController;
|
private UwbPreferenceController mController;
|
||||||
|
private ArgumentCaptor<UwbManager.AdapterStateCallback> mAdapterStateCallbackArgumentCaptor =
|
||||||
|
ArgumentCaptor.forClass(UwbManager.AdapterStateCallback.class);
|
||||||
|
private ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverArgumentCaptor =
|
||||||
|
ArgumentCaptor.forClass(BroadcastReceiver.class);
|
||||||
|
private TestLooper mTestLooper;
|
||||||
@Mock
|
@Mock
|
||||||
private UwbManager mUwbManager;
|
private UwbManager mUwbManager;
|
||||||
|
@Mock
|
||||||
|
private UwbUtils mUwbUtils;
|
||||||
|
@Mock
|
||||||
|
private Preference mPreference;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
@Mock
|
||||||
|
private Resources mResources;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mTestLooper = new TestLooper();
|
||||||
mPackageManager = spy(mContext.getPackageManager());
|
|
||||||
mController = new UwbPreferenceController(mContext, "uwb_settings");
|
|
||||||
mController.mUwbManager = mUwbManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_uwbDisabled_shouldReturnDisabled() {
|
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||||
doReturn(true).when(mPackageManager)
|
doReturn(true).when(mPackageManager)
|
||||||
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
||||||
mController.mAirplaneModeOn = true;
|
when(mResources.getString(R.string.uwb_settings_summary))
|
||||||
|
.thenReturn(TEST_SUMMARY);
|
||||||
|
when(mResources.getString(R.string.uwb_settings_summary_airplane_mode))
|
||||||
|
.thenReturn(TEST_AIRPLANE_SUMMARY);
|
||||||
|
when(mResources.getString(R.string.uwb_settings_summary_no_uwb_regulatory))
|
||||||
|
.thenReturn(TEST_NO_UWB_REGULATORY_SUMMARY);
|
||||||
|
when(mContext.getMainLooper()).thenReturn(mTestLooper.getLooper());
|
||||||
|
when(mContext.getSystemService(UwbManager.class)).thenReturn(mUwbManager);
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
when(mUwbUtils.isAirplaneModeOn(any())).thenReturn(false);
|
||||||
|
doReturn(STATE_ENABLED_ACTIVE).when(mUwbManager).getAdapterState();
|
||||||
|
mController = new UwbPreferenceController(mContext, "uwb_settings", mUwbUtils);
|
||||||
|
when(mPreferenceScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||||
|
mController.displayPreference(mPreferenceScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startControllerAndCaptureCallbacks() {
|
||||||
|
mController.onStart();
|
||||||
|
verify(mContext).registerReceiver(
|
||||||
|
mBroadcastReceiverArgumentCaptor.capture(), any(), any(), any());
|
||||||
|
verify(mUwbManager).registerAdapterStateCallback(
|
||||||
|
any(), mAdapterStateCallbackArgumentCaptor.capture());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_uwbDisabled_shouldReturnDisabled() throws Exception {
|
||||||
|
when(mUwbUtils.isAirplaneModeOn(any())).thenReturn(true);
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
assertThat(mController.getAvailabilityStatus())
|
assertThat(mController.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_uwbShown_shouldReturnAvailable() {
|
public void getAvailabilityStatus_uwbShown_shouldReturnAvailable() throws Exception {
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
when(mUwbUtils.isAirplaneModeOn(any())).thenReturn(false);
|
||||||
doReturn(true).when(mPackageManager)
|
startControllerAndCaptureCallbacks();
|
||||||
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
|
||||||
mController.mAirplaneModeOn = false;
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus())
|
assertThat(mController.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_uwbNotShown_shouldReturnUnsupported() {
|
public void getAvailabilityStatus_uwbNotShown_shouldReturnUnsupported() {
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
|
||||||
doReturn(false).when(mPackageManager)
|
doReturn(false).when(mPackageManager)
|
||||||
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
||||||
|
|
||||||
|
mController.onStart();
|
||||||
|
verify(mContext, never()).registerReceiver(any(), any(), any(), any());
|
||||||
|
verify(mUwbManager, never()).registerAdapterStateCallback(any(), any());
|
||||||
assertThat(mController.getAvailabilityStatus())
|
assertThat(mController.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_uwbEnabled_shouldReturnTrue() {
|
public void isChecked_uwbEnabled_shouldReturnTrue() {
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
doReturn(STATE_ENABLED_ACTIVE).when(mUwbManager).getAdapterState();
|
||||||
doReturn(true).when(mPackageManager)
|
|
||||||
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
|
||||||
doReturn(mController.STATE_ENABLED_ACTIVE).when(mUwbManager).getAdapterState();
|
|
||||||
|
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
assertThat(mController.isChecked()).isTrue();
|
assertThat(mController.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_uwbDisabled_shouldReturnFalse() {
|
public void isChecked_uwbDisabled_shouldReturnFalse() {
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
doReturn(STATE_DISABLED).when(mUwbManager).getAdapterState();
|
||||||
doReturn(true).when(mPackageManager)
|
|
||||||
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
|
||||||
doReturn(mController.STATE_DISABLED).when(mUwbManager).getAdapterState();
|
|
||||||
|
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
assertThat(mController.isChecked()).isFalse();
|
assertThat(mController.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setChecked_uwbDisabled_shouldEnableUwb() {
|
public void setChecked_uwbDisabled_shouldEnableUwb() {
|
||||||
clearInvocations(mUwbManager);
|
clearInvocations(mUwbManager);
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
|
||||||
doReturn(true).when(mPackageManager)
|
|
||||||
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
|
||||||
|
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
|
|
||||||
verify(mUwbManager).setUwbEnabled(true);
|
verify(mUwbManager).setUwbEnabled(true);
|
||||||
@@ -129,14 +176,65 @@ public class UwbPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void setChecked_uwbEnabled_shouldDisableUwb() {
|
public void setChecked_uwbEnabled_shouldDisableUwb() {
|
||||||
clearInvocations(mUwbManager);
|
clearInvocations(mUwbManager);
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
|
||||||
doReturn(true).when(mPackageManager)
|
|
||||||
.hasSystemFeature(PackageManager.FEATURE_UWB);
|
|
||||||
|
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
mController.setChecked(false);
|
mController.setChecked(false);
|
||||||
|
|
||||||
verify(mUwbManager).setUwbEnabled(false);
|
verify(mUwbManager).setUwbEnabled(false);
|
||||||
verify(mUwbManager, never()).setUwbEnabled(true);
|
verify(mUwbManager, never()).setUwbEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateStateAndSummary_uwbDisabledAndEnabled() {
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
|
clearInvocations(mUwbManager, mPreference);
|
||||||
|
|
||||||
|
mAdapterStateCallbackArgumentCaptor.getValue().onStateChanged(
|
||||||
|
STATE_DISABLED, STATE_CHANGED_REASON_SYSTEM_POLICY);
|
||||||
|
|
||||||
|
verify(mPreference).setEnabled(true);
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
verify(mPreference, times(2)).setSummary(TEST_SUMMARY);
|
||||||
|
|
||||||
|
mAdapterStateCallbackArgumentCaptor.getValue().onStateChanged(
|
||||||
|
STATE_ENABLED_INACTIVE, STATE_CHANGED_REASON_SYSTEM_POLICY);
|
||||||
|
|
||||||
|
verify(mPreference, times(2)).setEnabled(true);
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
verify(mPreference, times(4)).setSummary(TEST_SUMMARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateStateAndSummary_apmEnabledAndDisabled() {
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
|
clearInvocations(mUwbManager, mPreference);
|
||||||
|
|
||||||
|
when(mUwbUtils.isAirplaneModeOn(any())).thenReturn(true);
|
||||||
|
mBroadcastReceiverArgumentCaptor.getValue().onReceive(
|
||||||
|
mock(Context.class), mock(Intent.class));
|
||||||
|
|
||||||
|
verify(mPreference).setEnabled(false);
|
||||||
|
verify(mPreference, times(2)).setSummary(TEST_AIRPLANE_SUMMARY);
|
||||||
|
|
||||||
|
when(mUwbUtils.isAirplaneModeOn(any())).thenReturn(false);
|
||||||
|
mBroadcastReceiverArgumentCaptor.getValue().onReceive(
|
||||||
|
mock(Context.class), mock(Intent.class));
|
||||||
|
|
||||||
|
verify(mPreference).setEnabled(true);
|
||||||
|
verify(mPreference, times(2)).setSummary(TEST_SUMMARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateStateAndSummary_uwbDisabledDueToRegulatory() {
|
||||||
|
startControllerAndCaptureCallbacks();
|
||||||
|
clearInvocations(mUwbManager, mPreference);
|
||||||
|
|
||||||
|
mAdapterStateCallbackArgumentCaptor.getValue().onStateChanged(
|
||||||
|
STATE_DISABLED, STATE_CHANGED_REASON_SYSTEM_REGULATION);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
|
verify(mPreference, times(2)).setSummary(TEST_NO_UWB_REGULATORY_SUMMARY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user