From d2e33e73a16973926d52858b7a92281a9c90b15f Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Mon, 12 Feb 2018 14:26:47 -0800 Subject: [PATCH 1/5] Fix instrumentation tests Change-Id: I4f6891f095f4803e822b55a3f44d67ee4d173180 Fixes: 73242024 Test: atest --- res/xml/accessibility_vibration_settings.xml | 2 +- .../android/settings/core/UniquePreferenceTest.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/res/xml/accessibility_vibration_settings.xml b/res/xml/accessibility_vibration_settings.xml index d61454d0b46..17468ea05f5 100644 --- a/res/xml/accessibility_vibration_settings.xml +++ b/res/xml/accessibility_vibration_settings.xml @@ -15,7 +15,7 @@ --> diff --git a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java index 3daecce7aa7..637280d03cf 100644 --- a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java +++ b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java @@ -91,7 +91,16 @@ public class UniquePreferenceTest { "imei_info", "wifi_ip_address", "wifi_mac_address", - "safety_info" + "safety_info", + // Dupe keys from data usage v2. + "data_usage_screen", + "cellular_data_usage", + "data_usage_wifi_screen", + "status_header", + "billing_preference", + "data_usage_cellular_screen", + "wifi_data_usage", + "data_usage_enable" ); private Context mContext; From 404d96058cb5983dd3c958521894a5616ab3e4ae Mon Sep 17 00:00:00 2001 From: Matthew Fritze Date: Mon, 12 Feb 2018 13:52:48 -0800 Subject: [PATCH 2/5] Handle Looper in PreferenceController When indexing content in search, the preference controllers are init'd on the background thread, thus you can't create a handler without calling Looper.prepare(). We have PreferenceConttrollerContractTest to catch these errors, but it was not running in presubmit. Bug tracking: b/73242024 This caused the indexing thread to crash, thus not adding any non-indexable keys for settings results. Test: atest PreferenceControllerContractTest Fixes: 73168342 Change-Id: I89fe596435d317bb3e3baebdaace97a67700d77e --- .../batterysaver/AutoBatterySeekBarPreferenceController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java index 1c787abd5d4..1cc72a79fbb 100644 --- a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java +++ b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java @@ -20,6 +20,7 @@ import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; +import android.os.Looper; import android.provider.Settings; import android.support.annotation.VisibleForTesting; import android.support.v7.preference.Preference; @@ -46,7 +47,7 @@ public class AutoBatterySeekBarPreferenceController extends BasePreferenceContro public AutoBatterySeekBarPreferenceController(Context context, Lifecycle lifecycle) { super(context, KEY_AUTO_BATTERY_SEEK_BAR); - mContentObserver = new AutoBatterySaverSettingObserver(new Handler()); + mContentObserver = new AutoBatterySaverSettingObserver(new Handler(Looper.getMainLooper())); if (lifecycle != null) { lifecycle.addObserver(this); } From b25ffe2c9faab58e6859e2c8b06ea5f50215572d Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Tue, 13 Feb 2018 18:09:09 -0800 Subject: [PATCH 3/5] Re-added support for deprecated BIND_AUTOFILL permission. This permission was renamed during the O previews but it was supported on the final O release, so we need to carry it over. Test: manual verification Bug: 70682223 Change-Id: I24b41358fba7449d9216b49aa8b90480906cfb67 --- .../applications/defaultapps/DefaultAutofillPicker.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java index d116f91d601..30835fb2297 100644 --- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java +++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java @@ -195,6 +195,14 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment { candidates.add(new DefaultAppInfo(context, mPm, mUserId, new ComponentName( info.serviceInfo.packageName, info.serviceInfo.name))); } + if (Manifest.permission.BIND_AUTOFILL.equals(permission)) { + // Let it go for now... + Log.w(TAG, "AutofillService from '" + info.serviceInfo.packageName + + "' uses unsupported permission " + Manifest.permission.BIND_AUTOFILL + + ". It works for now, but might not be supported on future releases"); + candidates.add(new DefaultAppInfo(context, mPm, mUserId, new ComponentName( + info.serviceInfo.packageName, info.serviceInfo.name))); + } } return candidates; } From da4fa8071717e514b37dd33580d66a43bac2d655 Mon Sep 17 00:00:00 2001 From: Daniel Nishi Date: Tue, 23 Jan 2018 18:28:11 -0800 Subject: [PATCH 4/5] Centralize the automatic storage manager on check. Bug: 70893105 Test: Existing tests pass. Change-Id: I83fa0e1033eb530a02eca230d0dd79495cbcbc9d --- ...rageManagerDescriptionPreferenceController.java | 8 ++------ .../AutomaticStorageManagerSettings.java | 10 ++-------- ...AutomaticStorageManagerSwitchBarController.java | 9 ++------- ...torageManagementSwitchPreferenceController.java | 14 +++++++------- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java index 261f66cea6e..23fc35b3619 100644 --- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java +++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java @@ -23,6 +23,7 @@ import android.text.format.Formatter; import com.android.settings.R; import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.Utils; import com.android.settingslib.core.AbstractPreferenceController; /** @@ -57,7 +58,7 @@ public class AutomaticStorageManagerDescriptionPreferenceController cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_BYTES_CLEARED, 0); long lastRunMillis = Settings.Secure.getLong(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_LAST_RUN, 0); - if (freedBytes == 0 || lastRunMillis == 0 || !isStorageManagerEnabled(cr)) { + if (freedBytes == 0 || lastRunMillis == 0 || !Utils.isStorageManagerEnabled(context)) { preference.setSummary(R.string.automatic_storage_manager_text); } else { preference.setSummary( @@ -68,9 +69,4 @@ public class AutomaticStorageManagerDescriptionPreferenceController context, lastRunMillis, DateUtils.FORMAT_SHOW_DATE))); } } - - private boolean isStorageManagerEnabled(ContentResolver cr) { - return Settings.Secure.getInt(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) - != 0; - } } diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java index 184c0c57ae7..22ecb0939c2 100644 --- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java +++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -96,7 +96,7 @@ public class AutomaticStorageManagerSettings extends DashboardFragment @Override public void onResume() { super.onResume(); - mDaysToRetain.setEnabled(isStorageManagerEnabled()); + mDaysToRetain.setEnabled(Utils.isStorageManagerEnabled(getContext())); } @Override @@ -153,12 +153,6 @@ public class AutomaticStorageManagerSettings extends DashboardFragment return indices.length - 1; } - private boolean isStorageManagerEnabled() { - return Settings.Secure.getInt( - getContentResolver(), Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) - != 0; - } - private static List buildPreferenceControllers(Context context) { final List controllers = new ArrayList<>(); controllers.add(new AutomaticStorageManagerDescriptionPreferenceController(context)); diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java index a20afa1060a..c02fb102833 100644 --- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java +++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java @@ -27,6 +27,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.util.Preconditions; import com.android.settings.widget.SwitchBar; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; +import com.android.settingslib.Utils; /** Handles the logic for flipping the storage management toggle on a {@link SwitchBar}. */ public class AutomaticStorageManagerSwitchBarController @@ -56,13 +57,7 @@ public class AutomaticStorageManagerSwitchBarController } private void initializeCheckedStatus() { - boolean isStorageManagerChecked = - Settings.Secure.getInt( - mContext.getContentResolver(), - Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, - 0) - != 0; - mSwitchBar.setChecked(isStorageManagerChecked); + mSwitchBar.setChecked(Utils.isStorageManagerEnabled(mContext)); mSwitchBar.addOnSwitchChangeListener(this); } diff --git a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java index 8ab21b36fdb..7724b009f71 100644 --- a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -23,12 +23,14 @@ import android.os.SystemProperties; import android.provider.Settings; import android.support.annotation.VisibleForTesting; import android.support.v7.preference.PreferenceScreen; + import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.deletionhelper.ActivationWarningFragment; import com.android.settings.widget.MasterSwitchController; import com.android.settings.widget.MasterSwitchPreference; import com.android.settings.widget.SwitchWidgetController; +import com.android.settingslib.Utils; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.lifecycle.LifecycleObserver; @@ -74,9 +76,7 @@ public class AutomaticStorageManagementSwitchPreferenceController extends if (!isAvailable()) { return; } - boolean isStorageManagerEnabled = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0; - mSwitch.setChecked(isStorageManagerEnabled); + mSwitch.setChecked(Utils.isStorageManagerEnabled(mContext)); if (mSwitch != null) { mSwitchController = new MasterSwitchController(mSwitch); @@ -97,9 +97,9 @@ public class AutomaticStorageManagementSwitchPreferenceController extends SystemProperties.getBoolean(STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, false); final boolean storageManagerDisabledByPolicy = Settings.Secure.getInt( - mContext.getContentResolver(), - Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY, - 0) + mContext.getContentResolver(), + Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY, + 0) != 0; // Show warning if it is disabled by default and turning it on or if it was disabled by // policy and we're turning it on. From a5bbad439ce347a371b77c3cf1269a8e48c5a12c Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Wed, 14 Feb 2018 13:15:19 -0800 Subject: [PATCH 5/5] Add android.permission.MANAGE_SCOPED_ACCESS_DIRECTORY_PERMISSIONS This permission is required to access the ScopedAccessProvider. Although Settings doesn't currently needs it because it has implicit access because it runs as UID 1000, it's better to explicitly grant it. Bug: 72055774 Test: atest CtsAppSecurityHostTestCases:ScopedDirectoryAccessTest#testResetDoNotAskAgain,testResetGranted Change-Id: I843d7e4a1f674b4e012ac7f744d6ffccadde5a24 --- AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index dec12ba4e5c..0d556f8eaa5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -92,6 +92,7 @@ +