Merge "Migrate Android version preference" into main
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7e363e6..4780e52 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -13670,4 +13670,11 @@
<!-- Text for Search bar of Settings home screen [CHAR LIMIT=34] -->
<string name="homepage_search">Search Settings</string>
+
+ <!-- Keywords for contacts storage item [CHAR LIMIT=NONE] -->
+ <string name="keywords_contacts_storage">contacts, storage, account</string>
+ <!-- Text for Contacts Storage Settings title [CHAR LIMIT=50]-->
+ <string name="contacts_storage_settings_title">Contacts storage</string>
+ <!-- Text for displaying when no account is set as default account [CHAR LIMIT=50] -->
+ <string name="contacts_storage_no_account_set">No default set</string>
</resources>
diff --git a/res/xml/accessibility_settings_for_setup_wizard.xml b/res/xml/accessibility_settings_for_setup_wizard.xml
index a69dc26..25b8a5a 100644
--- a/res/xml/accessibility_settings_for_setup_wizard.xml
+++ b/res/xml/accessibility_settings_for_setup_wizard.xml
@@ -43,7 +43,8 @@
android:title="@string/auto_brightness_title"
android:fragment="com.android.settings.accessibility.AutoBrightnessPreferenceFragmentForSetupWizard"
settings:useAdminDisabledSummary="true"
- settings:userRestriction="no_config_brightness"/>
+ settings:userRestriction="no_config_brightness"
+ settings:controller="com.android.settings.display.AutoBrightnessPreferenceControllerForSetupWizard"/>
<Preference
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard"
diff --git a/res/xml/apps.xml b/res/xml/apps.xml
index 2ffd0b1..a66cea3 100644
--- a/res/xml/apps.xml
+++ b/res/xml/apps.xml
@@ -80,6 +80,15 @@
android:order="10"/>
<Preference
+ android:key="contacts_storage"
+ android:title="@string/contacts_storage_settings_title"
+ android:summary="@string/summary_placeholder"
+ android:order="13"
+ settings:controller="com.android.settings.applications.contacts.ContactsStoragePreferenceController"
+ settings:keywords="@string/keywords_contacts_storage">
+ </Preference>
+
+ <Preference
android:key="hibernated_apps"
android:title="@string/unused_apps"
android:summary="@string/summary_placeholder"
diff --git a/src/com/android/settings/LegalSettings.java b/src/com/android/settings/LegalSettings.java
index 9cb3bf4..e48da26 100644
--- a/src/com/android/settings/LegalSettings.java
+++ b/src/com/android/settings/LegalSettings.java
@@ -17,8 +17,13 @@
package com.android.settings;
import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.deviceinfo.legal.LegalSettingsScreen;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@@ -44,4 +49,10 @@
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.about_legal);
+
+ @Nullable
+ @Override
+ public String getPreferenceScreenBindingKey(@NonNull Context context) {
+ return LegalSettingsScreen.KEY;
+ }
}
diff --git a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
index 447e34e..11cbd16 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
@@ -41,8 +41,7 @@
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.display.AutoBrightnessPreferenceController;
-import com.android.settings.display.BrightnessLevelPreferenceController;
+import com.android.settings.display.BrightnessLevelPreferenceControllerForSetupWizard;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -168,16 +167,10 @@
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ // Requires lifecycle, so added programmatically (normally via resId).
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- BrightnessLevelPreferenceController brightnessLevelPreferenceController =
- new BrightnessLevelPreferenceController(context, getSettingsLifecycle());
- brightnessLevelPreferenceController.setInSetupWizard(true);
- controllers.add(brightnessLevelPreferenceController);
- String autoBrightnessKey = context.getString(R.string.preference_key_auto_brightness);
- AutoBrightnessPreferenceController autoBrightnessPreferenceController =
- new AutoBrightnessPreferenceController(context, autoBrightnessKey);
- autoBrightnessPreferenceController.setInSetupWizard(true);
- controllers.add(autoBrightnessPreferenceController);
+ controllers.add(new BrightnessLevelPreferenceControllerForSetupWizard(
+ context, getSettingsLifecycle()));
return controllers;
}
diff --git a/src/com/android/settings/applications/contacts/ContactsStoragePreferenceController.java b/src/com/android/settings/applications/contacts/ContactsStoragePreferenceController.java
new file mode 100644
index 0000000..bc6931d
--- /dev/null
+++ b/src/com/android/settings/applications/contacts/ContactsStoragePreferenceController.java
@@ -0,0 +1,68 @@
+
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.applications.contacts;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.os.UserHandle;
+import android.provider.ContactsContract;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.flags.Flags;
+import com.android.settingslib.accounts.AuthenticatorHelper;
+
+/**
+ * A preference controller handling the logic for updating summary of contacts default account.
+ */
+public class ContactsStoragePreferenceController extends BasePreferenceController {
+ private static final String TAG = "ContactsStorageController";
+
+ private final AuthenticatorHelper mAuthenticatorHelper;
+
+ public ContactsStoragePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mAuthenticatorHelper = new AuthenticatorHelper(mContext,
+ new UserHandle(UserHandle.myUserId()), null);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return Flags.enableContactsDefaultAccountInSettings()
+ ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ Account currentDefaultAccount =
+ ContactsContract.Settings.getDefaultAccount(mContext.getContentResolver());
+ if (currentDefaultAccount == null) {
+ return mContext.getResources().getString(
+ R.string.contacts_storage_no_account_set);
+ }
+ String accountTypeLabel = (String) mAuthenticatorHelper.getLabelForType(mContext,
+ currentDefaultAccount.type);
+ // If there's no account type, or the account type is the same as the
+ // current default account name, just return the account name.
+ if (accountTypeLabel == null || accountTypeLabel.equals(currentDefaultAccount.name)) {
+ return currentDefaultAccount.name;
+ }
+ return accountTypeLabel + " | " + currentDefaultAccount.name;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceController.java b/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceController.java
index 68e51f4..4c2413a 100644
--- a/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceController.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.content.Intent;
+// LINT.IfChange
public class CopyrightPreferenceController extends LegalPreferenceController {
private static final Intent INTENT = new Intent("android.settings.COPYRIGHT");
@@ -30,3 +31,4 @@
return INTENT;
}
}
+// LINT.ThenChange(LegalPreference.kt)
diff --git a/src/com/android/settings/deviceinfo/legal/LegalPreference.kt b/src/com/android/settings/deviceinfo/legal/LegalPreference.kt
new file mode 100644
index 0000000..af3537b
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/LegalPreference.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo.legal
+
+import android.content.Context
+import android.content.Intent
+import android.content.pm.ApplicationInfo
+import android.content.pm.ResolveInfo
+import androidx.annotation.StringRes
+import com.android.settingslib.metadata.PreferenceAvailabilityProvider
+import com.android.settingslib.metadata.PreferenceMetadata
+import com.android.settingslib.metadata.PreferenceTitleProvider
+
+// LINT.IfChange
+class LegalPreference(
+ override val key: String,
+ @StringRes val defaultTitle: Int = 0,
+ val intentAction: String,
+) : PreferenceMetadata, PreferenceTitleProvider, PreferenceAvailabilityProvider {
+
+ override fun getTitle(context: Context): CharSequence? {
+ val resolveInfo =
+ findMatchingSpecificActivity(context) ?: return context.getText(defaultTitle)
+ return resolveInfo.loadLabel(context.packageManager)
+ }
+
+ override fun isAvailable(context: Context) = (findMatchingSpecificActivity(context) != null)
+
+ override fun intent(context: Context) =
+ findMatchingSpecificActivity(context)?.let {
+ Intent()
+ .setClassName(it.activityInfo.packageName, it.activityInfo.name)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+
+ private fun findMatchingSpecificActivity(context: Context): ResolveInfo? {
+ val intent = Intent(intentAction)
+ // Find the activity that is in the system image
+ val list: List<ResolveInfo> = context.packageManager.queryIntentActivities(intent, 0)
+ return list.firstOrNull {
+ (it.activityInfo.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
+ }
+ }
+}
+// LINT.ThenChange(LegalPreferenceController.java)
diff --git a/src/com/android/settings/deviceinfo/legal/LegalPreferenceController.java b/src/com/android/settings/deviceinfo/legal/LegalPreferenceController.java
index fe45923..adbc2d7 100644
--- a/src/com/android/settings/deviceinfo/legal/LegalPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/legal/LegalPreferenceController.java
@@ -27,6 +27,7 @@
import java.util.List;
+// LINT.IfChange
public abstract class LegalPreferenceController extends BasePreferenceController {
private final PackageManager mPackageManager;
private Preference mPreference;
@@ -94,3 +95,4 @@
mPreference.setTitle(resolveInfo.loadLabel(mPackageManager));
}
}
+// LINT.ThenChange(LegalPreference.kt)
diff --git a/src/com/android/settings/deviceinfo/legal/LegalSettingsScreen.kt b/src/com/android/settings/deviceinfo/legal/LegalSettingsScreen.kt
new file mode 100644
index 0000000..f990b5d
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/LegalSettingsScreen.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo.legal
+
+import android.content.Context
+import com.android.settings.LegalSettings
+import com.android.settings.R
+import com.android.settings.flags.Flags
+import com.android.settingslib.metadata.ProvidePreferenceScreen
+import com.android.settingslib.metadata.preferenceHierarchy
+import com.android.settingslib.preference.PreferenceScreenCreator
+
+@ProvidePreferenceScreen
+open class LegalSettingsScreen : PreferenceScreenCreator {
+ override val key: String
+ get() = KEY
+
+ override val title: Int
+ get() = R.string.legal_information
+
+ override fun isFlagEnabled(context: Context) = Flags.catalystLegalInformation()
+
+ override fun fragmentClass() = LegalSettings::class.java
+
+ override fun getPreferenceHierarchy(context: Context) =
+ preferenceHierarchy(this) {
+ +LegalPreference("copyright", R.string.copyright_title, "android.settings.COPYRIGHT")
+ +LegalPreference("license", R.string.license_title, "android.settings.LICENSE")
+ +LegalPreference("terms", R.string.terms_title, "android.settings.TERMS")
+ +ModuleLicensesScreen.KEY // Use screen key in case it is overlaid.
+ +LegalPreference(
+ "webview_license",
+ R.string.webview_license_title,
+ "android.settings.WEBVIEW_LICENSE",
+ )
+ +WallpaperAttributionsPreference()
+ }
+
+ companion object {
+ const val KEY = "legal_information"
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/legal/LicensePreferenceController.java b/src/com/android/settings/deviceinfo/legal/LicensePreferenceController.java
index 67af15b..9bd74fd 100644
--- a/src/com/android/settings/deviceinfo/legal/LicensePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/legal/LicensePreferenceController.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.content.Intent;
+// LINT.IfChange
public class LicensePreferenceController extends LegalPreferenceController {
private static final Intent INTENT = new Intent("android.settings.LICENSE");
@@ -30,3 +31,4 @@
return INTENT;
}
}
+// LINT.ThenChange(LegalPreference.kt)
diff --git a/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceController.java b/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceController.java
index 9faff85..7b6ca46 100644
--- a/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceController.java
@@ -24,6 +24,7 @@
import java.util.List;
+// LINT.IfChange
public class ModuleLicensesListPreferenceController extends BasePreferenceController {
public ModuleLicensesListPreferenceController(Context context,
String preferenceKey) {
@@ -39,3 +40,4 @@
: CONDITIONALLY_UNAVAILABLE;
}
}
+// LINT.ThenChange(ModuleLicensesScreen.kt)
diff --git a/src/com/android/settings/deviceinfo/legal/ModuleLicensesScreen.kt b/src/com/android/settings/deviceinfo/legal/ModuleLicensesScreen.kt
new file mode 100644
index 0000000..c7f5e9c
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/ModuleLicensesScreen.kt
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo.legal
+
+import android.content.Context
+import com.android.settings.R
+import com.android.settingslib.metadata.PreferenceAvailabilityProvider
+import com.android.settingslib.metadata.ProvidePreferenceScreen
+import com.android.settingslib.metadata.preferenceHierarchy
+import com.android.settingslib.preference.PreferenceScreenCreator
+
+// LINT.IfChange
+@ProvidePreferenceScreen
+class ModuleLicensesScreen : PreferenceScreenCreator, PreferenceAvailabilityProvider {
+ override val key: String
+ get() = KEY
+
+ override val title: Int
+ get() = R.string.module_license_title
+
+ // We need to avoid directly assign fragment attribute in the bind() API. So we need to create
+ // a screen and provide it to its parent screen LegalSettingsScreen.
+ // By the way, we also need to set the isFlagEnabled() as false. Let system render the legacy
+ // UI. The hierarchy will be added while migrating this page.
+ override fun isFlagEnabled(context: Context) = false
+
+ override fun fragmentClass() = ModuleLicensesDashboard::class.java
+
+ override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) {}
+
+ override fun isAvailable(context: Context): Boolean {
+ val modules = context.packageManager.getInstalledModules(/* flags= */ 0)
+ return modules.any {
+ try {
+ ModuleLicenseProvider.getPackageAssetManager(context.packageManager, it.packageName)
+ .list("")
+ ?.contains(ModuleLicenseProvider.GZIPPED_LICENSE_FILE_NAME) == true
+ } catch (e: Exception) {
+ false
+ }
+ }
+ }
+
+ companion object {
+ const val KEY = "module_license"
+ }
+}
+// LINT.ThenChange(ModuleLicensesListPreferenceController.java)
diff --git a/src/com/android/settings/deviceinfo/legal/TermsPreferenceController.java b/src/com/android/settings/deviceinfo/legal/TermsPreferenceController.java
index bccc445..764bde4 100644
--- a/src/com/android/settings/deviceinfo/legal/TermsPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/legal/TermsPreferenceController.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.content.Intent;
+// LINT.IfChange
public class TermsPreferenceController extends LegalPreferenceController {
private static final Intent INTENT = new Intent("android.settings.TERMS");
@@ -30,3 +31,4 @@
return INTENT;
}
}
+// LINT.ThenChange(LegalPreference.kt)
diff --git a/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreference.kt b/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreference.kt
new file mode 100644
index 0000000..7a934c2
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreference.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo.legal
+
+import android.content.Context
+import androidx.preference.Preference
+import com.android.settings.R
+import com.android.settingslib.metadata.PreferenceAvailabilityProvider
+import com.android.settingslib.metadata.PreferenceMetadata
+import com.android.settingslib.preference.PreferenceBinding
+
+// LINT.IfChange
+class WallpaperAttributionsPreference :
+ PreferenceMetadata, PreferenceBinding, PreferenceAvailabilityProvider {
+ override val key: String
+ get() = KEY
+
+ override val title: Int
+ get() = R.string.wallpaper_attributions
+
+ override val summary: Int
+ get() = R.string.wallpaper_attributions_values
+
+ override fun bind(preference: Preference, metadata: PreferenceMetadata) {
+ super.bind(preference, metadata)
+ preference.isSelectable = false
+ }
+
+ override fun isAvailable(context: Context) =
+ context.resources.getBoolean(R.bool.config_show_wallpaper_attribution)
+
+ companion object {
+ const val KEY = "wallpaper_attributions"
+ }
+}
+// LINT.ThenChange(WallpaperAttributionsPreferenceController.java)
diff --git a/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceController.java b/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceController.java
index caa5afc..cc9c092 100644
--- a/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceController.java
@@ -20,6 +20,7 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+// LINT.IfChange
public class WallpaperAttributionsPreferenceController extends BasePreferenceController {
public WallpaperAttributionsPreferenceController(Context context, String key) {
@@ -33,3 +34,4 @@
: UNSUPPORTED_ON_DEVICE;
}
}
+// LINT.ThenChange(WallpaperAttributionsPreference.kt)
diff --git a/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceController.java b/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceController.java
index 9d8b3f9..ebb9152 100644
--- a/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceController.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.content.Intent;
+// LINT.IfChange
public class WebViewLicensePreferenceController extends LegalPreferenceController {
private static final Intent INTENT = new Intent("android.settings.WEBVIEW_LICENSE");
@@ -30,3 +31,4 @@
return INTENT;
}
}
+// LINT.ThenChange(LegalPreference.kt)
diff --git a/src/com/android/settings/display/AutoBrightnessPreferenceController.java b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
index 3014f62..0a80d69 100644
--- a/src/com/android/settings/display/AutoBrightnessPreferenceController.java
+++ b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
@@ -22,28 +22,25 @@
import android.os.UserManager;
import android.provider.Settings;
+import androidx.annotation.NonNull;
import androidx.preference.Preference;
import com.android.settings.R;
-import com.android.settings.accessibility.Flags;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.PrimarySwitchPreference;
+/**
+ * The top-level preference controller that updates the adaptive brightness.
+ */
public class AutoBrightnessPreferenceController extends TogglePreferenceController {
private final String SYSTEM_KEY = SCREEN_BRIGHTNESS_MODE;
private final int DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL;
- private boolean mInSetupWizard;
-
- public AutoBrightnessPreferenceController(Context context, String key) {
+ public AutoBrightnessPreferenceController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
- public void setInSetupWizard(boolean inSetupWizard) {
- mInSetupWizard = inSetupWizard;
- }
-
@Override
public boolean isChecked() {
return Settings.System.getInt(mContext.getContentResolver(),
@@ -60,14 +57,10 @@
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
- if (!mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_automatic_brightness_available)) {
- return UNSUPPORTED_ON_DEVICE;
- }
- if (mInSetupWizard && !Flags.addBrightnessSettingsInSuw()) {
- return CONDITIONALLY_UNAVAILABLE;
- }
- return AVAILABLE_UNSEARCHABLE;
+ return mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_automatic_brightness_available)
+ ? AVAILABLE_UNSEARCHABLE
+ : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/display/AutoBrightnessPreferenceControllerForSetupWizard.java b/src/com/android/settings/display/AutoBrightnessPreferenceControllerForSetupWizard.java
new file mode 100644
index 0000000..7cdf3e0
--- /dev/null
+++ b/src/com/android/settings/display/AutoBrightnessPreferenceControllerForSetupWizard.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.display;
+
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+
+import com.android.settings.accessibility.Flags;
+
+/**
+ * The top-level preference controller that updates the adaptive brightness in the SetupWizard.
+ */
+public class AutoBrightnessPreferenceControllerForSetupWizard
+ extends AutoBrightnessPreferenceController {
+
+ public AutoBrightnessPreferenceControllerForSetupWizard(@NonNull Context context,
+ @NonNull String key) {
+ super(context, key);
+ }
+
+ @Override
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ if (!Flags.addBrightnessSettingsInSuw()) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ return super.getAvailabilityStatus();
+ }
+}
diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceController.java b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
index a32c965..96043db 100644
--- a/src/com/android/settings/display/BrightnessLevelPreferenceController.java
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
@@ -20,7 +20,6 @@
import static com.android.settingslib.display.BrightnessUtils.GAMMA_SPACE_MIN;
import static com.android.settingslib.display.BrightnessUtils.convertLinearToGammaFloat;
-import android.annotation.Nullable;
import android.app.ActivityOptions;
import android.content.ContentResolver;
import android.content.Context;
@@ -37,12 +36,13 @@
import android.provider.Settings.System;
import android.text.TextUtils;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settings.accessibility.Flags;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SettingsBaseActivity;
@@ -54,18 +54,17 @@
import java.text.NumberFormat;
+/**
+ * The top-level preference controller that updates the adaptive brightness level.
+ */
public class BrightnessLevelPreferenceController extends BasePreferenceController implements
PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
-
- private static final String TAG = "BrightnessPrefCtrl";
-
private static final Uri BRIGHTNESS_ADJ_URI;
private final ContentResolver mContentResolver;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final DisplayManager mDisplayManager;
@Nullable
private Preference mPreference;
- private boolean mInSetupWizard;
static {
BRIGHTNESS_ADJ_URI = System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ);
@@ -94,11 +93,13 @@
}
};
- public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
+ public BrightnessLevelPreferenceController(@NonNull Context context,
+ @Nullable Lifecycle lifecycle) {
this(context, context.getString(R.string.preference_key_brightness_level), lifecycle);
}
- private BrightnessLevelPreferenceController(Context context, String key, Lifecycle lifecycle) {
+ private BrightnessLevelPreferenceController(@NonNull Context context, @NonNull String key,
+ @Nullable Lifecycle lifecycle) {
super(context, key);
mDisplayManager = context.getSystemService(DisplayManager.class);
@@ -108,15 +109,8 @@
mContentResolver = mContext.getContentResolver();
}
- public void setInSetupWizard(boolean inSetupWizard) {
- mInSetupWizard = inSetupWizard;
- }
-
@Override
public int getAvailabilityStatus() {
- if (mInSetupWizard && !Flags.addBrightnessSettingsInSuw()) {
- return CONDITIONALLY_UNAVAILABLE;
- }
return AVAILABLE;
}
diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceControllerForSetupWizard.java b/src/com/android/settings/display/BrightnessLevelPreferenceControllerForSetupWizard.java
new file mode 100644
index 0000000..6e002ae
--- /dev/null
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceControllerForSetupWizard.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.display;
+
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.settings.accessibility.Flags;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+/**
+ * The top-level preference controller that updates the adaptive brightness level in the
+ * SetupWizard.
+ */
+public class BrightnessLevelPreferenceControllerForSetupWizard extends
+ BrightnessLevelPreferenceController {
+
+ public BrightnessLevelPreferenceControllerForSetupWizard(@NonNull Context context,
+ @Nullable Lifecycle lifecycle) {
+ super(context, lifecycle);
+ }
+
+ @Override
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ if (!Flags.addBrightnessSettingsInSuw()) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ return super.getAvailabilityStatus();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java
index 2ae5984..58578e7 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java
@@ -46,8 +46,7 @@
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
-import com.android.settings.display.AutoBrightnessPreferenceController;
-import com.android.settings.display.BrightnessLevelPreferenceController;
+import com.android.settings.display.BrightnessLevelPreferenceControllerForSetupWizard;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -146,16 +145,15 @@
}
@Test
- public void createPreferenceControllers_brightnessPreferencesControllersAreCreated() {
+ public void createPreferenceControllers_lifeCycleDependencyControllerIsCreated() {
mFragment.onAttach(mContext);
List<AbstractPreferenceController> controllers =
mFragment.createPreferenceControllers(mContext);
assertTrue(controllers.stream().anyMatch(
- controller -> controller instanceof BrightnessLevelPreferenceController));
- assertTrue(controllers.stream().anyMatch(
- controller -> controller instanceof AutoBrightnessPreferenceController));
+ controller ->
+ controller instanceof BrightnessLevelPreferenceControllerForSetupWizard));
}
private void addEnabledServiceInfo(ComponentName componentName, boolean isAccessibilityTool) {
diff --git a/tests/robotests/src/com/android/settings/applications/contacts/ContactsStoragePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/contacts/ContactsStoragePreferenceControllerTest.java
new file mode 100644
index 0000000..a934cba
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/contacts/ContactsStoragePreferenceControllerTest.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.contacts;
+
+import static android.provider.ContactsContract.Settings.KEY_DEFAULT_ACCOUNT;
+import static android.provider.ContactsContract.Settings.QUERY_DEFAULT_ACCOUNT_METHOD;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+import android.provider.ContactsContract;
+
+import com.android.settings.R;
+import com.android.settings.flags.Flags;
+import com.android.settings.testutils.shadow.ShadowAuthenticationHelper;
+
+import org.junit.Before;
+import android.platform.test.annotations.RequiresFlagsDisabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowAuthenticationHelper.class)
+public class ContactsStoragePreferenceControllerTest {
+
+ private static final String CONTACTS_DEFAULT_ACCOUNT_PREFERENCE_KEY =
+ "contacts_default_account";
+ private static final Account TEST_ACCOUNT1 = new Account("test@gmail.com", "type1");
+
+ private static final Account TEST_ACCOUNT2 = new Account("test@samsung.com", "type2");
+
+ private static final Account TEST_ACCOUNT3 = new Account("LABEL3", "type3");
+
+ @Rule
+ public final MockitoRule mockito = MockitoJUnit.rule();
+
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ @Mock
+ private Context mContext;
+
+ @Mock
+ private ContentResolver mContentResolver;
+
+ @Mock
+ private Resources mResources;
+
+ @Mock
+ private AccountManager mAccountManager;
+
+ private ContactsStoragePreferenceController mPreferenceController;
+
+ @Before
+ public void setUp() throws Exception {
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ when(mContext.getSystemService(eq(Context.ACCOUNT_SERVICE))).thenReturn(mAccountManager);
+ when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[]{});
+
+ mPreferenceController = new ContactsStoragePreferenceController(mContext,
+ CONTACTS_DEFAULT_ACCOUNT_PREFERENCE_KEY);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_CONTACTS_DEFAULT_ACCOUNT_IN_SETTINGS)
+ public void getAvailabilityStatus_flagIsOn_shouldReturnAvailable() {
+
+ assertThat(mPreferenceController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ @RequiresFlagsDisabled(Flags.FLAG_ENABLE_CONTACTS_DEFAULT_ACCOUNT_IN_SETTINGS)
+ public void getAvailabilityStatus_flagIsOff_shouldReturnConditionallyUnavailable() {
+
+ assertThat(mPreferenceController.getAvailabilityStatus()).isEqualTo(
+ CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getSummary_noAccountIsSetAsDefault_shouldReturnNoAccountSetSummary() {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY_DEFAULT_ACCOUNT, null);
+ when(mContentResolver.call(eq(ContactsContract.AUTHORITY_URI),
+ eq(QUERY_DEFAULT_ACCOUNT_METHOD), any(), any())).thenReturn(bundle);
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getString(eq(R.string.contacts_storage_no_account_set))).thenReturn(
+ "No default set");
+
+ assertThat(mPreferenceController.getSummary()).isEqualTo("No default set");
+ }
+
+ @Test
+ public void getSummary_googleAccountIsSetAsDefault_shouldReturnGoogleAccountTypeAndAccountName() {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY_DEFAULT_ACCOUNT, TEST_ACCOUNT1);
+ when(mContentResolver.call(eq(ContactsContract.AUTHORITY_URI),
+ eq(QUERY_DEFAULT_ACCOUNT_METHOD), any(), any())).thenReturn(bundle);
+
+ assertThat(mPreferenceController.getSummary()).isEqualTo("LABEL1 | test@gmail.com");
+ }
+
+ @Test
+ public void getSummary_samsungAccountIsSetAsDefault_shouldReturnSamsungAccountTypeAndAccountName() {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY_DEFAULT_ACCOUNT, TEST_ACCOUNT2);
+ when(mContentResolver.call(eq(ContactsContract.AUTHORITY_URI),
+ eq(QUERY_DEFAULT_ACCOUNT_METHOD), any(), any())).thenReturn(bundle);
+
+ assertThat(mPreferenceController.getSummary()).isEqualTo("LABEL2 | test@samsung.com");
+ }
+
+ @Test
+ public void getSummary_accountLabelSameAsAccountName_onlyReturnAccountName() {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY_DEFAULT_ACCOUNT, TEST_ACCOUNT3);
+ when(mContentResolver.call(eq(ContactsContract.AUTHORITY_URI),
+ eq(QUERY_DEFAULT_ACCOUNT_METHOD), any(), any())).thenReturn(bundle);
+
+ // Since package name and account name is the same, we only return account name.
+ assertThat(mPreferenceController.getSummary()).isEqualTo("LABEL3");
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceControllerTest.java
index 3a6e494..2877298 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/CopyrightPreferenceControllerTest.java
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.List;
+// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class CopyrightPreferenceControllerTest {
@@ -119,3 +120,4 @@
return testResolveInfo;
}
}
+// LINT.ThenChange(LegalPreferenceTest.kt)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/LegalPreferenceTest.kt b/tests/robotests/src/com/android/settings/deviceinfo/legal/LegalPreferenceTest.kt
new file mode 100644
index 0000000..5b65b16
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/LegalPreferenceTest.kt
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo.legal
+
+import android.content.Context
+import android.content.ContextWrapper
+import android.content.Intent
+import android.content.pm.ActivityInfo
+import android.content.pm.ApplicationInfo
+import android.content.pm.PackageManager
+import android.content.pm.ResolveInfo
+import androidx.test.core.app.ApplicationProvider
+import com.android.settings.R
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.any
+import org.mockito.ArgumentMatchers.anyInt
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.stub
+import org.robolectric.RobolectricTestRunner
+
+// LINT.IfChange
+@RunWith(RobolectricTestRunner::class)
+class LegalPreferenceTest {
+ private val pkgManager = mock<PackageManager>()
+
+ private val context: Context =
+ object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
+ override fun getPackageManager(): PackageManager = pkgManager
+ }
+
+ private val copyrightPreference =
+ LegalPreference("copyright", R.string.copyright_title, "android.settings.COPYRIGHT")
+
+ @Test
+ fun isAvailable_systemApp_shouldReturnTrue() {
+ val testResolveInfos: MutableList<ResolveInfo> = ArrayList()
+ testResolveInfos.add(getTestResolveInfo(/* isSystemApp= */ true))
+
+ pkgManager.stub {
+ on { queryIntentActivities(any(Intent::class.java), anyInt()) } doReturn
+ testResolveInfos
+ }
+
+ assertThat(copyrightPreference.isAvailable(context)).isTrue()
+ }
+
+ @Test
+ fun isAvailable_nonSystemApp_shouldReturnFalse() {
+ val testResolveInfos: MutableList<ResolveInfo> = ArrayList()
+ testResolveInfos.add(getTestResolveInfo(/* isSystemApp= */ false))
+
+ pkgManager.stub {
+ on { queryIntentActivities(any(Intent::class.java), anyInt()) } doReturn
+ testResolveInfos
+ }
+
+ assertThat(copyrightPreference.isAvailable(context)).isFalse()
+ }
+
+ private fun getTestResolveInfo(isSystemApp: Boolean): ResolveInfo {
+ val testResolveInfo = ResolveInfo()
+ val testAppInfo = ApplicationInfo()
+ if (isSystemApp) {
+ testAppInfo.flags = testAppInfo.flags or ApplicationInfo.FLAG_SYSTEM
+ }
+
+ testResolveInfo.activityInfo =
+ ActivityInfo().apply {
+ name = "TestActivityName"
+ packageName = "TestPackageName"
+ applicationInfo = testAppInfo
+ }
+ return testResolveInfo
+ }
+}
+// LINT.ThenChange(CopyrightPreferenceControllerTest.java)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/LegalSettingsScreenTest.kt b/tests/robotests/src/com/android/settings/deviceinfo/legal/LegalSettingsScreenTest.kt
new file mode 100644
index 0000000..48e21b4
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/LegalSettingsScreenTest.kt
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo.legal
+
+import android.content.Context
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
+import android.platform.test.flag.junit.SetFlagsRule
+import android.text.TextUtils
+import androidx.test.core.app.ApplicationProvider
+import com.android.settings.flags.Flags
+import com.google.common.truth.Truth.assertThat
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+
+@RunWith(RobolectricTestRunner::class)
+class LegalSettingsScreenTest {
+ @get:Rule val setFlagsRule = SetFlagsRule()
+ private val context: Context = ApplicationProvider.getApplicationContext()
+ private val legalSettingsScreen = LegalSettingsScreen()
+
+ @Test
+ fun screenKey_exist() {
+ assertThat(TextUtils.equals(legalSettingsScreen.key, LegalSettingsScreen.KEY)).isTrue()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_CATALYST_LEGAL_INFORMATION)
+ fun isFlagEnabled_returnTrue() {
+ assertThat(legalSettingsScreen.isFlagEnabled(context)).isTrue()
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_CATALYST_LEGAL_INFORMATION)
+ fun isFlagDisabled_returnTrue() {
+ assertThat(legalSettingsScreen.isFlagEnabled(context)).isFalse()
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/LicensePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/LicensePreferenceControllerTest.java
index f51c7ad..d6fdf73 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/legal/LicensePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/LicensePreferenceControllerTest.java
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.List;
+// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class LicensePreferenceControllerTest {
@@ -119,3 +120,4 @@
return testResolveInfo;
}
}
+// LINT.ThenChange(LegalPreferenceTest.kt)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/TermsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/TermsPreferenceControllerTest.java
index 2a91fe1..f8ccd0e 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/legal/TermsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/TermsPreferenceControllerTest.java
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.List;
+// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class TermsPreferenceControllerTest {
@@ -119,3 +120,4 @@
return testResolveInfo;
}
}
+// LINT.ThenChange(LegalPreferenceTest.kt)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceControllerTest.java
index c06f069..2f8a8d4 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceControllerTest.java
@@ -29,6 +29,7 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class WallpaperAttributionsPreferenceControllerTest {
@@ -54,4 +55,5 @@
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
-}
\ No newline at end of file
+}
+// LINT.ThenChange(WallpaperAttributionsPreferenceTest.kt)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceTest.kt b/tests/robotests/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceTest.kt
new file mode 100644
index 0000000..00e0b01
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/WallpaperAttributionsPreferenceTest.kt
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo.legal
+
+import android.content.Context
+import android.content.ContextWrapper
+import android.content.res.Resources
+import androidx.test.core.app.ApplicationProvider
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.anyInt
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.stub
+import org.robolectric.RobolectricTestRunner
+
+// LINT.IfChange
+@RunWith(RobolectricTestRunner::class)
+class WallpaperAttributionsPreferenceTest {
+ private val mockResources = mock<Resources>()
+
+ private val context: Context =
+ object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
+ override fun getResources(): Resources = mockResources
+ }
+
+ private val wallpaperAttributionsPreference = WallpaperAttributionsPreference()
+
+ @Test
+ fun isAvailable_configTrue_shouldReturnTrue() {
+ mockResources.stub { on { getBoolean(anyInt()) } doReturn true }
+
+ assertThat(wallpaperAttributionsPreference.isAvailable(context)).isTrue()
+ }
+
+ @Test
+ fun isAvailable_configFalse_shouldReturnFalse() {
+ mockResources.stub { on { getBoolean(anyInt()) } doReturn false }
+
+ assertThat(wallpaperAttributionsPreference.isAvailable(context)).isFalse()
+ }
+}
+// LINT.ThenChange(WallpaperAttributionsPreferenceControllerTest.java)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceControllerTest.java
index 55604c3..0836839 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/WebViewLicensePreferenceControllerTest.java
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.List;
+// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class WebViewLicensePreferenceControllerTest {
@@ -119,3 +120,4 @@
return testResolveInfo;
}
}
+// LINT.ThenChange(LegalPreferenceTest.kt)
diff --git a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerForSetupWizardTest.java b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerForSetupWizardTest.java
new file mode 100644
index 0000000..1113d68
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerForSetupWizardTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.display;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import com.android.settings.accessibility.Flags;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+/**
+ * Tests for {@link AutoBrightnessPreferenceControllerForSetupWizard}.
+ */
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {SettingsShadowResources.class})
+public class AutoBrightnessPreferenceControllerForSetupWizardTest {
+
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ private static final String PREFERENCE_KEY = "auto_brightness";
+
+ private Context mContext;
+ private AutoBrightnessPreferenceControllerForSetupWizard mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController =
+ new AutoBrightnessPreferenceControllerForSetupWizard(mContext, PREFERENCE_KEY);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void getAvailabilityStatus_configTrueAndFlagOn_shouldReturnAvailableUnsearchable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_automatic_brightness_available, true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void getAvailabilityStatus_configFalseSetAndFlagOn_shouldReturnUnsupportedOnDevice() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_automatic_brightness_available, false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void getAvailabilityStatus_flagOff_shouldReturnConditionallyUnavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_automatic_brightness_available, true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+}
+
diff --git a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
index 13cd86d..0122044 100644
--- a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
@@ -21,24 +21,18 @@
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
-import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import android.content.ContentResolver;
import android.content.Context;
-import android.platform.test.annotations.DisableFlags;
-import android.platform.test.annotations.EnableFlags;
-import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import com.android.settings.R;
-import com.android.settings.accessibility.Flags;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -46,13 +40,13 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+/**
+ * Tests for {@link AutoBrightnessPreferenceController}.
+ */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {SettingsShadowResources.class})
public class AutoBrightnessPreferenceControllerTest {
- @Rule
- public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
-
private static final String PREFERENCE_KEY = "auto_brightness";
private Context mContext;
@@ -130,7 +124,7 @@
}
@Test
- public void getAvailabilityStatusNotInSUW_configTrueSet_shouldReturnAvailableUnsearchable() {
+ public void getAvailabilityStatus_configTrueSet_shouldReturnAvailableUnsearchable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, true);
@@ -138,27 +132,6 @@
}
@Test
- @EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
- public void getAvailabilityStatusInSUW_configTrueAndFlagOn_shouldReturnAvailableUnsearchable() {
- SettingsShadowResources.overrideResource(
- com.android.internal.R.bool.config_automatic_brightness_available, true);
- mController.setInSetupWizard(true);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
- }
-
- @Test
- @DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
- public void
- getAvailabilityStatusInSUW_configTrueAndFlagOff_shouldReturnConditionallyUnavailable() {
- SettingsShadowResources.overrideResource(
- com.android.internal.R.bool.config_automatic_brightness_available, true);
- mController.setInSetupWizard(true);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
public void getAvailabilityStatus_configFalseSet_shouldReturnUnsupportedOnDevice() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, false);
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerForSetupWizardTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerForSetupWizardTest.java
new file mode 100644
index 0000000..25ddd1e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerForSetupWizardTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.display;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import com.android.settings.accessibility.Flags;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+/**
+ * Tests for {@link BrightnessLevelPreferenceControllerForSetupWizard}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class BrightnessLevelPreferenceControllerForSetupWizardTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ private Context mContext;
+ private BrightnessLevelPreferenceControllerForSetupWizard mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new BrightnessLevelPreferenceControllerForSetupWizard(mContext,
+ /* lifecycle= */ null);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void getAvailabilityStatus_flagOn_shouldReturnAvailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void getAvailabilityStatus_flagOff_shouldReturnConditionallyUnavailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
index 009ca95..eb83040 100644
--- a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
@@ -33,9 +33,6 @@
import android.content.Intent;
import android.hardware.display.BrightnessInfo;
import android.os.PowerManager;
-import android.platform.test.annotations.DisableFlags;
-import android.platform.test.annotations.EnableFlags;
-import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings.System;
import android.view.Display;
@@ -43,12 +40,10 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.accessibility.Flags;
import com.android.settings.core.SettingsBaseActivity;
import com.android.settingslib.transition.SettingsTransitionHelper;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -61,12 +56,11 @@
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowContentResolver;
+/**
+ * Tests for {@link BrightnessLevelPreferenceController}.
+ */
@RunWith(RobolectricTestRunner.class)
public class BrightnessLevelPreferenceControllerTest {
-
- @Rule
- public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
-
@Mock
private PowerManager mPowerManager;
@Mock
@@ -95,29 +89,15 @@
mPowerManager);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
doReturn(mDisplay).when(mContext).getDisplay();
- mController = spy(new BrightnessLevelPreferenceController(mContext, null));
+ mController = spy(new BrightnessLevelPreferenceController(mContext, /* lifecycle= */ null));
}
@Test
- public void isAvailable_shouldAlwaysReturnTrueWhenNotInSetupWizard() {
+ public void isAvailable_shouldAlwaysReturnTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
- @EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
- public void isAvailable_inSetupWizardAndFlagOn_shouldReturnTrue() {
- mController.setInSetupWizard(true);
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
- @DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
- public void isAvailable_inSetupWizardAndFlagOff_shouldReturnFalse() {
- mController.setInSetupWizard(true);
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
public void onStart_shouldRegisterObserver() {
BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(mContext, null);