diff --git a/res/drawable/circle.xml b/res/drawable/circle.xml new file mode 100644 index 00000000000..f207cc2c8f3 --- /dev/null +++ b/res/drawable/circle.xml @@ -0,0 +1,27 @@ + + + + + + + \ No newline at end of file diff --git a/res/drawable/ic_files_go_round.xml b/res/drawable/ic_files_go_round.xml new file mode 100644 index 00000000000..2025b000ea8 --- /dev/null +++ b/res/drawable/ic_files_go_round.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout-land/confirm_lock_pattern.xml b/res/layout-land/confirm_lock_pattern.xml index 1fd6824ae5f..1126052df47 100644 --- a/res/layout-land/confirm_lock_pattern.xml +++ b/res/layout-land/confirm_lock_pattern.xml @@ -48,13 +48,13 @@ android:src="@drawable/ic_enterprise" /> - - + + + - - - - + android:layout_width="wrap_content" + android:layout_gravity="center_vertical" + android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Notification"/> + android:scaleType="centerInside" /> diff --git a/res/values/config.xml b/res/values/config.xml index 2546d8d0f76..5a8f6363efb 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -522,4 +522,7 @@ content://com.android.providers.media.documents/root/documents_root + + + true diff --git a/res/values/strings.xml b/res/values/strings.xml index 2e98ec57de3..e5784e39a8c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -933,6 +933,43 @@ Skip fingerprint? Fingerprint setup only takes a minute or two. If you skip this, you can add your fingerprint later in settings. + + + + When you see this icon, use your fingerprint for authentication, like when you sign in to apps or approve a purchase + + Keep in mind + + Using your fingerprint to unlock your phone may be less secure than a strong pattern or PIN + + How it works + + Fingerprint Unlock creates a unique model of your fingerprint to recognize you during authentication. To create this fingerprint model during setup, you will take images of your fingerprint from different positions. + + The phone will also use images from your interactions with Fingerprint Unlock to update your fingerprint model. Your fingerprint images and model are stored securely on your phone and never leave the phone. All processing occurs securely on your phone. + + You can delete your fingerprint images and model, or turn off Fingerprint Unlock at any time in Settings. Fingerprint images and models are stored on the phone until you delete them. + + + + + Change the position of your finger slightly each time + + Cover the icon with the center of your fingerprint + + This fingerprint has already been added + + Clean your screen near the sensor and try again + + Lift your finger after you feel a vibration + + Move somewhere with gentler lighting and try again + + You\u2019ve reached the maximum number of attempts + + + Use your fingerprint to unlock your phone or for authentication, like when you sign in to apps or approve a purchase + Skip screen lock? @@ -1067,6 +1104,9 @@ Do you want to delete this fingerprint? + + This deletes the fingerprint images and model associated with \'%1$s\' that are stored on your device + You won\'t be able to use your fingerprints to unlock your phone, authorize purchases, or sign in to apps with them @@ -1728,7 +1768,7 @@ When Bluetooth is turned on, your device can communicate with other nearby Bluetooth devices. - When Bluetooth is turned on, your device can communicate with other nearby Bluetooth devices.\n\nTo improve device experience, apps and services can still scan for nearby devices at any time, even when Bluetooth is off. This can be used, for example, to improve location-based features and services. you can change this in scanning settings. + When Bluetooth is turned on, your device can communicate with other nearby Bluetooth devices.\n\nTo improve device experience, apps and services can still scan for nearby devices at any time, even when Bluetooth is off. This can be used, for example, to improve location-based features and services. you can change this in Bluetooth scanning settings. @@ -1981,13 +2021,13 @@ - To improve location accuracy, apps and services can still scan for Wi\u2011Fi networks at any time, even when Wi\u2011Fi is off. This can be used, for example, to improve location-based features and services. You can change this in LINK_BEGINscanning settingsLINK_END. + To improve location accuracy, apps and services can still scan for Wi\u2011Fi networks at any time, even when Wi\u2011Fi is off. This can be used, for example, to improve location-based features and services. You can change this in LINK_BEGINWi\u2011Fi scanning settingsLINK_END. To improve location accuracy, turn on Wi-Fi scanning in - LINK_BEGINscanning + LINK_BEGINWi\u2011Fi scanning settingsLINK_END. Don\u2019t show again diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index 3b87ae4583f..df17052daa6 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -38,7 +38,17 @@ + settings:initialExpandedChildrenCount="3"> + + + - - - - - - - - + + + android:summary="@string/storage_free_up_space_summary" + settings:allowDividerAbove="true" + android:icon="@drawable/ic_files_go_round"/> + + android:icon="@drawable/ic_photo_library" + android:order="101"/> + android:icon="@drawable/ic_local_movies" + android:order="102"/> + android:icon="@drawable/ic_media_stream" + android:order="103"/> + android:icon="@drawable/ic_storage_apps" + android:order="104"/> + android:icon="@drawable/ic_videogame_vd_theme_24" + android:order="105"/> + android:icon="@drawable/ic_folder_vd_theme_24" + android:order="106"/> + android:icon="@drawable/ic_system_update" + android:order="107"/> + android:icon="@drawable/ic_trash_can" + android:order="108"/> 0); - addLinkPreference.setOnPreferenceClickListener(preference -> { - final int stateNoneLinksNo = getLinksNumber(DOMAIN_STATE_NONE); - IntentPickerUtils.logd("The number of the state none links: " + stateNoneLinksNo); - if (stateNoneLinksNo > 0) { - showProgressDialogFragment(); - } - return true; - }); - } + mAddLinkPreference = findPreference(ADD_LINK_PREF_KEY); + mAddLinkPreference.setEnabled(isAddLinksNotEmpty()); + mAddLinkPreference.setOnPreferenceClickListener(preference -> { + final int stateNoneLinksNo = getLinksNumber(DOMAIN_STATE_NONE); + IntentPickerUtils.logd("The number of the state none links: " + stateNoneLinksNo); + if (stateNoneLinksNo > 0) { + showProgressDialogFragment(); + } + return true; + }); + } + + private boolean isAddLinksNotEmpty() { + return getLinksNumber(DOMAIN_STATE_NONE) > 0; } private void showProgressDialogFragment() { diff --git a/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java index 27f10da320d..3bf913209c2 100644 --- a/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java +++ b/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java @@ -23,7 +23,7 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.core.SubSettingLauncher; -import com.android.settings.location.LocationServices; +import com.android.settings.location.BluetoothScanningFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.utils.AnnotationSpan; import com.android.settings.widget.SwitchWidgetController; @@ -100,7 +100,7 @@ public class BluetoothSwitchPreferenceController public void onClick(View v) { // send users to scanning settings if they click on the link in the summary text new SubSettingLauncher(mContext) - .setDestination(LocationServices.class.getName()) + .setDestination(BluetoothScanningFragment.class.getName()) .setSourceMetricsCategory(SettingsEnums.BLUETOOTH_FRAGMENT) .launch(); } @@ -117,4 +117,4 @@ public class BluetoothSwitchPreferenceController mFooterPreference.setTitle(R.string.bluetooth_empty_list_bluetooth_off); } } -} \ No newline at end of file +} diff --git a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java index 2891e3a90dc..c324acaf54a 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java @@ -20,7 +20,7 @@ import android.util.ArrayMap; import com.android.settings.accounts.AccountDashboardFragment; import com.android.settings.applications.manageapplications.ManageApplications; -import com.android.settings.location.LocationSettings; +import com.android.settings.location.LocationServices; import com.android.settings.location.RecentLocationAccessSeeAllFragment; import java.util.Map; @@ -42,9 +42,9 @@ public class ProfileFragmentBridge { ProfileSelectAccountFragment.class.getName()); FRAGMENT_MAP.put(ManageApplications.class.getName(), ProfileSelectManageApplications.class.getName()); - FRAGMENT_MAP.put(LocationSettings.class.getName(), - ProfileSelectLocationFragment.class.getName()); FRAGMENT_MAP.put(RecentLocationAccessSeeAllFragment.class.getName(), ProfileSelectRecentLocationAccessFragment.class.getName()); + FRAGMENT_MAP.put(LocationServices.class.getName(), + ProfileSelectLocationServicesFragment.class.getName()); } } diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java new file mode 100644 index 00000000000..b6f03d6b820 --- /dev/null +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 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.dashboard.profileselector; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import com.android.settings.location.LocationServices; +import com.android.settings.location.LocationServicesForWork; + +/** + * Location Services page for personal/managed profile. + */ +public class ProfileSelectLocationServicesFragment extends ProfileSelectFragment { + + @Override + public Fragment[] getFragments() { + final Bundle workOnly = new Bundle(); + workOnly.putInt(EXTRA_PROFILE, ProfileType.WORK); + final Fragment workFragment = new LocationServicesForWork(); + workFragment.setArguments(workOnly); + + final Bundle personalOnly = new Bundle(); + personalOnly.putInt(EXTRA_PROFILE, ProfileType.PERSONAL); + final Fragment personalFragment = new LocationServices(); + personalFragment.setArguments(personalOnly); + return new Fragment[]{ + personalFragment, // 0 + workFragment + }; + } +} diff --git a/src/com/android/settings/datetime/timezone/RegionSearchPicker.java b/src/com/android/settings/datetime/timezone/RegionSearchPicker.java index 07986e29a9f..85d5d705b49 100644 --- a/src/com/android/settings/datetime/timezone/RegionSearchPicker.java +++ b/src/com/android/settings/datetime/timezone/RegionSearchPicker.java @@ -71,14 +71,14 @@ public class RegionSearchPicker extends BaseTimeZonePicker { final FilteredCountryTimeZones countryTimeZones = mTimeZoneData.lookupCountryTimeZones( regionId); final Activity activity = getActivity(); - if (countryTimeZones == null || countryTimeZones.getTimeZoneIds().isEmpty()) { + if (countryTimeZones == null || countryTimeZones.getPreferredTimeZoneIds().isEmpty()) { Log.e(TAG, "Region has no time zones: " + regionId); activity.setResult(Activity.RESULT_CANCELED); activity.finish(); return; } - List timeZoneIds = countryTimeZones.getTimeZoneIds(); + List timeZoneIds = countryTimeZones.getPreferredTimeZoneIds(); // Choose the time zone associated the region if there is only one time zone in that region if (timeZoneIds.size() == 1) { final Intent resultData = new Intent() diff --git a/src/com/android/settings/datetime/timezone/RegionZonePicker.java b/src/com/android/settings/datetime/timezone/RegionZonePicker.java index 8e4aa055322..7f988cd0ef0 100644 --- a/src/com/android/settings/datetime/timezone/RegionZonePicker.java +++ b/src/com/android/settings/datetime/timezone/RegionZonePicker.java @@ -103,7 +103,7 @@ public class RegionZonePicker extends BaseTimeZoneInfoPicker { // It could be a timely operations if there are many time zones. A region in time zone data // contains a maximum of 29 time zones currently. It may change in the future, but it's // unlikely to be changed drastically. - return getRegionTimeZoneInfo(filteredCountryTimeZones.getTimeZoneIds()); + return getRegionTimeZoneInfo(filteredCountryTimeZones.getPreferredTimeZoneIds()); } /** diff --git a/src/com/android/settings/datetime/timezone/TimeZoneSettings.java b/src/com/android/settings/datetime/timezone/TimeZoneSettings.java index 60cd6363ec2..6c779b54a0c 100644 --- a/src/com/android/settings/datetime/timezone/TimeZoneSettings.java +++ b/src/com/android/settings/datetime/timezone/TimeZoneSettings.java @@ -214,10 +214,11 @@ public class TimeZoneSettings extends DashboardFragment { mTimeZoneData.lookupCountryTimeZones(regionId); use(RegionZonePreferenceController.class).setTimeZoneInfo(tzInfo); - // Only clickable when the region has more than 1 time zones or no time zone is selected. + // Only clickable when the region has more than 1 time zones or no time zone is selected. use(RegionZonePreferenceController.class).setClickable(tzInfo == null || - (countryTimeZones != null && countryTimeZones.getTimeZoneIds().size() > 1)); + (countryTimeZones != null + && countryTimeZones.getPreferredTimeZoneIds().size() > 1)); use(TimeZoneInfoPreferenceController.class).setTimeZoneInfo(tzInfo); updatePreferenceStates(); @@ -244,7 +245,8 @@ public class TimeZoneSettings extends DashboardFragment { FilteredCountryTimeZones countryTimeZones = timeZoneData.lookupCountryTimeZones(regionId); - if (countryTimeZones == null || !countryTimeZones.getTimeZoneIds().contains(tzId)) { + if (countryTimeZones == null + || !countryTimeZones.getPreferredTimeZoneIds().contains(tzId)) { Log.e(TAG, "Unknown time zone id is selected: " + tzId); return; } diff --git a/src/com/android/settings/datetime/timezone/model/FilteredCountryTimeZones.java b/src/com/android/settings/datetime/timezone/model/FilteredCountryTimeZones.java index 7a3885326ba..05a542d9bcd 100644 --- a/src/com/android/settings/datetime/timezone/model/FilteredCountryTimeZones.java +++ b/src/com/android/settings/datetime/timezone/model/FilteredCountryTimeZones.java @@ -16,11 +16,15 @@ package com.android.settings.datetime.timezone.model; +import android.util.ArraySet; + import com.android.i18n.timezone.CountryTimeZones; +import java.time.Instant; +import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; +import java.util.Set; /** * Wrap {@class CountryTimeZones} to filter time zone that are shown in the picker. @@ -39,31 +43,46 @@ public class FilteredCountryTimeZones { * a timestamp known to be in the recent past is used. This should be updated occasionally but * it doesn't have to be very often. */ - private static final long MIN_USE_DATE_OF_TIMEZONE = 1546300800000L; // 1/1/2019 00:00 UTC + private static final Instant MIN_USE_DATE_OF_TIMEZONE = + Instant.ofEpochMilli(1546300800000L); // 1/1/2019 00:00 UTC private final CountryTimeZones mCountryTimeZones; - private final List mTimeZoneIds; + private final List mPreferredTimeZoneIds; + private final Set mAlternativeTimeZoneIds; public FilteredCountryTimeZones(CountryTimeZones countryTimeZones) { mCountryTimeZones = countryTimeZones; - List timeZoneIds = countryTimeZones.getTimeZoneMappings().stream() - .filter(timeZoneMapping -> - timeZoneMapping.isShownInPicker() - && (timeZoneMapping.getNotUsedAfter() == null - || timeZoneMapping.getNotUsedAfter() >= MIN_USE_DATE_OF_TIMEZONE)) - .map(timeZoneMapping -> timeZoneMapping.getTimeZoneId()) - .collect(Collectors.toList()); - mTimeZoneIds = Collections.unmodifiableList(timeZoneIds); + List timeZoneIds = new ArrayList<>(); + Set alternativeTimeZoneIds = new ArraySet<>(); + for (CountryTimeZones.TimeZoneMapping timeZoneMapping : + countryTimeZones.getTimeZoneMappings()) { + if (timeZoneMapping.isShownInPickerAt(MIN_USE_DATE_OF_TIMEZONE)) { + String timeZoneId = timeZoneMapping.getTimeZoneId(); + timeZoneIds.add(timeZoneId); + alternativeTimeZoneIds.addAll(timeZoneMapping.getAlternativeIds()); + } + } + mPreferredTimeZoneIds = Collections.unmodifiableList(timeZoneIds); + mAlternativeTimeZoneIds = Collections.unmodifiableSet(alternativeTimeZoneIds); } - public List getTimeZoneIds() { - return mTimeZoneIds; + public List getPreferredTimeZoneIds() { + return mPreferredTimeZoneIds; } public CountryTimeZones getCountryTimeZones() { return mCountryTimeZones; } + /** + * Returns whether {@code timeZoneId} is currently used in the country or is an alternative + * name of a currently used time zone. + */ + public boolean matches(String timeZoneId) { + return mPreferredTimeZoneIds.contains(timeZoneId) + || mAlternativeTimeZoneIds.contains(timeZoneId); + } + public String getRegionId() { return TimeZoneData.normalizeRegionId(mCountryTimeZones.getCountryIso()); } diff --git a/src/com/android/settings/datetime/timezone/model/TimeZoneData.java b/src/com/android/settings/datetime/timezone/model/TimeZoneData.java index 335e6e2cd6a..06f2de0f139 100644 --- a/src/com/android/settings/datetime/timezone/model/TimeZoneData.java +++ b/src/com/android/settings/datetime/timezone/model/TimeZoneData.java @@ -71,7 +71,7 @@ public class TimeZoneData { Set regionIds = new ArraySet<>(); for (CountryTimeZones countryTimeZone : countryTimeZones) { FilteredCountryTimeZones filteredZones = new FilteredCountryTimeZones(countryTimeZone); - if (filteredZones.getTimeZoneIds().contains(tzId)) { + if (filteredZones.matches(tzId)) { regionIds.add(filteredZones.getRegionId()); } } diff --git a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java index 536f6997e89..e6d9dfdbb78 100644 --- a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java +++ b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java @@ -58,7 +58,7 @@ public class DeviceNamePreferenceController extends BasePreferenceController public DeviceNamePreferenceController(Context context, String key) { super(context, key); - mWifiManager = context.getSystemService(WifiManager.class); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiDeviceNameTextValidator = new WifiDeviceNameTextValidator(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java index b8c4e286777..03a7b970ff1 100644 --- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java +++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java @@ -248,15 +248,19 @@ public class StorageDashboardFragment extends DashboardFragment mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo()); - if (mSelectedStorageEntry.isPrivate() && mSelectedStorageEntry.isMounted()) { + if (!mSelectedStorageEntry.isMounted()) { + // Set null volume to hide category stats. + mPreferenceController.setVolume(null); + return; + } + if (mSelectedStorageEntry.isPrivate()) { // Stats data is only available on private volumes. getLoaderManager().restartLoader(STORAGE_JOB_ID, Bundle.EMPTY, this); getLoaderManager() .restartLoader(VOLUME_SIZE_JOB_ID, Bundle.EMPTY, new VolumeSizeCallbacks()); getLoaderManager().restartLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks()); } else { - // Set null volume to hide category stats. - mPreferenceController.setVolume(null); + mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo()); } } diff --git a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java index 9e969a8211e..7d20aa715db 100644 --- a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java +++ b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java @@ -121,7 +121,7 @@ public class StorageWizardMigrateConfirm extends StorageWizardBase { try { moveId = getPackageManager().movePrimaryStorage(mVolume); } catch (IllegalArgumentException e) { - StorageManager sm = getSystemService(StorageManager.class); + StorageManager sm = (StorageManager) getSystemService(STORAGE_SERVICE); if (Objects.equals(mVolume.getFsUuid(), sm.getPrimaryStorageVolume().getUuid())) { final Intent intent = new Intent(this, StorageWizardReady.class); diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java index fcbd5d3b769..4af5d79c37f 100644 --- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java +++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java @@ -146,8 +146,8 @@ public class MyDeviceInfoFragment extends DashboardFragment // TODO: There may be an avatar setting action we can use here. final int iconId = bundle.getInt("icon_id", 0); if (iconId == 0) { - final UserManager userManager = getActivity().getSystemService( - UserManager.class); + final UserManager userManager = (UserManager) getActivity().getSystemService( + Context.USER_SERVICE); final UserInfo info = Utils.getExistingUser(userManager, android.os.Process.myUserHandle()); controller.setLabel(info.name); diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceController.java index 14e86b4475d..d6cf442b11c 100644 --- a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceController.java +++ b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceController.java @@ -49,7 +49,7 @@ public class FirmwareVersionDetailPreferenceController extends BasePreferenceCon public FirmwareVersionDetailPreferenceController(Context context, String key) { super(context, key); - mUserManager = mContext.getSystemService(UserManager.class); + mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); initializeAdminPermissions(); } diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java index fbb29a7a981..967eea6155d 100644 --- a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java +++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java @@ -49,7 +49,7 @@ public class ImeiInfoPreferenceController extends BasePreferenceController { public ImeiInfoPreferenceController(Context context, String key) { super(context, key); - mTelephonyManager = context.getSystemService(TelephonyManager.class); + mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mIsMultiSim = mTelephonyManager.getPhoneCount() > 1; } diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java index c3917505278..02c191679d1 100644 --- a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java +++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java @@ -46,9 +46,9 @@ public class SimStatusPreferenceController extends public SimStatusPreferenceController(Context context, Fragment fragment) { super(context); - mTelephonyManager = context.getSystemService(TelephonyManager.class); - mSubscriptionManager = context.getSystemService( - SubscriptionManager.class); + mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + mSubscriptionManager = (SubscriptionManager) context.getSystemService( + Context.TELEPHONY_SUBSCRIPTION_SERVICE); mFragment = fragment; } diff --git a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java index f733c72737d..f753868a6d0 100644 --- a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java @@ -26,6 +26,7 @@ import androidx.annotation.VisibleForTesting; import androidx.fragment.app.FragmentManager; import androidx.preference.PreferenceScreen; +import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.deletionhelper.ActivationWarningFragment; import com.android.settings.overlay.FeatureFactory; @@ -66,6 +67,9 @@ public class AutomaticStorageManagementSwitchPreferenceController extends @Override public int getAvailabilityStatus() { + if (!mContext.getResources().getBoolean(R.bool.config_show_smart_storage_toggle)) { + return UNSUPPORTED_ON_DEVICE; + } return !ActivityManager.isLowRamDeviceStatic() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @@ -108,4 +112,4 @@ public class AutomaticStorageManagementSwitchPreferenceController extends return true; } -} \ No newline at end of file +} diff --git a/src/com/android/settings/deviceinfo/storage/StorageEntry.java b/src/com/android/settings/deviceinfo/storage/StorageEntry.java index f71811602d5..9ea0292d195 100644 --- a/src/com/android/settings/deviceinfo/storage/StorageEntry.java +++ b/src/com/android/settings/deviceinfo/storage/StorageEntry.java @@ -236,6 +236,14 @@ public class StorageEntry implements Comparable, Parcelable { return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PUBLIC; } + /** + * Stub volume is a volume that is maintained by external party such as the ChromeOS processes + * in ARC++. + */ + public boolean isStub() { + return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_STUB; + } + /** Returns description. */ public String getDescription() { if (isVolumeInfo()) { diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java index 7d7768799d8..e5259f996e3 100644 --- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java @@ -69,6 +69,8 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle private static final String SYSTEM_FRAGMENT_TAG = "SystemInfo"; + @VisibleForTesting + static final String PUBLIC_STORAGE_KEY = "pref_public_storage"; @VisibleForTesting static final String IMAGES_KEY = "pref_images"; @VisibleForTesting @@ -103,9 +105,11 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle private long mUsedBytes; private long mTotalSize; - private List mStorageItemPreferences; + private List mPrivateStorageItemPreferences; private PreferenceScreen mScreen; @VisibleForTesting + Preference mPublicStoragePreference; + @VisibleForTesting StorageItemPreference mImagesPreference; @VisibleForTesting StorageItemPreference mVideosPreference; @@ -167,6 +171,9 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle return false; } switch (preference.getKey()) { + case PUBLIC_STORAGE_KEY: + launchPublicStorageIntent(); + return true; case IMAGES_KEY: launchImagesIntent(); return true; @@ -210,37 +217,45 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle public void setVolume(VolumeInfo volume) { mVolume = volume; - final boolean isValidVolume = isValidVolume(); - setCategoryPreferencesVisibility(isValidVolume); - if (isValidVolume) { - updateCategoryPreferencesOrder(); - } + updateCategoryPreferencesVisibility(); + updatePrivateStorageCategoryPreferencesOrder(); } // Stats data is only available on private volumes. - private boolean isValidVolume() { + private boolean isValidPrivateVolume() { return mVolume != null && mVolume.getType() == VolumeInfo.TYPE_PRIVATE && (mVolume.getState() == VolumeInfo.STATE_MOUNTED || mVolume.getState() == VolumeInfo.STATE_MOUNTED_READ_ONLY); } - private void setCategoryPreferencesVisibility(boolean visible) { + private boolean isValidPublicVolume() { + return mVolume != null + && (mVolume.getType() == VolumeInfo.TYPE_PUBLIC + || mVolume.getType() == VolumeInfo.TYPE_STUB) + && (mVolume.getState() == VolumeInfo.STATE_MOUNTED + || mVolume.getState() == VolumeInfo.STATE_MOUNTED_READ_ONLY); + } + + private void updateCategoryPreferencesVisibility() { if (mScreen == null) { return; } - mImagesPreference.setVisible(visible); - mVideosPreference.setVisible(visible); - mAudiosPreference.setVisible(visible); - mAppsPreference.setVisible(visible); - mGamesPreference.setVisible(visible); - mDocumentsAndOtherPreference.setVisible(visible); - mSystemPreference.setVisible(visible); + mPublicStoragePreference.setVisible(isValidPublicVolume()); + + final boolean privateStoragePreferencesVisible = isValidPrivateVolume(); + mImagesPreference.setVisible(privateStoragePreferencesVisible); + mVideosPreference.setVisible(privateStoragePreferencesVisible); + mAudiosPreference.setVisible(privateStoragePreferencesVisible); + mAppsPreference.setVisible(privateStoragePreferencesVisible); + mGamesPreference.setVisible(privateStoragePreferencesVisible); + mDocumentsAndOtherPreference.setVisible(privateStoragePreferencesVisible); + mSystemPreference.setVisible(privateStoragePreferencesVisible); // TODO(b/170918505): Shows trash category after trash category feature complete. mTrashPreference.setVisible(false); - if (visible) { + if (privateStoragePreferencesVisible) { final VolumeInfo sharedVolume = mSvp.findEmulatedForPrivate(mVolume); // If we don't have a shared volume for our internal storage (or the shared volume isn't // mounted as readable for whatever reason), we should hide the File preference. @@ -250,22 +265,22 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle } } - private void updateCategoryPreferencesOrder() { - if (mScreen == null) { + private void updatePrivateStorageCategoryPreferencesOrder() { + if (mScreen == null || !isValidPrivateVolume()) { return; } - if (mStorageItemPreferences == null) { - mStorageItemPreferences = new ArrayList<>(); + if (mPrivateStorageItemPreferences == null) { + mPrivateStorageItemPreferences = new ArrayList<>(); - mStorageItemPreferences.add(mImagesPreference); - mStorageItemPreferences.add(mVideosPreference); - mStorageItemPreferences.add(mAudiosPreference); - mStorageItemPreferences.add(mAppsPreference); - mStorageItemPreferences.add(mGamesPreference); - mStorageItemPreferences.add(mDocumentsAndOtherPreference); - mStorageItemPreferences.add(mSystemPreference); - mStorageItemPreferences.add(mTrashPreference); + mPrivateStorageItemPreferences.add(mImagesPreference); + mPrivateStorageItemPreferences.add(mVideosPreference); + mPrivateStorageItemPreferences.add(mAudiosPreference); + mPrivateStorageItemPreferences.add(mAppsPreference); + mPrivateStorageItemPreferences.add(mGamesPreference); + mPrivateStorageItemPreferences.add(mDocumentsAndOtherPreference); + mPrivateStorageItemPreferences.add(mSystemPreference); + mPrivateStorageItemPreferences.add(mTrashPreference); } mScreen.removePreference(mImagesPreference); mScreen.removePreference(mVideosPreference); @@ -277,10 +292,10 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle mScreen.removePreference(mTrashPreference); // Sort display order by size. - Collections.sort(mStorageItemPreferences, + Collections.sort(mPrivateStorageItemPreferences, Comparator.comparingLong(StorageItemPreference::getStorageSize)); int orderIndex = LAST_STORAGE_CATEGORY_PREFERENCE_ORDER; - for (StorageItemPreference preference : mStorageItemPreferences) { + for (StorageItemPreference preference : mPrivateStorageItemPreferences) { preference.setOrder(orderIndex--); mScreen.addPreference(preference); } @@ -292,6 +307,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle public void setUserId(UserHandle userHandle) { mUserId = userHandle.getIdentifier(); + tintPreference(mPublicStoragePreference); tintPreference(mImagesPreference); tintPreference(mVideosPreference); tintPreference(mAudiosPreference); @@ -320,6 +336,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle @Override public void displayPreference(PreferenceScreen screen) { mScreen = screen; + mPublicStoragePreference = screen.findPreference(PUBLIC_STORAGE_KEY); mImagesPreference = screen.findPreference(IMAGES_KEY); mVideosPreference = screen.findPreference(VIDEOS_KEY); mAudiosPreference = screen.findPreference(AUDIOS_KEY); @@ -329,11 +346,8 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle mSystemPreference = screen.findPreference(SYSTEM_KEY); mTrashPreference = screen.findPreference(TRASH_KEY); - final boolean isValidVolume = isValidVolume(); - setCategoryPreferencesVisibility(isValidVolume); - if (isValidVolume) { - updateCategoryPreferencesOrder(); - } + updateCategoryPreferencesVisibility(); + updatePrivateStorageCategoryPreferencesOrder(); } public void onLoadFinished(SparseArray result, @@ -371,7 +385,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle mSystemPreference.setStorageSize(systemSize, mTotalSize); } - updateCategoryPreferencesOrder(); + updatePrivateStorageCategoryPreferencesOrder(); } public void setUsedSize(long usedSizeBytes) { @@ -382,6 +396,13 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle mTotalSize = totalSizeBytes; } + private void launchPublicStorageIntent() { + final Intent intent = mVolume.buildBrowseIntent(); + if (intent != null) { + mContext.startActivity(intent); + } + } + // TODO(b/183078080): To simplify StorageItemPreferenceController, move launchxxxIntent to a // utility object. private void launchImagesIntent() { diff --git a/src/com/android/settings/fuelgauge/BatteryEntry.java b/src/com/android/settings/fuelgauge/BatteryEntry.java index 09380ff5590..ed52f480e94 100644 --- a/src/com/android/settings/fuelgauge/BatteryEntry.java +++ b/src/com/android/settings/fuelgauge/BatteryEntry.java @@ -52,6 +52,19 @@ import java.util.Locale; * and icon image. */ public class BatteryEntry { + + public static final class NameAndIcon { + public final String name; + public final Drawable icon; + public final int iconId; + + public NameAndIcon(String name, Drawable icon, int iconId) { + this.name = name; + this.icon = icon; + this.iconId = iconId; + } + } + public static final int MSG_UPDATE_NAME_ICON = 1; public static final int MSG_REPORT_FULLY_DRAWN = 2; @@ -186,22 +199,16 @@ public class BatteryEntry { } else if (batteryConsumer instanceof SystemBatteryConsumer) { mConsumedPower = batteryConsumer.getConsumedPower() - ((SystemBatteryConsumer) batteryConsumer).getPowerConsumedByApps(); - final Pair resourcePair = getResourcePairFromDrainType( + final NameAndIcon nameAndIcon = getNameAndIconFromDrainType( context, ((SystemBatteryConsumer) batteryConsumer).getDrainType()); - iconId = resourcePair.first; - name = resourcePair.second; + iconId = nameAndIcon.iconId; + name = nameAndIcon.name; } else if (batteryConsumer instanceof UserBatteryConsumer) { mConsumedPower = batteryConsumer.getConsumedPower(); - - UserInfo info = um.getUserInfo(((UserBatteryConsumer) batteryConsumer).getUserId()); - if (info != null) { - icon = Utils.getUserIcon(context, um, info); - name = Utils.getUserLabel(context, info); - } else { - icon = null; - name = context.getResources().getString( - R.string.running_process_item_removed_user_label); - } + final NameAndIcon nameAndIcon = getNameAndIconFromUserId( + context, ((UserBatteryConsumer) batteryConsumer).getUserId()); + icon = nameAndIcon.icon; + name = nameAndIcon.name; } if (iconId != 0) { @@ -238,15 +245,9 @@ public class BatteryEntry { } if (packages == null || packages.length == 0) { - if (uid == 0) { - name = mContext.getResources().getString(R.string.process_kernel_label); - } else if ("mediaserver".equals(name)) { - name = mContext.getResources().getString(R.string.process_mediaserver_label); - } else if ("dex2oat".equals(name)) { - name = mContext.getResources().getString(R.string.process_dex2oat_label); - } - iconId = R.drawable.ic_power_system; - icon = mContext.getDrawable(iconId); + final NameAndIcon nameAndIcon = getNameAndIconFromUid(mContext, name, uid); + icon = nameAndIcon.icon; + name = nameAndIcon.name; } else { icon = mContext.getPackageManager().getDefaultActivityIcon(); } @@ -418,6 +419,13 @@ public class BatteryEntry { } } + /** + * Returns the BatteryConsumer of the app described by this entry. + */ + public BatteryConsumer getBatteryConsumer() { + return mBatteryConsumer; + } + /** * Returns foreground foreground time (in milliseconds) that is attributed to this entry. */ @@ -462,10 +470,46 @@ public class BatteryEntry { } /** - * Gets icon ID and name from system battery consumer drain type. + * Gets name and icon resource from UserBatteryConsumer userId. */ - public static Pair getResourcePairFromDrainType( - Context context, int drainType) { + public static NameAndIcon getNameAndIconFromUserId( + Context context, final int userId) { + UserManager um = context.getSystemService(UserManager.class); + UserInfo info = um.getUserInfo(userId); + + Drawable icon = null; + String name = null; + if (info != null) { + icon = Utils.getUserIcon(context, um, info); + name = Utils.getUserLabel(context, info); + } else { + name = context.getResources().getString( + R.string.running_process_item_removed_user_label); + } + return new NameAndIcon(name, icon, 0 /* iconId */); + } + + /** + * Gets name and icon resource from UidBatteryConsumer uid. + */ + public static NameAndIcon getNameAndIconFromUid( + Context context, String name, final int uid) { + Drawable icon = context.getDrawable(R.drawable.ic_power_system); + if (uid == 0) { + name = context.getResources().getString(R.string.process_kernel_label); + } else if ("mediaserver".equals(name)) { + name = context.getResources().getString(R.string.process_mediaserver_label); + } else if ("dex2oat".equals(name)) { + name = context.getResources().getString(R.string.process_dex2oat_label); + } + return new NameAndIcon(name, icon, 0 /* iconId */); + } + + /** + * Gets name annd icon resource from SystemBatteryConsumer drain type. + */ + public static NameAndIcon getNameAndIconFromDrainType( + Context context, final int drainType) { String name = null; int iconId = 0; switch (drainType) { @@ -511,6 +555,6 @@ public class BatteryEntry { iconId = R.drawable.ic_power_system; break; } - return new Pair<>(Integer.valueOf(iconId), name); + return new NameAndIcon(name, null /* icon */, iconId); } } diff --git a/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java b/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java index ea277a12add..27b70cb6129 100644 --- a/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java +++ b/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java @@ -20,27 +20,23 @@ package com.android.settings.fuelgauge; import android.content.Context; import android.provider.Settings; import android.text.TextUtils; -import android.widget.Switch; import androidx.preference.Preference; -import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreference; import com.android.settings.core.BasePreferenceController; import com.android.settings.overlay.FeatureFactory; -import com.android.settingslib.widget.MainSwitchPreference; -import com.android.settingslib.widget.OnMainSwitchChangeListener; /** * Controller to change and update the smart battery toggle */ public class SmartBatteryPreferenceController extends BasePreferenceController implements - OnMainSwitchChangeListener { + Preference.OnPreferenceChangeListener { private static final String KEY_SMART_BATTERY = "smart_battery"; private static final int ON = 1; private static final int OFF = 0; private PowerUsageFeatureProvider mPowerUsageFeatureProvider; - private MainSwitchPreference mPreference; public SmartBatteryPreferenceController(Context context) { super(context, KEY_SMART_BATTERY); @@ -70,19 +66,14 @@ public class SmartBatteryPreferenceController extends BasePreferenceController i super.updateState(preference); final boolean smartBatteryOn = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON) == ON; - ((MainSwitchPreference) preference).updateStatus(smartBatteryOn); + ((SwitchPreference) preference).setChecked(smartBatteryOn); } @Override - public void displayPreference(PreferenceScreen screen) { - super.displayPreference(screen); - mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey()); - mPreference.addOnSwitchChangeListener(this); - } - - @Override - public void onSwitchChanged(Switch switchView, boolean isChecked) { + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean smartBatteryOn = (Boolean) newValue; Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, isChecked ? ON : OFF); + Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, smartBatteryOn ? ON : OFF); + return true; } } diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index 7b7ca1662be..b5105ed67ca 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -85,7 +85,6 @@ public class LocationSettings extends DashboardFragment { use(RecentLocationAccessPreferenceController.class).init(this); use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this); use(LocationForWorkPreferenceController.class).init(this); - use(LocationInjectedServicesForWorkPreferenceController.class).init(this); } @Override diff --git a/src/com/android/settings/network/EthernetTetherPreferenceController.java b/src/com/android/settings/network/EthernetTetherPreferenceController.java index 3559edb948f..06cd6a7feed 100644 --- a/src/com/android/settings/network/EthernetTetherPreferenceController.java +++ b/src/com/android/settings/network/EthernetTetherPreferenceController.java @@ -43,7 +43,7 @@ public final class EthernetTetherPreferenceController extends TetherBasePreferen super(context, preferenceKey); mEthernetRegex = context.getString( com.android.internal.R.string.config_ethernet_iface_regex); - mEthernetManager = context.getSystemService(EthernetManager.class); + mEthernetManager = (EthernetManager) context.getSystemService(Context.ETHERNET_SERVICE); } @OnLifecycleEvent(Lifecycle.Event.ON_START) diff --git a/src/com/android/settings/network/InternetUpdater.java b/src/com/android/settings/network/InternetUpdater.java index 39672765725..dd70cef62af 100644 --- a/src/com/android/settings/network/InternetUpdater.java +++ b/src/com/android/settings/network/InternetUpdater.java @@ -142,13 +142,13 @@ public class InternetUpdater implements AirplaneModeEnabler.OnAirplaneModeChange private NetworkCallback mNetworkCallback = new NetworkCallback() { public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) { - checkNetworkCapabilities(networkCapabilities); + updateInternetAvailable(networkCapabilities); } @Override public void onLost(@NonNull Network network) { mInternetAvailable = false; - update(); + updateInternetType(); } }; @@ -203,7 +203,7 @@ public class InternetUpdater implements AirplaneModeEnabler.OnAirplaneModeChange Network activeNetwork = mConnectivityManager.getActiveNetwork(); if (activeNetwork == null) { mInternetAvailable = false; - update(); + updateInternetType(); return; } @@ -211,36 +211,34 @@ public class InternetUpdater implements AirplaneModeEnabler.OnAirplaneModeChange mConnectivityManager.getNetworkCapabilities(activeNetwork); if (activeNetworkCapabilities == null) { mInternetAvailable = false; - update(); + updateInternetType(); return; } - checkNetworkCapabilities(activeNetworkCapabilities); - } - - private void checkNetworkCapabilities(@NonNull NetworkCapabilities networkCapabilities) { - if (!networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { - mInternetAvailable = false; - update(); - return; - } - - boolean internetAvailable = false; - for (int transport : networkCapabilities.getTransportTypes()) { - if (sTransportMap.containsKey(transport)) { - mTransport = transport; - internetAvailable = true; - Log.i(TAG, "Detect an internet capability network with transport type: " - + mTransport); - break; - } - } - mInternetAvailable = internetAvailable; - update(); + updateInternetAvailable(activeNetworkCapabilities); } @VisibleForTesting - void update() { + void updateInternetAvailable(@NonNull NetworkCapabilities capabilities) { + boolean internetAvailable = false; + if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) + && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) { + for (int transport : capabilities.getTransportTypes()) { + if (sTransportMap.containsKey(transport)) { + mTransport = transport; + internetAvailable = true; + Log.i(TAG, "Detect an internet available network with transport type: " + + mTransport); + break; + } + } + } + mInternetAvailable = internetAvailable; + updateInternetType(); + } + + @VisibleForTesting + void updateInternetType() { @InternetType int internetType = INTERNET_NETWORKS_AVAILABLE; if (mInternetAvailable) { internetType = sTransportMap.get(mTransport); diff --git a/src/com/android/settings/network/MobilePlanPreferenceController.java b/src/com/android/settings/network/MobilePlanPreferenceController.java index 65439bc2065..d8963ad9374 100644 --- a/src/com/android/settings/network/MobilePlanPreferenceController.java +++ b/src/com/android/settings/network/MobilePlanPreferenceController.java @@ -73,9 +73,9 @@ public class MobilePlanPreferenceController extends AbstractPreferenceController MobilePlanPreferenceHost host) { super(context); mHost = host; - mCm = context.getSystemService(ConnectivityManager.class); - mTm = context.getSystemService(TelephonyManager.class); - mUserManager = context.getSystemService(UserManager.class); + mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + mTm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mIsSecondaryUser = !mUserManager.isAdminUser(); } diff --git a/src/com/android/settings/network/NetworkResetRestrictionChecker.java b/src/com/android/settings/network/NetworkResetRestrictionChecker.java index c873f9dffae..46227f9f5a0 100644 --- a/src/com/android/settings/network/NetworkResetRestrictionChecker.java +++ b/src/com/android/settings/network/NetworkResetRestrictionChecker.java @@ -31,7 +31,7 @@ public class NetworkResetRestrictionChecker { public NetworkResetRestrictionChecker(Context context) { mContext = context; - mUserManager = context.getSystemService(UserManager.class); + mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); } @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) diff --git a/src/com/android/settings/network/NetworkScorerPicker.java b/src/com/android/settings/network/NetworkScorerPicker.java index 011cf054d0b..9ecab3bfb6f 100644 --- a/src/com/android/settings/network/NetworkScorerPicker.java +++ b/src/com/android/settings/network/NetworkScorerPicker.java @@ -140,6 +140,6 @@ public class NetworkScorerPicker extends InstrumentedPreferenceFragment implemen @VisibleForTesting NetworkScoreManager createNetworkScorerManager(Context context) { - return context.getSystemService(NetworkScoreManager.class); + return (NetworkScoreManager) context.getSystemService(Context.NETWORK_SCORE_SERVICE); } } diff --git a/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java b/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java index 2abe3901c40..4b452c01c15 100644 --- a/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java +++ b/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java @@ -37,7 +37,7 @@ public class NetworkScorerPickerPreferenceController extends BasePreferenceContr public NetworkScorerPickerPreferenceController(Context context, String key) { super(context, key); mNetworkScoreManager = - mContext.getSystemService(NetworkScoreManager.class); + (NetworkScoreManager) mContext.getSystemService(Context.NETWORK_SCORE_SERVICE); } @Override diff --git a/src/com/android/settings/network/ProviderModelSlice.java b/src/com/android/settings/network/ProviderModelSlice.java index 18765a8e2fe..beb74890d0b 100644 --- a/src/com/android/settings/network/ProviderModelSlice.java +++ b/src/com/android/settings/network/ProviderModelSlice.java @@ -21,6 +21,7 @@ import static android.app.slice.Slice.EXTRA_TOGGLE_STATE; import static com.android.settings.slices.CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI; +import android.annotation.ColorInt; import android.app.settings.SettingsEnums; import android.content.Context; import android.content.Intent; @@ -30,6 +31,7 @@ import android.telephony.SubscriptionManager; import android.util.Log; import androidx.annotation.VisibleForTesting; +import androidx.core.graphics.drawable.IconCompat; import androidx.slice.Slice; import androidx.slice.builders.ListBuilder; @@ -83,9 +85,10 @@ public class ProviderModelSlice extends WifiSlice { // Second section: Add a carrier item. // Third section: Add the Wi-Fi items which are not connected. // Fourth section: If device has connection problem, this row show the message for user. - boolean hasEthernet = isEthernetConnected(); + @InternetUpdater.InternetType int internetType = getInternetType(); final ListBuilder listBuilder = mHelper.createListBuilder(getUri()); - if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled() && !hasEthernet) { + if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled() + && internetType != InternetUpdater.INTERNET_ETHERNET) { log("Airplane mode is enabled."); return listBuilder.build(); } @@ -105,15 +108,17 @@ public class ProviderModelSlice extends WifiSlice { log("hasCarrier: " + hasCarrier); // First section: Add a Ethernet or Wi-Fi item which state is connected. + boolean isConnectedWifiAddedTop = false; final WifiSliceItem connectedWifiItem = mHelper.getConnectedWifiItem(wifiList); - if (hasEthernet) { + if (internetType == InternetUpdater.INTERNET_ETHERNET) { log("get Ethernet item which is connected"); listBuilder.addRow(createEthernetRow()); maxListSize--; } else { - if (connectedWifiItem != null) { - log("get Wi-Fi item which is connected"); + if (connectedWifiItem != null && internetType == InternetUpdater.INTERNET_WIFI) { + log("get Wi-Fi item which is connected to internet"); listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem)); + isConnectedWifiAddedTop = true; maxListSize--; } } @@ -128,7 +133,7 @@ public class ProviderModelSlice extends WifiSlice { } // Third section: Add the connected Wi-Fi item to Wi-Fi list if the Ethernet is connected. - if (connectedWifiItem != null && hasEthernet) { + if (connectedWifiItem != null && !isConnectedWifiAddedTop) { log("get Wi-Fi item which is connected"); listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem)); maxListSize--; @@ -222,12 +227,12 @@ public class ProviderModelSlice extends WifiSlice { return SliceBackgroundWorker.getInstance(getUri()); } - private boolean isEthernetConnected() { + private @InternetUpdater.InternetType int getInternetType() { final NetworkProviderWorker worker = getWorker(); if (worker == null) { - return false; + return InternetUpdater.INTERNET_NETWORKS_AVAILABLE; } - return worker.isEthernetConnected(); + return worker.getInternetType(); } @VisibleForTesting @@ -243,6 +248,20 @@ public class ProviderModelSlice extends WifiSlice { .setSubtitle(mContext.getText(R.string.to_switch_networks_disconnect_ethernet)); } + @Override + protected IconCompat getWifiSliceItemLevelIcon(WifiSliceItem wifiSliceItem) { + if (wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED + && getInternetType() != InternetUpdater.INTERNET_WIFI) { + final @ColorInt int tint = Utils.getColorAttrDefaultColor(mContext, + android.R.attr.colorControlNormal); + final Drawable drawable = mContext.getDrawable( + Utils.getWifiIconResource(wifiSliceItem.getLevel())); + drawable.setTint(tint); + return Utils.createIconWithDrawable(drawable); + } + return super.getWifiSliceItemLevelIcon(wifiSliceItem); + } + /** * Wrap the subscriptionManager call for test mocking. */ diff --git a/src/com/android/settings/network/TetherEnabler.java b/src/com/android/settings/network/TetherEnabler.java index 550d324d6e2..ef031f69639 100644 --- a/src/com/android/settings/network/TetherEnabler.java +++ b/src/com/android/settings/network/TetherEnabler.java @@ -128,10 +128,10 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe mSwitchWidgetController = switchWidgetController; mDataSaverBackend = new DataSaverBackend(context); mConnectivityManager = - context.getSystemService(ConnectivityManager.class); - mTetheringManager = context.getSystemService(TetheringManager.class); - mWifiManager = context.getSystemService(WifiManager.class); - mUserManager = context.getSystemService(UserManager.class); + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + mTetheringManager = (TetheringManager) context.getSystemService(Context.TETHERING_SERVICE); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothPan = bluetoothPan; mEthernetRegex = diff --git a/src/com/android/settings/network/apn/ApnEditor.java b/src/com/android/settings/network/apn/ApnEditor.java index 78b7ccc264a..afc68d5bb29 100644 --- a/src/com/android/settings/network/apn/ApnEditor.java +++ b/src/com/android/settings/network/apn/ApnEditor.java @@ -1291,8 +1291,8 @@ public class ApnEditor extends SettingsPreferenceFragment mReadOnlyApnTypes = null; mReadOnlyApnFields = null; - final CarrierConfigManager configManager = - getSystemService(CarrierConfigManager.class); + final CarrierConfigManager configManager = (CarrierConfigManager) + getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager != null) { final PersistableBundle b = configManager.getConfigForSubId(mSubId); if (b != null) { diff --git a/src/com/android/settings/network/apn/ApnSettings.java b/src/com/android/settings/network/apn/ApnSettings.java index 3ba667cc047..02d9b3d1f35 100755 --- a/src/com/android/settings/network/apn/ApnSettings.java +++ b/src/com/android/settings/network/apn/ApnSettings.java @@ -209,8 +209,8 @@ public class ApnSettings extends RestrictedSettingsFragment mSubscriptionInfo = getSubscriptionInfo(mSubId); mTelephonyManager = activity.getSystemService(TelephonyManager.class); - final CarrierConfigManager configManager = - getSystemService(CarrierConfigManager.class); + final CarrierConfigManager configManager = (CarrierConfigManager) + getSystemService(Context.CARRIER_CONFIG_SERVICE); final PersistableBundle b = configManager.getConfigForSubId(mSubId); mHideImsApn = b.getBoolean(CarrierConfigManager.KEY_HIDE_IMS_APN_BOOL); mAllowAddingApns = b.getBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL); diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java index 7eb53b9877c..9a4cb408f20 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java @@ -202,7 +202,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings { super.onCreate(icicle); final Context context = getContext(); - mUserManager = context.getSystemService(UserManager.class); + mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mTelephonyManager = context.getSystemService(TelephonyManager.class) .createForSubscriptionId(mSubId); diff --git a/src/com/android/settings/network/telephony/NetworkProviderWorker.java b/src/com/android/settings/network/telephony/NetworkProviderWorker.java index 57f17b59560..698e779d8e6 100644 --- a/src/com/android/settings/network/telephony/NetworkProviderWorker.java +++ b/src/com/android/settings/network/telephony/NetworkProviderWorker.java @@ -288,9 +288,9 @@ public class NetworkProviderWorker extends WifiScanWorker implements } /** - * Returns true, if the ethernet network is connected. + * Returns the internet type. */ - public boolean isEthernetConnected() { - return mInternetType == INTERNET_ETHERNET; + public @InternetUpdater.InternetType int getInternetType() { + return mInternetType; } } diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java index 588d828980a..c8121c491be 100644 --- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java +++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java @@ -106,8 +106,8 @@ public class NetworkSelectSettings extends DashboardFragment { .createForSubscriptionId(mSubId); mNetworkScanHelper = new NetworkScanHelper( mTelephonyManager, mCallback, mNetworkScanExecutor); - PersistableBundle bundle = (getContext().getSystemService( - CarrierConfigManager.class)).getConfigForSubId(mSubId); + PersistableBundle bundle = ((CarrierConfigManager) getContext().getSystemService( + Context.CARRIER_CONFIG_SERVICE)).getConfigForSubId(mSubId); if (bundle != null) { mShow4GForLTE = bundle.getBoolean( CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL); diff --git a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java index 6cb627b8197..c782b66c677 100644 --- a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java +++ b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java @@ -212,8 +212,8 @@ public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragmen @Override public View getView(int position, View convertView, ViewGroup parent) { - final LayoutInflater inflater = - mContext.getSystemService(LayoutInflater.class); + final LayoutInflater inflater = (LayoutInflater) + mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (convertView == null) { convertView = inflater.inflate(mItemResId, null); diff --git a/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java b/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java index 8be6016cc43..d4ad9944765 100644 --- a/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java +++ b/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java @@ -72,7 +72,7 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC return true; } - Preference getClearAll(PreferenceGroup parent) { + LayoutPreference getClearAll(PreferenceGroup parent) { LayoutPreference pref = new LayoutPreference( mContext, R.layout.conversations_clear_recents); pref.setOrder(1); @@ -80,10 +80,21 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC button.setOnClickListener(v -> { try { mPs.removeAllRecentConversations(); + // Removing recents is asynchronous, so we can't immediately reload the list from + // the backend. Instead, proactively remove all of items that were marked as + // clearable, so long as we didn't get an error + + for (int i = parent.getPreferenceCount() - 1; i >= 0; i--) { + Preference p = parent.getPreference(i); + if (p instanceof RecentConversationPreference) { + if (((RecentConversationPreference) p).hasClearListener()) { + parent.removePreference(p); + } + } + } } catch (RemoteException e) { Slog.w(TAG, "Could not clear recents", e); } - updateState(parent); }); return pref; } @@ -118,36 +129,45 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC protected void populateList(List conversations, PreferenceGroup containerGroup) { containerGroup.removeAll(); + boolean hasClearable = false; if (conversations != null) { - populateConversations(conversations, containerGroup); + hasClearable = populateConversations(conversations, containerGroup); } if (containerGroup.getPreferenceCount() == 0) { containerGroup.setVisible(false); } else { containerGroup.setVisible(true); - Preference clearAll = getClearAll(containerGroup); - if (clearAll != null) { - containerGroup.addPreference(clearAll); + if (hasClearable) { + Preference clearAll = getClearAll(containerGroup); + if (clearAll != null) { + containerGroup.addPreference(clearAll); + } } } } - protected void populateConversations(List conversations, + protected boolean populateConversations(List conversations, PreferenceGroup containerGroup) { int order = 100; + boolean hasClearable = false; for (ConversationChannel conversation : conversations) { if (conversation.getParentNotificationChannel().getImportance() == IMPORTANCE_NONE || (conversation.getParentNotificationChannelGroup() != null && conversation.getParentNotificationChannelGroup().isBlocked())) { continue; } - containerGroup.addPreference( - createConversationPref(containerGroup, conversation, order++)); + RecentConversationPreference pref = + createConversationPref(containerGroup, conversation, order++); + containerGroup.addPreference(pref); + if (pref.hasClearListener()) { + hasClearable = true; + } } + return hasClearable; } - protected Preference createConversationPref(PreferenceGroup parent, + protected RecentConversationPreference createConversationPref(PreferenceGroup parent, final ConversationChannel conversation, int order) { final String pkg = conversation.getShortcutInfo().getPackage(); final int uid = conversation.getUid(); diff --git a/src/com/android/settings/notification/history/NotificationSbnAdapter.java b/src/com/android/settings/notification/history/NotificationSbnAdapter.java index f836855c195..e0328542803 100644 --- a/src/com/android/settings/notification/history/NotificationSbnAdapter.java +++ b/src/com/android/settings/notification/history/NotificationSbnAdapter.java @@ -34,6 +34,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.os.UserHandle; import android.os.UserManager; @@ -110,6 +111,7 @@ public class NotificationSbnAdapter extends int position) { final StatusBarNotification sbn = mValues.get(position); if (sbn != null) { + holder.setIconBackground(loadBackground(sbn)); holder.setIcon(loadIcon(sbn)); holder.setPackageLabel(loadPackageLabel(sbn.getPackageName()).toString()); holder.setTitle(getTitleString(sbn.getNotification())); @@ -140,6 +142,19 @@ public class NotificationSbnAdapter extends } } + private Drawable loadBackground(StatusBarNotification sbn) { + Drawable bg = mContext.getDrawable(R.drawable.circle); + int color = sbn.getNotification().color; + if (color == COLOR_DEFAULT) { + color = Utils.getColorAttrDefaultColor( + mContext, com.android.internal.R.attr.colorAccent); + } + color = ContrastColorUtil.resolveContrastColor( + mContext, color, mBackgroundColor, mInNightMode); + bg.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)); + return bg; + } + @Override public int getItemCount() { return mValues.size(); @@ -229,7 +244,7 @@ public class NotificationSbnAdapter extends return null; } draw.mutate(); - draw.setColorFilter(getContrastedColor(sbn.getNotification()), PorterDuff.Mode.SRC_ATOP); + draw.setColorFilter(mBackgroundColor, PorterDuff.Mode.SRC_ATOP); return draw; } @@ -240,13 +255,4 @@ public class NotificationSbnAdapter extends } return userId; } - - private int getContrastedColor(Notification n) { - int rawColor = n.color; - if (rawColor != COLOR_DEFAULT) { - rawColor |= 0xFF000000; // no alpha for custom colors - } - return ContrastColorUtil.resolveContrastColor( - mContext, rawColor, mBackgroundColor, mInNightMode); - } } diff --git a/src/com/android/settings/notification/history/NotificationSbnViewHolder.java b/src/com/android/settings/notification/history/NotificationSbnViewHolder.java index 1219143b465..c98b036d7e2 100644 --- a/src/com/android/settings/notification/history/NotificationSbnViewHolder.java +++ b/src/com/android/settings/notification/history/NotificationSbnViewHolder.java @@ -75,6 +75,10 @@ public class NotificationSbnViewHolder extends RecyclerView.ViewHolder { mIcon.setImageDrawable(icon); } + void setIconBackground(Drawable background) { + mIcon.setBackground(background); + } + void setPackageLabel(String pkg) { mPkgName.setText(pkg); } diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java index c52b4104288..4b9883ada85 100644 --- a/src/com/android/settings/password/ChooseLockPattern.java +++ b/src/com/android/settings/password/ChooseLockPattern.java @@ -32,6 +32,7 @@ import android.util.Pair; import android.util.TypedValue; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.Surface; import android.view.View; import android.view.ViewGroup; import android.widget.ScrollView; @@ -508,6 +509,12 @@ public class ChooseLockPattern extends SettingsActivity { Bundle savedInstanceState) { final GlifLayout layout = (GlifLayout) inflater.inflate( R.layout.choose_lock_pattern, container, false); + switch(getContext().getDisplay().getRotation()) { + case Surface.ROTATION_90: + case Surface.ROTATION_270: + layout.setLandscapeHeaderAreaVisible(false /* visible */); + break; + } layout.setHeaderText(getActivity().getTitle()); if (getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)) { View iconView = layout.findViewById(R.id.sud_layout_icon); diff --git a/src/com/android/settings/password/ConfirmLockPattern.java b/src/com/android/settings/password/ConfirmLockPattern.java index 598e09a1bb3..0e18436b26a 100644 --- a/src/com/android/settings/password/ConfirmLockPattern.java +++ b/src/com/android/settings/password/ConfirmLockPattern.java @@ -28,6 +28,7 @@ import android.os.UserManager; import android.os.storage.StorageManager; import android.text.TextUtils; import android.view.LayoutInflater; +import android.view.Surface; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; @@ -45,6 +46,8 @@ import com.android.settingslib.animation.AppearAnimationCreator; import com.android.settingslib.animation.AppearAnimationUtils; import com.android.settingslib.animation.DisappearAnimationUtils; +import com.google.android.setupdesign.GlifLayout; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -90,8 +93,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { private boolean mDisappearing = false; private CountDownTimer mCountdownTimer; - private TextView mHeaderTextView; - private TextView mDetailsTextView; + private GlifLayout mGlifLayout; // caller-supplied text for various prompts private CharSequence mHeaderText; @@ -117,9 +119,14 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { : R.layout.confirm_lock_pattern, container, false); - mHeaderTextView = (TextView) view.findViewById(R.id.headerText); + mGlifLayout = view.findViewById(R.id.setup_wizard_layout); + switch(getContext().getDisplay().getRotation()) { + case Surface.ROTATION_90: + case Surface.ROTATION_270: + mGlifLayout.setLandscapeHeaderAreaVisible(false /* visible */); + break; + } mLockPatternView = (LockPatternView) view.findViewById(R.id.lockPattern); - mDetailsTextView = (TextView) view.findViewById(R.id.sud_layout_description); mErrorTextView = (TextView) view.findViewById(R.id.errorText); mIsManagedProfile = UserManager.get(getActivity()).isManagedProfile(mEffectiveUserId); @@ -177,7 +184,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { return (float)(numRows - row) / numRows; } }); - setAccessibilityTitle(mHeaderTextView.getText()); + setAccessibilityTitle(mGlifLayout.getHeaderText()); mCredentialCheckResultTracker = (CredentialCheckResultTracker) getFragmentManager() .findFragmentByTag(FRAGMENT_TAG_CHECK_LOCK_RESULT); @@ -242,13 +249,13 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { @Override public void prepareEnterAnimation() { super.prepareEnterAnimation(); - mHeaderTextView.setAlpha(0f); + mGlifLayout.getHeaderTextView().setAlpha(0f); mCancelButton.setAlpha(0f); if (mForgotButton != null) { mForgotButton.setAlpha(0f); } mLockPatternView.setAlpha(0f); - mDetailsTextView.setAlpha(0f); + mGlifLayout.getDescriptionTextView().setAlpha(0f); } private int getDefaultDetails() { @@ -269,8 +276,9 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { private Object[][] getActiveViews() { ArrayList> result = new ArrayList<>(); - result.add(new ArrayList<>(Collections.singletonList(mHeaderTextView))); - result.add(new ArrayList<>(Collections.singletonList(mDetailsTextView))); + result.add(new ArrayList<>(Collections.singletonList(mGlifLayout.getHeaderTextView()))); + result.add(new ArrayList<>( + Collections.singletonList(mGlifLayout.getDescriptionTextView()))); if (mCancelButton.getVisibility() == View.VISIBLE) { result.add(new ArrayList<>(Collections.singletonList(mCancelButton))); } @@ -306,14 +314,14 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { switch (stage) { case NeedToUnlock: if (mHeaderText != null) { - mHeaderTextView.setText(mHeaderText); + mGlifLayout.setHeaderText(mHeaderText); } else { - mHeaderTextView.setText(getDefaultHeader()); + mGlifLayout.setHeaderText(getDefaultHeader()); } if (mDetailsText != null) { - mDetailsTextView.setText(mDetailsText); + mGlifLayout.setDescriptionText(mDetailsText); } else { - mDetailsTextView.setText(getDefaultDetails()); + mGlifLayout.setDescriptionText(getDefaultDetails()); } mErrorTextView.setText(""); updateErrorMessage( @@ -341,7 +349,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { // Always announce the header for accessibility. This is a no-op // when accessibility is disabled. - mHeaderTextView.announceForAccessibility(mHeaderTextView.getText()); + mGlifLayout.getHeaderTextView().announceForAccessibility(mGlifLayout.getHeaderText()); } private int getDefaultHeader() { diff --git a/src/com/android/settings/security/CredentialManagementAppAdapter.java b/src/com/android/settings/security/CredentialManagementAppAdapter.java index e56fc63c443..6b37f7f73f8 100644 --- a/src/com/android/settings/security/CredentialManagementAppAdapter.java +++ b/src/com/android/settings/security/CredentialManagementAppAdapter.java @@ -25,6 +25,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -61,6 +62,7 @@ public class CredentialManagementAppAdapter extends RecyclerView.Adapter(); + if (mIsLayoutRtl) { + RelativeLayout appDetails = view.findViewById(R.id.app_details); + RelativeLayout.LayoutParams params = + (RelativeLayout.LayoutParams) appDetails.getLayoutParams(); + params.addRule(RelativeLayout.LEFT_OF, R.id.app_icon); + params.addRule(RelativeLayout.RIGHT_OF, R.id.expand); + view.setLayoutParams(params); + } + mExpanderIconView.setOnClickListener(view1 -> { final String appName = mSortedAppNames.get(getBindingAdapterPosition()); if (mExpandedApps.contains(appName)) { @@ -195,6 +206,8 @@ public class CredentialManagementAppAdapter extends RecyclerView.Adapter ops = service.getOpsForPackage(application.uid, application.packageName, new int[]{OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN}); return !ArrayUtils.isEmpty(ops); diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java index 2620426ad7f..cdc65372aed 100644 --- a/src/com/android/settings/vpn2/VpnSettings.java +++ b/src/com/android/settings/vpn2/VpnSettings.java @@ -116,9 +116,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - mUserManager = getSystemService(UserManager.class); - mConnectivityManager = getSystemService(ConnectivityManager.class); - mVpnManager = getSystemService(VpnManager.class); + mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); + mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + mVpnManager = (VpnManager) getSystemService(Context.VPN_MANAGEMENT_SERVICE); mUnavailable = isUiRestricted(); setHasOptionsMenu(!mUnavailable); @@ -511,7 +511,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements } // Fetch VPN-enabled apps from AppOps. - AppOpsManager aom = context.getSystemService(AppOpsManager.class); + AppOpsManager aom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); List apps = aom.getPackagesForOps(new int[] {OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN}); if (apps != null) { diff --git a/src/com/android/settings/wifi/ChangeWifiStateDetails.java b/src/com/android/settings/wifi/ChangeWifiStateDetails.java index 4e3e62eb11c..9841615a690 100644 --- a/src/com/android/settings/wifi/ChangeWifiStateDetails.java +++ b/src/com/android/settings/wifi/ChangeWifiStateDetails.java @@ -49,7 +49,7 @@ public class ChangeWifiStateDetails extends AppInfoWithHeader super.onCreate(savedInstanceState); final Context context = getActivity(); mAppBridge = new AppStateChangeWifiStateBridge(context, mState, null); - mAppOpsManager = context.getSystemService(AppOpsManager.class); + mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); // find preferences addPreferencesFromResource(R.xml.change_wifi_state_details); diff --git a/src/com/android/settings/wifi/ConfigureWifiSettings.java b/src/com/android/settings/wifi/ConfigureWifiSettings.java index 484d3ccd6bf..ff313c7ca4e 100644 --- a/src/com/android/settings/wifi/ConfigureWifiSettings.java +++ b/src/com/android/settings/wifi/ConfigureWifiSettings.java @@ -69,7 +69,7 @@ public class ConfigureWifiSettings extends DashboardFragment { @Override protected List createPreferenceControllers(Context context) { - final WifiManager wifiManager = getSystemService(WifiManager.class); + final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); final List controllers = new ArrayList<>(); controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(), wifiManager)); diff --git a/src/com/android/settings/wifi/UseOpenWifiPreferenceController.java b/src/com/android/settings/wifi/UseOpenWifiPreferenceController.java index 5fa4dfb4e66..44114e5aa75 100644 --- a/src/com/android/settings/wifi/UseOpenWifiPreferenceController.java +++ b/src/com/android/settings/wifi/UseOpenWifiPreferenceController.java @@ -51,7 +51,7 @@ public class UseOpenWifiPreferenceController extends TogglePreferenceController super(context, KEY_USE_OPEN_WIFI_AUTOMATICALLY); mContentResolver = context.getContentResolver(); mNetworkScoreManager = - context.getSystemService(NetworkScoreManager.class); + (NetworkScoreManager) context.getSystemService(Context.NETWORK_SCORE_SERVICE); mSettingObserver = new SettingObserver(); updateEnableUseWifiComponentName(); checkForFeatureSupportedScorers(); diff --git a/src/com/android/settings/wifi/WifiAPITest.java b/src/com/android/settings/wifi/WifiAPITest.java index 498539d9d6d..15465edb04b 100644 --- a/src/com/android/settings/wifi/WifiAPITest.java +++ b/src/com/android/settings/wifi/WifiAPITest.java @@ -64,7 +64,7 @@ public class WifiAPITest extends SettingsPreferenceFragment implements public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mWifiManager = getSystemService(WifiManager.class); + mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE); } @Override diff --git a/src/com/android/settings/wifi/WifiConfigInfo.java b/src/com/android/settings/wifi/WifiConfigInfo.java index 18ac2e57cd5..0de306396a2 100644 --- a/src/com/android/settings/wifi/WifiConfigInfo.java +++ b/src/com/android/settings/wifi/WifiConfigInfo.java @@ -38,7 +38,7 @@ public class WifiConfigInfo extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mWifiManager = getSystemService(WifiManager.class); + mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE); setContentView(R.layout.wifi_config_info); mConfigList = (TextView) findViewById(R.id.config_list); } diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java index ba1ee3c2347..dc5be4209a8 100644 --- a/src/com/android/settings/wifi/WifiEnabler.java +++ b/src/com/android/settings/wifi/WifiEnabler.java @@ -75,7 +75,7 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene public WifiEnabler(Context context, SwitchWidgetController switchWidget, MetricsFeatureProvider metricsFeatureProvider) { this(context, switchWidget, metricsFeatureProvider, - context.getSystemService(ConnectivityManager.class)); + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)); } @VisibleForTesting @@ -86,7 +86,7 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene mSwitchWidget = switchWidget; mSwitchWidget.setListener(this); mMetricsFeatureProvider = metricsFeatureProvider; - mWifiManager = context.getSystemService(WifiManager.class); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mConnectivityManager = connectivityManager; mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); diff --git a/src/com/android/settings/wifi/WifiNoInternetDialog.java b/src/com/android/settings/wifi/WifiNoInternetDialog.java index 3cd8a8a0adc..57e42f82ace 100644 --- a/src/com/android/settings/wifi/WifiNoInternetDialog.java +++ b/src/com/android/settings/wifi/WifiNoInternetDialog.java @@ -107,7 +107,7 @@ public class WifiNoInternetDialog extends AlertActivity implements } }; - mCM = getSystemService(ConnectivityManager.class); + mCM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mCM.registerNetworkCallback(request, mNetworkCallback); final NetworkInfo ni = mCM.getNetworkInfo(mNetwork); diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index 5545de6ced8..97a74d767a6 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -63,7 +63,7 @@ import com.android.settings.core.FeatureFlags; import com.android.settings.core.SubSettingLauncher; import com.android.settings.datausage.DataUsagePreference; import com.android.settings.datausage.DataUsageUtils; -import com.android.settings.location.LocationServices; +import com.android.settings.location.WifiScanningFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.MainSwitchBarController; @@ -921,8 +921,8 @@ public class WifiSettings extends RestrictedSettingsFragment : getText(R.string.wifi_scan_notify_text_scanning_off); final LinkifyUtils.OnClickListener clickListener = () -> new SubSettingLauncher(getContext()) - .setDestination(LocationServices.class.getName()) - .setTitleRes(R.string.location_services_screen_title) + .setDestination(WifiScanningFragment.class.getName()) + .setTitleRes(R.string.location_scanning_wifi_always_scanning_title) .setSourceMetricsCategory(getMetricsCategory()) .launch(); mStatusMessagePreference.setText(title, description, clickListener); diff --git a/src/com/android/settings/wifi/WifiStatusTest.java b/src/com/android/settings/wifi/WifiStatusTest.java index 06242e3575b..249cd710fd6 100644 --- a/src/com/android/settings/wifi/WifiStatusTest.java +++ b/src/com/android/settings/wifi/WifiStatusTest.java @@ -116,7 +116,7 @@ public class WifiStatusTest extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mWifiManager = getSystemService(WifiManager.class); + mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE); mWifiStateFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); mWifiStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java index e576851fa91..d05260afe1f 100644 --- a/src/com/android/settings/wifi/WifiUtils.java +++ b/src/com/android/settings/wifi/WifiUtils.java @@ -83,7 +83,7 @@ public class WifiUtils { final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); final PackageManager pm = context.getPackageManager(); - final UserManager um = context.getSystemService(UserManager.class); + final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); // Check if device has DPM capability. If it has and dpm is still null, then we // treat this case with suspicion and bail out. diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java index 3aa62b97a64..e9fd35004da 100644 --- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java +++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java @@ -73,7 +73,7 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i public WifiWakeupPreferenceController(Context context) { super(context, KEY_ENABLE_WIFI_WAKEUP); - mLocationManager = context.getSystemService(LocationManager.class); + mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE); mWifiManager = context.getSystemService(WifiManager.class); } diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java index 3cfe514ae2b..de64b911111 100644 --- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java +++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java @@ -128,8 +128,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment boolean isWfcModeEditable = true; boolean isWfcRoamingModeEditable = false; - final CarrierConfigManager configManager = - activity.getSystemService(CarrierConfigManager.class); + final CarrierConfigManager configManager = (CarrierConfigManager) + activity.getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager != null) { PersistableBundle b = configManager.getConfigForSubId(WifiCallingSettingsForSub.this.mSubId); @@ -343,8 +343,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment return; } - final CarrierConfigManager configManager = - getSystemService(CarrierConfigManager.class); + final CarrierConfigManager configManager = (CarrierConfigManager) + getSystemService(Context.CARRIER_CONFIG_SERVICE); boolean isWifiOnlySupported = true; if (configManager != null) { diff --git a/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java b/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java index 9ab64c7a661..8f9741a6b34 100644 --- a/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java +++ b/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java @@ -42,7 +42,7 @@ public class AddDevicePreferenceController2 extends BasePreferenceController { public AddDevicePreferenceController2(Context context) { super(context, KEY_ADD_DEVICE); - mWifiManager = context.getSystemService(WifiManager.class); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); } public void setWifiEntry(WifiEntry wifiEntry) { diff --git a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java index 488ffcb5a5b..104761f7c88 100644 --- a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java +++ b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java @@ -143,8 +143,8 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements if (admin == null) { final DevicePolicyManager dpm = (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE); - final UserManager um = - getContext().getSystemService(UserManager.class); + final UserManager um = (UserManager) + getContext().getSystemService(Context.USER_SERVICE); final int profileOwnerUserId = Utils.getManagedProfileId( um, UserHandle.myUserId()); if (profileOwnerUserId != UserHandle.USER_NULL) { diff --git a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java index 72a23615249..c4849225641 100644 --- a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java +++ b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java @@ -45,7 +45,7 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i public WifiPrivacyPreferenceController2(Context context) { super(context, KEY_WIFI_PRIVACY); - mWifiManager = context.getSystemService(WifiManager.class); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); } public void setWifiEntry(WifiEntry wifiEntry) { diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java index 081e160e44c..abf5becfbc3 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java +++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java @@ -373,8 +373,8 @@ public class WifiDppUtils { * device security or if lock screen is unlocked */ public static void showLockScreen(Context context, Runnable successRunnable) { - final KeyguardManager keyguardManager = context.getSystemService( - KeyguardManager.class); + final KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService( + Context.KEYGUARD_SERVICE); if (keyguardManager.isKeyguardSecure()) { final BiometricPrompt.AuthenticationCallback authenticationCallback = diff --git a/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java b/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java index 8696bef2a62..96044100647 100644 --- a/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java +++ b/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java @@ -71,7 +71,7 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController super(context); mWifiManager = wifiManager; lifecycle.addObserver(this); - mLocationManager = context.getSystemService(LocationManager.class); + mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE); } @Override diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java index 0aac0bb46dc..9578c802ab0 100644 --- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java +++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java @@ -200,7 +200,7 @@ public class WifiP2pSettings extends DashboardFragment public void onActivityCreated(Bundle savedInstanceState) { final Activity activity = getActivity(); if (mWifiP2pManager == null) { - mWifiP2pManager = getSystemService(WifiP2pManager.class); + mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); } if (mWifiP2pManager != null) { diff --git a/src/com/android/settings/wifi/qrcode/QrCamera.java b/src/com/android/settings/wifi/qrcode/QrCamera.java index 274655d45d4..3865eb1f116 100644 --- a/src/com/android/settings/wifi/qrcode/QrCamera.java +++ b/src/com/android/settings/wifi/qrcode/QrCamera.java @@ -202,7 +202,7 @@ public class QrCamera extends Handler { } final WindowManager winManager = - mContext.get().getSystemService(WindowManager.class); + (WindowManager) mContext.get().getSystemService(Context.WINDOW_SERVICE); final int rotation = winManager.getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { diff --git a/src/com/android/settings/wifi/slice/WifiSlice.java b/src/com/android/settings/wifi/slice/WifiSlice.java index 898de56c836..e4a571d13e2 100644 --- a/src/com/android/settings/wifi/slice/WifiSlice.java +++ b/src/com/android/settings/wifi/slice/WifiSlice.java @@ -164,7 +164,7 @@ public class WifiSlice implements CustomSliceable { return rowBuilder; } - private IconCompat getWifiSliceItemLevelIcon(WifiSliceItem wifiSliceItem) { + protected IconCompat getWifiSliceItemLevelIcon(WifiSliceItem wifiSliceItem) { final @ColorInt int tint; if (wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED) { tint = Utils.getColorAccentDefaultColor(mContext); diff --git a/src/com/android/settings/wifi/tether/TetherService.java b/src/com/android/settings/wifi/tether/TetherService.java index a3321bb27c7..59027193ed5 100644 --- a/src/com/android/settings/wifi/tether/TetherService.java +++ b/src/com/android/settings/wifi/tether/TetherService.java @@ -255,7 +255,7 @@ public class TetherService extends Service { } private void disableTethering(final int tetheringType) { - final TetheringManager tm = getSystemService(TetheringManager.class); + final TetheringManager tm = (TetheringManager) getSystemService(Context.TETHERING_SERVICE); tm.stopTethering(tetheringType); } diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java index 1fa41b2f359..70b6a45eb52 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java @@ -63,7 +63,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController boolean initSoftApManager) { super(context); mTetheringManager = context.getSystemService(TetheringManager.class); - mWifiManager = context.getSystemService(WifiManager.class); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiRegexs = mTetheringManager.getTetherableWifiRegexs(); mLifecycle = lifecycle; if (lifecycle != null) { diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java index 41b439bab55..e34255035e5 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java +++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java @@ -110,7 +110,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment @Override public void onAttach(Context context) { super.onAttach(context); - mWifiManager = context.getSystemService(WifiManager.class); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mTetherChangeReceiver = new TetherChangeReceiver(); mSSIDPreferenceController = use(WifiTetherSSIDPreferenceController.class); diff --git a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java index 379bf6d944f..3d8cd3e76c1 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java @@ -73,8 +73,8 @@ public class WifiTetherSwitchBarController implements mSwitch = mSwitchBar.getSwitch(); mDataSaverBackend = new DataSaverBackend(context); mConnectivityManager = - context.getSystemService(ConnectivityManager.class); - mWifiManager = context.getSystemService(WifiManager.class); + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mSwitchBar.setChecked(mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED); updateWifiSwitch(); } diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java index d21aa04f3dc..784b3bb06c8 100644 --- a/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java +++ b/tests/robotests/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java @@ -92,4 +92,23 @@ public class TimeZoneDataTest { .containsExactly("US", "GB"); assertThat(timeZoneData.lookupCountryCodesForZoneId("Unknown/Secret_City2")).isEmpty(); } + + @Test + public void lookupCountryCodesForNonCanonicalZoneId_returnsCurrentZone() { + TimeZoneData timeZoneData = new TimeZoneData(mCountryZonesFinder); + + CountryTimeZones greenland = mock(CountryTimeZones.class); + when(greenland.getCountryIso()).thenReturn("gl"); + when(greenland.getTimeZoneMappings()).thenReturn(Arrays.asList( + TimeZoneMapping.createForTests( + "America/Nuuk", + true /* showInPicker */, + null /* notUsedAfter */, + Arrays.asList("America/Godthab")))); + when(mCountryZonesFinder.lookupCountryTimeZonesForZoneId("America/Godthab")) + .thenReturn(Arrays.asList(greenland)); + + assertThat(timeZoneData.lookupCountryCodesForZoneId("America/Godthab")) + .containsExactly("GL"); + } } diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java index 60eab127d3f..997c35e19e5 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java @@ -181,8 +181,8 @@ public class ImeiInfoPreferenceControllerTest { mController.copy(); - final ClipboardManager clipboard = mContext.getSystemService( - ClipboardManager.class); + final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService( + CLIPBOARD_SERVICE); final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText(); assertThat(data.toString()).isEqualTo(meid); } diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java index d1371a21320..384ddc3e6ac 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java @@ -22,12 +22,14 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; 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.ContentResolver; import android.content.Context; +import android.content.res.Resources; import android.os.SystemProperties; import android.provider.Settings; @@ -38,6 +40,7 @@ import androidx.preference.PreferenceScreen; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.os.RoSystemProperties; +import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.deletionhelper.ActivationWarningFragment; import com.android.settings.overlay.FeatureFactory; @@ -67,13 +70,16 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest { private FragmentManager mFragmentManager; private Context mContext; + private Resources mResources; private AutomaticStorageManagementSwitchPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application.getApplicationContext(); + mContext = spy(RuntimeEnvironment.application.getApplicationContext()); FeatureFactory.getFactory(mContext); + mResources = spy(mContext.getResources()); + when(mContext.getResources()).thenReturn(mResources); mController = new AutomaticStorageManagementSwitchPreferenceController(mContext, "testkey"); mController.setFragmentManager(mFragmentManager); @@ -81,14 +87,27 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest { } @Test - public void isAvailable_shouldReturnTrue_forHighRamDevice() { + public void getAvailabilityStatus_configFalse_shouldUnsupportedOnDevice() { + when(mResources.getBoolean(R.bool.config_show_smart_storage_toggle)).thenReturn(false); + + assertThat(mController.isAvailable()).isFalse(); + assertThat(mController.getAvailabilityStatus()).isEqualTo( + BasePreferenceController.UNSUPPORTED_ON_DEVICE); + } + + @Test + public void getAvailabilityStatus_forHighRamDevice_shouldAvailable() { + when(mResources.getBoolean(R.bool.config_show_smart_storage_toggle)).thenReturn(true); + assertThat(mController.isAvailable()).isTrue(); assertThat(mController.getAvailabilityStatus()).isEqualTo( BasePreferenceController.AVAILABLE); } @Test - public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() { + public void getAvailabilityStatus_forLowRamDevice_shouldUnsupportedOnDevice() { + when(mResources.getBoolean(R.bool.config_show_smart_storage_toggle)).thenReturn(true); + ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", true); assertThat(mController.isAvailable()).isFalse(); assertThat(mController.getAvailabilityStatus()).isEqualTo( diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java index 6f9c4514c69..b7bf7f56606 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java @@ -104,6 +104,8 @@ public class StorageItemPreferenceControllerTest { } private PreferenceScreen getPreferenceScreen() { + final StorageItemPreference publicStorage = spy(new StorageItemPreference(mContext)); + publicStorage.setIcon(R.drawable.ic_folder_vd_theme_24); final StorageItemPreference images = spy(new StorageItemPreference(mContext)); images.setIcon(R.drawable.ic_photo_library); final StorageItemPreference videos = spy(new StorageItemPreference(mContext)); @@ -122,6 +124,8 @@ public class StorageItemPreferenceControllerTest { trash.setIcon(R.drawable.ic_trash_can); final PreferenceScreen screen = mock(PreferenceScreen.class); + when(screen.findPreference(eq(StorageItemPreferenceController.PUBLIC_STORAGE_KEY))) + .thenReturn(publicStorage); when(screen.findPreference(eq(StorageItemPreferenceController.IMAGES_KEY))) .thenReturn(images); when(screen.findPreference(eq(StorageItemPreferenceController.VIDEOS_KEY))) @@ -148,6 +152,24 @@ public class StorageItemPreferenceControllerTest { .isEqualTo(mContext.getString(R.string.memory_calculating_size)); } + @Test + public void launchPublicStorageIntent_nonNullBrowseIntent_settingsIntent() { + final String fakeBrowseAction = "FAKE_BROWSE_ACTION"; + final Intent fakeBrowseIntent = new Intent(fakeBrowseAction); + // mContext is not the activity, add FLAG_ACTIVITY_NEW_TASK to avoid AndroidRuntimeException + // during this test. + fakeBrowseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + when(mVolume.buildBrowseIntent()).thenReturn(fakeBrowseIntent); + mPreference.setKey(StorageItemPreferenceController.PUBLIC_STORAGE_KEY); + mController.handlePreferenceTreeClick(mPreference); + + final ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(mContext).startActivity(argumentCaptor.capture()); + + final Intent intent = argumentCaptor.getValue(); + assertThat(intent.getAction()).isEqualTo(fakeBrowseAction); + } + @Test public void launchImagesIntent_resolveActionViewNull_settingsIntent() { mPreference.setKey(StorageItemPreferenceController.IMAGES_KEY); @@ -191,6 +213,7 @@ public class StorageItemPreferenceControllerTest { mController.setVolume(null); + assertThat(mController.mPublicStoragePreference.isVisible()).isFalse(); assertThat(mController.mImagesPreference.isVisible()).isFalse(); assertThat(mController.mVideosPreference.isVisible()).isFalse(); assertThat(mController.mAudiosPreference.isVisible()).isFalse(); @@ -347,6 +370,7 @@ public class StorageItemPreferenceControllerTest { mController.setUserId(new UserHandle(10)); + verify(mController.mPublicStoragePreference, times(2)).setIcon(nullable(Drawable.class)); verify(mController.mImagesPreference, times(2)).setIcon(nullable(Drawable.class)); verify(mController.mVideosPreference, times(2)).setIcon(nullable(Drawable.class)); verify(mController.mAudiosPreference, times(2)).setIcon(nullable(Drawable.class)); @@ -418,4 +442,26 @@ public class StorageItemPreferenceControllerTest { assertThat(mController.mDocumentsAndOtherPreference.isVisible()).isTrue(); } + + @Test + public void setVolume_publicStorage_showFilePreference() { + // This will hide it initially. + mController.displayPreference(mPreferenceScreen); + when(mVolume.getType()).thenReturn(VolumeInfo.TYPE_PUBLIC); + when(mVolume.getState()).thenReturn(VolumeInfo.STATE_MOUNTED); + when(mVolume.isMountedReadable()).thenReturn(true); + + // And we bring it back. + mController.setVolume(mVolume); + + assertThat(mController.mPublicStoragePreference.isVisible()).isTrue(); + assertThat(mController.mImagesPreference.isVisible()).isFalse(); + assertThat(mController.mVideosPreference.isVisible()).isFalse(); + assertThat(mController.mAudiosPreference.isVisible()).isFalse(); + assertThat(mController.mAppsPreference.isVisible()).isFalse(); + assertThat(mController.mGamesPreference.isVisible()).isFalse(); + assertThat(mController.mDocumentsAndOtherPreference.isVisible()).isFalse(); + assertThat(mController.mSystemPreference.isVisible()).isFalse(); + assertThat(mController.mTrashPreference.isVisible()).isFalse(); + } } diff --git a/tests/robotests/src/com/android/settings/emergency/MoreSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/emergency/MoreSettingsPreferenceControllerTest.java new file mode 100644 index 00000000000..844d0ac3264 --- /dev/null +++ b/tests/robotests/src/com/android/settings/emergency/MoreSettingsPreferenceControllerTest.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2021 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.emergency; + +import static com.android.settings.core.BasePreferenceController.AVAILABLE; +import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.ResolveInfo; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settings.testutils.shadow.SettingsShadowResources; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.Shadows; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowPackageManager; + +@RunWith(RobolectricTestRunner.class) +@Config(shadows = SettingsShadowResources.class) +public class MoreSettingsPreferenceControllerTest { + + private static final String TEST_PKG_NAME = "test_pkg"; + private static final String TEST_CLASS_NAME = "name"; + + private static final Intent SETTING_INTENT = new Intent(Intent.ACTION_MAIN) + .setPackage(TEST_PKG_NAME); + + private Context mContext; + private ShadowPackageManager mPackageManager; + private static final String PREF_KEY = "more_settings_button"; + + @Before + public void setUp() { + mContext = ApplicationProvider.getApplicationContext(); + mPackageManager = Shadows.shadowOf(mContext.getPackageManager()); + } + + @After + public void tearDown() { + SettingsShadowResources.reset(); + } + + @Test + public void constructor_hasPackageConfig_shouldSetIntent() { + // Provide override package name and provide resolvable intent + SettingsShadowResources.overrideResource( + R.string.config_emergency_package_name, + TEST_PKG_NAME); + prepareCustomIntent(); + + MoreSettingsPreferenceController controller = new MoreSettingsPreferenceController( + mContext, PREF_KEY); + + assertThat(controller.mIntent).isNotNull(); + } + + @Test + public void getAvailabilityStatus_whenIntentSet_shouldReturnAvailable() { + // Provide override package name and provide resolvable intent + SettingsShadowResources.overrideResource( + R.string.config_emergency_package_name, + TEST_PKG_NAME); + prepareCustomIntent(); + + MoreSettingsPreferenceController controller = new MoreSettingsPreferenceController( + mContext, PREF_KEY); + + assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE); + } + + @Test + public void getAvailabilityStatus_whenPackageConfigIsUnavailable_shouldReturnUnsupported() { + // No package name is configured + MoreSettingsPreferenceController controller = new MoreSettingsPreferenceController( + mContext, PREF_KEY); + + assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); + } + + @Test + public void getAvailabilityStatus_noSuitableIntent_shouldReturnUnsupportedDevice() { + // Provide override package name but don't provide resolvable intent + SettingsShadowResources.overrideResource( + R.string.config_emergency_package_name, + TEST_PKG_NAME); + + MoreSettingsPreferenceController controller = new MoreSettingsPreferenceController( + mContext, PREF_KEY); + + assertThat(controller.mIntent).isNull(); + assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); + } + + @Test + public void getAvailabilityStatus_intentForANonSystemApp_shouldReturnUnsupportedDevice() { + // Provide override package name and provide resolvable intent for a non system app. + SettingsShadowResources.overrideResource( + R.string.config_emergency_package_name, + TEST_PKG_NAME); + prepareCustomIntentForANonSystemApp(); + + MoreSettingsPreferenceController controller = new MoreSettingsPreferenceController( + mContext, PREF_KEY); + + assertThat(controller.mIntent).isNull(); + assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); + } + + private void prepareCustomIntent() { + final ResolveInfo info = new ResolveInfo(); + info.activityInfo = new ActivityInfo(); + info.activityInfo.packageName = TEST_PKG_NAME; + info.activityInfo.name = TEST_CLASS_NAME; + + // Resolve to a system app. + info.activityInfo.applicationInfo = new ApplicationInfo(); + info.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; + mPackageManager.addResolveInfoForIntent(SETTING_INTENT, info); + } + + + private void prepareCustomIntentForANonSystemApp() { + final ResolveInfo info = new ResolveInfo(); + info.activityInfo = new ActivityInfo(); + info.activityInfo.packageName = TEST_PKG_NAME; + info.activityInfo.name = TEST_CLASS_NAME; + + mPackageManager.addResolveInfoForIntent(SETTING_INTENT, info); + } +} diff --git a/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java index a1f3bda371c..b132a9708ab 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java @@ -21,9 +21,10 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doReturn; import android.content.ContentResolver; -import android.content.Context; import android.provider.Settings; +import androidx.preference.SwitchPreference; + import com.android.settings.core.BasePreferenceController; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settingslib.widget.MainSwitchPreference; @@ -42,50 +43,48 @@ public class SmartBatteryPreferenceControllerTest { private static final int OFF = 0; private SmartBatteryPreferenceController mController; + private SwitchPreference mPreference; private ContentResolver mContentResolver; private FakeFeatureFactory mFeatureFactory; - private Context mContext; @Before public void setUp() { MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; mFeatureFactory = FakeFeatureFactory.setupForTest(); mContentResolver = RuntimeEnvironment.application.getContentResolver(); mController = new SmartBatteryPreferenceController(RuntimeEnvironment.application); + mPreference = new SwitchPreference(RuntimeEnvironment.application); } @Test public void testUpdateState_smartBatteryOn_preferenceChecked() { putSmartBatteryValue(ON); - final MainSwitchPreference preference = new MainSwitchPreference(mContext); - mController.updateState(preference); + mController.updateState(mPreference); - assertThat(preference.isChecked()).isTrue(); + assertThat(mPreference.isChecked()).isTrue(); } @Test public void testUpdateState_smartBatteryOff_preferenceUnchecked() { putSmartBatteryValue(OFF); - final MainSwitchPreference preference = new MainSwitchPreference(mContext); - mController.updateState(preference); + mController.updateState(mPreference); - assertThat(preference.isChecked()).isFalse(); + assertThat(mPreference.isChecked()).isFalse(); } @Test public void testUpdateState_checkPreference_smartBatteryOn() { - mController.onSwitchChanged(null, true); + mController.onPreferenceChange(mPreference, true); assertThat(getSmartBatteryValue()).isEqualTo(ON); } @Test public void testUpdateState_unCheckPreference_smartBatteryOff() { - mController.onSwitchChanged(null, false); + mController.onPreferenceChange(mPreference, false); assertThat(getSmartBatteryValue()).isEqualTo(OFF); } diff --git a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java index 53dd95917ff..d3a3129f4a2 100644 --- a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java @@ -57,7 +57,7 @@ public class BluetoothTetherPreferenceControllerTest { mContext = spy(ApplicationProvider.getApplicationContext()); mSwitchPreference = spy(SwitchPreference.class); - when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager); + when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""}); mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH"); mController.setTetherEnabler(mTetherEnabler); diff --git a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java index de642f65ab1..8a819087296 100644 --- a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java @@ -62,9 +62,9 @@ public class EthernetTetherPreferenceControllerTest { public void setUp() { mContext = spy(ApplicationProvider.getApplicationContext()); mPreference = spy(SwitchPreference.class); - when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager); + when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX}); - when(mContext.getSystemService(EthernetManager.class)).thenReturn(mEthernetManager); + when(mContext.getSystemService(Context.ETHERNET_SERVICE)).thenReturn(mEthernetManager); mController = new EthernetTetherPreferenceController(mContext, "ethernet"); mController.setTetherEnabler(mTetherEnabler); ReflectionHelpers.setField(mController, "mEthernetRegex", ETHERNET_REGEX); diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java index d7c0ffe5f03..c1377ff2aa9 100644 --- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java +++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java @@ -44,6 +44,7 @@ import android.os.Bundle; import android.os.PowerManager; import android.os.UserManager; import android.provider.Settings; +import android.util.FeatureFlagUtils; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; @@ -131,6 +132,7 @@ public class NetworkProviderSettingsTest { mNetworkProviderSettings.mResetInternetPreference = mResetInternetPreference; mNetworkProviderSettings.mAirplaneModeMsgPreference = mAirplaneModeMsgPreference; mNetworkProviderSettings.mAirplaneModeEnabler = mAirplaneModeEnabler; + FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false); } @Test diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java index 293b6493a5a..8996c1d24a2 100644 --- a/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java +++ b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java @@ -45,14 +45,14 @@ public class NetworkResetRestrictionCheckerTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); + when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); mRestrictionChecker = spy(new NetworkResetRestrictionChecker(mContext)); } @Test public void testHasRestriction_notAdmin_shouldReturnTrue() { final Context context = mock(Context.class); - when(context.getSystemService(UserManager.class)).thenReturn(mUserManager); + when(context.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); when(mUserManager.isAdminUser()).thenReturn(false); assertThat(mRestrictionChecker.hasRestriction()).isTrue(); diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java index fce95178567..390a6744d1d 100644 --- a/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java @@ -125,7 +125,7 @@ public class PrivateDnsPreferenceControllerTest { mContext = spy(RuntimeEnvironment.application); mContentResolver = mContext.getContentResolver(); mShadowContentResolver = Shadow.extract(mContentResolver); - when(mContext.getSystemService(ConnectivityManager.class)) + when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)) .thenReturn(mConnectivityManager); doNothing().when(mConnectivityManager).registerDefaultNetworkCallback( mCallbackCaptor.capture(), nullable(Handler.class)); diff --git a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java index cd93865be78..bb4b0c41492 100644 --- a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java +++ b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java @@ -95,10 +95,10 @@ public class TetherEnablerTest { AtomicReference panReference = spy(AtomicReference.class); mSwitchBar = spy(new SwitchBar(context)); mSwitchWidgetController = spy(new SwitchBarController(mSwitchBar)); - when(context.getSystemService(WifiManager.class)).thenReturn(mWifiManager); - when(context.getSystemService(ConnectivityManager.class)).thenReturn( + when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); + when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn( mConnectivityManager); - when(context.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager); + when(context.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); when(context.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn( mNetworkPolicyManager); when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]); @@ -311,4 +311,4 @@ public class TetherEnablerTest { assertThat(TetherEnabler.isTethering(TETHERING_ETHERNET_ON, TETHERING_ETHERNET)).isTrue(); assertThat(TetherEnabler.isTethering(~TETHERING_ETHERNET_ON, TETHERING_ETHERNET)).isFalse(); } -} +} \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java index 0639ef320c0..e02da9002a9 100644 --- a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java @@ -55,7 +55,7 @@ public class UsbTetherPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = spy(ApplicationProvider.getApplicationContext()); - when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager); + when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{""}); mController = new UsbTetherPreferenceController(mContext, "USB"); mController.setTetherEnabler(mTetherEnabler); diff --git a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java index 22ed55cbd90..a82a71f18f5 100644 --- a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java @@ -100,7 +100,7 @@ public class WifiTetherDisablePreferenceControllerTest { mContext = spy(ApplicationProvider.getApplicationContext()); mPreference = spy(SwitchPreference.class); - when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager); + when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{""}); mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY); mController.setTetherEnabler(mTetherEnabler); diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java index acc6b1a2967..ba37c30389a 100644 --- a/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java +++ b/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java @@ -74,7 +74,7 @@ public class MobileDataSliceTest { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); - doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class); + doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE); doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class); doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID); doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); diff --git a/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java b/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java index 0d864080eb7..6bee38fba9e 100644 --- a/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java +++ b/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java @@ -77,7 +77,7 @@ public class NetworkSelectSettingsTest { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); - when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); + when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager); diff --git a/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java index 660b4e1ed57..15bc5989e60 100644 --- a/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java @@ -47,8 +47,10 @@ import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceViewHolder; +import com.android.settings.R; import com.android.settings.applications.AppInfoBase; import com.android.settings.notification.NotificationBackend; +import com.android.settingslib.widget.LayoutPreference; import org.junit.Before; import org.junit.Test; @@ -105,9 +107,9 @@ public class RecentConversationsPreferenceControllerTest { ps.addPreference(outerContainer); ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6, - new NotificationChannel("hi", "hi", 4), - new NotificationChannelGroup("hi", "hi"), 7, - true); + new NotificationChannel("hi", "hi", 4), + new NotificationChannelGroup("hi", "hi"), 7, + false); ArrayList list = new ArrayList<>(); list.add(ccw); @@ -124,19 +126,19 @@ public class RecentConversationsPreferenceControllerTest { ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6, new NotificationChannel("hi", "hi", 4), new NotificationChannelGroup("hi", "hi"), 7, - true); + false); ConversationChannel ccw2 = new ConversationChannel(mock(ShortcutInfo.class), 6, new NotificationChannel("hi", "hi", 0), new NotificationChannelGroup("hi", "hi"), 7, - true); + false); NotificationChannelGroup blockedGroup = new NotificationChannelGroup("hi", "hi"); blockedGroup.setBlocked(true); ConversationChannel ccw3 = new ConversationChannel(mock(ShortcutInfo.class), 6, new NotificationChannel("hi", "hi", 4), blockedGroup, 7, - true); + false); ArrayList list = new ArrayList<>(); list.add(ccw); @@ -198,7 +200,6 @@ public class RecentConversationsPreferenceControllerTest { new NotificationChannelGroup("hi", "group"), 7, true); - Intent intent = mController.getSubSettingLauncher(ccw, "title").toIntent(); Bundle extras = intent.getExtras(); @@ -257,6 +258,51 @@ public class RecentConversationsPreferenceControllerTest { si.getPackage(), UserHandle.getUserId(ccw.getUid()), si.getId()); } + @Test + public void testRemoveConversations() throws Exception { + ShortcutInfo si = mock(ShortcutInfo.class); + when(si.getId()).thenReturn("person"); + when(si.getPackage()).thenReturn("pkg"); + ConversationChannel ccw = new ConversationChannel(si, 6, + new NotificationChannel("hi", "hi", 4), + new NotificationChannelGroup("hi", "group"), 7, + false); + + ConversationChannel ccw2 = new ConversationChannel(si, 6, + new NotificationChannel("bye", "bye", 4), + new NotificationChannelGroup("hi", "group"), 7, + true); + + PreferenceCategory group = new PreferenceCategory(mContext); + PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext); + screen.addPreference(group); + + RecentConversationPreference pref = mController.createConversationPref( + new PreferenceCategory(mContext), ccw, 100); + final View view = View.inflate(mContext, pref.getLayoutResource(), null); + PreferenceViewHolder holder = spy(PreferenceViewHolder.createInstanceForTests(view)); + View delete = View.inflate(mContext, pref.getSecondTargetResId(), null); + when(holder.findViewById(pref.getClearId())).thenReturn(delete); + group.addPreference(pref); + + RecentConversationPreference pref2 = mController.createConversationPref( + new PreferenceCategory(mContext), ccw2, 100); + final View view2 = View.inflate(mContext, pref2.getLayoutResource(), null); + PreferenceViewHolder holder2 = spy(PreferenceViewHolder.createInstanceForTests(view2)); + View delete2 = View.inflate(mContext, pref2.getSecondTargetResId(), null); + when(holder2.findViewById(pref.getClearId())).thenReturn(delete2); + group.addPreference(pref2); + + LayoutPreference clearAll = mController.getClearAll(group); + group.addPreference(clearAll); + + clearAll.findViewById(R.id.conversation_settings_clear_recents).performClick(); + + verify(mPs).removeAllRecentConversations(); + assertThat((Preference) group.findPreference("hi:person")).isNull(); + assertThat((Preference) group.findPreference("bye:person")).isNotNull(); + } + @Test public void testNonremoveableConversation() throws Exception { ShortcutInfo si = mock(ShortcutInfo.class); @@ -272,4 +318,24 @@ public class RecentConversationsPreferenceControllerTest { new PreferenceCategory(mContext), ccw, 100); assertThat(pref.hasClearListener()).isFalse(); } + + @Test + public void testPopulateList_onlyNonremoveableConversations() { + final PreferenceManager preferenceManager = new PreferenceManager(mContext); + PreferenceScreen ps = preferenceManager.createPreferenceScreen(mContext); + PreferenceCategory outerContainer = spy(new PreferenceCategory(mContext)); + ps.addPreference(outerContainer); + + ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6, + new NotificationChannel("hi", "hi", 4), + new NotificationChannelGroup("hi", "hi"), 7, + true /* hasactivenotifs */); + + ArrayList list = new ArrayList<>(); + list.add(ccw); + + mController.populateList(list, outerContainer); + // one for the preference, none for 'clear all' + verify(outerContainer, times(1)).addPreference(any()); + } } diff --git a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java index 3494c6305ad..c542c55bd21 100644 --- a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java +++ b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java @@ -34,6 +34,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.robolectric.Shadows.shadowOf; +import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -61,6 +62,7 @@ import com.android.settings.testutils.shadow.ShadowDevicePolicyManager; import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedPreference; +import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import org.junit.After; import org.junit.Before; @@ -111,6 +113,8 @@ public class UserSettingsTest { private RestrictedPreference mAddGuestPreference; @Mock private UserManager mUserManager; + @Mock + private MetricsFeatureProvider mMetricsFeatureProvider; private FragmentActivity mActivity; private Context mContext; @@ -134,6 +138,7 @@ public class UserSettingsTest { ReflectionHelpers.setField(mFragment, "mUserCaps", mUserCapabilities); ReflectionHelpers.setField(mFragment, "mDefaultIconDrawable", mDefaultIconDrawable); ReflectionHelpers.setField(mFragment, "mAddingUser", false); + ReflectionHelpers.setField(mFragment, "mMetricsFeatureProvider", mMetricsFeatureProvider); doReturn(mUserManager).when(mActivity).getSystemService(UserManager.class); @@ -616,6 +621,7 @@ public class UserSettingsTest { .isEqualTo(createdGuest.id); assertThat(arguments.getBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, false)) .isEqualTo(true); + verify(mMetricsFeatureProvider).action(any(), eq(SettingsEnums.ACTION_USER_GUEST_ADD)); } @Test diff --git a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java index be3267e5628..094e2826459 100644 --- a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java +++ b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java @@ -78,7 +78,7 @@ public class NetworkRequestDialogActivityTest { mActivity = spy(activity); mWifiManager = mock(WifiManager.class); - when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager); + when(mActivity.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); } @Test diff --git a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java index 2475d807f94..65cc8111e36 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java @@ -53,7 +53,7 @@ public class WifiEnablerTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager); + when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); mEnabler = new WifiEnabler(mContext, mock(SwitchWidgetController.class), mock(MetricsFeatureProvider.class), mConnectivityManager); } diff --git a/tests/robotests/src/com/android/settings/wifi/WifiNoInternetDialogTest.java b/tests/robotests/src/com/android/settings/wifi/WifiNoInternetDialogTest.java index dc5ccb41122..6cbb19da6f8 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiNoInternetDialogTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiNoInternetDialogTest.java @@ -44,6 +44,7 @@ import android.os.Bundle; import com.android.settings.R; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -87,6 +88,7 @@ public class WifiNoInternetDialogTest { Robolectric.setupActivity(WifiNoInternetDialog.class); } + @Ignore @Test public void setupPromptUnvalidated_shouldShowNoInternetAccessRemember() { setupActivityWithAction(ACTION_PROMPT_UNVALIDATED, FAKE_URL); @@ -98,6 +100,7 @@ public class WifiNoInternetDialogTest { mActivity.getString(R.string.no_internet_access_remember)); } + @Ignore @Test public void setupPromptPartialConnectivity_shouldShowNoInternetAccessRemember() { setupActivityWithAction(ACTION_PROMPT_PARTIAL_CONNECTIVITY, FAKE_URL); @@ -109,6 +112,7 @@ public class WifiNoInternetDialogTest { mActivity.getString(R.string.no_internet_access_remember)); } + @Ignore @Test public void setupPromptLostValidationAction_shouldShowLostInternetAccessPersist() { setupActivityWithAction(ACTION_PROMPT_LOST_VALIDATION, FAKE_URL); @@ -120,6 +124,7 @@ public class WifiNoInternetDialogTest { mActivity.getString(R.string.lost_internet_access_persist)); } + @Ignore @Test public void clickPositiveButton_whenPromptUnvalidated_shouldCallSetAcceptUnvalidated() { setupActivityWithAction(ACTION_PROMPT_UNVALIDATED, FAKE_URL); @@ -131,6 +136,7 @@ public class WifiNoInternetDialogTest { verify(mConnectivityManager).setAcceptUnvalidated(any(Network.class), eq(true), eq(false)); } + @Ignore @Test public void positiveButton_withPartialConnectivity_shouldCallSetAcceptPartialConnectivity() { setupActivityWithAction(ACTION_PROMPT_PARTIAL_CONNECTIVITY, FAKE_URL); @@ -143,6 +149,7 @@ public class WifiNoInternetDialogTest { eq(false)); } + @Ignore @Test public void positiveButton_withLostValidation_shouldCallSetAvoidUnvalidated() { setupActivityWithAction(ACTION_PROMPT_LOST_VALIDATION, FAKE_URL); @@ -154,6 +161,7 @@ public class WifiNoInternetDialogTest { verify(mConnectivityManager).setAvoidUnvalidated(any(Network.class)); } + @Ignore @Test public void destroyWithNoClick_inPartialConnectivity_shouldCallSetAcceptPartialConnectivity() { setupActivityWithAction(ACTION_PROMPT_PARTIAL_CONNECTIVITY, FAKE_URL); @@ -167,6 +175,7 @@ public class WifiNoInternetDialogTest { eq(false)); } + @Ignore @Test public void destroyWithNoClick_whenUnvalidated_shouldCallSetAcceptUnvalidated() { setupActivityWithAction(ACTION_PROMPT_UNVALIDATED, FAKE_URL); @@ -179,6 +188,7 @@ public class WifiNoInternetDialogTest { verify(mConnectivityManager).setAcceptUnvalidated(any(Network.class), eq(false), eq(false)); } + @Ignore @Test public void networkCallbackOnLost_shouldFinish() { setupActivityWithAction(ACTION_PROMPT_UNVALIDATED, FAKE_URL); @@ -192,6 +202,7 @@ public class WifiNoInternetDialogTest { verify(mActivity).finish(); } + @Ignore @Test public void networkCallbackOnCapabilitiesChanged_shouldFinish() { setupActivityWithAction(ACTION_PROMPT_UNVALIDATED, FAKE_URL); diff --git a/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java index 4100d058050..b94df29401e 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java @@ -78,7 +78,7 @@ public class WifiPrimarySwitchPreferenceControllerTest { when(mContext.getSystemService(NetworkScoreManager.class)).thenReturn(mNetworkScoreManager); mController = new WifiPrimarySwitchPreferenceController(mContext, mMetricsFeatureProvider); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); - when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager); + when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); when(mWifiManager.getWifiState()).thenReturn(WifiManager.WIFI_STATE_DISABLED); } diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java index 428a3600a13..1f5abd3d72e 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java @@ -43,6 +43,7 @@ import android.os.Bundle; import android.os.PowerManager; import android.os.UserManager; import android.provider.Settings; +import android.util.FeatureFlagUtils; import android.view.ContextMenu; import android.view.View; @@ -105,6 +106,7 @@ public class WifiSettingsTest { mWifiSettings.mConfigureWifiSettingsPreference = new Preference(mContext); mWifiSettings.mWifiPickerTracker = mMockWifiPickerTracker; mWifiSettings.mWifiManager = mWifiManager; + FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false); } @Test @@ -209,7 +211,7 @@ public class WifiSettingsTest { final Resources.Theme theme = mContext.getTheme(); when(activity.getTheme()).thenReturn(theme); UserManager userManager = mock(UserManager.class); - when(activity.getSystemService(UserManager.class)) + when(activity.getSystemService(Context.USER_SERVICE)) .thenReturn(userManager); when(mWifiSettings.findPreference(WifiSettings.PREF_KEY_DATA_USAGE)) diff --git a/tests/robotests/src/com/android/settings/wifi/calling/DisclaimerItemListAdapterTest.java b/tests/robotests/src/com/android/settings/wifi/calling/DisclaimerItemListAdapterTest.java index 3e15348c9f3..8478a5471ac 100644 --- a/tests/robotests/src/com/android/settings/wifi/calling/DisclaimerItemListAdapterTest.java +++ b/tests/robotests/src/com/android/settings/wifi/calling/DisclaimerItemListAdapterTest.java @@ -77,7 +77,7 @@ public class DisclaimerItemListAdapterTest { when(mLayoutInflater.inflate(anyInt(), anyObject(), anyBoolean())).thenReturn(mView); when(mViewGroup.getContext()).thenReturn(mContext); - when(mViewGroup.getContext().getSystemService(LayoutInflater.class)).thenReturn( + when(mViewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).thenReturn( mLayoutInflater); when(mView.findViewById(ID_DISCLAIMER_ITEM_TITLE)).thenReturn(mTestView); when(mView.findViewById(ID_DISCLAIMER_ITEM_DESCRIPTION)).thenReturn(mDescView); diff --git a/tests/robotests/src/com/android/settings/wifi/calling/EmergencyCallLimitationDisclaimerTest.java b/tests/robotests/src/com/android/settings/wifi/calling/EmergencyCallLimitationDisclaimerTest.java index c15e8507397..985edda69b5 100644 --- a/tests/robotests/src/com/android/settings/wifi/calling/EmergencyCallLimitationDisclaimerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/calling/EmergencyCallLimitationDisclaimerTest.java @@ -54,7 +54,7 @@ public class EmergencyCallLimitationDisclaimerTest { mContext = spy(RuntimeEnvironment.application); doReturn(mCarrierConfigManager).when(mContext).getSystemService( - CarrierConfigManager.class); + Context.CARRIER_CONFIG_SERVICE); when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle); doReturn(getSharedPreferences()).when(mContext).getSharedPreferences(anyString(), anyInt()); diff --git a/tests/robotests/src/com/android/settings/wifi/calling/LocationPolicyDisclaimerTest.java b/tests/robotests/src/com/android/settings/wifi/calling/LocationPolicyDisclaimerTest.java index 108acf8195e..3fe9678c26e 100644 --- a/tests/robotests/src/com/android/settings/wifi/calling/LocationPolicyDisclaimerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/calling/LocationPolicyDisclaimerTest.java @@ -54,7 +54,7 @@ public class LocationPolicyDisclaimerTest { mContext = spy(RuntimeEnvironment.application); doReturn(mCarrierConfigManager).when(mContext).getSystemService( - CarrierConfigManager.class); + Context.CARRIER_CONFIG_SERVICE); when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle); doReturn(getSharedPreferences()).when(mContext).getSharedPreferences(anyString(), anyInt()); } diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java index 252d876c1b0..d777a597936 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java @@ -73,8 +73,8 @@ public class WifiTetherApBandPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); mPreference = new ListPreference(RuntimeEnvironment.application); - when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager); - when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager); + when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); + when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"}); when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources()); when(mScreen.findPreference(anyString())).thenReturn(mPreference); diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java index a42307193ec..c1d6c16a687 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java @@ -17,6 +17,7 @@ package com.android.settings.wifi.tether; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -57,7 +58,8 @@ public class WifiTetherFooterPreferenceControllerTest { public void setUp() { MockitoAnnotations.initMocks(this); - when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); + doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class); + doReturn(mTetheringManager).when(mContext).getSystemService(TetheringManager.class); when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"}); mController = new WifiTetherFooterPreferenceController(mContext); diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java index 8f8477fcff7..bb61eb9dc2c 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java @@ -19,6 +19,7 @@ package com.android.settings.wifi.tether; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -75,9 +76,9 @@ public class WifiTetherPasswordPreferenceControllerTest { .setPassphrase(INITIAL_PASSWORD, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) .build(); - when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); + doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class); when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig); - when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); + doReturn(mTetheringManager).when(mContext).getSystemService(TetheringManager.class); when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"}); when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources()); when(mScreen.findPreference(anyString())).thenReturn(mPreference); diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java index 147cd64b437..2d887227ace 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java @@ -19,6 +19,7 @@ package com.android.settings.wifi.tether; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -67,8 +68,8 @@ public class WifiTetherSSIDPreferenceControllerTest { MockitoAnnotations.initMocks(this); mPreference = new WifiTetherSsidPreference(RuntimeEnvironment.application); - when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); - when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager); + doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class); + doReturn(mTetheringManager).when(mContext).getSystemService(TetheringManager.class); when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"}); when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources()); when(mScreen.findPreference(anyString())).thenReturn(mPreference); diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java index 9a3432392f0..2ecc7d26d54 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java @@ -80,10 +80,10 @@ public class WifiTetherSettingsTest { MockitoAnnotations.initMocks(this); doReturn(mConnectivityManager) - .when(mContext).getSystemService(ConnectivityManager.class); - doReturn(mTetheringManager).when(mContext).getSystemService(TetheringManager.class); + .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE); + doReturn(mTetheringManager).when(mContext).getSystemService(Context.TETHERING_SERVICE); doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs(); - doReturn(mUserManager).when(mContext).getSystemService(UserManager.class); + doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE); mWifiTetherSettings = new WifiTetherSettings(); } @@ -133,7 +133,7 @@ public class WifiTetherSettingsTest { when(settings.getContext()).thenReturn(mContext); final Resources.Theme theme = mContext.getTheme(); when(activity.getTheme()).thenReturn(theme); - when(activity.getSystemService(UserManager.class)).thenReturn(mUserManager); + when(activity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); doNothing().when(settings) .onCreatePreferences(any(Bundle.class), nullable(String.class)); final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest(); diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageEntryTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageEntryTest.java index cf1b6b2c8ec..3cd35395e01 100644 --- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageEntryTest.java +++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageEntryTest.java @@ -208,6 +208,24 @@ public class StorageEntryTest { assertThat(privateStorage.isPrivate()).isTrue(); } + @Test + public void isPublic_prublicVolume_shouldReturnTrue() { + final VolumeInfo publicVolumeInfo = mock(VolumeInfo.class); + final StorageEntry publicStorage = new StorageEntry(mContext, publicVolumeInfo); + when(publicVolumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PUBLIC); + + assertThat(publicStorage.isPublic()).isTrue(); + } + + @Test + public void isStub_stubVolume_shouldReturnTrue() { + final VolumeInfo stubVolumeInfo = mock(VolumeInfo.class); + final StorageEntry stubStorage = new StorageEntry(mContext, stubVolumeInfo); + when(stubVolumeInfo.getType()).thenReturn(VolumeInfo.TYPE_STUB); + + assertThat(stubStorage.isStub()).isTrue(); + } + @Test public void isPrivate_nonVolumeInfo_shouldReturnFalse() { final DiskInfo diskInfo = mock(DiskInfo.class); diff --git a/tests/unit/src/com/android/settings/network/InternetUpdaterTest.java b/tests/unit/src/com/android/settings/network/InternetUpdaterTest.java index 94456fe3f1d..3e9cdc7a763 100644 --- a/tests/unit/src/com/android/settings/network/InternetUpdaterTest.java +++ b/tests/unit/src/com/android/settings/network/InternetUpdaterTest.java @@ -38,6 +38,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.IntentFilter; import android.net.ConnectivityManager; +import android.net.NetworkCapabilities; import android.net.wifi.WifiManager; import androidx.lifecycle.Lifecycle; @@ -107,57 +108,80 @@ public class InternetUpdaterTest { } @Test - public void update_apmOnWifiOff_getInternetApm() { + public void updateInternetAvailable_wifiConnectedAndNoValidated_internetUnavailable() { + final NetworkCapabilities networkCapabilities = new NetworkCapabilities(); + networkCapabilities.addTransportType(TRANSPORT_WIFI); + networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); + + mInternetUpdater.updateInternetAvailable(networkCapabilities); + + assertThat(mInternetUpdater.mInternetAvailable).isEqualTo(false); + } + + @Test + public void updateInternetAvailable_wifiConnectedAndValidated_internetAvailable() { + final NetworkCapabilities networkCapabilities = new NetworkCapabilities(); + networkCapabilities.addTransportType(TRANSPORT_WIFI); + networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); + networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); + + mInternetUpdater.updateInternetAvailable(networkCapabilities); + + assertThat(mInternetUpdater.mInternetAvailable).isEqualTo(true); + } + + @Test + public void updateInternetType_apmOnWifiOff_getInternetApm() { doReturn(true).when(mAirplaneModeEnabler).isAirplaneModeOn(); doReturn(WifiManager.WIFI_STATE_DISABLED).when(mWifiManager).getWifiState(); mInternetUpdater.mInternetAvailable = false; - mInternetUpdater.update(); + mInternetUpdater.updateInternetType(); assertThat(mInternetUpdater.getInternetType()).isEqualTo(INTERNET_OFF); } @Test - public void update_apmOnWifiOnNotConnected_getInternetNetworksAvailable() { + public void updateInternetType_apmOnWifiOnNotConnected_getInternetNetworksAvailable() { doReturn(true).when(mAirplaneModeEnabler).isAirplaneModeOn(); doReturn(WifiManager.WIFI_STATE_ENABLED).when(mWifiManager).getWifiState(); mInternetUpdater.mInternetAvailable = false; - mInternetUpdater.update(); + mInternetUpdater.updateInternetType(); assertThat(mInternetUpdater.getInternetType()).isEqualTo(INTERNET_NETWORKS_AVAILABLE); } @Test - public void update_apmOnWifiConnected_getInternetWifi() { + public void updateInternetType_apmOnWifiConnected_getInternetWifi() { doReturn(true).when(mAirplaneModeEnabler).isAirplaneModeOn(); doReturn(true).when(mWifiManager).isWifiEnabled(); mInternetUpdater.mInternetAvailable = true; mInternetUpdater.mTransport = TRANSPORT_WIFI; - mInternetUpdater.update(); + mInternetUpdater.updateInternetType(); assertThat(mInternetUpdater.getInternetType()).isEqualTo(INTERNET_WIFI); } @Test - public void update_apmOnCellularConnected_getInternetCellular() { + public void updateInternetType_apmOnCellularConnected_getInternetCellular() { doReturn(true).when(mAirplaneModeEnabler).isAirplaneModeOn(); mInternetUpdater.mInternetAvailable = true; mInternetUpdater.mTransport = TRANSPORT_CELLULAR; - mInternetUpdater.update(); + mInternetUpdater.updateInternetType(); assertThat(mInternetUpdater.getInternetType()).isEqualTo(INTERNET_CELLULAR); } @Test - public void update_apmOnEthernetConnected_getInternetEthernet() { + public void updateInternetType_apmOnEthernetConnected_getInternetEthernet() { doReturn(true).when(mAirplaneModeEnabler).isAirplaneModeOn(); mInternetUpdater.mInternetAvailable = true; mInternetUpdater.mTransport = TRANSPORT_ETHERNET; - mInternetUpdater.update(); + mInternetUpdater.updateInternetType(); assertThat(mInternetUpdater.getInternetType()).isEqualTo(INTERNET_ETHERNET); } diff --git a/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java b/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java index 4760daacef8..a323ed6ebef 100644 --- a/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java +++ b/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java @@ -236,7 +236,8 @@ public class ProviderModelSliceTest { mWifiList.add(mMockWifiSliceItem2); mMockNetworkProviderWorker.updateSelfResults(mWifiList); mockHelperCondition(false, true, true, null); - when(mMockNetworkProviderWorker.isEthernetConnected()).thenReturn(true); + when(mMockNetworkProviderWorker.getInternetType()) + .thenReturn(InternetUpdater.INTERNET_ETHERNET); final Slice slice = mMockProviderModelSlice.getSlice(); @@ -258,7 +259,8 @@ public class ProviderModelSliceTest { mWifiList.add(mMockWifiSliceItem2); mMockNetworkProviderWorker.updateSelfResults(mWifiList); mockHelperCondition(false, true, true, mWifiList.get(0)); - when(mMockNetworkProviderWorker.isEthernetConnected()).thenReturn(true); + when(mMockNetworkProviderWorker.getInternetType()) + .thenReturn(InternetUpdater.INTERNET_ETHERNET); final Slice slice = mMockProviderModelSlice.getSlice(); diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java index 0c8ffb9c9b0..45f3693a298 100644 --- a/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java @@ -74,7 +74,7 @@ public class MobileDataPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = spy(ApplicationProvider.getApplicationContext()); - doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class); + doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID); diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java index 97f8e11f796..d052f31c854 100644 --- a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java @@ -261,24 +261,24 @@ public class NetworkProviderWorkerTest { } @Test - public void isEthernetConnected_connectedEthernet_shouldBeTrue() { + public void getInternetType_connectedEthernet_returnInternetEthernet() { mMockNetworkProviderWorker.onInternetTypeChanged(INTERNET_ETHERNET); - assertThat(mMockNetworkProviderWorker.isEthernetConnected()).isTrue(); + assertThat(mMockNetworkProviderWorker.getInternetType()).isEqualTo(INTERNET_ETHERNET); } @Test - public void isEthernetConnected_connectedWifi_shouldBeFalse() { + public void getInternetType_connectedWifi_returnInternetWifi() { mMockNetworkProviderWorker.onInternetTypeChanged(INTERNET_WIFI); - assertThat(mMockNetworkProviderWorker.isEthernetConnected()).isFalse(); + assertThat(mMockNetworkProviderWorker.getInternetType()).isEqualTo(INTERNET_WIFI); } @Test - public void isEthernetConnected_connectedCarrier_shouldBeFalse() { + public void getInternetType__connectedCarrier_returnInternetCellular() { mMockNetworkProviderWorker.onInternetTypeChanged(INTERNET_CELLULAR); - assertThat(mMockNetworkProviderWorker.isEthernetConnected()).isFalse(); + assertThat(mMockNetworkProviderWorker.getInternetType()).isEqualTo(INTERNET_CELLULAR); } public class MockNetworkProviderWorker extends NetworkProviderWorker {