Merge "Using ACTION_SIM_CARD_STATE_CHANGED to detect simSlotMapping is complete" into main
diff --git a/Android.bp b/Android.bp
index 9b4cfde..8353634 100644
--- a/Android.bp
+++ b/Android.bp
@@ -103,6 +103,8 @@
"settings-logtags",
"settings-telephony-protos-lite",
"statslog-settings",
+ "androidx.test.rules",
+ "telephony_flags_core_java_lib",
],
plugins: ["androidx.room_room-compiler-plugin"],
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 321c437..6ad4c05 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -139,6 +139,7 @@
<uses-permission android:name="android.permission.REMAP_MODIFIER_KEYS" />
<uses-permission android:name="android.permission.ACCESS_GPU_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
+ <uses-permission android:name="android.permission.MANAGE_GAME_MODE" />
<application
android:name=".SettingsApplication"
@@ -311,6 +312,19 @@
android:value="true" />
</activity>
+ <activity android:name=".Settings$ResetMobileNetworkSettingsActivity"
+ android:exported="true"
+ android:label="@string/reset_mobile_network_settings_title">
+ <intent-filter android:priority="1">
+ <action android:name="android.telephony.action.RESET_MOBILE_NETWORK_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.ResetNetwork"/>
+ <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
+ android:value="@string/menu_key_system"/>
+ </activity>
+
<activity
android:name=".Settings$ConnectedDeviceDashboardActivity"
android:label="@string/connected_devices_dashboard_title"
diff --git a/aconfig/settings_development_flag_declarations.aconfig b/aconfig/settings_development_flag_declarations.aconfig
index c23a38f..e12bccc 100644
--- a/aconfig/settings_development_flag_declarations.aconfig
+++ b/aconfig/settings_development_flag_declarations.aconfig
@@ -6,6 +6,13 @@
# flags with 'development' to prevent naming collision.
flag {
+ name: "development_game_default_frame_rate"
+ namespace: "game"
+ description: "This flag guards the new behavior with the addition of Game Default Frame Rate feature."
+ bug: "286084594"
+}
+
+flag {
name: "development_hdr_sdr_ratio"
namespace: "core_graphics"
description: "Shows hdr/sdr dev opton on the development options page from aconfig"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2be3f3a..257d952 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1938,6 +1938,12 @@
<string name="wifi_notify_open_networks">Notify for public networks</string>
<!-- Checkbox summary for option to notify user when open networks are nearby-->
<string name="wifi_notify_open_networks_summary">Notify when a high\u2011quality public network is available</string>
+ <!-- Checkbox title for option to allow user to connect to wep networks-->
+ <string name="wifi_allow_wep_networks">Allow WEP networks</string>
+ <!-- Checkbox summary for option to allow user to connect to wep networks-->
+ <string name="wifi_allow_wep_networks_summary">WEP is an older security protocol that\u0027s less secure</string>
+ <!-- Checkbox summary for option to allow user to connect to wep networks when it is blocked by carrier-->
+ <string name="wifi_allow_wep_networks_summary_carrier_not_allow">Your carrier doesn\u0027t allow WEP networks because they\u0027re less secure</string>
<!-- Checkbox title for option to enable Wi-Fi when saved networks are nearby -->
<string name="wifi_wakeup">Turn on Wi\u2011Fi automatically</string>
<!-- Checkbox summary for option to enable Wi-Fi when high quality saved networks are nearby-->
@@ -1987,6 +1993,18 @@
<string name="wifi_settings_scanning_required_turn_on">Turn on</string>
<!-- Wi-Fi settings dialog. Text to show in toast for when user turns on wifi scanning. [CHAR LIMIT=NONE] -->
<string name="wifi_settings_scanning_required_enabled">Wi\u2011Fi scanning turned on</string>
+ <!-- Wi-Fi settings dialog. Warning on the password entry page for a WEP network, when WEP networks are allowed. [CHAR LIMIT=NONE] -->
+ <string name="wifi_settings_warning_wep_network">This network uses an older security protocol that\u0027s less secure</string>
+ <!-- Wi-Fi settings dialog. Title of dialog displayed when WEP network is blocked. [CHAR LIMIT=NONE] -->
+ <string name="wifi_settings_wep_networks_blocked_title"><xliff:g id="name">%1$s</xliff:g> is blocked</string>
+ <!-- Wi-Fi settings dialog. Summary text of dialog displayed when WEP network toggle is turned off. [CHAR LIMIT=NONE] -->
+ <string name="wifi_settings_wep_networks_summary_toggle_off">This network uses an older security protocol called WEP, which is less secure. To connect anyway, you can allow WEP networks.</string>
+ <!-- Wi-Fi settings dialog. Summary text of dialog displayed when WEP network is blocked by the carrier. [CHAR LIMIT=NONE] -->
+ <string name="wifi_settings_wep_networks_summary_blocked_by_carrier">Your carrier doesn\u0027t allow you to connect to this network because it uses an older security protocol that’s less secure</string>
+ <!-- Wi-Fi settings dialog. Button text of dialog displayed when WEP network toggle is turned off. [CHAR LIMIT=NONE] -->
+ <string name="wifi_settings_wep_networks_button_allow">Allow WEP</string>
+ <!-- Wi-Fi settings dialog. Button text of dialog displayed when WEP network toggle is blocked. [CHAR LIMIT=NONE] -->
+ <string name="wifi_settings_ssid_block_button_close">Close</string>
<!-- Dialog for Access Points --> <skip />
<!-- Label to show/hide advanced options [CHAR LIMIT=40] -->
@@ -2639,8 +2657,12 @@
<string name="display_white_balance_summary"></string>
<!-- Display settings screen, setting option name to change Fold setting -->
<string name="fold_lock_behavior_title">Continue using apps on fold</string>
+ <!-- Display settings screen, game default frame rate settings title [CHAR LIMIT=30] -->
+ <string name="disable_game_default_frame_rate_title">Disable default frame rate for games</string>
+ <!-- Display settings screen, game default frame rate settings summary [CHAR LIMIT=NONE] -->
+ <string name="disable_game_default_frame_rate_summary">Disable limiting the maximum frame rate for games at <xliff:g id="frame_rate" example="60">%1$d</xliff:g> Hz.</string>
<!-- Display settings screen, peak refresh rate settings title [CHAR LIMIT=30] -->
- <string name="peak_refresh_rate_title">Smooth Display</string>
+ <string name="peak_refresh_rate_title">Smooth display</string>
<!-- Display settings screen, peak refresh rate settings summary [CHAR LIMIT=NONE] -->
<string name="peak_refresh_rate_summary">Automatically raises the refresh rate up to <xliff:g name="refresh_rate" example="120">%1$d</xliff:g> Hz for some content. Increases battery usage.</string>
<!-- Display developer settings: Force to the highest refresh rate [CHAR LIMIT=NONE] -->
@@ -9460,6 +9482,13 @@
other {# apps used memory in the last {time}}
}</string>
+ <!-- Label for toggle that enables the profiling/aggregating of memory usage [CHAR LIMIT=40]-->
+ <string name="force_enable_pss_profiling_title">Enable memory usage profiling</string>
+ <!-- Description with an explanation of the extra resources used if profiling of memory usage is enabled [CHAR LIMIT=NONE]-->
+ <string name="force_enable_pss_profiling_summary">Memory usage profiling requires additional system resources.</string>
+ <!-- Summary that shows the current memory usage profiling status as disabled. [CHAR LIMIT=NONE]-->
+ <string name="pss_profiling_disabled">Memory profiling disabled</string>
+
<!-- Label for frequency that the app is runnig (e.g. always, sometimes, etc.) [CHAR LIMIT=25] -->
<string name="running_frequency">Frequency</string>
@@ -11755,7 +11784,7 @@
<!-- Description of toggle to enable or disable the media resumption on lockscreen [CHAR LIMIT=NONE]-->
<string name="media_controls_lockscreen_description">To quickly resume playback, media player stays open on lock screen</string>
<!-- Title of toggle to enable or disable media recommendations in quick settings [CHAR LIMIT=NONE] -->
- <string name="media_controls_recommendations_title">Show media recommendations</string>
+ <string name="media_controls_recommendations_title">Show Assistant media recommendations</string>
<!-- Description of toggle to enable or disable media recommendations based on user's activity [CHAR LIMIT=NONE] -->
<string name="media_controls_recommendations_description">Based on your activity</string>
<!-- Subtext for media settings when the player will be hidden [CHAR LIMIT=50] -->
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index f0a2881..2fc173e 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -255,6 +255,11 @@
android:title="@string/enable_angle_as_system_driver"
android:summary="@string/enable_angle_as_system_driver_summary" />
+ <SwitchPreferenceCompat
+ android:key="disable_game_default_frame_rate"
+ android:title="@string/disable_game_default_frame_rate_title"
+ android:summary="@string/disable_game_default_frame_rate_summary"/>
+
<Preference
android:key="graphics_driver_dashboard"
android:title="@string/graphics_driver_dashboard_title"
diff --git a/res/xml/process_stats_summary.xml b/res/xml/process_stats_summary.xml
index 3b3271d..9def18f 100644
--- a/res/xml/process_stats_summary.xml
+++ b/res/xml/process_stats_summary.xml
@@ -19,45 +19,52 @@
android:title="@string/app_memory_use"
android:key="app_list">
+ <SwitchPreference
+ android:key="force_enable_pss_profiling"
+ android:title="@string/force_enable_pss_profiling_title"
+ android:summary="@string/force_enable_pss_profiling_summary" />
+
<PreferenceCategory
- android:title="@string/average_memory_use"/>
+ android:title="@string/average_memory_use"
+ android:key="memory_info">
- <com.android.settings.SummaryPreference
- android:key="status_header"
- android:selectable="false" />
+ <com.android.settings.SummaryPreference
+ android:key="status_header"
+ android:selectable="false" />
- <com.android.settings.applications.SpacePreference
- android:layout_height="5dp" />
+ <com.android.settings.applications.SpacePreference
+ android:layout_height="5dp" />
- <Preference
- android:key="performance"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/memory_performance" />
+ <Preference
+ android:key="performance"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/memory_performance" />
- <Preference
- android:key="total_memory"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/total_memory" />
+ <Preference
+ android:key="total_memory"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/total_memory" />
- <Preference
- android:key="average_used"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/average_used" />
+ <Preference
+ android:key="average_used"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/average_used" />
- <Preference
- android:key="free"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/free_memory" />
+ <Preference
+ android:key="free"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/free_memory" />
- <com.android.settings.applications.SpacePreference
- android:layout_height="15dp" />
+ <com.android.settings.applications.SpacePreference
+ android:layout_height="15dp" />
- <Preference
- android:key="apps_list"
- android:title="@string/memory_usage_apps" />
+ <Preference
+ android:key="apps_list"
+ android:title="@string/memory_usage_apps" />
+ </PreferenceCategory>
</PreferenceScreen>
diff --git a/src/com/android/settings/ResetNetwork.java b/src/com/android/settings/ResetNetwork.java
index 80f5962..8e59a7f 100644
--- a/src/com/android/settings/ResetNetwork.java
+++ b/src/com/android/settings/ResetNetwork.java
@@ -44,6 +44,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
+import com.android.internal.telephony.flags.Flags;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.network.ResetNetworkRestrictionViewBuilder;
@@ -121,16 +122,22 @@
void showFinalConfirmation() {
Bundle args = new Bundle();
- ResetNetworkRequest request = new ResetNetworkRequest(
- ResetNetworkRequest.RESET_CONNECTIVITY_MANAGER |
- ResetNetworkRequest.RESET_VPN_MANAGER
- );
+ // TODO(b/317276437) Simplify the logic once flag is released
+ int resetOptions = ResetNetworkRequest.RESET_CONNECTIVITY_MANAGER
+ | ResetNetworkRequest.RESET_VPN_MANAGER;
+ if (Flags.resetMobileNetworkSettings()) {
+ resetOptions |= ResetNetworkRequest.RESET_IMS_STACK;
+ }
+ ResetNetworkRequest request = new ResetNetworkRequest(resetOptions);
if (mSubscriptions != null && mSubscriptions.size() > 0) {
int selectedIndex = mSubscriptionSpinner.getSelectedItemPosition();
SubscriptionInfo subscription = mSubscriptions.get(selectedIndex);
int subId = subscription.getSubscriptionId();
request.setResetTelephonyAndNetworkPolicyManager(subId)
.setResetApn(subId);
+ if (Flags.resetMobileNetworkSettings()) {
+ request.setResetImsSubId(subId);
+ }
}
if (mEsimContainer.getVisibility() == View.VISIBLE && mEsimCheckbox.isChecked()) {
request.setResetEsim(getContext().getPackageName())
diff --git a/src/com/android/settings/ResetNetworkRequest.java b/src/com/android/settings/ResetNetworkRequest.java
index 40eebb0..71c12b1 100644
--- a/src/com/android/settings/ResetNetworkRequest.java
+++ b/src/com/android/settings/ResetNetworkRequest.java
@@ -48,11 +48,23 @@
/* Reset option - reset BluetoothManager */
public static final int RESET_BLUETOOTH_MANAGER = 0x10;
- /* Subscription ID for not performing reset TelephonyAndNetworkPolicy or reset APN */
+ /* Reset option - reset IMS stack */
+ public static final int RESET_IMS_STACK = 0x20;
+
+ /**
+ * Subscription ID indicates NOT resetting any of the components below:
+ * - TelephonyAndNetworkPolicy
+ * - APN
+ * - IMS
+ */
public static final int INVALID_SUBSCRIPTION_ID = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
- /* Subscription ID for performing reset TelephonyAndNetworkPolicy or reset APN
- on all subscriptions */
+ /**
+ * Subscription ID indicates resetting components below for ALL subscriptions:
+ * - TelephonyAndNetworkPolicy
+ * - APN
+ * - IMS
+ */
public static final int ALL_SUBSCRIPTION_ID = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
/* Key within Bundle. To store some connectivity options for reset */
@@ -75,10 +87,14 @@
@VisibleForTesting
protected static final String KEY_APN_SUBID = "resetApnSubId";
+ /** Key within Bundle. To store subscription ID for resetting IMS. */
+ protected static final String KEY_RESET_IMS_SUBID = "resetImsSubId";
+
private int mResetOptions = RESET_NONE;
private String mResetEsimPackageName;
private int mResetTelephonyManager = INVALID_SUBSCRIPTION_ID;
private int mResetApn = INVALID_SUBSCRIPTION_ID;
+ private int mSubscriptionIdToResetIms = INVALID_SUBSCRIPTION_ID;
/**
* Reconstruct based on keys stored within Bundle.
@@ -93,6 +109,8 @@
mResetTelephonyManager = optionsFromBundle.getInt(
KEY_TELEPHONY_NET_POLICY_MANAGER_SUBID, INVALID_SUBSCRIPTION_ID);
mResetApn = optionsFromBundle.getInt(KEY_APN_SUBID, INVALID_SUBSCRIPTION_ID);
+ mSubscriptionIdToResetIms = optionsFromBundle.getInt(KEY_RESET_IMS_SUBID,
+ INVALID_SUBSCRIPTION_ID);
}
/**
@@ -173,6 +191,29 @@
}
/**
+ * Get the subscription ID applied for resetting IMS.
+ * @return subscription ID.
+ * {@code ALL_SUBSCRIPTION_ID} for applying to all subscriptions.
+ * {@code INVALID_SUBSCRIPTION_ID} means resetting IMS
+ * is not part of the option within this request.
+ */
+ public int getResetImsSubId() {
+ return mSubscriptionIdToResetIms;
+ }
+
+ /**
+ * Set the subscription ID applied for resetting APN.
+ * @param subId is the subscription ID referenced from SubscriptionManager.
+ * {@code ALL_SUBSCRIPTION_ID} for applying to all subscriptions.
+ * {@code INVALID_SUBSCRIPTION_ID} means resetting IMS will not take place.
+ * @return this
+ */
+ public ResetNetworkRequest setResetImsSubId(int subId) {
+ mSubscriptionIdToResetIms = subId;
+ return this;
+ }
+
+ /**
* Store a copy of this request into Bundle given.
* @param writeToBundle is a Bundle for storing configurations of this request.
* @return this request
@@ -182,6 +223,7 @@
writeToBundle.putString(KEY_ESIM_PACKAGE, mResetEsimPackageName);
writeToBundle.putInt(KEY_TELEPHONY_NET_POLICY_MANAGER_SUBID, mResetTelephonyManager);
writeToBundle.putInt(KEY_APN_SUBID, mResetApn);
+ writeToBundle.putInt(KEY_RESET_IMS_SUBID, mSubscriptionIdToResetIms);
return this;
}
@@ -219,6 +261,9 @@
if (mResetApn != INVALID_SUBSCRIPTION_ID) {
builder.resetApn(mResetApn);
}
+ if ((mResetOptions & RESET_IMS_STACK) != 0) {
+ builder.resetIms(mSubscriptionIdToResetIms);
+ }
return builder;
}
}
diff --git a/src/com/android/settings/ResetSubscriptionContract.java b/src/com/android/settings/ResetSubscriptionContract.java
index 580e907..528a16d 100644
--- a/src/com/android/settings/ResetSubscriptionContract.java
+++ b/src/com/android/settings/ResetSubscriptionContract.java
@@ -23,8 +23,8 @@
import androidx.annotation.VisibleForTesting;
-import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.IntStream;
@@ -53,8 +53,8 @@
mContext = context;
// Only keeps specific subscription ID required to perform reset operation
IntStream subIdStream = IntStream.of(
- resetRequest.getResetTelephonyAndNetworkPolicyManager()
- , resetRequest.getResetApnSubId());
+ resetRequest.getResetTelephonyAndNetworkPolicyManager(),
+ resetRequest.getResetApnSubId(), resetRequest.getResetImsSubId());
mResetSubscriptionIds = subIdStream.sorted().distinct()
.filter(id -> SubscriptionManager.isUsableSubscriptionId(id))
.toArray();
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 01ccbb2..3e48a9c 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -482,4 +482,7 @@
public static class PreviouslyConnectedDeviceActivity extends SettingsActivity { /* empty */ }
public static class ScreenTimeoutActivity extends SettingsActivity { /* empty */ }
+
+ /** Activity for the Reset mobile network settings. */
+ public static class ResetMobileNetworkSettingsActivity extends SettingsActivity { /* empty */ }
}
diff --git a/src/com/android/settings/accessibility/AccessibilityButtonPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityButtonPreferenceController.java
index f076472..53d9c55 100644
--- a/src/com/android/settings/accessibility/AccessibilityButtonPreferenceController.java
+++ b/src/com/android/settings/accessibility/AccessibilityButtonPreferenceController.java
@@ -17,12 +17,16 @@
package com.android.settings.accessibility;
import android.content.Context;
+import android.content.res.Resources;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.search.SearchIndexableRaw;
+
+import java.util.List;
/**
* Preference controller for accessibility button preference.
@@ -41,10 +45,23 @@
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- final int titleResource = AccessibilityUtil.isGestureNavigateEnabled(mContext)
- ? R.string.accessibility_button_gesture_title : R.string.accessibility_button_title;
final Preference preference = screen.findPreference(getPreferenceKey());
- preference.setTitle(titleResource);
+ preference.setTitle(getPreferenceTitleResource());
}
+
+ @Override
+ public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
+ SearchIndexableRaw data = new SearchIndexableRaw(mContext);
+ data.key = getPreferenceKey();
+ final Resources res = mContext.getResources();
+ data.title = res.getString(getPreferenceTitleResource());
+ data.screenTitle = res.getString(R.string.accessibility_shortcuts_settings_title);
+ rawData.add(data);
+ }
+
+ private int getPreferenceTitleResource() {
+ return AccessibilityUtil.isGestureNavigateEnabled(mContext)
+ ? R.string.accessibility_button_gesture_title : R.string.accessibility_button_title;
+ }
}
diff --git a/src/com/android/settings/applications/ProcessStatsSummary.java b/src/com/android/settings/applications/ProcessStatsSummary.java
index 4044794..ef76cd5 100644
--- a/src/com/android/settings/applications/ProcessStatsSummary.java
+++ b/src/com/android/settings/applications/ProcessStatsSummary.java
@@ -16,20 +16,26 @@
package com.android.settings.applications;
import android.app.settings.SettingsEnums;
+import android.content.ContentResolver;
import android.content.Context;
import android.icu.text.MessageFormat;
import android.os.Bundle;
+import android.os.Flags;
+import android.provider.Settings;
import android.text.format.Formatter;
import android.text.format.Formatter.BytesResult;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceClickListener;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.SummaryPreference;
import com.android.settings.Utils;
import com.android.settings.applications.ProcStatsData.MemInfo;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.development.DisableDevSettingsDialogFragment;
import java.util.HashMap;
import java.util.Locale;
@@ -37,6 +43,8 @@
public class ProcessStatsSummary extends ProcessStatsBase implements OnPreferenceClickListener {
+ private static final String KEY_PREF_SCREEN = "app_list";
+ private static final String KEY_MEMORY_INFO_PREF_GROUP = "memory_info";
private static final String KEY_STATUS_HEADER = "status_header";
private static final String KEY_PERFORMANCE = "performance";
@@ -44,7 +52,9 @@
private static final String KEY_AVERAGY_USED = "average_used";
private static final String KEY_FREE = "free";
private static final String KEY_APP_LIST = "apps_list";
+ private static final String KEY_FORCE_ENABLE_PSS_PROFILING = "force_enable_pss_profiling";
+ private PreferenceCategory mMemoryInfoPrefCategory;
private SummaryPreference mSummaryPref;
private Preference mPerformance;
@@ -52,12 +62,14 @@
private Preference mAverageUsed;
private Preference mFree;
private Preference mAppListPreference;
+ private SwitchPreference mForceEnablePssProfiling;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.process_stats_summary);
+ mMemoryInfoPrefCategory = (PreferenceCategory) findPreference(KEY_MEMORY_INFO_PREF_GROUP);
mSummaryPref = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
mPerformance = findPreference(KEY_PERFORMANCE);
mTotalMemory = findPreference(KEY_TOTAL_MEMORY);
@@ -65,11 +77,37 @@
mFree = findPreference(KEY_FREE);
mAppListPreference = findPreference(KEY_APP_LIST);
mAppListPreference.setOnPreferenceClickListener(this);
+
+ // This preference is only applicable if the flag for PSS deprecation in AppProfiler is
+ // enabled. Otherwise, it can immediately be hidden.
+ mForceEnablePssProfiling =
+ (SwitchPreference) findPreference(KEY_FORCE_ENABLE_PSS_PROFILING);
+ if (Flags.removeAppProfilerPssCollection()) {
+ mForceEnablePssProfiling.setOnPreferenceClickListener(this);
+ // Make the toggle reflect the current state of the global setting.
+ mForceEnablePssProfiling.setChecked(isPssProfilingForceEnabled(getContext()));
+ } else {
+ mForceEnablePssProfiling.setVisible(false);
+ }
+ }
+
+ private void refreshPreferences() {
+ // The memory fields should be static if the flag is not enabled.
+ if (!Flags.removeAppProfilerPssCollection()) {
+ return;
+ }
+ mMemoryInfoPrefCategory.setVisible(mForceEnablePssProfiling.isChecked());
}
@Override
public void refreshUi() {
Context context = getContext();
+ refreshPreferences();
+
+ // If PSS collection is not enabled, none of the following work needs to be done.
+ if (Flags.removeAppProfilerPssCollection() && !isPssProfilingForceEnabled(context)) {
+ return;
+ }
MemInfo memInfo = mStatsManager.getMemInfo();
@@ -100,7 +138,8 @@
String durationString = getString(sDurationLabels[mDurationIndex]);
int numApps = mStatsManager.getEntries().size();
MessageFormat msgFormat = new MessageFormat(
- getResources().getString(R.string.memory_usage_apps_summary), Locale.getDefault());
+ getResources().getString(R.string.memory_usage_apps_summary),
+ Locale.getDefault());
Map<String, Object> arguments = new HashMap<>();
arguments.put("count", numApps);
arguments.put("time", durationString);
@@ -131,7 +170,34 @@
.setSourceMetricsCategory(getMetricsCategory())
.launch();
return true;
+ } else if (preference == mForceEnablePssProfiling) {
+ DisableDevSettingsDialogFragment.show(this);
}
return false;
}
+
+ private boolean isPssProfilingForceEnabled(Context context) {
+ ContentResolver cr = context.getContentResolver();
+ return Settings.Global.getInt(cr, Settings.Global.FORCE_ENABLE_PSS_PROFILING, 0) == 1;
+ }
+
+ /**
+ * Called when the reboot confirmation button is clicked.
+ */
+ public void onRebootDialogConfirmed() {
+ Context context = getContext();
+ ContentResolver cr = context.getContentResolver();
+ Settings.Global.putInt(cr, Settings.Global.FORCE_ENABLE_PSS_PROFILING,
+ mForceEnablePssProfiling.isChecked() ? 1 : 0);
+ refreshPreferences();
+ }
+
+ /**
+ * Called when the reboot deny button is clicked.
+ */
+ public void onRebootDialogCanceled() {
+ // Set the toggle to reflect the state of the setting, which should not have changed.
+ mForceEnablePssProfiling.setChecked(isPssProfilingForceEnabled(getContext()));
+ }
+
}
diff --git a/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java b/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java
index 02d5c27..ef054df 100644
--- a/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java
+++ b/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java
@@ -21,6 +21,7 @@
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
@@ -51,6 +52,9 @@
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.widget.ActionButtonsPreference;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+
import java.util.ArrayList;
import java.util.List;
@@ -63,29 +67,41 @@
private static final String KEY_HEADER_SUMMARY = "app_aspect_ratio_summary";
private static final String KEY_HEADER_BUTTONS = "header_view";
- private static final String KEY_PREF_FULLSCREEN = "fullscreen_pref";
+
private static final String KEY_PREF_HALF_SCREEN = "half_screen_pref";
private static final String KEY_PREF_DISPLAY_SIZE = "display_size_pref";
private static final String KEY_PREF_16_9 = "16_9_pref";
private static final String KEY_PREF_4_3 = "4_3_pref";
@VisibleForTesting
+ static final String KEY_PREF_FULLSCREEN = "fullscreen_pref";
+ @VisibleForTesting
static final String KEY_PREF_DEFAULT = "app_default_pref";
@VisibleForTesting
static final String KEY_PREF_3_2 = "3_2_pref";
+ @VisibleForTesting
+ @NonNull String mSelectedKey = KEY_PREF_DEFAULT;
+
+ /** Radio button preference key mapped to {@link PackageManager.UserMinAspectRatio} value */
+ @VisibleForTesting
+ final BiMap<String, Integer> mKeyToAspectRatioMap = HashBiMap.create();
+
private final List<RadioWithImagePreference> mAspectRatioPreferences = new ArrayList<>();
@NonNull private UserAspectRatioManager mUserAspectRatioManager;
- @NonNull private String mSelectedKey = KEY_PREF_DEFAULT;
+ private boolean mIsOverrideToFullscreenEnabled;
@Override
public void onCreate(@NonNull Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUserAspectRatioManager = new UserAspectRatioManager(getContext());
+ mIsOverrideToFullscreenEnabled = getAspectRatioManager()
+ .isOverrideToFullscreenEnabled(mPackageName, mUserId);
+
initPreferences();
try {
- final int userAspectRatio = mUserAspectRatioManager
+ final int userAspectRatio = getAspectRatioManager()
.getUserMinAspectRatioValue(mPackageName, mUserId);
mSelectedKey = getSelectedKey(userAspectRatio);
} catch (RemoteException e) {
@@ -148,43 +164,23 @@
}
@PackageManager.UserMinAspectRatio
- private int getSelectedUserMinAspectRatio(@NonNull String selectedKey) {
- switch (selectedKey) {
- case KEY_PREF_FULLSCREEN:
- return USER_MIN_ASPECT_RATIO_FULLSCREEN;
- case KEY_PREF_HALF_SCREEN:
- return USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
- case KEY_PREF_DISPLAY_SIZE:
- return USER_MIN_ASPECT_RATIO_DISPLAY_SIZE;
- case KEY_PREF_3_2:
- return USER_MIN_ASPECT_RATIO_3_2;
- case KEY_PREF_4_3:
- return USER_MIN_ASPECT_RATIO_4_3;
- case KEY_PREF_16_9:
- return USER_MIN_ASPECT_RATIO_16_9;
- default:
- return USER_MIN_ASPECT_RATIO_UNSET;
- }
+ @VisibleForTesting
+ int getSelectedUserMinAspectRatio(@NonNull String selectedKey) {
+ final int appDefault = mKeyToAspectRatioMap
+ .getOrDefault(KEY_PREF_DEFAULT, USER_MIN_ASPECT_RATIO_UNSET);
+ return mKeyToAspectRatioMap.getOrDefault(selectedKey, appDefault);
}
@NonNull
private String getSelectedKey(@PackageManager.UserMinAspectRatio int userMinAspectRatio) {
- switch (userMinAspectRatio) {
- case USER_MIN_ASPECT_RATIO_FULLSCREEN:
- return KEY_PREF_FULLSCREEN;
- case USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
- return KEY_PREF_HALF_SCREEN;
- case USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
- return KEY_PREF_DISPLAY_SIZE;
- case USER_MIN_ASPECT_RATIO_3_2:
- return KEY_PREF_3_2;
- case USER_MIN_ASPECT_RATIO_4_3:
- return KEY_PREF_4_3;
- case USER_MIN_ASPECT_RATIO_16_9:
- return KEY_PREF_16_9;
- default:
- return KEY_PREF_DEFAULT;
+ final String appDefault = mKeyToAspectRatioMap.inverse()
+ .getOrDefault(USER_MIN_ASPECT_RATIO_UNSET, KEY_PREF_DEFAULT);
+
+ if (userMinAspectRatio == USER_MIN_ASPECT_RATIO_UNSET && mIsOverrideToFullscreenEnabled) {
+ // Pre-select fullscreen option if device manufacturer has overridden app to fullscreen
+ userMinAspectRatio = USER_MIN_ASPECT_RATIO_FULLSCREEN;
}
+ return mKeyToAspectRatioMap.inverse().getOrDefault(userMinAspectRatio, appDefault);
}
@Override
@@ -217,7 +213,11 @@
.setButton1Icon(R.drawable.ic_settings_open)
.setButton1OnClickListener(v -> launchApplication());
- addPreference(KEY_PREF_DEFAULT, USER_MIN_ASPECT_RATIO_UNSET);
+ if (mIsOverrideToFullscreenEnabled) {
+ addPreference(KEY_PREF_DEFAULT, USER_MIN_ASPECT_RATIO_APP_DEFAULT);
+ } else {
+ addPreference(KEY_PREF_DEFAULT, USER_MIN_ASPECT_RATIO_UNSET);
+ }
addPreference(KEY_PREF_FULLSCREEN, USER_MIN_ASPECT_RATIO_FULLSCREEN);
addPreference(KEY_PREF_DISPLAY_SIZE, USER_MIN_ASPECT_RATIO_DISPLAY_SIZE);
addPreference(KEY_PREF_HALF_SCREEN, USER_MIN_ASPECT_RATIO_SPLIT_SCREEN);
@@ -232,12 +232,13 @@
if (pref == null) {
return;
}
- if (!mUserAspectRatioManager.hasAspectRatioOption(aspectRatio, mPackageName)) {
+ if (!getAspectRatioManager().hasAspectRatioOption(aspectRatio, mPackageName)) {
pref.setVisible(false);
return;
}
pref.setTitle(mUserAspectRatioManager.getAccessibleEntry(aspectRatio, mPackageName));
pref.setOnClickListener(this);
+ mKeyToAspectRatioMap.put(key, aspectRatio);
mAspectRatioPreferences.add(pref);
}
diff --git a/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java b/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java
index 3cca5f6..3bf6109 100644
--- a/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java
+++ b/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java
@@ -16,19 +16,32 @@
package com.android.settings.applications.appcompat;
+import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION_TO_USER;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
import static android.os.UserHandle.getUserHandleForUid;
+import static android.os.UserHandle.getUserId;
+import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE;
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE;
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE;
import static java.lang.Boolean.FALSE;
import android.app.AppGlobals;
+import android.app.compat.CompatChanges;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.os.RemoteException;
+import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
@@ -37,6 +50,7 @@
import com.android.settings.R;
import com.android.settings.Utils;
+import com.android.window.flags.Flags;
import com.google.common.annotations.VisibleForTesting;
@@ -55,6 +69,8 @@
"enable_app_compat_user_aspect_ratio_fullscreen";
private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN = true;
+ final boolean mIsUserMinAspectRatioAppDefaultFlagEnabled = Flags.userMinAspectRatioAppDefault();
+
private final Context mContext;
private final IPackageManager mIPm;
/** Apps that have launcher entry defined in manifest */
@@ -62,8 +78,13 @@
private final Map<Integer, CharSequence> mUserAspectRatioA11yMap;
public UserAspectRatioManager(@NonNull Context context) {
+ this(context, AppGlobals.getPackageManager());
+ }
+
+ @VisibleForTesting
+ UserAspectRatioManager(@NonNull Context context, @NonNull IPackageManager pm) {
mContext = context;
- mIPm = AppGlobals.getPackageManager();
+ mIPm = pm;
mUserAspectRatioA11yMap = new ArrayMap<>();
mUserAspectRatioMap = getUserMinAspectRatioMapping();
}
@@ -86,7 +107,7 @@
throws RemoteException {
final int aspectRatio = mIPm.getUserMinAspectRatio(packageName, uid);
return hasAspectRatioOption(aspectRatio, packageName)
- ? aspectRatio : PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
+ ? aspectRatio : USER_MIN_ASPECT_RATIO_UNSET;
}
/**
@@ -94,11 +115,18 @@
*/
@NonNull
public String getUserMinAspectRatioEntry(@PackageManager.UserMinAspectRatio int aspectRatio,
- String packageName) {
- if (!hasAspectRatioOption(aspectRatio, packageName)) {
- return mUserAspectRatioMap.get(PackageManager.USER_MIN_ASPECT_RATIO_UNSET);
+ @NonNull String packageName, int userId) {
+ final String appDefault = getAspectRatioStringOrDefault(
+ mUserAspectRatioMap.get(USER_MIN_ASPECT_RATIO_UNSET),
+ USER_MIN_ASPECT_RATIO_UNSET);
+
+ if (!hasAspectRatioOption(aspectRatio, packageName)) {
+ return appDefault;
}
- return mUserAspectRatioMap.get(aspectRatio);
+
+ return isCurrentSelectionFromManufacturerOverride(packageName, userId, aspectRatio)
+ ? getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN, packageName, userId)
+ : mUserAspectRatioMap.getOrDefault(aspectRatio, appDefault);
}
/**
@@ -106,19 +134,22 @@
*/
@NonNull
public CharSequence getAccessibleEntry(@PackageManager.UserMinAspectRatio int aspectRatio,
- String packageName) {
- return mUserAspectRatioA11yMap.getOrDefault(aspectRatio,
- getUserMinAspectRatioEntry(aspectRatio, packageName));
+ @NonNull String packageName) {
+ final int userId = mContext.getUserId();
+ return isCurrentSelectionFromManufacturerOverride(packageName, userId, aspectRatio)
+ ? getAccessibleEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN, packageName)
+ : mUserAspectRatioA11yMap.getOrDefault(aspectRatio,
+ getUserMinAspectRatioEntry(aspectRatio, packageName, userId));
}
/**
* @return corresponding aspect ratio string for package name and user
*/
@NonNull
- public String getUserMinAspectRatioEntry(@NonNull String packageName, int uid)
+ public String getUserMinAspectRatioEntry(@NonNull String packageName, int userId)
throws RemoteException {
- final int aspectRatio = getUserMinAspectRatioValue(packageName, uid);
- return getUserMinAspectRatioEntry(aspectRatio, packageName);
+ final int aspectRatio = getUserMinAspectRatioValue(packageName, userId);
+ return getUserMinAspectRatioEntry(aspectRatio, packageName, userId);
}
/**
@@ -128,8 +159,7 @@
*/
public boolean hasAspectRatioOption(@PackageManager.UserMinAspectRatio int option,
String packageName) {
- if (option == PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN
- && !isFullscreenOptionEnabled(packageName)) {
+ if (option == USER_MIN_ASPECT_RATIO_FULLSCREEN && !isFullscreenOptionEnabled(packageName)) {
return false;
}
return mUserAspectRatioMap.containsKey(option);
@@ -155,6 +185,18 @@
}
/**
+ * Whether the app has been overridden to fullscreen by device manufacturer or
+ * whether the app's aspect ratio has been overridden by the user.
+ */
+ public boolean isAppOverridden(@NonNull ApplicationInfo app,
+ @PackageManager.UserMinAspectRatio int userOverride) {
+ return (userOverride != USER_MIN_ASPECT_RATIO_UNSET
+ && userOverride != USER_MIN_ASPECT_RATIO_APP_DEFAULT)
+ || isCurrentSelectionFromManufacturerOverride(app.packageName, getUserId(app.uid),
+ userOverride);
+ }
+
+ /**
* Whether fullscreen option in per-app user aspect ratio settings is enabled
*/
@VisibleForTesting
@@ -168,6 +210,32 @@
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN);
}
+ /**
+ * Whether the device manufacturer has overridden app's orientation to
+ * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_USER} to force app to fullscreen
+ * and app has not opted-out from the treatment
+ */
+ boolean isOverrideToFullscreenEnabled(String pkgName, int userId) {
+ Boolean appAllowsOrientationOverride = readComponentProperty(mContext.getPackageManager(),
+ pkgName, PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE);
+ return mIsUserMinAspectRatioAppDefaultFlagEnabled
+ && hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN, pkgName)
+ && !FALSE.equals(appAllowsOrientationOverride)
+ && isFullscreenCompatChangeEnabled(pkgName, userId);
+ }
+
+ @VisibleForTesting
+ boolean isFullscreenCompatChangeEnabled(String pkgName, int userId) {
+ return CompatChanges.isChangeEnabled(
+ OVERRIDE_ANY_ORIENTATION_TO_USER, pkgName, UserHandle.of(userId));
+ }
+
+ private boolean isCurrentSelectionFromManufacturerOverride(String pkgName, int userId,
+ @PackageManager.UserMinAspectRatio int aspectRatio) {
+ return aspectRatio == USER_MIN_ASPECT_RATIO_UNSET
+ && isOverrideToFullscreenEnabled(pkgName, userId);
+ }
+
private boolean hasLauncherEntry(@NonNull ApplicationInfo app) {
return !mContext.getSystemService(LauncherApps.class)
.getActivityList(app.packageName, getUserHandleForUid(app.uid))
@@ -197,13 +265,13 @@
boolean containsColon = aspectRatioString.contains(":");
switch (aspectRatioVal) {
// Only map known values of UserMinAspectRatio and ignore unknown entries
- case PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN:
- case PackageManager.USER_MIN_ASPECT_RATIO_UNSET:
- case PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
- case PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
- case PackageManager.USER_MIN_ASPECT_RATIO_4_3:
- case PackageManager.USER_MIN_ASPECT_RATIO_16_9:
- case PackageManager.USER_MIN_ASPECT_RATIO_3_2:
+ case USER_MIN_ASPECT_RATIO_FULLSCREEN:
+ case USER_MIN_ASPECT_RATIO_UNSET:
+ case USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
+ case USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
+ case USER_MIN_ASPECT_RATIO_4_3:
+ case USER_MIN_ASPECT_RATIO_16_9:
+ case USER_MIN_ASPECT_RATIO_3_2:
if (containsColon) {
String[] aspectRatioDigits = aspectRatioString.split(":");
String accessibleString = getAccessibleOption(aspectRatioDigits[0],
@@ -215,10 +283,18 @@
userMinAspectRatioMap.put(aspectRatioVal, aspectRatioString);
}
}
- if (!userMinAspectRatioMap.containsKey(PackageManager.USER_MIN_ASPECT_RATIO_UNSET)) {
+ if (!userMinAspectRatioMap.containsKey(USER_MIN_ASPECT_RATIO_UNSET)) {
throw new RuntimeException("config_userAspectRatioOverrideValues options must have"
+ " USER_MIN_ASPECT_RATIO_UNSET value");
}
+ if (mIsUserMinAspectRatioAppDefaultFlagEnabled) {
+ userMinAspectRatioMap.put(USER_MIN_ASPECT_RATIO_APP_DEFAULT,
+ userMinAspectRatioMap.get(USER_MIN_ASPECT_RATIO_UNSET));
+ if (mUserAspectRatioA11yMap.containsKey(USER_MIN_ASPECT_RATIO_UNSET)) {
+ mUserAspectRatioA11yMap.put(USER_MIN_ASPECT_RATIO_APP_DEFAULT,
+ mUserAspectRatioA11yMap.get(USER_MIN_ASPECT_RATIO_UNSET));
+ }
+ }
return userMinAspectRatioMap;
}
@@ -236,17 +312,17 @@
}
// Options are customized per device and if strings are set to @null, use default
switch (aspectRatioVal) {
- case PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN:
+ case USER_MIN_ASPECT_RATIO_FULLSCREEN:
return mContext.getString(R.string.user_aspect_ratio_fullscreen);
- case PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
+ case USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
return mContext.getString(R.string.user_aspect_ratio_half_screen);
- case PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
+ case USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
return mContext.getString(R.string.user_aspect_ratio_device_size);
- case PackageManager.USER_MIN_ASPECT_RATIO_4_3:
+ case USER_MIN_ASPECT_RATIO_4_3:
return mContext.getString(R.string.user_aspect_ratio_4_3);
- case PackageManager.USER_MIN_ASPECT_RATIO_16_9:
+ case USER_MIN_ASPECT_RATIO_16_9:
return mContext.getString(R.string.user_aspect_ratio_16_9);
- case PackageManager.USER_MIN_ASPECT_RATIO_3_2:
+ case USER_MIN_ASPECT_RATIO_3_2:
return mContext.getString(R.string.user_aspect_ratio_3_2);
default:
return mContext.getString(R.string.user_aspect_ratio_app_default);
diff --git a/src/com/android/settings/applications/intentpicker/AppLaunchSettings.java b/src/com/android/settings/applications/intentpicker/AppLaunchSettings.java
index 72f7543..676c35a 100644
--- a/src/com/android/settings/applications/intentpicker/AppLaunchSettings.java
+++ b/src/com/android/settings/applications/intentpicker/AppLaunchSettings.java
@@ -288,6 +288,7 @@
.create();
if (dialog.getListView() != null) {
dialog.getListView().setTextDirection(View.TEXT_DIRECTION_LOCALE);
+ dialog.getListView().setEnabled(false);
} else {
Log.w(TAG, "createVerifiedLinksDialog: dialog.getListView() is null, please check it.");
}
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioController.java b/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioController.java
index 0ce1b97..e5fb365 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioController.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.media.AudioDeviceAttributes;
import android.media.AudioDeviceInfo;
-import android.media.AudioManager;
import android.media.Spatializer;
import android.text.TextUtils;
import android.util.Log;
@@ -35,8 +34,12 @@
import androidx.preference.TwoStatePreference;
import com.android.settings.R;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.utils.ThreadUtils;
+
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* The controller of the Spatial audio setting in the bluetooth detail settings.
@@ -56,14 +59,16 @@
@VisibleForTesting
AudioDeviceAttributes mAudioDevice = null;
+ AtomicBoolean mHasHeadTracker = new AtomicBoolean(false);
+
public BluetoothDetailsSpatialAudioController(
Context context,
PreferenceFragmentCompat fragment,
CachedBluetoothDevice device,
Lifecycle lifecycle) {
super(context, fragment, device, lifecycle);
- AudioManager audioManager = context.getSystemService(AudioManager.class);
- mSpatializer = audioManager.getSpatializer();
+ mSpatializer = FeatureFactory.getFeatureFactory().getBluetoothFeatureProvider()
+ .getSpatializer(context);
}
@Override
@@ -77,7 +82,13 @@
String key = switchPreference.getKey();
if (TextUtils.equals(key, KEY_SPATIAL_AUDIO)) {
updateSpatializerEnabled(switchPreference.isChecked());
- refreshSpatialAudioEnabled(switchPreference);
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ mHasHeadTracker.set(
+ mAudioDevice != null && mSpatializer.hasHeadTracker(mAudioDevice));
+ mContext.getMainExecutor()
+ .execute(() -> refreshSpatialAudioEnabled(switchPreference));
+ });
return true;
} else if (TextUtils.equals(key, KEY_HEAD_TRACKING)) {
updateSpatializerHeadTracking(switchPreference.isChecked());
@@ -124,7 +135,15 @@
if (mAudioDevice == null) {
getAvailableDevice();
}
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ mHasHeadTracker.set(
+ mAudioDevice != null && mSpatializer.hasHeadTracker(mAudioDevice));
+ mContext.getMainExecutor().execute(this::refreshUi);
+ });
+ }
+ private void refreshUi() {
TwoStatePreference spatialAudioPref = mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO);
if (spatialAudioPref == null && mAudioDevice != null) {
spatialAudioPref = createSpatialAudioPreference(mProfilesContainer.getContext());
@@ -145,7 +164,8 @@
refreshSpatialAudioEnabled(spatialAudioPref);
}
- private void refreshSpatialAudioEnabled(TwoStatePreference spatialAudioPref) {
+ private void refreshSpatialAudioEnabled(
+ TwoStatePreference spatialAudioPref) {
boolean isSpatialAudioOn = mSpatializer.getCompatibleAudioDevices().contains(mAudioDevice);
Log.d(TAG, "refresh() isSpatialAudioOn : " + isSpatialAudioOn);
spatialAudioPref.setChecked(isSpatialAudioOn);
@@ -160,9 +180,8 @@
private void refreshHeadTracking(TwoStatePreference spatialAudioPref,
TwoStatePreference headTrackingPref) {
- boolean isHeadTrackingAvailable =
- spatialAudioPref.isChecked() && mSpatializer.hasHeadTracker(mAudioDevice);
- Log.d(TAG, "refresh() has head tracker : " + mSpatializer.hasHeadTracker(mAudioDevice));
+ boolean isHeadTrackingAvailable = spatialAudioPref.isChecked() && mHasHeadTracker.get();
+ Log.d(TAG, "refresh() has head tracker : " + mHasHeadTracker.get());
headTrackingPref.setVisible(isHeadTrackingAvailable);
if (isHeadTrackingAvailable) {
headTrackingPref.setChecked(mSpatializer.isHeadTrackerEnabled(mAudioDevice));
diff --git a/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java b/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java
index 648ca30..1bc7184 100644
--- a/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java
+++ b/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java
@@ -18,6 +18,8 @@
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
+import android.content.Context;
+import android.media.Spatializer;
import android.net.Uri;
import java.util.List;
@@ -50,4 +52,12 @@
* @return list of {@link ComponentName}
*/
List<ComponentName> getRelatedTools();
+
+ /**
+ * Gets the instance of {@link Spatializer}.
+ *
+ * @param context Context
+ * @return the Spatializer instance
+ */
+ Spatializer getSpatializer(Context context);
}
diff --git a/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java b/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java
index 6d0e15c..ba02020 100644
--- a/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java
+++ b/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java
@@ -18,6 +18,9 @@
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.Spatializer;
import android.net.Uri;
import com.android.settingslib.bluetooth.BluetoothUtils;
@@ -45,4 +48,10 @@
public List<ComponentName> getRelatedTools() {
return null;
}
+
+ @Override
+ public Spatializer getSpatializer(Context context) {
+ AudioManager audioManager = context.getSystemService(AudioManager.class);
+ return audioManager.getSpatializer();
+ }
}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 69a9fb3..3433e12 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -20,6 +20,7 @@
import com.android.settings.IccLockSettings;
import com.android.settings.MainClear;
import com.android.settings.MainClearConfirm;
+import com.android.settings.ResetNetwork;
import com.android.settings.Settings;
import com.android.settings.TestingSettings;
import com.android.settings.TrustedCredentialsSettings;
@@ -374,6 +375,7 @@
BatteryInfoFragment.class.getName(),
UserAspectRatioDetails.class.getName(),
ScreenTimeoutSettings.class.getName(),
+ ResetNetwork.class.getName(),
};
public static final String[] SETTINGS_FOR_RESTRICTED = {
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index b52409d..e841eac 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -688,6 +688,7 @@
controllers.add(new HardwareLayersUpdatesPreferenceController(context));
controllers.add(new DebugGpuOverdrawPreferenceController(context));
controllers.add(new DebugNonRectClipOperationsPreferenceController(context));
+ controllers.add(new GameDefaultFrameRatePreferenceController(context));
controllers.add(new ForceDarkPreferenceController(context));
controllers.add(new EnableBlursPreferenceController(context));
controllers.add(new ForceMSAAPreferenceController(context));
diff --git a/src/com/android/settings/development/DevelopmentSystemPropertiesWrapper.java b/src/com/android/settings/development/DevelopmentSystemPropertiesWrapper.java
new file mode 100644
index 0000000..e8a64d2
--- /dev/null
+++ b/src/com/android/settings/development/DevelopmentSystemPropertiesWrapper.java
@@ -0,0 +1,66 @@
+/*
+ * 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.development;
+
+import android.annotation.NonNull;
+import android.os.SystemProperties;
+/**
+ * Wrapper interface to access {@link SystemProperties}.
+ *
+ * @hide
+ */
+
+public interface DevelopmentSystemPropertiesWrapper {
+ /**
+ * Get the String value for the given {@code key}.
+ *
+ * @param key the key to lookup
+ * @param def the default value in case the property is not set or empty
+ * @return if the {@code key} isn't found, return {@code def} if it isn't null, or an empty
+ * string otherwise
+ */
+ @NonNull
+ String get(@NonNull String key, @NonNull String def);
+ /**
+ * Set the value for the given {@code key} to {@code val}.
+ *
+ * @throws IllegalArgumentException if the {@code val} exceeds 91 characters
+ * @throws RuntimeException if the property cannot be set, for example, if it was blocked by
+ * SELinux. libc will log the underlying reason.
+ */
+ void set(@NonNull String key, @NonNull String val);
+
+ /**
+ * Get the Integer value for the given {@code key}.
+ *
+ * @param key the key to lookup
+ * @param def the default value in case the property is not set or empty
+ * @return if the {@code key} isn't found, return {@code def} if it isn't null, not parsable
+ * or an empty string otherwise
+ */
+ @NonNull
+ int getInt(@NonNull String key, @NonNull int def);
+
+ /**
+ * Get the boolean value for the given {@code key}.
+ *
+ * @param key the key to lookup
+ * @param def the default value in case the property is not set or empty
+ * @return if the {@code key} isn't found, return {@code def}.
+ */
+ boolean getBoolean(@NonNull String key, @NonNull boolean def);
+}
diff --git a/src/com/android/settings/development/DisableDevSettingsDialogFragment.java b/src/com/android/settings/development/DisableDevSettingsDialogFragment.java
index 224768b..4355f27 100644
--- a/src/com/android/settings/development/DisableDevSettingsDialogFragment.java
+++ b/src/com/android/settings/development/DisableDevSettingsDialogFragment.java
@@ -29,6 +29,8 @@
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.applications.ProcessStatsSummary;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
public class DisableDevSettingsDialogFragment extends InstrumentedDialogFragment
@@ -42,7 +44,7 @@
return dialog;
}
- public static void show(DevelopmentSettingsDashboardFragment host) {
+ public static void show(SettingsPreferenceFragment host) {
final DisableDevSettingsDialogFragment dialog = new DisableDevSettingsDialogFragment();
dialog.setTargetFragment(host, 0 /* requestCode */);
// We need to handle data changes and switch state based on which button user clicks,
@@ -75,18 +77,31 @@
@Override
public void onClick(DialogInterface dialog, int which) {
Fragment fragment = getTargetFragment();
- if (!(fragment instanceof DevelopmentSettingsDashboardFragment)){
+ if (!(fragment instanceof DevelopmentSettingsDashboardFragment)
+ && !(fragment instanceof ProcessStatsSummary)) {
Log.e(TAG, "getTargetFragment return unexpected type");
}
- final DevelopmentSettingsDashboardFragment host =
- (DevelopmentSettingsDashboardFragment) fragment;
- if (which == DialogInterface.BUTTON_POSITIVE) {
- host.onDisableDevelopmentOptionsConfirmed();
- PowerManager pm = getContext().getSystemService(PowerManager.class);
- pm.reboot(null);
- } else {
- host.onDisableDevelopmentOptionsRejected();
+ if (fragment instanceof DevelopmentSettingsDashboardFragment) {
+ final DevelopmentSettingsDashboardFragment host =
+ (DevelopmentSettingsDashboardFragment) fragment;
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ host.onDisableDevelopmentOptionsConfirmed();
+ PowerManager pm = getContext().getSystemService(PowerManager.class);
+ pm.reboot(null);
+ } else {
+ host.onDisableDevelopmentOptionsRejected();
+ }
+ } else if (fragment instanceof ProcessStatsSummary) {
+ final ProcessStatsSummary host =
+ (ProcessStatsSummary) fragment;
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ host.onRebootDialogConfirmed();
+ PowerManager pm = getContext().getSystemService(PowerManager.class);
+ pm.reboot(null);
+ } else {
+ host.onRebootDialogCanceled();
+ }
}
}
}
diff --git a/src/com/android/settings/development/GameDefaultFrameRatePreferenceController.java b/src/com/android/settings/development/GameDefaultFrameRatePreferenceController.java
new file mode 100644
index 0000000..00001fb
--- /dev/null
+++ b/src/com/android/settings/development/GameDefaultFrameRatePreferenceController.java
@@ -0,0 +1,146 @@
+/*
+ * 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.development;
+
+
+import android.app.IGameManagerService;
+import android.content.Context;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.TwoStatePreference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.flags.Flags;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+public class GameDefaultFrameRatePreferenceController extends DeveloperOptionsPreferenceController
+ implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+ private static final String TAG = "GameDefFrameRatePrefCtr";
+ private static final String DISABLE_GAME_DEFAULT_FRAME_RATE_KEY =
+ "disable_game_default_frame_rate";
+ private final IGameManagerService mGameManagerService;
+ static final String PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED =
+ "debug.graphics.game_default_frame_rate.disabled";
+
+ private final DevelopmentSystemPropertiesWrapper mSysProps;
+ private int mGameDefaultFrameRateValue;
+
+ @VisibleForTesting
+ static class Injector {
+ public DevelopmentSystemPropertiesWrapper createSystemPropertiesWrapper() {
+ return new DevelopmentSystemPropertiesWrapper() {
+ @Override
+ public String get(String key, String def) {
+ return SystemProperties.get(key, def);
+ }
+ @Override
+ public boolean getBoolean(String key, boolean def) {
+ return SystemProperties.getBoolean(key, def);
+ }
+
+ @Override
+ public int getInt(String key, int def) {
+ return SystemProperties.getInt(key, def);
+ }
+
+ @Override
+ public void set(String key, String val) {
+ SystemProperties.set(key, val);
+ }
+ };
+ }
+ }
+
+ public GameDefaultFrameRatePreferenceController(Context context) {
+ super(context);
+ mGameManagerService = IGameManagerService.Stub.asInterface(
+ ServiceManager.getService(Context.GAME_SERVICE));
+
+ mSysProps = new Injector().createSystemPropertiesWrapper();
+
+ mGameDefaultFrameRateValue = mSysProps.getInt(
+ "ro.surface_flinger.game_default_frame_rate_override", 60);
+ }
+
+ @VisibleForTesting
+ GameDefaultFrameRatePreferenceController(Context context,
+ IGameManagerService gameManagerService,
+ Injector injector) {
+ super(context);
+ mGameManagerService = gameManagerService;
+ mSysProps = injector.createSystemPropertiesWrapper();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return DISABLE_GAME_DEFAULT_FRAME_RATE_KEY;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean isDisabled = (Boolean) newValue;
+ try {
+ mGameManagerService.toggleGameDefaultFrameRate(!isDisabled);
+ updateGameDefaultPreferenceSetting();
+ } catch (RemoteException e) {
+ // intentional no-op
+ }
+ return true;
+ }
+
+ private void updateGameDefaultPreferenceSetting() {
+ final boolean isDisabled =
+ mSysProps.getBoolean(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED,
+ false);
+ ((TwoStatePreference) mPreference).setChecked(isDisabled);
+ mPreference.setSummary(mContext.getString(
+ R.string.disable_game_default_frame_rate_summary,
+ mGameDefaultFrameRateValue));
+ }
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ updateGameDefaultPreferenceSetting();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return Flags.developmentGameDefaultFrameRate();
+ }
+
+ @Override
+ protected void onDeveloperOptionsSwitchDisabled() {
+ super.onDeveloperOptionsSwitchDisabled();
+ final TwoStatePreference preference = (TwoStatePreference) mPreference;
+ if (preference.isChecked()) {
+ // When the developer option is disabled, we should set everything
+ // to off, that is, enabling game default frame rate.
+ try {
+ mGameManagerService.toggleGameDefaultFrameRate(true);
+ } catch (RemoteException e) {
+ // intentional no-op
+ }
+ }
+ preference.setChecked(false);
+ }
+
+}
diff --git a/src/com/android/settings/development/MemoryUsagePreferenceController.java b/src/com/android/settings/development/MemoryUsagePreferenceController.java
index 1b20e70..ca8effa 100644
--- a/src/com/android/settings/development/MemoryUsagePreferenceController.java
+++ b/src/com/android/settings/development/MemoryUsagePreferenceController.java
@@ -17,6 +17,8 @@
package com.android.settings.development;
import android.content.Context;
+import android.os.Flags;
+import android.provider.Settings;
import android.text.format.Formatter;
import androidx.annotation.VisibleForTesting;
@@ -65,9 +67,13 @@
(long) memInfo.realUsedRam);
final String totalResult = Formatter.formatShortFileSize(mContext,
(long) memInfo.realTotalRam);
- ThreadUtils.postOnMainThread(
- () -> mPreference.setSummary(mContext.getString(R.string.memory_summary,
- usedResult, totalResult)));
+ boolean displayMemorySummary = !Flags.removeAppProfilerPssCollection();
+ displayMemorySummary |= Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.FORCE_ENABLE_PSS_PROFILING, 0) == 1;
+ String summary = displayMemorySummary
+ ? mContext.getString(R.string.memory_summary, usedResult, totalResult)
+ : mContext.getString(R.string.pss_profiling_disabled);
+ ThreadUtils.postOnMainThread(() -> mPreference.setSummary(summary));
});
}
diff --git a/src/com/android/settings/development/OWNERS b/src/com/android/settings/development/OWNERS
index 6443afe..09a4914 100644
--- a/src/com/android/settings/development/OWNERS
+++ b/src/com/android/settings/development/OWNERS
@@ -1,3 +1,6 @@
+# GameDefaultFrameRatePreferenceController
+per-file GameDefaultFrameRatePreferenceController.java=file:platform/frameworks/base:/GAME_MANAGER_OWNERS
+
# ShowHdrSdrRatioPreferenceController
per-file ShowHdrSdrRatioPreferenceController.java=file:platform/frameworks/native:/services/surfaceflinger/OWNERS
diff --git a/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java b/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java
index 15f2094..e0b6543 100644
--- a/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java
+++ b/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java
@@ -31,6 +31,7 @@
import androidx.annotation.VisibleForTesting;
import java.io.PrintWriter;
+import java.util.Arrays;
import java.util.Set;
/** A class to dynamically manage per apps {@link NetworkPolicyManager} POLICY_ flags. */
@@ -87,6 +88,7 @@
/** Set policy flags for specific UID. */
public void setUidPolicyLocked(int uid, int policy) {
+ Log.i(TAG, "setUidPolicyLocked: uid=" + uid + " policy=" + policy);
synchronized (mLock) {
mNetworkPolicyManager.setUidPolicy(uid, policy);
}
@@ -152,17 +154,21 @@
/** Reset the UIDs in the denylist if needed. */
public void resetDenylistIfNeeded(String packageName, boolean force) {
if (!force && !SETTINGS_PACKAGE_NAME.equals(packageName)) {
+ Log.w(TAG, "resetDenylistIfNeeded: invalid conditions");
return;
}
synchronized (mLock) {
final int[] uids = mNetworkPolicyManager
.getUidsWithPolicy(POLICY_REJECT_METERED_BACKGROUND);
if (uids != null && uids.length != 0) {
+ Log.i(TAG, "resetDenylistIfNeeded: " + Arrays.toString(uids));
for (int uid : uids) {
if (!getDenylistAllUids(getManualDenylistPref()).contains(uid)) {
mNetworkPolicyManager.setUidPolicy(uid, POLICY_NONE);
}
}
+ } else {
+ Log.w(TAG, "resetDenylistIfNeeded: there is no valid UIDs");
}
}
clearSharedPreferences();
@@ -209,6 +215,7 @@
}
void clearSharedPreferences() {
+ Log.i(TAG, "clearSharedPreferences()");
getManualDenylistPref().edit().clear().apply();
getDynamicDenylistPref().edit().clear().apply();
}
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index 6cf3061..5510301 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -119,6 +119,7 @@
private SplitControllerCallbackAdapter mSplitControllerAdapter;
private SplitInfoCallback mCallback;
+ private boolean mAllowUpdateSuggestion = true;
/** A listener receiving homepage loaded events. */
public interface HomepageLoadedListener {
@@ -155,15 +156,18 @@
* to avoid the flicker caused by the suggestion suddenly appearing/disappearing.
*/
public void showHomepageWithSuggestion(boolean showSuggestion) {
+ if (mAllowUpdateSuggestion) {
+ Log.i(TAG, "showHomepageWithSuggestion: " + showSuggestion);
+ mAllowUpdateSuggestion = false;
+ mSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE);
+ mTwoPaneSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE);
+ }
+
if (mHomepageView == null) {
return;
}
- Log.i(TAG, "showHomepageWithSuggestion: " + showSuggestion);
final View homepageView = mHomepageView;
- mSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE);
- mTwoPaneSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE);
mHomepageView = null;
-
mLoadedListeners.forEach(listener -> listener.onHomepageLoaded());
mLoadedListeners.clear();
homepageView.setVisibility(View.VISIBLE);
@@ -284,6 +288,7 @@
@Override
protected void onStop() {
super.onStop();
+ mAllowUpdateSuggestion = true;
if (mSplitControllerAdapter != null && mCallback != null) {
mSplitControllerAdapter.removeSplitListener(mCallback);
mCallback = null;
diff --git a/src/com/android/settings/network/AllowedNetworkTypesListener.java b/src/com/android/settings/network/AllowedNetworkTypesListener.java
index 3d93664..38c5871 100644
--- a/src/com/android/settings/network/AllowedNetworkTypesListener.java
+++ b/src/com/android/settings/network/AllowedNetworkTypesListener.java
@@ -27,7 +27,11 @@
/**
* {@link TelephonyCallback} to listen to Allowed Network Types changed
+ *
+ * @deprecated Please use {@link com.android.settings.network.telephony.AllowedNetworkTypesFlowKt}
+ * instead.
*/
+@Deprecated
public class AllowedNetworkTypesListener extends TelephonyCallback implements
TelephonyCallback.AllowedNetworkTypesListener {
private static final String LOG_TAG = "NetworkModeListener";
diff --git a/src/com/android/settings/network/ResetNetworkOperationBuilder.java b/src/com/android/settings/network/ResetNetworkOperationBuilder.java
index 3583d06..61f57f9 100644
--- a/src/com/android/settings/network/ResetNetworkOperationBuilder.java
+++ b/src/com/android/settings/network/ResetNetworkOperationBuilder.java
@@ -33,6 +33,7 @@
import android.telephony.TelephonyManager;
import android.util.Log;
+import com.android.settings.ResetNetworkRequest;
import com.android.settings.network.apn.ApnSettings;
import java.util.ArrayList;
@@ -213,6 +214,32 @@
}
/**
+ * Append a step of resetting IMS stack.
+ *
+ * @return this
+ */
+ public ResetNetworkOperationBuilder resetIms(int subId) {
+ attachSystemServiceWork(Context.TELEPHONY_SERVICE,
+ (Consumer<TelephonyManager>) tm -> {
+ if (subId == ResetNetworkRequest.INVALID_SUBSCRIPTION_ID) {
+ // Do nothing
+ return;
+ }
+ if (subId == ResetNetworkRequest.ALL_SUBSCRIPTION_ID) {
+ // Reset IMS for all slots
+ for (int slotIndex = 0; slotIndex < tm.getActiveModemCount(); slotIndex++) {
+ tm.resetIms(slotIndex);
+ }
+ } else {
+ // Reset IMS for the slot specified by the sucriptionId.
+ final int slotIndex = SubscriptionManager.getSlotIndex(subId);
+ tm.resetIms(slotIndex);
+ }
+ });
+ return this;
+ }
+
+ /**
* Construct a Runnable containing all operations appended.
* @return Runnable
*/
diff --git a/src/com/android/settings/network/helper/ServiceStateStatus.java b/src/com/android/settings/network/helper/ServiceStateStatus.java
index 871884d..40e9e3f 100644
--- a/src/com/android/settings/network/helper/ServiceStateStatus.java
+++ b/src/com/android/settings/network/helper/ServiceStateStatus.java
@@ -19,7 +19,6 @@
import android.telephony.ServiceState;
import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
-import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
@@ -34,8 +33,10 @@
* Only got update when Lifecycle.State is considered as STARTED or RESUMED.
*
* {@code null} when status unknown. Other values are {@link ServiceState}.
+ *
+ * @deprecated Please us {@link com.android.settings.network.telephony.ServiceStateFlowKt} instead.
*/
-@VisibleForTesting
+@Deprecated
public class ServiceStateStatus extends LiveData<ServiceState> {
private static final String TAG = "ServiceStateStatus";
diff --git a/src/com/android/settings/network/telephony/AllowedNetworkTypesFlow.kt b/src/com/android/settings/network/telephony/AllowedNetworkTypesFlow.kt
new file mode 100644
index 0000000..cb507ab
--- /dev/null
+++ b/src/com/android/settings/network/telephony/AllowedNetworkTypesFlow.kt
@@ -0,0 +1,39 @@
+/*
+ * 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.network.telephony
+
+import android.content.Context
+import android.telephony.TelephonyCallback
+import android.telephony.TelephonyManager
+import android.util.Log
+import kotlinx.coroutines.flow.Flow
+
+private const val TAG = "AllowedNetworkTypesFlow"
+
+/** Creates an instance of a cold Flow for Allowed Network Types of given [subId]. */
+fun Context.allowedNetworkTypesFlow(subId: Int): Flow<Long> = telephonyCallbackFlow(subId) {
+ object : TelephonyCallback(), TelephonyCallback.AllowedNetworkTypesListener {
+ override fun onAllowedNetworkTypesChanged(reason: Int, allowedNetworkType: Long) {
+ if (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER ||
+ reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER
+ ) {
+ trySend(allowedNetworkType)
+ Log.d(TAG, "[$subId] reason: $reason, allowedNetworkType: $allowedNetworkType")
+ }
+ }
+ }
+}
diff --git a/src/com/android/settings/network/telephony/CallStateFlow.kt b/src/com/android/settings/network/telephony/CallStateFlow.kt
index 9d82602..f5164e0 100644
--- a/src/com/android/settings/network/telephony/CallStateFlow.kt
+++ b/src/com/android/settings/network/telephony/CallStateFlow.kt
@@ -18,28 +18,15 @@
import android.content.Context
import android.telephony.TelephonyCallback
-import android.telephony.TelephonyManager
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.asExecutor
-import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.callbackFlow
-import kotlinx.coroutines.flow.conflate
-import kotlinx.coroutines.flow.flowOn
/**
* Flow for call state.
*/
-fun Context.callStateFlow(subId: Int): Flow<Int> = callbackFlow {
- val telephonyManager = getSystemService(TelephonyManager::class.java)!!
- .createForSubscriptionId(subId)
-
- val callback = object : TelephonyCallback(), TelephonyCallback.CallStateListener {
+fun Context.callStateFlow(subId: Int): Flow<Int> = telephonyCallbackFlow(subId) {
+ object : TelephonyCallback(), TelephonyCallback.CallStateListener {
override fun onCallStateChanged(state: Int) {
trySend(state)
}
}
- telephonyManager.registerTelephonyCallback(Dispatchers.Default.asExecutor(), callback)
-
- awaitClose { telephonyManager.unregisterTelephonyCallback(callback) }
-}.conflate().flowOn(Dispatchers.Default)
+}
diff --git a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.kt b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.kt
index 4e41038..bf95475 100644
--- a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.kt
+++ b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.kt
@@ -29,8 +29,13 @@
/**
* Preference controller for "MMS messages"
*/
-class MmsMessagePreferenceController(context: Context, key: String) :
- TelephonyTogglePreferenceController(context, key) {
+class MmsMessagePreferenceController @JvmOverloads constructor(
+ context: Context,
+ key: String,
+ private val getDefaultDataSubId: () -> Int = {
+ SubscriptionManager.getDefaultDataSubscriptionId()
+ },
+) : TelephonyTogglePreferenceController(context, key) {
private lateinit var telephonyManager: TelephonyManager
@@ -46,10 +51,17 @@
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID &&
!telephonyManager.isDataEnabled &&
telephonyManager.isApnMetered(ApnSetting.TYPE_MMS) &&
- !telephonyManager.isMobileDataPolicyEnabled(
+ !isFallbackDataEnabled()
+ ) AVAILABLE else CONDITIONALLY_UNAVAILABLE
+
+ private fun isFallbackDataEnabled(): Boolean {
+ val defaultDataSubId = getDefaultDataSubId()
+ return defaultDataSubId != mSubId &&
+ telephonyManager.createForSubscriptionId(defaultDataSubId).isDataEnabled &&
+ telephonyManager.isMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH
)
- ) AVAILABLE else CONDITIONALLY_UNAVAILABLE
+ }
override fun displayPreference(screen: PreferenceScreen) {
super.displayPreference(screen)
@@ -61,7 +73,8 @@
mContext.mobileDataEnabledFlow(mSubId),
mContext.subscriptionsChangedFlow(), // Capture isMobileDataPolicyEnabled() changes
) { _, _ -> }.collectLatestWithLifecycle(viewLifecycleOwner) {
- preferenceScreen?.let { super.displayPreference(it) } }
+ preferenceScreen?.let { super.displayPreference(it) }
+ }
}
override fun isChecked(): Boolean = telephonyManager.isMobileDataPolicyEnabled(
diff --git a/src/com/android/settings/network/telephony/ServiceStateFlow.kt b/src/com/android/settings/network/telephony/ServiceStateFlow.kt
new file mode 100644
index 0000000..8770321
--- /dev/null
+++ b/src/com/android/settings/network/telephony/ServiceStateFlow.kt
@@ -0,0 +1,35 @@
+/*
+ * 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.network.telephony
+
+import android.content.Context
+import android.telephony.ServiceState
+import android.telephony.TelephonyCallback
+import android.util.Log
+import kotlinx.coroutines.flow.Flow
+
+private const val TAG = "ServiceStateFlow"
+
+/** Creates an instance of a cold Flow for [ServiceState] of given [subId]. */
+fun Context.serviceStateFlow(subId: Int): Flow<ServiceState> = telephonyCallbackFlow(subId) {
+ object : TelephonyCallback(), TelephonyCallback.ServiceStateListener {
+ override fun onServiceStateChanged(serviceState: ServiceState) {
+ trySend(serviceState)
+ Log.d(TAG, "[$subId] serviceState: $serviceState")
+ }
+ }
+}
diff --git a/src/com/android/settings/network/telephony/TelephonyRepository.kt b/src/com/android/settings/network/telephony/TelephonyRepository.kt
new file mode 100644
index 0000000..678aaac
--- /dev/null
+++ b/src/com/android/settings/network/telephony/TelephonyRepository.kt
@@ -0,0 +1,44 @@
+/*
+ * 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.network.telephony
+
+import android.content.Context
+import android.telephony.TelephonyCallback
+import android.telephony.TelephonyManager
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.asExecutor
+import kotlinx.coroutines.channels.ProducerScope
+import kotlinx.coroutines.channels.awaitClose
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.callbackFlow
+import kotlinx.coroutines.flow.conflate
+import kotlinx.coroutines.flow.flowOn
+
+/** Creates an instance of a cold Flow for Telephony callback of given [subId]. */
+fun <T> Context.telephonyCallbackFlow(
+ subId: Int,
+ block: ProducerScope<T>.() -> TelephonyCallback,
+): Flow<T> = callbackFlow {
+ val telephonyManager = getSystemService(TelephonyManager::class.java)!!
+ .createForSubscriptionId(subId)
+
+ val callback = block()
+
+ telephonyManager.registerTelephonyCallback(Dispatchers.Default.asExecutor(), callback)
+
+ awaitClose { telephonyManager.unregisterTelephonyCallback(callback) }
+}.conflate().flowOn(Dispatchers.Default)
diff --git a/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java b/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java
deleted file mode 100644
index 7bc0dc1..0000000
--- a/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2018 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.gsm;
-
-import static androidx.lifecycle.Lifecycle.Event.ON_START;
-import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
-
-import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
-
-import android.content.Context;
-import android.content.Intent;
-import android.provider.Settings;
-import android.telephony.ServiceState;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-
-import androidx.lifecycle.LifecycleObserver;
-import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.network.AllowedNetworkTypesListener;
-import com.android.settings.network.telephony.MobileNetworkUtils;
-import com.android.settings.network.telephony.TelephonyBasePreferenceController;
-
-/**
- * Preference controller for "Open network select"
- */
-public class OpenNetworkSelectPagePreferenceController extends
- TelephonyBasePreferenceController implements
- AutoSelectPreferenceController.OnNetworkSelectModeListener, LifecycleObserver {
-
- private TelephonyManager mTelephonyManager;
- private Preference mPreference;
- private PreferenceScreen mPreferenceScreen;
- private AllowedNetworkTypesListener mAllowedNetworkTypesListener;
- private int mCacheOfModeStatus;
-
- public OpenNetworkSelectPagePreferenceController(Context context, String key) {
- super(context, key);
- mTelephonyManager = context.getSystemService(TelephonyManager.class);
- mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
- mCacheOfModeStatus = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
- mAllowedNetworkTypesListener = new AllowedNetworkTypesListener(
- context.getMainExecutor());
- mAllowedNetworkTypesListener.setAllowedNetworkTypesListener(
- () -> updatePreference());
-
- }
-
- private void updatePreference() {
- if (mPreferenceScreen != null) {
- displayPreference(mPreferenceScreen);
- }
- if (mPreference != null) {
- updateState(mPreference);
- }
- }
-
- @Override
- public int getAvailabilityStatus(int subId) {
- return MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, subId)
- ? AVAILABLE
- : CONDITIONALLY_UNAVAILABLE;
- }
-
- @OnLifecycleEvent(ON_START)
- public void onStart() {
- mAllowedNetworkTypesListener.register(mContext, mSubId);
- }
-
- @OnLifecycleEvent(ON_STOP)
- public void onStop() {
- mAllowedNetworkTypesListener.unregister(mContext, mSubId);
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreferenceScreen = screen;
- mPreference = screen.findPreference(getPreferenceKey());
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- preference.setEnabled(mCacheOfModeStatus
- != TelephonyManager.NETWORK_SELECTION_MODE_AUTO);
-
- Intent intent = new Intent();
- intent.setClassName(SETTINGS_PACKAGE_NAME,
- SETTINGS_PACKAGE_NAME + ".Settings$NetworkSelectActivity");
- intent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
- preference.setIntent(intent);
- }
-
- @Override
- public CharSequence getSummary() {
- final ServiceState ss = mTelephonyManager.getServiceState();
- if (ss != null && ss.getState() == ServiceState.STATE_IN_SERVICE) {
- return MobileNetworkUtils.getCurrentCarrierNameForDisplay(mContext, mSubId);
- } else {
- return mContext.getString(R.string.network_disconnected);
- }
- }
-
- /**
- * Initialization based on given subscription id.
- **/
- public OpenNetworkSelectPagePreferenceController init(int subId) {
- mSubId = subId;
- mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
- .createForSubscriptionId(mSubId);
- return this;
- }
-
- @Override
- public void onNetworkSelectModeUpdated(int mode) {
- mCacheOfModeStatus = mode;
- if (mPreference != null) {
- updateState(mPreference);
- }
- }
-}
diff --git a/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.kt b/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.kt
new file mode 100644
index 0000000..84cdec4
--- /dev/null
+++ b/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.kt
@@ -0,0 +1,96 @@
+/*
+ * 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.network.telephony.gsm
+
+import android.content.Context
+import android.content.Intent
+import android.provider.Settings
+import android.telephony.ServiceState
+import android.telephony.TelephonyManager
+import androidx.lifecycle.LifecycleOwner
+import androidx.preference.Preference
+import androidx.preference.PreferenceScreen
+import com.android.settings.R
+import com.android.settings.Settings.NetworkSelectActivity
+import com.android.settings.network.telephony.MobileNetworkUtils
+import com.android.settings.network.telephony.TelephonyBasePreferenceController
+import com.android.settings.network.telephony.allowedNetworkTypesFlow
+import com.android.settings.network.telephony.serviceStateFlow
+import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.withContext
+
+/**
+ * Preference controller for "Open network select"
+ */
+class OpenNetworkSelectPagePreferenceController @JvmOverloads constructor(
+ context: Context,
+ key: String,
+ private val allowedNetworkTypesFlowFactory: (subId: Int) -> Flow<Long> =
+ context::allowedNetworkTypesFlow,
+ private val serviceStateFlowFactory: (subId: Int) -> Flow<ServiceState> =
+ context::serviceStateFlow,
+) : TelephonyBasePreferenceController(context, key),
+ AutoSelectPreferenceController.OnNetworkSelectModeListener {
+
+ private var preference: Preference? = null
+
+ /**
+ * Initialization based on given subscription id.
+ */
+ fun init(subId: Int): OpenNetworkSelectPagePreferenceController {
+ mSubId = subId
+ return this
+ }
+
+ override fun getAvailabilityStatus(subId: Int) =
+ if (MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, subId)) AVAILABLE
+ else CONDITIONALLY_UNAVAILABLE
+
+ override fun displayPreference(screen: PreferenceScreen) {
+ super.displayPreference(screen)
+ preference = screen.findPreference(preferenceKey)
+ preference?.intent = Intent().apply {
+ setClass(mContext, NetworkSelectActivity::class.java)
+ putExtra(Settings.EXTRA_SUB_ID, mSubId)
+ }
+ }
+
+ override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
+ allowedNetworkTypesFlowFactory(mSubId).collectLatestWithLifecycle(viewLifecycleOwner) {
+ preference?.isVisible = withContext(Dispatchers.Default) {
+ MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, mSubId)
+ }
+ }
+
+ serviceStateFlowFactory(mSubId)
+ .collectLatestWithLifecycle(viewLifecycleOwner) { serviceState ->
+ preference?.summary = if (serviceState.state == ServiceState.STATE_IN_SERVICE) {
+ withContext(Dispatchers.Default) {
+ MobileNetworkUtils.getCurrentCarrierNameForDisplay(mContext, mSubId)
+ }
+ } else {
+ mContext.getString(R.string.network_disconnected)
+ }
+ }
+ }
+
+ override fun onNetworkSelectModeUpdated(mode: Int) {
+ preference?.isEnabled = mode != TelephonyManager.NETWORK_SELECTION_MODE_AUTO
+ }
+}
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index 76e342e..663b4e5 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -162,6 +162,7 @@
private boolean mRequestGatekeeperPasswordHandle = false;
private boolean mPasswordConfirmed = false;
private boolean mWaitingForConfirmation = false;
+ private boolean mWaitingForActivityResult = false;
private LockscreenCredential mUserPassword;
private FingerprintManager mFingerprintManager;
private FaceManager mFaceManager;
@@ -470,6 +471,7 @@
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mWaitingForConfirmation = false;
+ mWaitingForActivityResult = false;
if (requestCode == CONFIRM_EXISTING_REQUEST && resultCode == Activity.RESULT_OK) {
mPasswordConfirmed = true;
mUserPassword = data != null
@@ -479,7 +481,6 @@
} else if (requestCode == CHOOSE_LOCK_REQUEST) {
if (resultCode != RESULT_CANCELED) {
getActivity().setResult(resultCode, data);
- finish();
} else {
// If PASSWORD_TYPE_KEY is set, this activity is used as a trampoline to start
// the actual password enrollment. If the result is canceled, which means the
@@ -487,9 +488,9 @@
int quality = getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
if (quality != -1) {
getActivity().setResult(RESULT_CANCELED, data);
- finish();
}
}
+ finish();
} else if (requestCode == CHOOSE_LOCK_BEFORE_BIOMETRIC_REQUEST
&& resultCode == BiometricEnrollBase.RESULT_FINISHED) {
Intent intent = getBiometricEnrollIntent(getActivity());
@@ -821,6 +822,7 @@
}
if (getIntent().getBooleanExtra(EXTRA_KEY_REQUEST_WRITE_REPAIR_MODE_PW, false)) {
intent.putExtra(EXTRA_KEY_REQUEST_WRITE_REPAIR_MODE_PW, true);
+ mWaitingForActivityResult = true;
}
intent.putExtra(EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS, getIntent().getExtras());
// If the caller requested Gatekeeper Password Handle to be returned, we assume it
@@ -871,7 +873,7 @@
// Otherwise, bugs would be caused. (e.g. b/278488549, b/278530059)
final boolean hasCredential = mLockPatternUtils.isSecure(mUserId);
if (!getActivity().isChangingConfigurations()
- && !mWaitingForConfirmation && hasCredential) {
+ && !mWaitingForConfirmation && !mWaitingForActivityResult && hasCredential) {
getActivity().finish();
}
}
diff --git a/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppsPageProvider.kt b/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppsPageProvider.kt
index 7368750f..15cd1ba 100644
--- a/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppsPageProvider.kt
+++ b/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppsPageProvider.kt
@@ -22,6 +22,7 @@
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager.GET_ACTIVITIES
+import android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT
import android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET
import android.os.Build
import android.os.Bundle
@@ -139,7 +140,9 @@
recordList: List<UserAspectRatioAppListItemModel>
): List<SpinnerOption> {
val hasSuggested = recordList.any { it.suggested }
- val hasOverride = recordList.any { it.userOverride != USER_MIN_ASPECT_RATIO_UNSET }
+ val hasOverride = recordList.any {
+ userAspectRatioManager.isAppOverridden(it.app, it.userOverride)
+ }
val options = mutableListOf(SpinnerItem.All)
// Add suggested filter first as default
if (hasSuggested) options.add(0, SpinnerItem.Suggested)
@@ -187,7 +190,9 @@
): Flow<List<UserAspectRatioAppListItemModel>> = recordListFlow.filterItem(
when (SpinnerItem.entries.getOrNull(option)) {
SpinnerItem.Suggested -> ({ it.canDisplay && it.suggested })
- SpinnerItem.Overridden -> ({ it.userOverride != USER_MIN_ASPECT_RATIO_UNSET })
+ SpinnerItem.Overridden -> ({
+ userAspectRatioManager.isAppOverridden(it.app, it.userOverride)
+ })
else -> ({ it.canDisplay })
}
)
@@ -197,7 +202,7 @@
val summary by remember(record.userOverride) {
flow {
emit(userAspectRatioManager.getUserMinAspectRatioEntry(record.userOverride,
- record.app.packageName))
+ record.app.packageName, record.app.userId))
}.flowOn(Dispatchers.IO)
}.collectAsStateWithLifecycle(initialValue = stringResource(R.string.summary_placeholder))
return { summary }
diff --git a/tests/legacy_unit/src/com/android/settings/UserCredentialsTest.java b/tests/legacy_unit/src/com/android/settings/UserCredentialsTest.java
index a182416..113db7f 100644
--- a/tests/legacy_unit/src/com/android/settings/UserCredentialsTest.java
+++ b/tests/legacy_unit/src/com/android/settings/UserCredentialsTest.java
@@ -21,7 +21,8 @@
import android.os.Parcel;
import android.os.Process;
import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+
+import androidx.test.filters.SmallTest;
/**
* User credentials settings fragment tests
diff --git a/tests/legacy_unit/src/com/android/settings/UtilsTest.java b/tests/legacy_unit/src/com/android/settings/UtilsTest.java
index 5048fb5..24f921b 100644
--- a/tests/legacy_unit/src/com/android/settings/UtilsTest.java
+++ b/tests/legacy_unit/src/com/android/settings/UtilsTest.java
@@ -23,7 +23,8 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+
+import androidx.test.filters.SmallTest;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
diff --git a/tests/legacy_unit/src/com/android/settings/bluetooth/Utf8ByteLengthFilterTest.java b/tests/legacy_unit/src/com/android/settings/bluetooth/Utf8ByteLengthFilterTest.java
index 8cbf29b..1ee2100 100644
--- a/tests/legacy_unit/src/com/android/settings/bluetooth/Utf8ByteLengthFilterTest.java
+++ b/tests/legacy_unit/src/com/android/settings/bluetooth/Utf8ByteLengthFilterTest.java
@@ -17,10 +17,11 @@
package com.android.settings.bluetooth;
import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
import android.text.InputFilter;
import android.text.SpannableStringBuilder;
+import androidx.test.filters.SmallTest;
+
public class Utf8ByteLengthFilterTest extends AndroidTestCase {
@SmallTest
diff --git a/tests/legacy_unit/src/com/android/settings/vpn2/AppSettingsTest.java b/tests/legacy_unit/src/com/android/settings/vpn2/AppSettingsTest.java
index a30d610..a437ea7 100644
--- a/tests/legacy_unit/src/com/android/settings/vpn2/AppSettingsTest.java
+++ b/tests/legacy_unit/src/com/android/settings/vpn2/AppSettingsTest.java
@@ -27,7 +27,8 @@
import android.content.pm.ApplicationInfo;
import android.os.Process;
import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+
+import androidx.test.filters.SmallTest;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
diff --git a/tests/legacy_unit/src/com/android/settings/vpn2/PreferenceListTest.java b/tests/legacy_unit/src/com/android/settings/vpn2/PreferenceListTest.java
index 31856f5..7ce01c8 100644
--- a/tests/legacy_unit/src/com/android/settings/vpn2/PreferenceListTest.java
+++ b/tests/legacy_unit/src/com/android/settings/vpn2/PreferenceListTest.java
@@ -31,9 +31,10 @@
import static org.mockito.Mockito.verify;
import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
+import androidx.test.filters.SmallTest;
+
import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnProfile;
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityButtonPreferenceControllerTest.java
index 03f7887..ded9bcc 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityButtonPreferenceControllerTest.java
@@ -31,6 +31,7 @@
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
+import com.android.settingslib.search.SearchIndexableRaw;
import org.junit.Before;
import org.junit.Rule;
@@ -42,6 +43,9 @@
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
+import java.util.ArrayList;
+import java.util.List;
+
/** Tests for {@link AccessibilityButtonPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class AccessibilityButtonPreferenceControllerTest {
@@ -88,4 +92,36 @@
assertThat(mPreference.getTitle()).isEqualTo(
mContext.getText(R.string.accessibility_button_title));
}
+
+ @Test
+ public void updateDynamicRawDataToIndex_navigationGestureEnabled_setCorrectIndex() {
+ when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
+ .thenReturn(NAV_BAR_MODE_GESTURAL);
+ List<SearchIndexableRaw> rawDataList = new ArrayList<>();
+
+ mController.updateDynamicRawDataToIndex(rawDataList);
+
+ assertThat(rawDataList).hasSize(1);
+ SearchIndexableRaw raw = rawDataList.get(0);
+ assertThat(raw.title).isEqualTo(
+ mResources.getString(R.string.accessibility_button_gesture_title));
+ assertThat(raw.screenTitle).isEqualTo(
+ mResources.getString(R.string.accessibility_shortcuts_settings_title));
+ }
+
+ @Test
+ public void updateDynamicRawDataToIndex_navigationGestureDisabled_setCorrectIndex() {
+ when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
+ .thenReturn(NAV_BAR_MODE_2BUTTON);
+ List<SearchIndexableRaw> rawDataList = new ArrayList<>();
+
+ mController.updateDynamicRawDataToIndex(rawDataList);
+
+ assertThat(rawDataList).hasSize(1);
+ SearchIndexableRaw raw = rawDataList.get(0);
+ assertThat(raw.title).isEqualTo(
+ mResources.getString(R.string.accessibility_button_title));
+ assertThat(raw.screenTitle).isEqualTo(
+ mResources.getString(R.string.accessibility_shortcuts_settings_title));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/appcompat/UserAspectRatioDetailsTest.java b/tests/robotests/src/com/android/settings/applications/appcompat/UserAspectRatioDetailsTest.java
index b615163..f3b105b 100644
--- a/tests/robotests/src/com/android/settings/applications/appcompat/UserAspectRatioDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appcompat/UserAspectRatioDetailsTest.java
@@ -16,12 +16,21 @@
package com.android.settings.applications.appcompat;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
+
+import static com.android.settings.applications.AppInfoBase.ARG_PACKAGE_NAME;
import static com.android.settings.applications.appcompat.UserAspectRatioDetails.KEY_PREF_3_2;
import static com.android.settings.applications.appcompat.UserAspectRatioDetails.KEY_PREF_DEFAULT;
+import static com.android.settings.applications.appcompat.UserAspectRatioDetails.KEY_PREF_FULLSCREEN;
+import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -30,15 +39,20 @@
import android.app.IActivityManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.os.Bundle;
import android.os.RemoteException;
+import androidx.fragment.app.testing.EmptyFragmentActivity;
import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.rules.ActivityScenarioRule;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowActivityManager;
+import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
@@ -51,9 +65,13 @@
* To run test: atest SettingsRoboTests:UserAspectRatioDetailsTest
*/
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowActivityManager.class})
+@Config(shadows = {ShadowActivityManager.class, ShadowFragment.class})
public class UserAspectRatioDetailsTest {
+ @Rule
+ public ActivityScenarioRule<EmptyFragmentActivity> rule =
+ new ActivityScenarioRule<>(EmptyFragmentActivity.class);
+
@Mock
private UserAspectRatioManager mUserAspectRatioManager;
@Mock
@@ -72,6 +90,8 @@
mFragment = spy(new UserAspectRatioDetails());
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getAspectRatioManager()).thenReturn(mUserAspectRatioManager);
+ when(mUserAspectRatioManager.isOverrideToFullscreenEnabled(anyString(), anyInt()))
+ .thenReturn(false);
ShadowActivityManager.setService(mAm);
mRadioButtonPref = new RadioWithImagePreference(mContext);
final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
@@ -80,6 +100,8 @@
@Test
public void onRadioButtonClicked_prefChange_shouldStopActivity() throws RemoteException {
+ doReturn(USER_MIN_ASPECT_RATIO_UNSET).when(mFragment)
+ .getSelectedUserMinAspectRatio(anyString());
// Default was already selected
mRadioButtonPref.setKey(KEY_PREF_DEFAULT);
mFragment.onRadioButtonClicked(mRadioButtonPref);
@@ -92,6 +114,8 @@
@Test
public void onRadioButtonClicked_prefChange_shouldSetAspectRatio() throws RemoteException {
+ doReturn(USER_MIN_ASPECT_RATIO_UNSET).when(mFragment)
+ .getSelectedUserMinAspectRatio(anyString());
// Default was already selected
mRadioButtonPref.setKey(KEY_PREF_DEFAULT);
mFragment.onRadioButtonClicked(mRadioButtonPref);
@@ -105,6 +129,8 @@
@Test
public void onRadioButtonClicked_prefChange_logMetrics() throws NullPointerException {
+ doReturn(USER_MIN_ASPECT_RATIO_UNSET).when(mFragment)
+ .getSelectedUserMinAspectRatio(anyString());
// Default was already selected
mRadioButtonPref.setKey(KEY_PREF_DEFAULT);
mFragment.onRadioButtonClicked(mRadioButtonPref);
@@ -129,4 +155,47 @@
any(),
anyInt());
}
+
+ @Test
+ public void onButtonClicked_overrideEnabled_fullscreenPreselected()
+ throws RemoteException {
+ doReturn(true).when(mUserAspectRatioManager)
+ .isOverrideToFullscreenEnabled(anyString(), anyInt());
+ doReturn(USER_MIN_ASPECT_RATIO_UNSET).when(mUserAspectRatioManager)
+ .getUserMinAspectRatioValue(anyString(), anyInt());
+ doReturn(mRadioButtonPref).when(mFragment).findPreference(KEY_PREF_DEFAULT);
+ doReturn(mRadioButtonPref).when(mFragment).findPreference(KEY_PREF_FULLSCREEN);
+ doReturn(true).when(mUserAspectRatioManager)
+ .hasAspectRatioOption(anyInt(), anyString());
+
+ rule.getScenario().onActivity(a -> doReturn(a).when(mFragment).getActivity());
+ final Bundle args = new Bundle();
+ args.putString(ARG_PACKAGE_NAME, anyString());
+ mFragment.setArguments(args);
+ mFragment.onCreate(Bundle.EMPTY);
+
+ // Fullscreen should be pre-selected
+ assertEquals(KEY_PREF_FULLSCREEN, mFragment.mSelectedKey);
+ assertEquals(USER_MIN_ASPECT_RATIO_FULLSCREEN,
+ mFragment.getSelectedUserMinAspectRatio(mFragment.mSelectedKey));
+
+ // Revert to app default, should be set to app default from unset
+ mRadioButtonPref.setKey(KEY_PREF_DEFAULT);
+ mFragment.onRadioButtonClicked(mRadioButtonPref);
+ verify(mUserAspectRatioManager).setUserMinAspectRatio(
+ any(), anyInt(), anyInt());
+ assertEquals(USER_MIN_ASPECT_RATIO_APP_DEFAULT,
+ mFragment.getSelectedUserMinAspectRatio(mFragment.mSelectedKey));
+ assertEquals(KEY_PREF_DEFAULT, mFragment.mSelectedKey);
+
+ // Fullscreen override disabled, should be changed to unset from app default
+ when(mUserAspectRatioManager.isOverrideToFullscreenEnabled(anyString(), anyInt()))
+ .thenReturn(false);
+ mFragment.mKeyToAspectRatioMap.clear();
+ mFragment.onCreate(Bundle.EMPTY);
+
+ assertEquals(KEY_PREF_DEFAULT, mFragment.mSelectedKey);
+ assertEquals(USER_MIN_ASPECT_RATIO_UNSET,
+ mFragment.getSelectedUserMinAspectRatio(mFragment.mSelectedKey));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
index 49777bc..d24a83b 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
@@ -59,7 +59,6 @@
import java.util.HashSet;
import java.util.Set;
-@Ignore("b/313014781")
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowEntityHeaderController.class, ShadowDeviceConfig.class})
public class AdvancedBluetoothDetailsHeaderControllerTest {
@@ -386,6 +385,9 @@
.thenReturn("true".getBytes());
Set<CachedBluetoothDevice> cacheBluetoothDevices = new HashSet<>();
when(mCachedDevice.getMemberDevice()).thenReturn(cacheBluetoothDevices);
+ when(mBluetoothAdapter.addOnMetadataChangedListener(
+ mBluetoothDevice, mContext.getMainExecutor(), mController.mMetadataListener))
+ .thenReturn(true);
mController.onStart();
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioControllerTest.java
index de70330..2cc55a7 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsSpatialAudioControllerTest.java
@@ -43,6 +43,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowLooper;
import java.util.ArrayList;
import java.util.List;
@@ -120,6 +121,7 @@
when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices);
mController.refresh();
+ ShadowLooper.idleMainLooper();
assertThat(mSpatialAudioPref.isChecked()).isTrue();
}
@@ -130,6 +132,7 @@
when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices);
mController.refresh();
+ ShadowLooper.idleMainLooper();
assertThat(mSpatialAudioPref.isChecked()).isFalse();
}
@@ -142,6 +145,7 @@
when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(true);
mController.refresh();
+ ShadowLooper.idleMainLooper();
assertThat(mHeadTrackingPref.isVisible()).isTrue();
}
@@ -156,6 +160,7 @@
when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(false);
mController.refresh();
+ ShadowLooper.idleMainLooper();
verify(mProfilesContainer).removePreference(mHeadTrackingPref);
}
@@ -166,6 +171,7 @@
when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices);
mController.refresh();
+ ShadowLooper.idleMainLooper();
verify(mProfilesContainer).removePreference(mHeadTrackingPref);
}
@@ -181,6 +187,7 @@
when(mSpatializer.isHeadTrackerEnabled(mController.mAudioDevice)).thenReturn(true);
mController.refresh();
+ ShadowLooper.idleMainLooper();
assertThat(mHeadTrackingPref.isChecked()).isTrue();
}
@@ -196,6 +203,7 @@
when(mSpatializer.isHeadTrackerEnabled(mController.mAudioDevice)).thenReturn(false);
mController.refresh();
+ ShadowLooper.idleMainLooper();
assertThat(mHeadTrackingPref.isChecked()).isFalse();
}
diff --git a/tests/robotests/src/com/android/settings/development/GameDefaultFrameRatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/GameDefaultFrameRatePreferenceControllerTest.java
new file mode 100644
index 0000000..d433905
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/GameDefaultFrameRatePreferenceControllerTest.java
@@ -0,0 +1,177 @@
+/*
+ * 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.development;
+
+import static com.android.settings.development.GameDefaultFrameRatePreferenceController.Injector;
+import static com.android.settings.development.GameDefaultFrameRatePreferenceController.PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.IGameManagerService;
+import android.content.Context;
+import android.os.RemoteException;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+
+import com.android.settings.flags.Flags;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDefaultFrameRatePreferenceControllerTest {
+ @Mock
+ private Context mContext;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private TwoStatePreference mPreference;
+ @Mock
+ private IGameManagerService mGameManagerService;
+ @Mock
+ private DevelopmentSystemPropertiesWrapper mSysPropsMock;
+
+ private GameDefaultFrameRatePreferenceController mController;
+
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new GameDefaultFrameRatePreferenceController(mContext, mGameManagerService,
+ new Injector(){
+ @Override
+ public DevelopmentSystemPropertiesWrapper createSystemPropertiesWrapper() {
+ return mSysPropsMock;
+ }
+ });
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ }
+
+ @Test
+ public void onPreferenceChange_settingEnabled_shouldChecked() throws RemoteException {
+ mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ assertTrue(mController.isAvailable());
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
+ ArgumentMatchers.eq(false)))
+ .thenReturn(true);
+
+ mController.onPreferenceChange(mPreference, true /* new value */);
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void onPreferenceChange_settingDisabled_shouldUnchecked() throws RemoteException {
+ mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ assertTrue(mController.isAvailable());
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
+ ArgumentMatchers.eq(false)))
+ .thenReturn(false);
+ mController.onPreferenceChange(mPreference, false /* new value */);
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void updateState_settingEnabled_shouldChecked() throws RemoteException {
+ mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ assertTrue(mController.isAvailable());
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
+ ArgumentMatchers.eq(false)))
+ .thenReturn(true);
+ mController.updateState(mPreference);
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void updateState_settingDisabled_shouldUnchecked() throws RemoteException {
+ mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ assertTrue(mController.isAvailable());
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
+ ArgumentMatchers.eq(false)))
+ .thenReturn(false);
+ mController.updateState(mPreference);
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void settingNotAvailable_flagsOff() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ mController = new GameDefaultFrameRatePreferenceController(
+ mContext, mGameManagerService, new Injector());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void settingAvailable_flagsOn() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ mController = new GameDefaultFrameRatePreferenceController(
+ mContext, mGameManagerService, new Injector());
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void onDeveloperOptionsSwitchDisabled_preferenceUnchecked_shouldNotTurnOffPreference()
+ throws RemoteException {
+ mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
+ ArgumentMatchers.eq(false)))
+ .thenReturn(false);
+ assertTrue(mController.isAvailable());
+ when(mPreference.isChecked()).thenReturn(false);
+ mController.onDeveloperOptionsSwitchDisabled();
+
+ verify(mPreference).setChecked(false);
+ verify(mPreference).setEnabled(false);
+ }
+
+ @Test
+ public void onDeveloperOptionsSwitchDisabled_preferenceChecked_shouldTurnOffPreference()
+ throws RemoteException {
+ mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
+ ArgumentMatchers.eq(false)))
+ .thenReturn(true);
+ assertTrue(mController.isAvailable());
+
+ when(mPreference.isChecked()).thenReturn(true);
+ mController.onDeveloperOptionsSwitchDisabled();
+
+ verify(mPreference).setChecked(false);
+ verify(mPreference).setEnabled(false);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntryTest.java
index 6f1dce6..4567bc3 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntryTest.java
@@ -59,6 +59,7 @@
public final class BatteryDiffEntryTest {
private static final int UID = 100;
+ private static final int USER_ID = 0;
private static final int UNINSTALLED_UID = 101;
private static final String PACKAGE_NAME = "com.android.testing";
private static final String UNINSTALLED_PACKAGE_NAME = "com.android.testing.uninstalled";
@@ -87,13 +88,14 @@
doReturn(mMockPackageManager).when(mContext).getPackageManager();
doReturn(UID)
.when(mMockPackageManager)
- .getPackageUid(PACKAGE_NAME, PackageManager.GET_META_DATA);
+ .getPackageUidAsUser(PACKAGE_NAME, PackageManager.GET_META_DATA, USER_ID);
doReturn(BatteryUtils.UID_NULL)
.when(mMockPackageManager)
- .getPackageUid(UNINSTALLED_PACKAGE_NAME, PackageManager.GET_META_DATA);
+ .getPackageUidAsUser(
+ UNINSTALLED_PACKAGE_NAME, PackageManager.GET_META_DATA, USER_ID);
doReturn(BatteryUtils.UID_ZERO)
.when(mMockPackageManager)
- .getPackageUid(UID_ZERO_PACKAGE_NAME, PackageManager.GET_META_DATA);
+ .getPackageUidAsUser(UID_ZERO_PACKAGE_NAME, PackageManager.GET_META_DATA, USER_ID);
BatteryDiffEntry.clearCache();
}
diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
index 3857e64..27a85fd 100644
--- a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
@@ -169,6 +169,19 @@
}
@Test
+ public void showHomepageWithSuggestion_callAfterOnStop_shouldUpdateVisibility() {
+ final SettingsHomepageActivity activity = Robolectric.buildActivity(
+ SettingsHomepageActivity.class).create().get();
+ final View suggestionTile = activity.findViewById(R.id.suggestion_content);
+
+ activity.showHomepageWithSuggestion(true);
+ activity.onStop();
+ activity.showHomepageWithSuggestion(false);
+
+ assertThat(suggestionTile.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ @Test
public void onStart_isNotDebuggable_shouldHideSystemOverlay() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
index ca1ab54..e7e0b92 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
@@ -305,6 +305,16 @@
}
@Test
+ public void onActivityResult_requestcode102_resultCancel_shouldFinish() {
+ initActivity(null);
+
+ mFragment.onActivityResult(ChooseLockGenericFragment.CHOOSE_LOCK_REQUEST,
+ Activity.RESULT_CANCELED, null /* data */);
+
+ assertThat(mActivity.isFinishing()).isTrue();
+ }
+
+ @Test
public void onActivityResult_requestcode103_shouldFinish() {
initActivity(null);
diff --git a/tests/spa_unit/AndroidManifest.xml b/tests/spa_unit/AndroidManifest.xml
index 5a7f565..51ac1b7 100644
--- a/tests/spa_unit/AndroidManifest.xml
+++ b/tests/spa_unit/AndroidManifest.xml
@@ -22,6 +22,8 @@
<uses-permission android:name="android.permission.MANAGE_APPOPS" />
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
<uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG" />
+ <uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG" />
+ <uses-permission android:name="android.permission.LOG_COMPAT_CHANGE" />
<application android:debuggable="true">
<provider android:name="com.android.settings.slices.SettingsSliceProvider"
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/AllowedNetworkTypesFlowTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/AllowedNetworkTypesFlowTest.kt
new file mode 100644
index 0000000..288018d
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/AllowedNetworkTypesFlowTest.kt
@@ -0,0 +1,113 @@
+/*
+ * 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.network.telephony
+
+import android.content.Context
+import android.telephony.TelephonyCallback
+import android.telephony.TelephonyManager
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
+import com.android.settingslib.spa.testutils.toListWithTimeout
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.async
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+
+@RunWith(AndroidJUnit4::class)
+class AllowedNetworkTypesFlowTest {
+
+ private var allowedNetworkTypesListener: TelephonyCallback.AllowedNetworkTypesListener? = null
+
+ private val mockTelephonyManager = mock<TelephonyManager> {
+ on { createForSubscriptionId(SUB_ID) } doReturn mock
+ on { registerTelephonyCallback(any(), any()) } doAnswer {
+ allowedNetworkTypesListener =
+ it.arguments[1] as TelephonyCallback.AllowedNetworkTypesListener
+ }
+ }
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
+ }
+
+ @Test
+ fun allowedNetworkTypesFlow_initial_notSndInitialValue() = runBlocking {
+ val flow = context.allowedNetworkTypesFlow(SUB_ID)
+
+ val state = flow.firstWithTimeoutOrNull()
+
+ assertThat(state).isNull()
+ }
+
+ @Test
+ fun allowedNetworkTypesFlow_userReasonChanged_sendChanged(): Unit = runBlocking {
+ val listDeferred = async {
+ context.allowedNetworkTypesFlow(SUB_ID).toListWithTimeout()
+ }
+ delay(100)
+
+ allowedNetworkTypesListener?.onAllowedNetworkTypesChanged(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
+ ALLOWED_NETWORK_TYPE,
+ )
+
+ assertThat(listDeferred.await()).containsExactly(ALLOWED_NETWORK_TYPE)
+ }
+
+ @Test
+ fun allowedNetworkTypesFlow_carrierReasonChanged_sendChanged(): Unit = runBlocking {
+ val listDeferred = async {
+ context.allowedNetworkTypesFlow(SUB_ID).toListWithTimeout()
+ }
+ delay(100)
+
+ allowedNetworkTypesListener?.onAllowedNetworkTypesChanged(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
+ ALLOWED_NETWORK_TYPE,
+ )
+
+ assertThat(listDeferred.await()).containsExactly(ALLOWED_NETWORK_TYPE)
+ }
+
+ @Test
+ fun allowedNetworkTypesFlow_powerReasonChanged_notSendChanged() = runBlocking {
+ val listDeferred = async {
+ context.allowedNetworkTypesFlow(SUB_ID).toListWithTimeout()
+ }
+ delay(100)
+
+ allowedNetworkTypesListener?.onAllowedNetworkTypesChanged(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
+ ALLOWED_NETWORK_TYPE,
+ )
+
+ assertThat(listDeferred.await()).isEmpty()
+ }
+
+ private companion object {
+ const val SUB_ID = 1
+ const val ALLOWED_NETWORK_TYPE = 10L
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.kt
index 5888819..a2f635d 100644
--- a/tests/spa_unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.kt
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.kt
@@ -27,7 +27,6 @@
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
-import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
@@ -36,20 +35,35 @@
@RunWith(AndroidJUnit4::class)
class MmsMessagePreferenceControllerTest {
+ private val mockTelephonyManager1: TelephonyManager = mock<TelephonyManager> {
+ on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn true
+ }
+
+ private val mockTelephonyManager2: TelephonyManager = mock<TelephonyManager> {
+ on { createForSubscriptionId(SUB_1_ID) } doReturn mockTelephonyManager1
+ on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn true
+ }
+
private val mockTelephonyManager: TelephonyManager = mock<TelephonyManager> {
- on { createForSubscriptionId(any()) } doReturn mock
+ on { createForSubscriptionId(SUB_1_ID) } doReturn mockTelephonyManager1
+ on { createForSubscriptionId(SUB_2_ID) } doReturn mockTelephonyManager2
+ on { createForSubscriptionId(INVALID_SUBSCRIPTION_ID) } doReturn mock
}
private var context: Context = spy(ApplicationProvider.getApplicationContext()) {
on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
}
- private val controller = MmsMessagePreferenceController(context, KEY).apply {
- init(SUB_ID)
- }
+ private var defaultDataSubId = SUB_1_ID
+
+ private val controller = MmsMessagePreferenceController(
+ context = context,
+ key = KEY,
+ getDefaultDataSubId = { defaultDataSubId },
+ ).apply { init(SUB_2_ID) }
@Test
- fun getAvailabilityStatus_invalidSubscription_returnUnavailable() {
+ fun getAvailabilityStatus_invalidSubscription_unavailable() {
controller.init(INVALID_SUBSCRIPTION_ID)
val availabilityStatus = controller.getAvailabilityStatus(INVALID_SUBSCRIPTION_ID)
@@ -58,56 +72,92 @@
}
@Test
- fun getAvailabilityStatus_mobileDataOn_returnUnavailable() {
- mockTelephonyManager.stub {
+ fun getAvailabilityStatus_mobileDataOn_unavailable() {
+ mockTelephonyManager2.stub {
on { isDataEnabled } doReturn true
}
- val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_2_ID)
assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
}
@Test
- fun getAvailabilityStatus_meteredOff_returnUnavailable() {
- mockTelephonyManager.stub {
+ fun getAvailabilityStatus_meteredOff_unavailable() {
+ mockTelephonyManager2.stub {
on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn false
}
- val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_2_ID)
assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
}
@Test
- fun getAvailabilityStatus_autoDataSwitch_returnUnavailable() {
- mockTelephonyManager.stub {
- on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn true
+ fun getAvailabilityStatus_isDefaultDataAndDataOnAndAutoDataSwitchOn_unavailable() {
+ defaultDataSubId = SUB_2_ID
+ mockTelephonyManager2.stub {
+ on { isDataEnabled } doReturn true
on {
isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
} doReturn true
}
- val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_2_ID)
assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
}
@Test
- fun getAvailabilityStatus_mobileDataOffWithValidSubId_returnAvailable() {
- mockTelephonyManager.stub {
+ fun getAvailabilityStatus_isDefaultDataAndDataOffAndAutoDataSwitchOn_available() {
+ defaultDataSubId = SUB_2_ID
+ mockTelephonyManager2.stub {
on { isDataEnabled } doReturn false
- on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn true
+ on {
+ isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
+ } doReturn true
}
- val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_2_ID)
+
+ assertThat(availabilityStatus).isEqualTo(AVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_defaultDataOnAndAutoDataSwitchOn_unavailable() {
+ mockTelephonyManager1.stub {
+ on { isDataEnabled } doReturn true
+ }
+ mockTelephonyManager2.stub {
+ on {
+ isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
+ } doReturn true
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_2_ID)
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_defaultDataOffAndAutoDataSwitchOn_available() {
+ mockTelephonyManager1.stub {
+ on { isDataEnabled } doReturn false
+ }
+ mockTelephonyManager2.stub {
+ on {
+ isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
+ } doReturn true
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_2_ID)
assertThat(availabilityStatus).isEqualTo(AVAILABLE)
}
@Test
fun isChecked_whenMmsNotAlwaysAllowed_returnFalse() {
- mockTelephonyManager.stub {
+ mockTelephonyManager2.stub {
on {
isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED)
} doReturn false
@@ -120,7 +170,7 @@
@Test
fun isChecked_whenMmsAlwaysAllowed_returnTrue() {
- mockTelephonyManager.stub {
+ mockTelephonyManager2.stub {
on {
isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED)
} doReturn true
@@ -135,7 +185,7 @@
fun setChecked_setTrue_setDataIntoSubscriptionManager() {
controller.setChecked(true)
- verify(mockTelephonyManager).setMobileDataPolicyEnabled(
+ verify(mockTelephonyManager2).setMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, true
)
}
@@ -144,13 +194,14 @@
fun setChecked_setFalse_setDataIntoSubscriptionManager() {
controller.setChecked(false)
- verify(mockTelephonyManager).setMobileDataPolicyEnabled(
+ verify(mockTelephonyManager2).setMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, false
)
}
private companion object {
const val KEY = "mms_message"
- const val SUB_ID = 2
+ const val SUB_1_ID = 1
+ const val SUB_2_ID = 2
}
}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/ServiceStateFlowTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/ServiceStateFlowTest.kt
new file mode 100644
index 0000000..4ffc267
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/ServiceStateFlowTest.kt
@@ -0,0 +1,80 @@
+/*
+ * 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.network.telephony
+
+import android.content.Context
+import android.telephony.ServiceState
+import android.telephony.TelephonyCallback
+import android.telephony.TelephonyManager
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
+import com.android.settingslib.spa.testutils.toListWithTimeout
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.async
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+
+@RunWith(AndroidJUnit4::class)
+class ServiceStateFlowTest {
+
+ private var serviceStateListener: TelephonyCallback.ServiceStateListener? = null
+
+ private val mockTelephonyManager = mock<TelephonyManager> {
+ on { createForSubscriptionId(SUB_ID) } doReturn mock
+ on { registerTelephonyCallback(any(), any()) } doAnswer {
+ serviceStateListener = it.arguments[1] as TelephonyCallback.ServiceStateListener
+ serviceStateListener?.onServiceStateChanged(ServiceState())
+ }
+ }
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
+ }
+
+ @Test
+ fun serviceStateFlow_initial_sndInitialValue() = runBlocking {
+ val flow = context.serviceStateFlow(SUB_ID)
+
+ val state = flow.firstWithTimeoutOrNull()
+
+ assertThat(state).isNotNull()
+ }
+
+ @Test
+ fun serviceStateFlow_changed_sendChanged(): Unit = runBlocking {
+ val listDeferred = async {
+ context.serviceStateFlow(SUB_ID).toListWithTimeout()
+ }
+ delay(100)
+
+ serviceStateListener?.onServiceStateChanged(ServiceState())
+
+ assertThat(listDeferred.await()).hasSize(2)
+ }
+
+ private companion object {
+ const val SUB_ID = 1
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/TelephonyRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/TelephonyRepositoryTest.kt
new file mode 100644
index 0000000..b7e1dcc
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/TelephonyRepositoryTest.kt
@@ -0,0 +1,76 @@
+/*
+ * 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.network.telephony
+
+import android.content.Context
+import android.telephony.TelephonyCallback
+import android.telephony.TelephonyManager
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.verify
+
+@RunWith(AndroidJUnit4::class)
+class TelephonyRepositoryTest {
+ private var telephonyCallback: TelephonyCallback? = null
+
+ private val mockTelephonyManager = mock<TelephonyManager> {
+ on { createForSubscriptionId(SUB_ID) } doReturn mock
+ on { registerTelephonyCallback(any(), any()) } doAnswer {
+ telephonyCallback = it.arguments[1] as TelephonyCallback
+ }
+ }
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
+ }
+
+ @Test
+ fun telephonyCallbackFlow_callbackRegistered() = runBlocking {
+ val flow = context.telephonyCallbackFlow<Unit>(SUB_ID) {
+ object : TelephonyCallback() {}
+ }
+
+ flow.firstWithTimeoutOrNull()
+
+ assertThat(telephonyCallback).isNotNull()
+ }
+
+ @Test
+ fun telephonyCallbackFlow_callbackUnregistered() = runBlocking {
+ val flow = context.telephonyCallbackFlow<Unit>(SUB_ID) {
+ object : TelephonyCallback() {}
+ }
+
+ flow.firstWithTimeoutOrNull()
+
+ verify(mockTelephonyManager).unregisterTelephonyCallback(telephonyCallback!!)
+ }
+
+ private companion object {
+ const val SUB_ID = 1
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.kt
new file mode 100644
index 0000000..0deeafb
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.kt
@@ -0,0 +1,116 @@
+/*
+ * 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.network.telephony.gsm
+
+import android.content.Context
+import android.telephony.ServiceState
+import android.telephony.SubscriptionInfo
+import android.telephony.SubscriptionManager
+import android.telephony.TelephonyManager
+import androidx.lifecycle.testing.TestLifecycleOwner
+import androidx.preference.Preference
+import androidx.preference.PreferenceManager
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.emptyFlow
+import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.runBlocking
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+
+@RunWith(AndroidJUnit4::class)
+class OpenNetworkSelectPagePreferenceControllerTest {
+
+ private val subscriptionInfo = mock<SubscriptionInfo> {
+ on { subscriptionId } doReturn SUB_ID
+ on { carrierName } doReturn OPERATOR_NAME
+ }
+
+ private val mockSubscriptionManager = mock<SubscriptionManager> {
+ on { activeSubscriptionInfoList } doAnswer { listOf(subscriptionInfo) }
+ }
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(SubscriptionManager::class.java) } doReturn mockSubscriptionManager
+ }
+
+ private val preference = Preference(context).apply { key = TEST_KEY }
+ private val preferenceScreen = PreferenceManager(context).createPreferenceScreen(context)
+
+ private val serviceState = ServiceState()
+
+ private val controller = OpenNetworkSelectPagePreferenceController(
+ context = context,
+ key = TEST_KEY,
+ allowedNetworkTypesFlowFactory = { emptyFlow() },
+ serviceStateFlowFactory = { flowOf(serviceState) },
+ ).init(subId = SUB_ID)
+
+ @Before
+ fun setUp() {
+ preferenceScreen.addPreference(preference)
+ controller.displayPreference(preferenceScreen)
+ }
+
+ @Test
+ fun isEnabled_modeManual_enabled() {
+ controller.onNetworkSelectModeUpdated(TelephonyManager.NETWORK_SELECTION_MODE_MANUAL)
+
+ assertThat(preference.isEnabled).isTrue()
+ }
+
+ @Test
+ fun isEnabled_modeAuto_disabled() {
+ controller.onNetworkSelectModeUpdated(TelephonyManager.NETWORK_SELECTION_MODE_AUTO)
+
+ assertThat(preference.isEnabled).isFalse()
+ }
+
+ @Test
+ fun summary_inService_isOperatorName() = runBlocking {
+ serviceState.state = ServiceState.STATE_IN_SERVICE
+
+ controller.onViewCreated(TestLifecycleOwner())
+ delay(100)
+
+ assertThat(preference.summary).isEqualTo(OPERATOR_NAME)
+ }
+
+ @Test
+ fun summary_notInService_isDisconnect() = runBlocking {
+ serviceState.state = ServiceState.STATE_OUT_OF_SERVICE
+
+ controller.onViewCreated(TestLifecycleOwner())
+ delay(100)
+
+ assertThat(preference.summary).isEqualTo(context.getString(R.string.network_disconnected))
+ }
+
+ private companion object {
+ const val TEST_KEY = "test_key"
+ const val SUB_ID = 2
+ const val OPERATOR_NAME = "T-mobile"
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt
index dd5b929..15fe091 100644
--- a/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt
+++ b/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt
@@ -22,6 +22,8 @@
import android.content.pm.LauncherApps
import android.content.pm.PackageManager
import android.provider.DeviceConfig.NAMESPACE_WINDOW_MANAGER
+import android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE
+import android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE
import android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
@@ -96,6 +98,8 @@
whenever(launcherApps.getActivityList(anyString(), any())).thenReturn(launcherActivities)
// True is ignored but need this here or getBoolean will complain null object
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, true)
+ mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE, true)
+ mockProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, true)
}
@After
diff --git a/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java b/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
index 3a9fa08..da15c56 100644
--- a/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
@@ -21,8 +21,8 @@
import android.provider.Settings;
import android.system.helpers.SettingsHelper;
import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
+import androidx.test.filters.MediumTest;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.Direction;
import androidx.test.uiautomator.UiDevice;
diff --git a/tests/uitests/src/com/android/settings/ui/MemorySettingsTest.kt b/tests/uitests/src/com/android/settings/ui/MemorySettingsTest.kt
new file mode 100644
index 0000000..312e2c6
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/MemorySettingsTest.kt
@@ -0,0 +1,76 @@
+/*
+ * 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.ui
+
+import android.os.Flags
+import android.platform.test.annotations.RequiresFlagsDisabled
+import android.platform.test.annotations.RequiresFlagsEnabled
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.clickObject
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+class MemorySettingsTest {
+ private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
+
+ @Before
+ fun setUp() {
+ device.startMainActivityFromHomeScreen(Settings.ACTION_DEVICE_INFO_SETTINGS)
+ device.assertHasTexts(listOf(BUILD_NUMBER))
+ repeat(7) { // Enable development mode
+ device.clickObject(By.text(BUILD_NUMBER))
+ }
+ device.startMainActivityFromHomeScreen(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)
+ device.clickObject(By.text(MEMORY_PAGE))
+ }
+
+ @Test
+ @RequiresFlagsDisabled(Flags.FLAG_REMOVE_APP_PROFILER_PSS_COLLECTION)
+ fun memoryPageIfPssFlagDisabled() {
+ device.assertHasTexts(ON_SCREEN_TEXTS_DEFAULT)
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_REMOVE_APP_PROFILER_PSS_COLLECTION)
+ fun memoryPageIfPssFlagEnabled() {
+ device.assertHasTexts(ON_SCREEN_TEXTS_PSS_PROFILING_DISABLED)
+ }
+
+ private companion object {
+ private const val BUILD_NUMBER = "Build number"
+ private const val MEMORY_PAGE = "Memory"
+ val ON_SCREEN_TEXTS_DEFAULT = listOf(
+ "Performance",
+ "Total memory",
+ "Average used (%)",
+ "Free",
+ )
+ val ON_SCREEN_TEXTS_PSS_PROFILING_DISABLED = listOf(
+ "Enable memory usage profiling",
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
index 4bd3cfb..2dfcbbe 100644
--- a/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
+++ b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
@@ -23,10 +23,10 @@
import android.system.helpers.CommandsHelper;
import android.system.helpers.SettingsHelper;
import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.test.suitebuilder.annotation.Suppress;
import android.util.Log;
+import androidx.test.filters.MediumTest;
+import androidx.test.filters.Suppress;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.Direction;
diff --git a/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTests.java b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTests.java
index 25b4767..fd65b83 100644
--- a/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTests.java
@@ -21,15 +21,14 @@
import android.provider.Settings;
import android.system.helpers.SettingsHelper;
import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
+import androidx.test.filters.MediumTest;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.Direction;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
-
public class MoreWirelessSettingsTests extends InstrumentationTestCase {
private static final String SETTINGS_PACKAGE = "com.android.settings";
diff --git a/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java b/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java
index c1fd4de..b44f5ca 100644
--- a/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java
@@ -22,10 +22,10 @@
import android.system.helpers.ActivityHelper;
import android.system.helpers.SettingsHelper;
import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
import android.util.Log;
import android.widget.ListView;
+import androidx.test.filters.MediumTest;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.Direction;
diff --git a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
index 3582a1d..f981f7f 100644
--- a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
+++ b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
@@ -22,9 +22,9 @@
import android.system.helpers.SettingsHelper;
import android.system.helpers.SettingsHelper.SettingsType;
import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.test.suitebuilder.annotation.Suppress;
+import androidx.test.filters.MediumTest;
+import androidx.test.filters.Suppress;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
diff --git a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java b/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
index d320e08..22c73a9 100644
--- a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
@@ -17,6 +17,7 @@
package com.android.settings.ui;
import static com.android.settings.ui.testutils.SettingsTestUtils.SETTINGS_PACKAGE;
+
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
@@ -26,10 +27,10 @@
import android.provider.Settings;
import android.system.helpers.CommandsHelper;
import android.system.helpers.SettingsHelper;
-import android.test.suitebuilder.annotation.MediumTest;
import android.util.Log;
import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
diff --git a/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java b/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java
index 3783b8a..342212a 100644
--- a/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java
+++ b/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java
@@ -19,15 +19,19 @@
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3;
+import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
+import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
+import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE;
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE;
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE;
import static com.android.settings.applications.appcompat.UserAspectRatioManager.KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN;
import static com.android.settings.applications.appcompat.UserAspectRatioManager.KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS;
+import static com.android.window.flags.Flags.FLAG_USER_MIN_ASPECT_RATIO_APP_DEFAULT;
import static com.google.common.truth.Truth.assertThat;
@@ -44,12 +48,16 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.os.RemoteException;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.DeviceConfig;
+import androidx.annotation.NonNull;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -58,6 +66,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -68,30 +77,36 @@
*/
@RunWith(AndroidJUnit4.class)
public class UserAspectRatioManagerTest {
-
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT);
+ private final String mPackageName = "com.test.mypackage";
private Context mContext;
private Resources mResources;
- private UserAspectRatioManager mUtils;
+ private FakeUserAspectRatioManager mUtils;
private String mOriginalSettingsFlag;
private String mOriginalFullscreenFlag;
- private String mPackageName = "com.test.mypackage";
- private LauncherApps mLauncherApps;
+ private IPackageManager mIPm;
+ private PackageManager mPm;
private List<LauncherActivityInfo> mLauncherActivities;
@Before
- public void setUp() {
+ public void setUp() throws RemoteException, PackageManager.NameNotFoundException {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
- mLauncherApps = mock(LauncherApps.class);
+ final LauncherApps launcherApps = mock(LauncherApps.class);
mLauncherActivities = mock(List.class);
+ mIPm = mock(IPackageManager.class);
+ mPm = mock(PackageManager.class);
+ when(mContext.getPackageManager()).thenReturn(mPm);
when(mContext.getResources()).thenReturn(mResources);
- when(mContext.getSystemService(LauncherApps.class)).thenReturn(mLauncherApps);
+ when(mContext.getSystemService(LauncherApps.class)).thenReturn(launcherApps);
enableAllDefaultAspectRatioOptions();
+ mSetFlagsRule.disableFlags(FLAG_USER_MIN_ASPECT_RATIO_APP_DEFAULT);
- mUtils = new UserAspectRatioManager(mContext);
+ mUtils = new FakeUserAspectRatioManager(mContext, mIPm);
- doReturn(mLauncherActivities).when(mLauncherApps).getActivityList(anyString(), any());
+ doReturn(mLauncherActivities).when(launcherApps).getActivityList(anyString(), any());
mOriginalSettingsFlag = DeviceConfig.getProperty(
DeviceConfig.NAMESPACE_WINDOW_MANAGER, KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS);
@@ -102,6 +117,10 @@
DeviceConfig.NAMESPACE_WINDOW_MANAGER, KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN);
setAspectRatioFullscreenBuildTimeFlagEnabled(true);
setAspectRatioFullscreenDeviceConfigEnabled("true" /* enabled */, false /* makeDefault */);
+
+ mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE, true);
+ mockProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, true);
+ mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, true);
}
@After
@@ -114,13 +133,13 @@
@Test
public void testCanDisplayAspectRatioUi() {
final ApplicationInfo canDisplay = new ApplicationInfo();
- canDisplay.packageName = "com.app.candisplay";
+ canDisplay.packageName = mPackageName;
doReturn(false).when(mLauncherActivities).isEmpty();
assertTrue(mUtils.canDisplayAspectRatioUi(canDisplay));
final ApplicationInfo noLauncherEntry = new ApplicationInfo();
- noLauncherEntry.packageName = "com.app.nolauncherentry";
+ noLauncherEntry.packageName = mPackageName;
doReturn(true).when(mLauncherActivities).isEmpty();
assertFalse(mUtils.canDisplayAspectRatioUi(noLauncherEntry));
@@ -221,36 +240,40 @@
mPackageName));
}
+ private String getUserMinAspectRatioEntry(int aspectRatio, String packageName) {
+ return mUtils.getUserMinAspectRatioEntry(aspectRatio, packageName, mContext.getUserId());
+ }
+
@Test
public void testGetUserMinAspectRatioEntry() {
final Context context = ApplicationProvider.getApplicationContext();
// R.string.user_aspect_ratio_app_default
final String appDefault = ResourcesUtils.getResourcesString(context,
"user_aspect_ratio_app_default");
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
.isEqualTo(appDefault);
// should always return default if value does not correspond to anything
- assertThat(mUtils.getUserMinAspectRatioEntry(-1, mPackageName))
+ assertThat(getUserMinAspectRatioEntry(-1, mPackageName))
.isEqualTo(appDefault);
// R.string.user_aspect_ratio_half_screen
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN,
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN,
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(context,
"user_aspect_ratio_half_screen"));
// R.string.user_aspect_ratio_display_size
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_DISPLAY_SIZE,
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_DISPLAY_SIZE,
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(context,
"user_aspect_ratio_device_size"));
// R.string.user_aspect_ratio_16_9
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_16_9, mPackageName))
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_16_9, mPackageName))
.isEqualTo(ResourcesUtils.getResourcesString(context, "user_aspect_ratio_16_9"));
// R.string.user_aspect_ratio_4_3
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_4_3, mPackageName))
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_4_3, mPackageName))
.isEqualTo(ResourcesUtils.getResourcesString(context, "user_aspect_ratio_4_3"));
// R.string.user_aspect_ratio_3_2
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_3_2, mPackageName))
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_3_2, mPackageName))
.isEqualTo(ResourcesUtils.getResourcesString(context, "user_aspect_ratio_3_2"));
// R.string.user_aspect_ratio_fullscreen
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(context,
"user_aspect_ratio_fullscreen"));
}
@@ -258,7 +281,7 @@
@Test
public void testGetUserMinAspectRatioEntry_fullscreenDisabled_shouldReturnDefault() {
setAspectRatioFullscreenBuildTimeFlagEnabled(false);
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(
ApplicationProvider.getApplicationContext(),
"user_aspect_ratio_app_default"));
@@ -270,9 +293,9 @@
when(mResources.getIntArray(anyInt())).thenReturn(new int[] {USER_MIN_ASPECT_RATIO_UNSET});
when(mResources.getStringArray(anyInt())).thenReturn(new String[] {newOptionName});
- mUtils = new UserAspectRatioManager(mContext);
+ mUtils = new FakeUserAspectRatioManager(mContext, mIPm);
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
.isEqualTo(newOptionName);
}
@@ -282,7 +305,7 @@
when(mResources.getIntArray(anyInt())).thenReturn(new int[] {USER_MIN_ASPECT_RATIO_4_3});
when(mResources.getStringArray(anyInt())).thenReturn(new String[] {"4:3"});
- assertThrows(RuntimeException.class, () -> new UserAspectRatioManager(mContext));
+ assertThrows(RuntimeException.class, () -> new FakeUserAspectRatioManager(mContext, mIPm));
}
@Test
@@ -292,7 +315,88 @@
USER_MIN_ASPECT_RATIO_4_3});
when(mResources.getStringArray(anyInt())).thenReturn(new String[] {"4:3"});
- assertThrows(RuntimeException.class, () -> new UserAspectRatioManager(mContext));
+ assertThrows(RuntimeException.class, () -> new FakeUserAspectRatioManager(mContext, mIPm));
+ }
+
+ @Test
+ public void testGetUserMinAspectRatioMapping_appDefaultFlagEnabled() {
+ // Flag is disabled by default, app default not loaded
+ assertFalse(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_APP_DEFAULT, mPackageName));
+
+ mSetFlagsRule.enableFlags(FLAG_USER_MIN_ASPECT_RATIO_APP_DEFAULT);
+ mUtils = new FakeUserAspectRatioManager(mContext, mIPm);
+
+ assertTrue(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_APP_DEFAULT, mPackageName));
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_APP_DEFAULT, mPackageName))
+ .isEqualTo(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName));
+ }
+
+ @Test
+ public void testGetUserMinAspectRatioEntry_enabledFullscreenOverride_returnsFullscreen() {
+ setIsOverrideToFullscreenEnabled(true);
+ // Fullscreen option is pre-selected
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
+ .isEqualTo(ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(),
+ "user_aspect_ratio_fullscreen"));
+
+ // App default exists
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_APP_DEFAULT, mPackageName))
+ .isEqualTo(ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(),
+ "user_aspect_ratio_app_default"));
+ }
+
+ @Test
+ public void testGetUserMinAspectRatioEntry_disabledFullscreenOverride_returnsUnchanged() {
+ setIsOverrideToFullscreenEnabled(false);
+ // Fullscreen option is not pre-selected
+ assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
+ .isEqualTo(ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(),
+ "user_aspect_ratio_app_default"));
+ }
+
+ @Test
+ public void testIsOverrideToFullscreenEnabled_returnsTrue()
+ throws PackageManager.NameNotFoundException {
+ setIsOverrideToFullscreenEnabled(true);
+ assertTrue(mUtils.isOverrideToFullscreenEnabled(mPackageName, mContext.getUserId()));
+
+ mockProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, true);
+ assertTrue(mUtils.isOverrideToFullscreenEnabled(mPackageName, mContext.getUserId()));
+ }
+
+ @Test
+ public void testIsOverrideToFullscreenEnabled_optOut_returnsFalse()
+ throws PackageManager.NameNotFoundException {
+ setIsOverrideToFullscreenEnabled(true);
+ mockProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, false);
+ assertFalse(mUtils.isOverrideToFullscreenEnabled(mPackageName, mContext.getUserId()));
+ }
+
+ @Test
+ public void testIsOverrideToFullscreenEnabled_flagDisabled_returnsFalse() {
+ mUtils.setFullscreenCompatChange(true);
+ assertFalse(mUtils.isOverrideToFullscreenEnabled(mPackageName, mContext.getUserId()));
+ }
+
+ @Test
+ public void testIsOverrideToFullscreenEnabled_optionDisabled_returnsFalse() {
+ mUtils.setFullscreenCompatChange(true);
+ when(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN, mPackageName))
+ .thenReturn(false);
+ assertFalse(mUtils.isOverrideToFullscreenEnabled(mPackageName, mContext.getUserId()));
+ }
+
+ private void setIsOverrideToFullscreenEnabled(boolean enabled) {
+ if (enabled) {
+ mSetFlagsRule.enableFlags(FLAG_USER_MIN_ASPECT_RATIO_APP_DEFAULT);
+ mUtils = new FakeUserAspectRatioManager(mContext, mIPm);
+ }
+ mUtils.setFullscreenCompatChange(enabled);
+ when(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN, mPackageName))
+ .thenReturn(enabled);
}
private void enableAllDefaultAspectRatioOptions() {
@@ -328,9 +432,7 @@
throws PackageManager.NameNotFoundException {
PackageManager.Property prop = new PackageManager.Property(
propertyName, value, mPackageName, "" /* className */);
- PackageManager pm = mock(PackageManager.class);
- when(mContext.getPackageManager()).thenReturn(pm);
- when(pm.getProperty(propertyName, mPackageName)).thenReturn(prop);
+ when(mPm.getProperty(propertyName, mPackageName)).thenReturn(prop);
}
private void setAspectRatioSettingsBuildTimeFlagEnabled(boolean enabled) {
@@ -352,4 +454,21 @@
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER,
KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN, enabled, makeDefault);
}
+
+ private static class FakeUserAspectRatioManager extends UserAspectRatioManager {
+ private boolean mFullscreenCompatChange = false;
+
+ private FakeUserAspectRatioManager(@NonNull Context context, IPackageManager pm) {
+ super(context, pm);
+ }
+
+ @Override
+ boolean isFullscreenCompatChangeEnabled(String pkgName, int userId) {
+ return mFullscreenCompatChange;
+ }
+
+ void setFullscreenCompatChange(boolean enabled) {
+ mFullscreenCompatChange = enabled;
+ }
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/ResetNetworkOperationBuilderTest.java b/tests/unit/src/com/android/settings/network/ResetNetworkOperationBuilderTest.java
index 6f5440b..41b6b27 100644
--- a/tests/unit/src/com/android/settings/network/ResetNetworkOperationBuilderTest.java
+++ b/tests/unit/src/com/android/settings/network/ResetNetworkOperationBuilderTest.java
@@ -16,12 +16,12 @@
package com.android.settings.network;
-import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doReturn;
+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.when;
import android.content.Context;
import android.net.ConnectivityManager;
@@ -34,6 +34,8 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.settings.ResetNetworkRequest;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -129,4 +131,44 @@
verify(mTelephonyManager).resetSettings();
verify(mNetworkPolicyManager).factoryReset(imsi);
}
+
+ @Test
+ public void resetIms_performReset_whenBuildAndRun_withSingleValidSubId() {
+ final int subId = 1;
+ doReturn(mTelephonyManager).when(mTelephonyManager)
+ .createForSubscriptionId(anyInt());
+ doReturn(mTelephonyManager).when(mContext)
+ .getSystemService(Context.TELEPHONY_SERVICE);
+
+ mBuilder.resetIms(subId).build().run();
+
+ verify(mTelephonyManager).resetIms(anyInt());
+ }
+
+ @Test
+ public void resetIms_performReset_whenBuildAndRun_withInvalidSubId() {
+ final int subId = ResetNetworkRequest.INVALID_SUBSCRIPTION_ID;
+ doReturn(mTelephonyManager).when(mTelephonyManager)
+ .createForSubscriptionId(anyInt());
+ doReturn(mTelephonyManager).when(mContext)
+ .getSystemService(Context.TELEPHONY_SERVICE);
+
+ mBuilder.resetIms(subId).build().run();
+
+ verify(mTelephonyManager, never()).resetIms(anyInt());
+ }
+
+ @Test
+ public void resetIms_performReset_whenBuildAndRun_withAllValidSubId() {
+ final int subId = ResetNetworkRequest.ALL_SUBSCRIPTION_ID;
+ doReturn(mTelephonyManager).when(mTelephonyManager)
+ .createForSubscriptionId(anyInt());
+ doReturn(mTelephonyManager).when(mContext)
+ .getSystemService(Context.TELEPHONY_SERVICE);
+ doReturn(2).when(mTelephonyManager).getActiveModemCount();
+
+ mBuilder.resetIms(subId).build().run();
+
+ verify(mTelephonyManager, times(2)).resetIms(anyInt());
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.java
deleted file mode 100644
index b4d49b2..0000000
--- a/tests/unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2020 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.gsm;
-
-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.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.ServiceState;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-
-import androidx.preference.Preference;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.testutils.ResourcesUtils;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import java.util.Arrays;
-
-@RunWith(AndroidJUnit4.class)
-public class OpenNetworkSelectPagePreferenceControllerTest {
- private static final int SUB_ID = 2;
- private static final String OPERATOR_NAME = "T-mobile";
-
- @Mock
- private TelephonyManager mTelephonyManager;
- @Mock
- private SubscriptionManager mSubscriptionManager;
- @Mock
- private CarrierConfigManager mCarrierConfigManager;
- @Mock
- private ServiceState mServiceState;
- @Mock
- private SubscriptionInfo mSubscriptionInfo;
-
- private PersistableBundle mCarrierConfig;
- private OpenNetworkSelectPagePreferenceController mController;
- private Preference mPreference;
- private Context mContext;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = spy(ApplicationProvider.getApplicationContext());
-
- when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
- when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
- when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
- mCarrierConfigManager);
- when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
- when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
-
- mCarrierConfig = new PersistableBundle();
- when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
-
- when(mSubscriptionInfo.getSubscriptionId()).thenReturn(SUB_ID);
- when(mSubscriptionInfo.getCarrierName()).thenReturn(OPERATOR_NAME);
-
- when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
- Arrays.asList(mSubscriptionInfo));
-
- when(mTelephonyManager.getNetworkOperatorName()).thenReturn(OPERATOR_NAME);
-
- mPreference = new Preference(mContext);
- mController = new OpenNetworkSelectPagePreferenceController(mContext,
- "open_network_select") {
- @Override
- public void updateState(Preference preference) {
- super.updateState(mPreference);
- }
- };
- mController.init(SUB_ID);
- }
-
- @Test
- public void updateState_modeAuto_disabled() {
- mController.onNetworkSelectModeUpdated(TelephonyManager.NETWORK_SELECTION_MODE_AUTO);
- mController.updateState(mPreference);
-
- assertThat(mPreference.isEnabled()).isFalse();
- }
-
- @Test
- public void getSummary_inService_returnOperatorName() {
- when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
-
- assertThat(mController.getSummary()).isEqualTo(OPERATOR_NAME);
- }
-
- @Test
- public void getSummary_notInService_returnDisconnect() {
- when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
-
- assertThat(mController.getSummary()).isEqualTo(
- ResourcesUtils.getResourcesString(mContext, "network_disconnected"));
- }
-}