diff --git a/color-check-baseline.xml b/color-check-baseline.xml index 02b00e24b33..e0a02067223 100644 --- a/color-check-baseline.xml +++ b/color-check-baseline.xml @@ -3357,4 +3357,20 @@ column="5"/> + + + + diff --git a/res/values/config.xml b/res/values/config.xml index 496b5d2145e..1dbe079c57b 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -363,4 +363,7 @@ + + + diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml index 323a3b45e69..eccb0d13f42 100644 --- a/res/xml/app_and_notification.xml +++ b/res/xml/app_and_notification.xml @@ -43,6 +43,7 @@ diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index 2f43ce8cd88..9ab80a741cd 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -28,6 +28,7 @@ @@ -54,7 +55,8 @@ android:selectable="true" /> + android:key="location_services" + android:layout="@layout/preference_category_no_label"/> diff --git a/res/xml/managed_profile_settings.xml b/res/xml/managed_profile_settings.xml index bd44cc1a307..7b65a3d30b0 100644 --- a/res/xml/managed_profile_settings.xml +++ b/res/xml/managed_profile_settings.xml @@ -32,11 +32,18 @@ settings:useAdditionalSummary="true" settings:controller="com.android.settings.accounts.ContactSearchPreferenceController"/> - + + \ No newline at end of file diff --git a/res/xml/privacy_dashboard_settings.xml b/res/xml/privacy_dashboard_settings.xml index 45b9d1955e3..aa789b90424 100644 --- a/res/xml/privacy_dashboard_settings.xml +++ b/res/xml/privacy_dashboard_settings.xml @@ -64,7 +64,8 @@ + android:key="privacy_services" + android:layout="@layout/preference_category_no_label"/> diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml index 9fe3d5b2d22..6a896ced42c 100644 --- a/res/xml/security_dashboard_settings.xml +++ b/res/xml/security_dashboard_settings.xml @@ -96,7 +96,8 @@ + android:key="security_settings_device_admin_category" + android:layout="@layout/preference_category_no_label"> packages = dpm.getCrossProfileCalendarPackages(); + return packages != null && packages.isEmpty(); + } + + private static Context createPackageContextAsUser(Context context, int userId) { + try { + return context.createPackageContextAsUser( + context.getPackageName(), 0 /* flags */, UserHandle.of(userId)); + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Failed to create user context", e); + } + return null; + } } \ No newline at end of file diff --git a/src/com/android/settings/accounts/ManagedProfileSettings.java b/src/com/android/settings/accounts/ManagedProfileSettings.java index a4105efa779..1f18d07ec7e 100644 --- a/src/com/android/settings/accounts/ManagedProfileSettings.java +++ b/src/com/android/settings/accounts/ManagedProfileSettings.java @@ -16,17 +16,23 @@ package com.android.settings.accounts; +import android.app.admin.DevicePolicyManager; import android.app.settings.SettingsEnums; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; import android.provider.SearchIndexableResource; import android.util.Log; +import androidx.preference.Preference; +import androidx.preference.PreferenceGroup; +import androidx.preference.PreferenceManager; + import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.dashboard.DashboardFragment; @@ -36,6 +42,7 @@ import com.android.settingslib.search.SearchIndexable; import java.util.ArrayList; import java.util.List; +import java.util.Set; /** * Setting page for managed profile. @@ -72,6 +79,7 @@ public class ManagedProfileSettings extends DashboardFragment { use(WorkModePreferenceController.class).setManagedUser(mManagedUser); use(ContactSearchPreferenceController.class).setManagedUser(mManagedUser); use(CrossProfileCalendarPreferenceController.class).setManagedUser(mManagedUser); + use(CrossProfileCalendarDisabledPreferenceController.class).setManagedUser(mManagedUser); } @Override diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java index d6a668e61fe..112d7b81ee0 100644 --- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java +++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java @@ -26,6 +26,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Handler; import android.os.Looper; +import android.provider.DeviceConfig; import android.provider.MediaStore; import android.util.Log; import android.view.View; @@ -38,6 +39,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; +import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.fuelgauge.BatteryMeterView; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; @@ -64,7 +66,6 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont @VisibleForTesting final Map mIconCache; private CachedBluetoothDevice mCachedDevice; - private BluetoothDevice mBluetoothDevice; @VisibleForTesting BluetoothAdapter mBluetoothAdapter; @VisibleForTesting @@ -88,9 +89,11 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont @Override public int getAvailabilityStatus() { + final boolean advancedEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, true); final boolean untetheredHeadset = BluetoothUtils.getBooleanMetaData( mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET); - return untetheredHeadset ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; + return advancedEnabled && untetheredHeadset ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; } @Override @@ -138,7 +141,6 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont public void init(CachedBluetoothDevice cachedBluetoothDevice) { mCachedDevice = cachedBluetoothDevice; - mBluetoothDevice = mCachedDevice.getDevice(); } @VisibleForTesting diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java index ee630454dd9..f5096054c78 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java @@ -19,12 +19,14 @@ package com.android.settings.bluetooth; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.graphics.drawable.Drawable; +import android.provider.DeviceConfig; import android.util.Pair; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceScreen; import com.android.settings.R; +import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.widget.EntityHeaderController; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; @@ -53,8 +55,11 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController @Override public boolean isAvailable() { - return !BluetoothUtils.getBooleanMetaData(mCachedDevice.getDevice(), - BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET); + final boolean advancedEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, true); + return !advancedEnabled + || !BluetoothUtils.getBooleanMetaData(mCachedDevice.getDevice(), + BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET); } @Override diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java index 36cbd5d3fd8..c31b13ecb0f 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java @@ -22,7 +22,7 @@ import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.os.Bundle; -import android.util.FeatureFlagUtils; +import android.provider.DeviceConfig; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -30,7 +30,7 @@ import android.view.MenuItem; import androidx.annotation.VisibleForTesting; import com.android.settings.R; -import com.android.settings.core.FeatureFlags; +import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.dashboard.RestrictedDashboardFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.slices.BlockingSlicePrefController; @@ -117,10 +117,10 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment final BluetoothFeatureProvider featureProvider = FeatureFactory.getFactory( context).getBluetoothFeatureProvider(context); - final boolean injectionEnabled = FeatureFlagUtils.isEnabled(context, - FeatureFlags.SLICE_INJECTION); + final boolean sliceEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_SLICE_SETTINGS_ENABLED, true); - use(BlockingSlicePrefController.class).setSliceUri(injectionEnabled + use(BlockingSlicePrefController.class).setSliceUri(sliceEnabled ? featureProvider.getBluetoothDeviceSettingsUri(mCachedDevice.getDevice()) : null); } diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java index 260297aca86..0e935c0a5e0 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java @@ -115,6 +115,8 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, for (CachedBluetoothDevice cachedBluetoothDevice : cachedDevices) { update(cachedBluetoothDevice); } + } else { + removeAllDevicesFromPreference(); } } diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java index d5cfdcc1fa7..cbabb06eb61 100644 --- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java +++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java @@ -18,11 +18,13 @@ package com.android.settings.connecteddevice; import android.app.settings.SettingsEnums; import android.content.Context; import android.net.Uri; +import android.provider.DeviceConfig; import android.provider.SearchIndexableResource; import androidx.annotation.VisibleForTesting; import com.android.settings.R; +import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.slices.SlicePreferenceController; @@ -86,12 +88,15 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment { @Override public void onAttach(Context context) { super.onAttach(context); + final boolean nearbyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true); use(AvailableMediaDeviceGroupController.class).init(this); use(ConnectedDeviceGroupController.class).init(this); use(PreviouslyConnectedDevicePreferenceController.class).init(this); use(DiscoverableFooterPreferenceController.class).init(this); - use(SlicePreferenceController.class).setSliceUri( - Uri.parse(getString(R.string.config_nearby_devices_slice_uri))); + use(SlicePreferenceController.class).setSliceUri(nearbyEnabled + ? Uri.parse(getString(R.string.config_nearby_devices_slice_uri)) + : null); } /** diff --git a/src/com/android/settings/core/SettingsUIDeviceConfig.java b/src/com/android/settings/core/SettingsUIDeviceConfig.java new file mode 100644 index 00000000000..b7aa281408d --- /dev/null +++ b/src/com/android/settings/core/SettingsUIDeviceConfig.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 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.core; + +/** + * Class to store keys for settings related features, which comes from + * {@link android.provider.DeviceConfig} + */ +public class SettingsUIDeviceConfig { + /** + * {@code true} if slice settings is enabled in BT device detail page + */ + public static final String BT_SLICE_SETTINGS_ENABLED = "bt_slice_settings_enabled"; + /** + * {@code true} if advanced header is enabled in BT device detail page + */ + public static final String BT_ADVANCED_HEADER_ENABLED = "bt_advanced_header_enabled"; + /** + * {@code true} if near by device suggestion is enabled in connected device page + */ + public static final String BT_NEAR_BY_SUGGESTION_ENABLED = "bt_near_by_suggestion_enabled"; +} diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java index 16303116432..f2e3d73c8fe 100644 --- a/src/com/android/settings/dashboard/DashboardFragment.java +++ b/src/com/android/settings/dashboard/DashboardFragment.java @@ -24,12 +24,14 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.Log; +import androidx.annotation.CallSuper; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; +import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.core.BasePreferenceController; import com.android.settings.core.PreferenceControllerListHelper; @@ -43,6 +45,7 @@ import com.android.settingslib.drawer.DashboardCategory; import com.android.settingslib.drawer.Tile; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -65,12 +68,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment private DashboardTilePlaceholderPreferenceController mPlaceholderPreferenceController; private boolean mListeningToCategoryChange; private SummaryLoader mSummaryLoader; + private List mSuppressInjectedTileKeys; @VisibleForTesting UiBlockerController mBlockerController; @Override public void onAttach(Context context) { super.onAttach(context); + mSuppressInjectedTileKeys = Arrays.asList(context.getResources().getStringArray( + R.array.config_suppress_injected_tile_keys)); mDashboardFeatureProvider = FeatureFactory.getFactory(context). getDashboardFeatureProvider(context); final List controllers = new ArrayList<>(); @@ -283,7 +289,12 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment /** * Returns true if this tile should be displayed */ + @CallSuper protected boolean displayTile(Tile tile) { + if (mSuppressInjectedTileKeys != null && tile.hasKey()) { + // For suppressing injected tiles for OEMs. + return !mSuppressInjectedTileKeys.contains(tile.getKey(getContext())); + } return true; } diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java index f88239061bf..e7f642316bc 100644 --- a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java +++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java @@ -21,6 +21,7 @@ import android.os.SystemProperties; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; +import com.android.settings.slices.Sliceable; public class HardwareRevisionPreferenceController extends BasePreferenceController { @@ -44,6 +45,17 @@ public class HardwareRevisionPreferenceController extends BasePreferenceControll return true; } + @Override + public boolean isCopyableSlice() { + return true; + } + + @Override + public void copy() { + Sliceable.setCopyContent(mContext, getSummary(), + mContext.getText(R.string.hardware_revision)); + } + @Override public CharSequence getSummary() { return SystemProperties.get("ro.boot.hardware.revision"); diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java index c851a7178f7..33f25537327 100644 --- a/src/com/android/settings/fuelgauge/BatteryInfo.java +++ b/src/com/android/settings/fuelgauge/BatteryInfo.java @@ -34,6 +34,8 @@ import com.android.settings.Utils; import com.android.settings.overlay.FeatureFactory; import com.android.settings.widget.UsageView; import com.android.settingslib.R; +import com.android.settingslib.fuelgauge.Estimate; +import com.android.settingslib.fuelgauge.EstimateKt; import com.android.settingslib.utils.PowerUtil; import com.android.settingslib.utils.StringUtil; @@ -44,7 +46,7 @@ public class BatteryInfo { public int batteryLevel; public boolean discharging = true; public long remainingTimeUs = 0; - public long averageTimeToDischarge = Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN; + public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN; public String batteryPercentString; public String statusLabel; public String suggestionLabel; @@ -202,7 +204,7 @@ public class BatteryInfo { final Estimate estimate = new Estimate( PowerUtil.convertUsToMs(prediction), false, /* isBasedOnUsage */ - Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); + EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime); return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString); @@ -214,7 +216,7 @@ public class BatteryInfo { Estimate estimate = new Estimate( PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)), false, - Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); + EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); return getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString); } @@ -228,7 +230,7 @@ public class BatteryInfo { info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast); info.batteryPercentString = Utils.formatPercentage(info.batteryLevel); info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0; - info.averageTimeToDischarge = estimate.averageDischargeTime; + info.averageTimeToDischarge = estimate.getAverageDischargeTime(); final Resources resources = context.getResources(); info.statusLabel = Utils.getBatteryStatus(resources, batteryBroadcast); @@ -269,20 +271,20 @@ public class BatteryInfo { private static void updateBatteryInfoDischarging(Context context, boolean shortString, Estimate estimate, BatteryInfo info) { - final long drainTimeUs = PowerUtil.convertMsToUs(estimate.estimateMillis); + final long drainTimeUs = PowerUtil.convertMsToUs(estimate.getEstimateMillis()); if (drainTimeUs > 0) { info.remainingTimeUs = drainTimeUs; info.remainingLabel = PowerUtil.getBatteryRemainingStringFormatted( context, PowerUtil.convertUsToMs(drainTimeUs), null /* percentageString */, - estimate.isBasedOnUsage && !shortString + estimate.isBasedOnUsage() && !shortString ); info.chargeLabel = PowerUtil.getBatteryRemainingStringFormatted( context, PowerUtil.convertUsToMs(drainTimeUs), info.batteryPercentString, - estimate.isBasedOnUsage && !shortString + estimate.isBasedOnUsage() && !shortString ); info.suggestionLabel = PowerUtil.getBatteryTipStringFormatted( context, PowerUtil.convertUsToMs(drainTimeUs)); diff --git a/src/com/android/settings/fuelgauge/BatteryMeterView.java b/src/com/android/settings/fuelgauge/BatteryMeterView.java index 44855087170..27923ef7efd 100644 --- a/src/com/android/settings/fuelgauge/BatteryMeterView.java +++ b/src/com/android/settings/fuelgauge/BatteryMeterView.java @@ -82,7 +82,7 @@ public class BatteryMeterView extends ImageView { } public int getBatteryLevel() { - return mDrawable.getLevel(); + return mDrawable.getBatteryLevel(); } public void setCharging(boolean charging) { diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java index 6f779535943..cb22356aa90 100644 --- a/src/com/android/settings/fuelgauge/BatteryUtils.java +++ b/src/com/android/settings/fuelgauge/BatteryUtils.java @@ -47,6 +47,8 @@ import com.android.settings.fuelgauge.batterytip.AnomalyInfo; import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager; import com.android.settings.fuelgauge.batterytip.StatsManagerConfig; import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.fuelgauge.Estimate; +import com.android.settingslib.fuelgauge.EstimateKt; import com.android.settingslib.fuelgauge.PowerWhitelistBackend; import com.android.settingslib.utils.PowerUtil; import com.android.settingslib.utils.ThreadUtils; @@ -460,7 +462,7 @@ public class BatteryUtils { estimate = new Estimate( PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)), false /* isBasedOnUsage */, - Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); + EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); } BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime); diff --git a/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java b/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java index d27e4dcbcf7..c8dbb59a4bb 100644 --- a/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java +++ b/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java @@ -23,6 +23,8 @@ import android.os.SystemClock; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.fuelgauge.Estimate; +import com.android.settingslib.fuelgauge.EstimateKt; import com.android.settingslib.utils.AsyncLoaderCompat; import com.android.settingslib.utils.PowerUtil; @@ -60,7 +62,7 @@ public class DebugEstimatesLoader extends AsyncLoaderCompat> { Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context); if (estimate == null) { - estimate = new Estimate(0, false, Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); + estimate = new Estimate(0, false, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); } BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats, estimate, elapsedRealtimeUs, false); diff --git a/src/com/android/settings/fuelgauge/Estimate.java b/src/com/android/settings/fuelgauge/Estimate.java deleted file mode 100644 index f59bbf15ac1..00000000000 --- a/src/com/android/settings/fuelgauge/Estimate.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.android.settings.fuelgauge; - -public class Estimate { - - // Value to indicate averageTimeToDischarge could not be obtained - public static final int AVERAGE_TIME_TO_DISCHARGE_UNKNOWN = -1; - - public final long estimateMillis; - public final boolean isBasedOnUsage; - public final long averageDischargeTime; - - public Estimate(long estimateMillis, boolean isBasedOnUsage, - long averageDischargeTime) { - this.estimateMillis = estimateMillis; - this.isBasedOnUsage = isBasedOnUsage; - this.averageDischargeTime = averageDischargeTime; - } -} diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java index a6474fb21de..4f292dddacc 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java +++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java @@ -21,6 +21,7 @@ import android.content.Intent; import android.util.SparseIntArray; import com.android.internal.os.BatterySipper; +import com.android.settingslib.fuelgauge.Estimate; /** * Feature Provider used in power usage diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java index b76aef087c1..ab71c97e141 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java @@ -24,6 +24,7 @@ import android.util.SparseIntArray; import com.android.internal.os.BatterySipper; import com.android.internal.util.ArrayUtils; +import com.android.settingslib.fuelgauge.Estimate; public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider { diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index 75db2159dab..82ff4c227b8 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -45,6 +45,7 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settingslib.fuelgauge.EstimateKt; import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.utils.PowerUtil; import com.android.settingslib.utils.StringUtil; @@ -313,7 +314,7 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList @VisibleForTesting void updateLastFullChargePreference() { if (mBatteryInfo != null && mBatteryInfo.averageTimeToDischarge - != Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN) { + != EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN) { mLastFullChargePref.setTitle(R.string.battery_full_charge_last); mLastFullChargePref.setSubtitle( StringUtil.formatElapsedTime(getContext(), mBatteryInfo.averageTimeToDischarge, diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java index aa66aed8c61..a1fb076e648 100644 --- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java +++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java @@ -23,7 +23,6 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.fuelgauge.BatteryInfo; import com.android.settings.fuelgauge.BatteryUtils; -import com.android.settings.fuelgauge.Estimate; import com.android.settings.fuelgauge.batterytip.detectors.EarlyWarningDetector; import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector; import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector; @@ -33,6 +32,7 @@ import com.android.settings.fuelgauge.batterytip.detectors.SummaryDetector; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; import com.android.settings.fuelgauge.batterytip.tips.SummaryTip; +import com.android.settingslib.fuelgauge.EstimateKt; import com.android.settingslib.utils.AsyncLoaderCompat; import java.util.ArrayList; @@ -87,7 +87,7 @@ public class BatteryTipLoader extends AsyncLoaderCompat> { private List getFakeData() { final List tips = new ArrayList<>(); tips.add(new SummaryTip(BatteryTip.StateType.NEW, - Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN)); + EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN)); tips.add(new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */, "Fake data")); diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java index b0dc926e0a4..d615db6db19 100644 --- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java +++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java @@ -26,13 +26,13 @@ import androidx.preference.PreferenceScreen; import com.android.settings.SettingsActivity; import com.android.settings.core.BasePreferenceController; import com.android.settings.core.InstrumentedPreferenceFragment; -import com.android.settings.fuelgauge.Estimate; import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.SummaryTip; import com.android.settings.overlay.FeatureFactory; import com.android.settings.widget.CardPreference; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; +import com.android.settingslib.fuelgauge.EstimateKt; import java.util.HashMap; import java.util.List; @@ -93,7 +93,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController { // Add summary tip in advance to avoid UI flakiness final SummaryTip summaryTip = new SummaryTip(BatteryTip.StateType.NEW, - Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); + EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN); summaryTip.updatePreference(mCardPreference); } diff --git a/src/com/android/settings/network/TetherProvisioningActivity.java b/src/com/android/settings/network/TetherProvisioningActivity.java index b30950e5d17..48c570791b2 100644 --- a/src/com/android/settings/network/TetherProvisioningActivity.java +++ b/src/com/android/settings/network/TetherProvisioningActivity.java @@ -39,6 +39,7 @@ public class TetherProvisioningActivity extends Activity { private static final int PROVISION_REQUEST = 0; private static final String TAG = "TetherProvisioningAct"; private static final String EXTRA_TETHER_TYPE = "TETHER_TYPE"; + private static final String EXTRA_SUBID = "subId"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private ResultReceiver mResultReceiver; @@ -49,14 +50,21 @@ public class TetherProvisioningActivity extends Activity { mResultReceiver = (ResultReceiver)getIntent().getParcelableExtra( ConnectivityManager.EXTRA_PROVISION_CALLBACK); - int tetherType = getIntent().getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, + final int tetherType = getIntent().getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, ConnectivityManager.TETHERING_INVALID); + + final int tetherSubId = getIntent().getIntExtra(EXTRA_SUBID, + SubscriptionManager.INVALID_SUBSCRIPTION_ID); final int subId = SubscriptionManager.getDefaultDataSubscriptionId(); + if (tetherSubId != subId) { + Log.e(TAG, "This Provisioning request is outdated, current subId: " + subId); + return; + } final Resources res = Utils.getResourcesForSubId(this, subId); final String[] provisionApp = res.getStringArray( com.android.internal.R.array.config_mobile_hotspot_provision_app); - Intent intent = new Intent(Intent.ACTION_MAIN); + final Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName(provisionApp[0], provisionApp[1]); intent.putExtra(EXTRA_TETHER_TYPE, tetherType); if (DEBUG) { diff --git a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java index 0a8b931122f..d931f6c6fe2 100644 --- a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java +++ b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java @@ -16,7 +16,9 @@ package com.android.settings.notification; +import android.app.NotificationManager; import android.content.Context; +import android.provider.Settings; import androidx.preference.Preference; @@ -50,6 +52,16 @@ public class ZenModeCallsPreferenceController extends public void updateState(Preference preference) { super.updateState(preference); - preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy())); + switch (getZenMode()) { + case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS: + case Settings.Global.ZEN_MODE_ALARMS: + preference.setEnabled(false); + preference.setSummary(mBackend.getAlarmsTotalSilenceCallsMessagesSummary( + NotificationManager.Policy.PRIORITY_CATEGORY_CALLS)); + break; + default: + preference.setEnabled(true); + preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy())); + } } } diff --git a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java index 2e41f205f58..d51be27a206 100644 --- a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java +++ b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java @@ -16,7 +16,9 @@ package com.android.settings.notification; +import android.app.NotificationManager; import android.content.Context; +import android.provider.Settings; import androidx.preference.Preference; @@ -49,6 +51,16 @@ public class ZenModeMessagesPreferenceController extends public void updateState(Preference preference) { super.updateState(preference); - preference.setSummary(mSummaryBuilder.getMessagesSettingSummary(getPolicy())); + switch (getZenMode()) { + case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS: + case Settings.Global.ZEN_MODE_ALARMS: + preference.setEnabled(false); + preference.setSummary(mBackend.getAlarmsTotalSilenceCallsMessagesSummary( + NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES)); + break; + default: + preference.setEnabled(true); + preference.setSummary(mSummaryBuilder.getMessagesSettingSummary(getPolicy())); + } } } diff --git a/src/com/android/settings/panel/PanelSlicesAdapter.java b/src/com/android/settings/panel/PanelSlicesAdapter.java index e2444133970..dcd878e2291 100644 --- a/src/com/android/settings/panel/PanelSlicesAdapter.java +++ b/src/com/android/settings/panel/PanelSlicesAdapter.java @@ -44,6 +44,12 @@ import java.util.List; public class PanelSlicesAdapter extends RecyclerView.Adapter { + /** + * Maximum number of slices allowed on the panel view. + */ + @VisibleForTesting + static final int MAX_NUM_OF_SLICES = 5; + private final List> mSliceLiveData; private final int mMetricsCategory; private final PanelFragment mPanelFragment; @@ -70,14 +76,21 @@ public class PanelSlicesAdapter sliceRowViewHolder.onBind(mSliceLiveData.get(position)); } + /** + * Return the number of available items in the adapter with max number of slices enforced. + */ @Override public int getItemCount() { - return mSliceLiveData.size(); + return Math.min(mSliceLiveData.size(), MAX_NUM_OF_SLICES); } + /** + * Return the available data from the adapter. If the number of Slices over the max number + * allowed, the list will only have the first MAX_NUM_OF_SLICES of slices. + */ @VisibleForTesting List> getData() { - return mSliceLiveData; + return mSliceLiveData.subList(0, getItemCount()); } /** diff --git a/src/com/android/settings/widget/DisabledCheckBoxPreference.java b/src/com/android/settings/widget/DisabledCheckBoxPreference.java index be6deb3a0be..15c17dc88dd 100644 --- a/src/com/android/settings/widget/DisabledCheckBoxPreference.java +++ b/src/com/android/settings/widget/DisabledCheckBoxPreference.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.View; +import android.widget.TextView; import androidx.preference.CheckBoxPreference; import androidx.preference.PreferenceViewHolder; @@ -89,6 +90,12 @@ public class DisabledCheckBoxPreference extends CheckBoxPreference { mCheckBox = holder.findViewById(android.R.id.checkbox); enableCheckbox(mEnabledCheckBox); + + TextView title = (TextView) holder.findViewById(android.R.id.title); + if (title != null) { + title.setSingleLine(false); + title.setMaxLines(2); + } } @Override diff --git a/src/com/android/settings/wifi/tether/TetherService.java b/src/com/android/settings/wifi/tether/TetherService.java index 09781a8ed5b..34daccf6aea 100644 --- a/src/com/android/settings/wifi/tether/TetherService.java +++ b/src/com/android/settings/wifi/tether/TetherService.java @@ -55,6 +55,8 @@ public class TetherService extends Service { @VisibleForTesting public static final String EXTRA_RESULT = "EntitlementResult"; + @VisibleForTesting + public static final String EXTRA_SUBID = "subId"; // Activity results to match the activity provision protocol. // Default to something not ok. @@ -100,6 +102,18 @@ public class TetherService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + if (intent.hasExtra(EXTRA_SUBID)) { + final int tetherSubId = intent.getIntExtra(EXTRA_SUBID, + SubscriptionManager.INVALID_SUBSCRIPTION_ID); + final int subId = getTetherServiceWrapper().getDefaultDataSubscriptionId(); + if (tetherSubId != subId) { + Log.e(TAG, "This Provisioning request is outdated, current subId: " + subId); + if (!mInProvisionCheck) { + stopSelf(); + } + return START_NOT_STICKY; + } + } if (intent.hasExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE)) { int type = intent.getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, ConnectivityManager.TETHERING_INVALID); diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml index 78c3c088487..a6a84c9c376 100644 --- a/tests/robotests/res/values-mcc999/config.xml +++ b/tests/robotests/res/values-mcc999/config.xml @@ -88,4 +88,9 @@ intent:#Intent;action=test.test;end + + + + injected_tile_key + diff --git a/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceControllerTest.java new file mode 100644 index 00000000000..2226e2c4e1d --- /dev/null +++ b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceControllerTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.accounts; + +import static com.android.settings.core.BasePreferenceController.AVAILABLE; +import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.robolectric.RuntimeEnvironment.application; + +import android.app.admin.DevicePolicyManager; +import android.content.ComponentName; +import android.content.Context; +import android.os.UserHandle; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.Shadows; +import org.robolectric.shadows.ShadowDevicePolicyManager; + +import java.util.Collections; + +@RunWith(RobolectricTestRunner.class) +public class CrossProfileCalendarDisabledPreferenceControllerTest { + + private static final String PREF_KEY = "cross_profile_calendar_disabled"; + private static final int MANAGED_USER_ID = 10; + private static final String TEST_PACKAGE_NAME = "com.test"; + private static final ComponentName TEST_COMPONENT_NAME = new ComponentName("test", "test"); + + @Mock + private UserHandle mManagedUser; + + private Context mContext; + private CrossProfileCalendarDisabledPreferenceController mController; + private ShadowDevicePolicyManager mDpm; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + mController = new CrossProfileCalendarDisabledPreferenceController(mContext, PREF_KEY); + mController.setManagedUser(mManagedUser); + mDpm = Shadows.shadowOf(application.getSystemService(DevicePolicyManager.class)); + + when(mManagedUser.getIdentifier()).thenReturn(MANAGED_USER_ID); + doReturn(mContext).when(mContext).createPackageContextAsUser( + any(String.class), anyInt(), any(UserHandle.class)); + } + + @Test + public void getAvailabilityStatus_noPackageAllowed_shouldBeAvailable() { + mDpm.setProfileOwner(TEST_COMPONENT_NAME); + + assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); + } + + @Test + public void getAvailabilityStatus_somePackagesAllowed_shouldBeDisabledForUser() { + mDpm.setProfileOwner(TEST_COMPONENT_NAME); + mDpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME, + Collections.singleton(TEST_PACKAGE_NAME)); + + assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER); + } + + @Test + public void getAvailabilityStatus_allPackagesAllowed_shouldBeDisabledForUser() { + mDpm.setProfileOwner(TEST_COMPONENT_NAME); + mDpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME, null); + + assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER); + } +} \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java index c6a48a889a9..7c6077440e6 100644 --- a/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java @@ -17,6 +17,9 @@ package com.android.settings.accounts; import static android.provider.Settings.Secure.CROSS_PROFILE_CALENDAR_ENABLED; +import static com.android.settings.core.BasePreferenceController.AVAILABLE; +import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -37,6 +40,7 @@ import android.util.ArraySet; import com.android.settingslib.RestrictedSwitchPreference; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -88,6 +92,7 @@ public class CrossProfileCalendarPreferenceControllerTest { } @Test + @Ignore("b/130896049") public void getAvailabilityStatus_hasManagedUser_AVAILABLE() { mController.setManagedUser(mManagedUser); assertThat(mController.getAvailabilityStatus()) @@ -117,30 +122,27 @@ public class CrossProfileCalendarPreferenceControllerTest { } @Test - public void updateState_noPackageAllowed_preferenceShouldBeDisabled() throws Exception { + public void getAvailabilityStatus_noPackageAllowed_shouldBeDisabledForUser() throws Exception { dpm.setProfileOwner(TEST_COMPONENT_NAME); - mController.updateState(mPreference); - verify(mPreference).setDisabledByAdmin(any()); + assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER); } @Test - public void updateState_somePackagesAllowed_preferenceShouldNotBeDisabled() throws Exception { + public void getAvailabilityStatus_somePackagesAllowed_shouldBeAvailable() throws Exception { dpm.setProfileOwner(TEST_COMPONENT_NAME); dpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME, Collections.singleton(TEST_PACKAGE_NAME)); - mController.updateState(mPreference); - verify(mPreference).setDisabledByAdmin(null); + assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test - public void updateState_allPackagesAllowed_preferenceShouldNotBeDisabled() throws Exception { + public void getAvailabilityStatus_allPackagesAllowed_shouldBeAvailable() throws Exception { dpm.setProfileOwner(TEST_COMPONENT_NAME); dpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME, null); - mController.updateState(mPreference); - verify(mPreference).setDisabledByAdmin(null); + assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java index 362b0038d07..03e9b6f8158 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java @@ -27,6 +27,7 @@ import android.bluetooth.BluetoothDevice; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.provider.DeviceConfig; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; @@ -35,7 +36,9 @@ import android.widget.TextView; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; +import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.fuelgauge.BatteryMeterView; +import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowEntityHeaderController; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.widget.LayoutPreference; @@ -50,8 +53,8 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) -@Config(shadows = ShadowEntityHeaderController.class) -public class AdvancedBluetoothDetailsHeaderControllerTest{ +@Config(shadows = {ShadowEntityHeaderController.class, ShadowDeviceConfig.class}) +public class AdvancedBluetoothDetailsHeaderControllerTest { private static final int BATTERY_LEVEL_MAIN = 30; private static final int BATTERY_LEVEL_LEFT = 25; private static final int BATTERY_LEVEL_RIGHT = 45; @@ -141,7 +144,9 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{ } @Test - public void getAvailabilityStatus_untetheredHeadset_returnAvailable() { + public void getAvailabilityStatus_untetheredHeadsetWithConfigOn_returnAvailable() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) .thenReturn("true".getBytes()); @@ -150,7 +155,31 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{ } @Test - public void getAvailabilityStatus_notUntetheredHeadset_returnUnavailable() { + public void getAvailabilityStatus_untetheredHeadsetWithConfigOff_returnUnavailable() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "false", true); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) + .thenReturn("true".getBytes()); + + assertThat(mController.getAvailabilityStatus()).isEqualTo( + BasePreferenceController.CONDITIONALLY_UNAVAILABLE); + } + + @Test + public void getAvailabilityStatus_notUntetheredHeadsetWithConfigOn_returnUnavailable() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) + .thenReturn("false".getBytes()); + + assertThat(mController.getAvailabilityStatus()).isEqualTo( + BasePreferenceController.CONDITIONALLY_UNAVAILABLE); + } + + @Test + public void getAvailabilityStatus_notUntetheredHeadsetWithConfigOff_returnUnavailable() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "false", true); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) .thenReturn("false".getBytes()); @@ -169,17 +198,21 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{ @Test public void onStart_isAvailable_registerCallback() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) .thenReturn("true".getBytes()); mController.onStart(); verify(mBluetoothAdapter).addOnMetadataChangedListener(mBluetoothDevice, - mContext.getMainExecutor() ,mController.mMetadataListener); + mContext.getMainExecutor(), mController.mMetadataListener); } @Test public void onStop_isAvailable_unregisterCallback() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) .thenReturn("true".getBytes()); @@ -197,7 +230,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{ mController.onStart(); verify(mBluetoothAdapter, never()).addOnMetadataChangedListener(mBluetoothDevice, - mContext.getMainExecutor() ,mController.mMetadataListener); + mContext.getMainExecutor(), mController.mMetadataListener); } @Test @@ -213,6 +246,8 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{ @Test public void onDestroy_isAvailable_recycleBitmap() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) .thenReturn("true".getBytes()); mController.mIconCache.put(ICON_URI, mBitmap); diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java index 1ee1de6fd39..94f8cc52dc7 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java @@ -27,7 +27,9 @@ import android.bluetooth.BluetoothDevice; import android.graphics.drawable.Drawable; import com.android.settings.R; +import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.testutils.FakeFeatureFactory; +import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowEntityHeaderController; import com.android.settings.widget.EntityHeaderController; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; @@ -44,7 +46,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) -@Config(shadows = ShadowEntityHeaderController.class) +@Config(shadows = {ShadowEntityHeaderController.class, ShadowDeviceConfig.class}) public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase { private BluetoothDetailsHeaderController mController; @@ -123,10 +125,24 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro } @Test - public void isAvailable_untetheredHeadset_returnFalse() { + public void isAvailable_untetheredHeadsetWithConfigOn_returnFalse() { + android.provider.DeviceConfig.setProperty( + android.provider.DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "true", true); when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn("true".getBytes()); assertThat(mController.isAvailable()).isFalse(); } + + @Test + public void isAvailable_untetheredHeadsetWithConfigOff_returnTrue() { + android.provider.DeviceConfig.setProperty( + android.provider.DeviceConfig.NAMESPACE_SETTINGS_UI, + SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, "false", true); + when(mBluetoothDevice.getMetadata( + BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn("true".getBytes()); + + assertThat(mController.isAvailable()).isTrue(); + } } diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java index 24aae859a31..10665529a86 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java @@ -215,11 +215,14 @@ public class BluetoothDeviceUpdaterTest { } @Test - public void forceUpdate_bluetoothDisabled_doNothing() { + public void forceUpdate_bluetoothDisabled_removeAllDevicesFromPreference() { mShadowBluetoothAdapter.setEnabled(false); + mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, mPreference); + mBluetoothDeviceUpdater.forceUpdate(); - verify(mDevicePreferenceCallback, never()).onDeviceAdded(any(Preference.class)); + verify(mDevicePreferenceCallback).onDeviceRemoved(mPreference); + assertThat(mBluetoothDeviceUpdater.mPreferenceMap).isEmpty(); } @Test diff --git a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java index 4062bfb8f6a..5fdadb48662 100644 --- a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java +++ b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java @@ -24,6 +24,7 @@ import com.android.settings.search.SearchIndexProviderCodeInspector; import com.android.settings.slices.SliceControllerInXmlCodeInspector; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,6 +47,7 @@ public class CodeInspectionTest { } @Test + @Ignore("b/130897640") public void runInstrumentableFragmentCodeInspection() { new InstrumentableFragmentCodeInspector(mClasses).run(); } diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java index 438dfc18caf..9aae249c79b 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java @@ -16,6 +16,7 @@ package com.android.settings.dashboard; import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.DASHBOARD_CONTAINER; +import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT; import static com.google.common.truth.Truth.assertThat; @@ -53,6 +54,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; import java.util.ArrayList; @@ -79,6 +81,8 @@ public class DashboardFragmentTest { mActivityInfo = new ActivityInfo(); mActivityInfo.packageName = "pkg"; mActivityInfo.name = "class"; + mActivityInfo.metaData = new Bundle(); + mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "injected_tile_key"); mFakeFeatureFactory = FakeFeatureFactory.setupForTest(); mDashboardCategory = new DashboardCategory("key"); mDashboardCategory.addTile(new Tile(mActivityInfo, mDashboardCategory.key)); @@ -143,6 +147,20 @@ public class DashboardFragmentTest { verify(mTestFragment.mScreen, never()).addPreference(nullable(Preference.class)); } + @Test + @Config(qualifiers = "mcc999") + public void displayTilesAsPreference_shouldNotAddSuppressedTiles() { + when(mFakeFeatureFactory.dashboardFeatureProvider + .getTilesForCategory(nullable(String.class))) + .thenReturn(mDashboardCategory); + when(mFakeFeatureFactory.dashboardFeatureProvider + .getDashboardKeyForTile(nullable(Tile.class))) + .thenReturn("test_key"); + mTestFragment.onCreatePreferences(new Bundle(), "rootKey"); + + verify(mTestFragment.mScreen, never()).addPreference(nullable(Preference.class)); + } + @Test public void onAttach_shouldCreatePlaceholderPreferenceController() { final AbstractPreferenceController controller = mTestFragment.use( diff --git a/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceControllerTest.java new file mode 100644 index 00000000000..98ffbd01bbf --- /dev/null +++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceControllerTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.settings.deviceinfo.hardwareinfo; + +import static android.content.Context.CLIPBOARD_SERVICE; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.ClipboardManager; +import android.content.Context; +import android.os.SystemProperties; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(RobolectricTestRunner.class) +public class HardwareRevisionPreferenceControllerTest { + + private Context mContext; + private HardwareRevisionPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mController = new HardwareRevisionPreferenceController(mContext, + "hardware_info_device_revision"); + } + + @Test + public void isSliceable_shouldBeSliceable() { + assertThat(mController.isSliceable()).isTrue(); + } + + @Test + public void isCopyableSlice_shouldBeCopyableSlice() { + assertThat(mController.isCopyableSlice()).isTrue(); + } + + @Test + public void copy_shouldCopyHardwareRevisionToClipboard() { + final String fakeHardwareVer = "FakeVer1.0"; + SystemProperties.set("ro.boot.hardware.revision", fakeHardwareVer); + + mController.copy(); + + final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService( + CLIPBOARD_SERVICE); + final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText(); + + assertThat(data.toString()).isEqualTo(fakeHardwareVer); + } +} \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java index 9adb1ad2861..89388730742 100644 --- a/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java @@ -32,6 +32,7 @@ import com.android.settings.R; import com.android.settingslib.RestrictedPreference; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -40,6 +41,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) +@Ignore("b/130897305") public class AdaptiveSleepPreferenceControllerTest { private static final String PREFERENCE_KEY = "adaptive_sleep"; diff --git a/tests/robotests/src/com/android/settings/display/DarkUIInfoDialogFragmentTest.java b/tests/robotests/src/com/android/settings/display/DarkUIInfoDialogFragmentTest.java index 7a8bdedd63e..87284ede402 100644 --- a/tests/robotests/src/com/android/settings/display/DarkUIInfoDialogFragmentTest.java +++ b/tests/robotests/src/com/android/settings/display/DarkUIInfoDialogFragmentTest.java @@ -28,6 +28,7 @@ import android.content.DialogInterface; import android.content.SharedPreferences; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -49,6 +50,7 @@ public class DarkUIInfoDialogFragmentTest { } @Test + @Ignore("b/130897882") public void dialogDismissedOnConfirmation() { doReturn(RuntimeEnvironment.application).when(mFragment).getContext(); SharedPreferences prefs = RuntimeEnvironment.application.getSharedPreferences( diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java index d5e0ed88177..6b917f0bf46 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java @@ -41,6 +41,7 @@ import com.android.settings.testutils.BatteryTestUtils; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.widget.UsageView; import com.android.settingslib.R; +import com.android.settingslib.fuelgauge.Estimate; import org.junit.Before; import org.junit.Test; diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java index e91190224e1..df9a194f4e5 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java @@ -28,7 +28,6 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentActivity; import com.android.settings.R; -import com.android.settings.fuelgauge.Estimate; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip; import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip; @@ -37,6 +36,7 @@ import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.shadow.ShadowAlertDialogCompat; import com.android.settings.testutils.shadow.ShadowUtils; +import com.android.settingslib.fuelgauge.EstimateKt; import org.junit.Before; import org.junit.Test; @@ -96,7 +96,7 @@ public class BatteryTipDialogFragmentTest { mUnrestrictAppTip = new UnrestrictAppTip(BatteryTip.StateType.NEW, mAppInfo); mSummaryTip = spy(new SummaryTip(BatteryTip.StateType.NEW, - Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN)); + EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN)); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java index 88f8303b179..9d2754139fe 100644 --- a/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java @@ -139,7 +139,7 @@ public class AllowSoundPreferenceControllerTest { } @Test - public void testUpdateState_notConfigurable() { + public void testUpdateState_notBlockable() { String lockedId = "locked"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = lockedId; @@ -150,7 +150,7 @@ public class AllowSoundPreferenceControllerTest { Preference pref = new RestrictedSwitchPreference(mContext); mController.updateState(pref); - assertFalse(pref.isEnabled()); + assertTrue(pref.isEnabled()); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java index 8265295a76b..9ea201a531f 100644 --- a/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java @@ -187,7 +187,7 @@ public class BadgePreferenceControllerTest { } @Test - public void testUpdateState_channelNotConfigurable() { + public void testUpdateState_channelNotBlockable() { String lockedId = "locked"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = lockedId; @@ -198,7 +198,7 @@ public class BadgePreferenceControllerTest { Preference pref = new RestrictedSwitchPreference(mContext); mController.updateState(pref); - assertFalse(pref.isEnabled()); + assertTrue(pref.isEnabled()); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java index 54bbd0874c7..0d0b4852b58 100644 --- a/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java @@ -202,7 +202,7 @@ public class BubblePreferenceControllerTest { } @Test - public void testUpdateState_channelNotConfigurable() { + public void testUpdateState_channelNotBlockable() { String lockedId = "locked"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = lockedId; @@ -213,7 +213,7 @@ public class BubblePreferenceControllerTest { Preference pref = new RestrictedSwitchPreference(mContext); mController.updateState(pref); - assertFalse(pref.isEnabled()); + assertTrue(pref.isEnabled()); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java index 0b2af49e830..929c14d7db3 100644 --- a/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java @@ -110,7 +110,7 @@ public class DndPreferenceControllerTest { } @Test - public void testUpdateState_notConfigurable() { + public void testUpdateState_notBlockable() { String lockedId = "locked"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = lockedId; @@ -121,7 +121,7 @@ public class DndPreferenceControllerTest { Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application); mController.updateState(pref); - assertFalse(pref.isEnabled()); + assertTrue(pref.isEnabled()); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java index dd6a6208381..3724ddb9c43 100644 --- a/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java @@ -158,7 +158,7 @@ public class LightsPreferenceControllerTest { } @Test - public void testUpdateState_notConfigurable() { + public void testUpdateState_notBlockable() { String lockedId = "locked"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = lockedId; @@ -169,19 +169,6 @@ public class LightsPreferenceControllerTest { Preference pref = new RestrictedSwitchPreference(mContext); mController.updateState(pref); - assertFalse(pref.isEnabled()); - } - - @Test - public void testUpdateState_configurable() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.getId()).thenReturn("something"); - mController.onResume(appRow, channel, null, null); - - Preference pref = new RestrictedSwitchPreference(mContext); - mController.updateState(pref); - assertTrue(pref.isEnabled()); } diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java index 8c743348875..a72597b4ba7 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java @@ -209,6 +209,7 @@ public class NotificationPreferenceControllerTest { appRow.lockedChannelId = sameId; NotificationChannel channel = mock(NotificationChannel.class); when(channel.getId()).thenReturn(sameId); + when(channel.getImportance()).thenReturn(IMPORTANCE_LOW); mController.onResume(appRow, channel, null, null); assertFalse(mController.isChannelBlockable()); @@ -223,8 +224,10 @@ public class NotificationPreferenceControllerTest { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = "something"; appRow.lockedImportance = true; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getImportance()).thenReturn(IMPORTANCE_LOW); - mController.onResume(appRow, mock(NotificationChannel.class), null, null); + mController.onResume(appRow, channel, null, null); assertFalse(mController.isChannelBlockable()); appRow.lockedImportance = false; diff --git a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java index 866f8668a21..1d9836e2af1 100644 --- a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java @@ -161,7 +161,7 @@ public class SoundPreferenceControllerTest { } @Test - public void testUpdateState_notConfigurable() { + public void testUpdateState_notBlockable() { String lockedId = "locked"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = lockedId; @@ -173,7 +173,7 @@ public class SoundPreferenceControllerTest { Preference pref = new NotificationSoundPreference(mContext, attributeSet); mController.updateState(pref); - assertFalse(pref.isEnabled()); + assertTrue(pref.isEnabled()); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java index e1d5b73574c..adc10f46180 100644 --- a/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java @@ -140,7 +140,7 @@ public class VibrationPreferenceControllerTest { } @Test - public void testUpdateState_notConfigurable() { + public void testUpdateState_notBlockable() { String lockedId = "locked"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = lockedId; @@ -151,7 +151,7 @@ public class VibrationPreferenceControllerTest { Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application); mController.updateState(pref); - assertFalse(pref.isEnabled()); + assertTrue(pref.isEnabled()); } @Test diff --git a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java index fd2e806be77..793b44d5ba2 100644 --- a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java +++ b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java @@ -36,6 +36,7 @@ import com.android.settings.R; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -105,6 +106,7 @@ public class PanelFragmentTest { } @Test + @Ignore("b/130896218") public void onDestroy_logCloseEvent() { mPanelFragment.onDestroy(); verify(mFakeFeatureFactory.metricsFeatureProvider).action( @@ -115,6 +117,7 @@ public class PanelFragmentTest { 0); } @Test + @Ignore("b/130896218") public void panelSeeMoreClick_logsCloseEvent() { final View.OnClickListener listener = mPanelFragment.getSeeMoreListener(); @@ -130,6 +133,7 @@ public class PanelFragmentTest { } @Test + @Ignore("b/130896218") public void panelDoneClick_logsCloseEvent() { final View.OnClickListener listener = mPanelFragment.getCloseListener(); diff --git a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java index 14a7db9581a..922e629d1a6 100644 --- a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java +++ b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java @@ -16,12 +16,14 @@ package com.android.settings.panel; +import static com.android.settings.panel.PanelSlicesAdapter.MAX_NUM_OF_SLICES; import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -40,7 +42,6 @@ import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.runner.RunWith; import org.junit.Test; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; @@ -62,11 +63,6 @@ public class PanelSlicesAdapterTest { private FakePanelContent mFakePanelContent; private List> mData = new ArrayList<>(); - @Mock - private LiveData mLiveData; - - private Slice mSlice; - @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -91,17 +87,18 @@ public class PanelSlicesAdapterTest { } - private void constructTestLiveData(Uri uri) { + private void addTestLiveData(Uri uri) { // Create a slice to return for the LiveData - mSlice = spy(new Slice()); - doReturn(uri).when(mSlice).getUri(); - when(mLiveData.getValue()).thenReturn(mSlice); - mData.add(mLiveData); + final Slice slice = spy(new Slice()); + doReturn(uri).when(slice).getUri(); + final LiveData liveData = mock(LiveData.class); + when(liveData.getValue()).thenReturn(slice); + mData.add(liveData); } @Test public void onCreateViewHolder_returnsSliceRowViewHolder() { - constructTestLiveData(DATA_URI); + addTestLiveData(DATA_URI); final PanelSlicesAdapter adapter = new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */); final ViewGroup view = new FrameLayout(mContext); @@ -111,9 +108,27 @@ public class PanelSlicesAdapterTest { assertThat(viewHolder.sliceView).isNotNull(); } + @Test + public void sizeOfAdapter_shouldNotExceedMaxNum() { + for (int i = 0; i < MAX_NUM_OF_SLICES + 2; i++) { + addTestLiveData(DATA_URI); + } + + assertThat(mData.size()).isEqualTo(MAX_NUM_OF_SLICES + 2); + + final PanelSlicesAdapter adapter = + new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */); + final ViewGroup view = new FrameLayout(mContext); + final PanelSlicesAdapter.SliceRowViewHolder viewHolder = + adapter.onCreateViewHolder(view, 0); + + assertThat(adapter.getItemCount()).isEqualTo(MAX_NUM_OF_SLICES); + assertThat(adapter.getData().size()).isEqualTo(MAX_NUM_OF_SLICES); + } + @Test public void nonMediaOutputIndicatorSlice_shouldAllowDividerAboveAndBelow() { - constructTestLiveData(DATA_URI); + addTestLiveData(DATA_URI); final PanelSlicesAdapter adapter = new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */); final int position = 0; @@ -129,7 +144,7 @@ public class PanelSlicesAdapterTest { @Test public void mediaOutputIndicatorSlice_shouldNotAllowDividerAbove() { - constructTestLiveData(MEDIA_OUTPUT_INDICATOR_SLICE_URI); + addTestLiveData(MEDIA_OUTPUT_INDICATOR_SLICE_URI); final PanelSlicesAdapter adapter = new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */); diff --git a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java index fa15aa02b1d..4ca6395400a 100644 --- a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java +++ b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java @@ -35,6 +35,7 @@ import android.view.MotionEvent; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; @@ -89,6 +90,7 @@ public class SettingsPanelActivityTest { } @Test + @Ignore("b/130896218") public void onTouchEvent_outsideAction_logsPanelClosed() { final MotionEvent event = mock(MotionEvent.class); when(event.getAction()).thenReturn(MotionEvent.ACTION_OUTSIDE); diff --git a/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java b/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java index 11de7b31b60..154428de679 100644 --- a/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java +++ b/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java @@ -23,6 +23,7 @@ import android.net.Uri; import com.android.settings.slices.CustomSliceRegistry; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -41,6 +42,7 @@ public class VolumePanelTest { } @Test + @Ignore("b/130896218") public void getSlices_containsNecessarySlices() { final List uris = mPanel.getSlices(); diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java index 2acfc4a3a97..906c55c39f2 100644 --- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java @@ -83,6 +83,7 @@ import com.android.settingslib.wifi.WifiTracker; import com.android.settingslib.wifi.WifiTrackerFactory; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -105,6 +106,7 @@ import java.util.stream.Collectors; @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowDevicePolicyManager.class, ShadowEntityHeaderController.class}) +@Ignore("b/130896210") public class WifiDetailPreferenceControllerTest { private static final int LEVEL = 1; diff --git a/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java b/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java index 03320923d7a..0739ef0ce23 100644 --- a/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java +++ b/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java @@ -266,11 +266,26 @@ public class TetherServiceTest extends ServiceTestCase { assertEquals(TetherService.class.getName(), pi.getIntent().getComponent().getClassName()); } + public void testIgnoreOutdatedRequest() { + Intent intent = new Intent(); + intent.putExtra(EXTRA_ADD_TETHER_TYPE, TETHERING_WIFI); + intent.putExtra(EXTRA_RUN_PROVISION, true); + intent.putExtra(EXTRA_PROVISION_CALLBACK, mResultReceiver); + intent.putExtra(TetherService.EXTRA_SUBID, 1 /* Tested subId number */); + startService(intent); + + SystemClock.sleep(PROVISION_TIMEOUT); + assertEquals(TETHERING_INVALID, mLastTetherRequestType); + assertTrue(mWrapper.isAppInactive(ENTITLEMENT_PACKAGE_NAME)); + assertTrue(mWrapper.isAppInactive(FAKE_PACKAGE_NAME)); + } + private void runProvisioningForType(int type) { Intent intent = new Intent(); intent.putExtra(EXTRA_ADD_TETHER_TYPE, type); intent.putExtra(EXTRA_RUN_PROVISION, true); intent.putExtra(EXTRA_PROVISION_CALLBACK, mResultReceiver); + intent.putExtra(TetherService.EXTRA_SUBID, INVALID_SUBSCRIPTION_ID); startService(intent); } @@ -291,7 +306,7 @@ public class TetherServiceTest extends ServiceTestCase { long startTime = SystemClock.uptimeMillis(); while (true) { if (mLastTetherRequestType == expectedType) { - mLastTetherRequestType = -1; + mLastTetherRequestType = TETHERING_INVALID; return true; } if ((SystemClock.uptimeMillis() - startTime) > PROVISION_TIMEOUT) {