Merge "Update the logic for logging anomaly information to WW." into main
diff --git a/Android.bp b/Android.bp
index a9c3ea0..b716117 100644
--- a/Android.bp
+++ b/Android.bp
@@ -90,6 +90,7 @@
"MediaDrmSettingsFlagsLib",
"Settings-change-ids",
"SettingsLib",
+ "SettingsLibDataStore",
"SettingsLibActivityEmbedding",
"aconfig_settings_flags_lib",
"accessibility_settings_flags_lib",
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9a8aa75..927f38e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -4698,22 +4698,6 @@
</activity>
<activity
- android:name="Settings$AudioStreamConfirmDialogActivity"
- android:exported="true"
- android:theme="@style/Transparent"
- android:permission="android.permission.BLUETOOTH_CONNECT"
- android:configChanges="orientation|keyboardHidden|screenSize">
- <intent-filter android:priority="1">
- <action android:name="android.settings.AUDIO_STREAM_DIALOG" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialog" />
- <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
- android:value="true" />
- </activity>
-
- <activity
android:name=".Settings$PreviouslyConnectedDeviceActivity"
android:label="@string/connected_device_saved_title"
android:exported="true"
@@ -5068,16 +5052,6 @@
</activity>
<activity
- android:name="com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeActivity"
- android:permission="android.permission.BLUETOOTH_CONNECT"
- android:exported="false">
- <intent-filter>
- <action android:name="android.settings.BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER"/>
- <category android:name="android.intent.category.DEFAULT"/>
- </intent-filter>
- </activity>
-
- <activity
android:name=".spa.SpaActivity"
android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize"
android:knownActivityEmbeddingCerts="@array/config_known_host_certs"
diff --git a/res/drawable/ic_bt_audio_sharing.xml b/res/drawable/ic_bt_audio_sharing.xml
deleted file mode 100644
index 6186773..0000000
--- a/res/drawable/ic_bt_audio_sharing.xml
+++ /dev/null
@@ -1,87 +0,0 @@
-<!--
- ~ Copyright (C) 2023 The Android Open Source Project
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:autoMirrored="true"
- android:height="24dp"
- android:width="24dp"
- android:viewportHeight="24"
- android:viewportWidth="24"
- android:tint="?android:attr/colorControlNormal">
- <path
- android:fillColor="#000000"
- android:pathData="M16.984,24H7.279L12.131,15.508L16.984,24ZM10.481,22.144H13.781L12.131,19.257L10.481,22.144Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M12.131,14.295C13.471,14.295 14.558,13.209 14.558,11.869C14.558,10.529 13.471,9.442 12.131,9.442C10.791,9.442 9.705,10.529 9.705,11.869C9.705,13.209 10.791,14.295 12.131,14.295Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M4.573,21.368C4.052,20.943 3.967,20.179 4.379,19.657C4.804,19.136 5.568,19.051 6.09,19.463C6.611,19.876 6.696,20.64 6.284,21.174C6.041,21.465 5.689,21.623 5.338,21.623C5.071,21.623 4.804,21.538 4.573,21.368Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M17.991,21.162C17.579,20.628 17.663,19.876 18.185,19.451C18.707,19.039 19.471,19.124 19.896,19.646C20.308,20.167 20.223,20.931 19.702,21.344C19.471,21.526 19.204,21.611 18.949,21.611C18.586,21.611 18.234,21.453 17.991,21.162Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M1.213,17.145C0.91,16.551 1.165,15.823 1.771,15.532C2.378,15.241 3.093,15.495 3.397,16.09C3.688,16.697 3.433,17.424 2.827,17.715C2.657,17.8 2.475,17.837 2.305,17.837C1.844,17.837 1.419,17.582 1.213,17.145Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M21.449,17.691C20.842,17.4 20.588,16.684 20.879,16.077C21.17,15.471 21.898,15.216 22.504,15.507C23.099,15.798 23.354,16.526 23.062,17.133C22.856,17.557 22.419,17.812 21.971,17.812C21.789,17.812 21.619,17.776 21.449,17.691Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M0,11.892C0,11.225 0.546,10.679 1.213,10.679C1.88,10.679 2.426,11.212 2.426,11.892C2.426,12.559 1.88,13.105 1.213,13.105C0.546,13.105 0,12.559 0,11.892Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M21.837,11.869C21.837,11.857 21.837,11.845 21.837,11.833C21.824,11.153 22.37,10.62 23.05,10.607C23.717,10.607 24.251,11.153 24.263,11.821C24.263,11.833 24.263,11.845 24.263,11.845C24.263,11.857 24.263,11.869 24.263,11.869C24.263,12.536 23.717,13.082 23.05,13.082C22.382,13.082 21.837,12.536 21.837,11.869Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M1.759,8.242C1.152,7.963 0.898,7.235 1.189,6.628C1.48,6.022 2.196,5.767 2.802,6.058C3.409,6.349 3.664,7.077 3.372,7.684C3.166,8.108 2.729,8.363 2.281,8.363C2.099,8.363 1.929,8.327 1.759,8.242Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M20.866,7.622C20.563,7.028 20.818,6.3 21.424,6.009C22.019,5.706 22.747,5.96 23.038,6.567C23.038,6.567 23.038,6.567 23.05,6.567C23.341,7.161 23.087,7.889 22.48,8.181C22.31,8.265 22.128,8.302 21.958,8.302C21.509,8.302 21.073,8.059 20.866,7.622Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M4.355,4.104C3.931,3.582 4.016,2.818 4.537,2.406C5.071,1.981 5.823,2.066 6.248,2.588C6.672,3.109 6.588,3.874 6.066,4.298C5.835,4.48 5.569,4.565 5.302,4.565C4.95,4.565 4.598,4.407 4.355,4.104Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M18.161,4.262C17.627,3.838 17.542,3.073 17.955,2.552C18.379,2.03 19.132,1.945 19.666,2.358C20.187,2.77 20.272,3.534 19.86,4.068C19.617,4.359 19.265,4.517 18.913,4.517C18.646,4.517 18.379,4.432 18.161,4.262Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M8.492,1.497C8.334,0.854 8.747,0.199 9.402,0.041C10.057,-0.105 10.7,0.308 10.858,0.963C11.003,1.606 10.591,2.261 9.948,2.407C9.851,2.431 9.754,2.443 9.669,2.443C9.123,2.443 8.613,2.067 8.492,1.497Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M14.267,2.395C13.599,2.249 13.199,1.606 13.345,0.951C13.49,0.296 14.133,-0.116 14.788,0.029C15.443,0.175 15.856,0.83 15.71,1.485C15.589,2.043 15.08,2.431 14.534,2.431C14.437,2.431 14.352,2.419 14.267,2.395Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M7,17.037C6.527,16.564 6.527,15.8 7,15.326C7.473,14.841 8.237,14.841 8.71,15.314C9.196,15.787 9.196,16.552 8.723,17.025C8.48,17.267 8.177,17.389 7.861,17.389C7.546,17.389 7.242,17.267 7,17.037Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M15.565,17.012C15.092,16.539 15.092,15.762 15.565,15.289C16.038,14.816 16.814,14.816 17.288,15.289C17.761,15.762 17.761,16.539 17.288,17.012C17.045,17.243 16.742,17.364 16.426,17.364C16.111,17.364 15.807,17.243 15.565,17.012Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M4.853,11.917C4.853,11.237 5.386,10.691 6.054,10.691C6.721,10.691 7.279,11.225 7.279,11.892C7.279,12.56 6.745,13.106 6.078,13.118C5.398,13.118 4.853,12.584 4.853,11.917Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M16.984,11.868C16.984,11.856 16.984,11.844 16.984,11.832C16.984,11.832 16.984,11.82 16.984,11.807C16.972,11.14 17.506,10.582 18.185,10.582C18.852,10.57 19.398,11.116 19.41,11.783C19.41,11.795 19.41,11.82 19.41,11.832C19.41,11.844 19.41,11.856 19.41,11.868C19.41,12.535 18.865,13.081 18.197,13.081C17.53,13.081 16.984,12.535 16.984,11.868Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M6.952,8.471C6.478,7.997 6.478,7.233 6.952,6.76C6.952,6.76 6.952,6.76 6.939,6.76C7.413,6.275 8.189,6.275 8.662,6.748C9.135,7.221 9.147,7.985 8.674,8.458C8.432,8.701 8.116,8.822 7.813,8.822C7.497,8.822 7.194,8.701 6.952,8.471Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M15.529,8.399C15.043,7.938 15.043,7.161 15.504,6.688C15.977,6.203 16.742,6.203 17.227,6.664C17.7,7.137 17.712,7.901 17.239,8.387C17.009,8.629 16.693,8.751 16.378,8.751C16.075,8.751 15.759,8.629 15.529,8.399Z"/>
- <path
- android:fillColor="#000000"
- android:pathData="M10.87,5.815C10.858,5.148 11.392,4.59 12.071,4.59C12.738,4.578 13.284,5.124 13.284,5.791C13.296,6.458 12.762,7.016 12.083,7.016C11.416,7.016 10.87,6.483 10.87,5.815Z"/>
-</vector>
diff --git a/res/layout/preference_widget_lock.xml b/res/layout/preference_widget_lock.xml
deleted file mode 100644
index a5ee455..0000000
--- a/res/layout/preference_widget_lock.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2023 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<!-- A lock icon for preference in the audio streams page. -->
-<ImageView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/lock_icon"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center"
- android:paddingStart="24dp"
- android:paddingEnd="24dp"
- android:background="?android:attr/selectableItemBackground"
- android:scaleType="center"
- android:src="@drawable/ic_lock_closed"
- android:importantForAccessibility="no" />
-
diff --git a/res/xml/accessibility_hearing_aids.xml b/res/xml/accessibility_hearing_aids.xml
index 57a0fe2..9c6e661 100644
--- a/res/xml/accessibility_hearing_aids.xml
+++ b/res/xml/accessibility_hearing_aids.xml
@@ -32,6 +32,7 @@
android:title="@string/bluetooth_pairing_pref_title"
android:icon="@drawable/ic_add_24dp"
android:summary="@string/connected_device_add_device_summary"
+ android:fragment="com.android.settings.accessibility.HearingDevicePairingFragment"
settings:userRestriction="no_config_bluetooth"
settings:useAdminDisabledSummary="true"
settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
diff --git a/res/xml/audio_stream_details_fragment.xml b/res/xml/audio_stream_details_fragment.xml
deleted file mode 100644
index 2a84939..0000000
--- a/res/xml/audio_stream_details_fragment.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (C) 2023 The Android Open Source Project
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto"
- android:title="Audio stream details">
-
- <com.android.settingslib.widget.LayoutPreference
- android:key="audio_stream_header"
- android:layout="@layout/settings_entity_header"
- android:selectable="false"
- settings:allowDividerBelow="true"
- settings:searchable="false"
- settings:controller="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamHeaderController" />
-
- <com.android.settingslib.widget.ActionButtonsPreference
- android:key="audio_stream_button"
- settings:allowDividerBelow="true"
- settings:controller="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamButtonController" />
-
-</PreferenceScreen>
diff --git a/res/xml/bluetooth_audio_streams_dialog.xml b/res/xml/bluetooth_audio_streams_dialog.xml
deleted file mode 100644
index 024e537..0000000
--- a/res/xml/bluetooth_audio_streams_dialog.xml
+++ /dev/null
@@ -1,101 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (C) 2024 The Android Open Source Project
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <LinearLayout
- android:id="@+id/dialog_bg"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingStart="25dp"
- android:paddingEnd="25dp"
- android:orientation="vertical">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="25dp"
- android:orientation="vertical">
-
- <ImageView
- android:id="@+id/dialog_icon"
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginTop="24dp"
- android:layout_gravity="center"
- android:src="@drawable/ic_bt_audio_sharing"/>
-
- <TextView
- android:id="@+id/dialog_title"
- android:textAppearance="@android:style/TextAppearance.DeviceDefault.Headline"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:gravity="center"
- android:layout_gravity="center"/>
-
- <TextView
- android:id="@+id/dialog_subtitle"
- android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
- android:textStyle="bold"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:gravity="center"
- android:layout_gravity="center"
- android:visibility="gone"/>
-
- <TextView
- android:id="@+id/dialog_subtitle_2"
- android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:gravity="center"
- android:layout_gravity="center"
- android:visibility="gone"/>
- </LinearLayout>
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="@dimen/broadcast_dialog_margin">
- <Button
- android:id="@+id/left_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:visibility="gone"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- style="@style/BroadcastActionButton"/>
- <Button
- android:id="@+id/right_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:visibility="gone"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- style="@style/BroadcastActionButton"/>
- </androidx.constraintlayout.widget.ConstraintLayout>
-
- </LinearLayout>
-</FrameLayout>
\ No newline at end of file
diff --git a/res/xml/bluetooth_audio_streams_qr_code.xml b/res/xml/bluetooth_audio_streams_qr_code.xml
deleted file mode 100644
index 50b1429..0000000
--- a/res/xml/bluetooth_audio_streams_qr_code.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (C) 2023 The Android Open Source Project
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:clipToPadding="false"
- android:paddingLeft="25dp"
- android:paddingRight="25dp"
- android:gravity="center_horizontal"
- android:orientation="vertical">
-
- <TextView
- android:id="@android:id/summary"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="start"
- android:textSize="15sp"
- android:textColor="?android:attr/textColorPrimary"
- android:text="To listen to this audio stream, other people can connect compatible headphones to their Android device. They can then scan this QR code."/>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:orientation="vertical"
- android:paddingTop="70dp">
-
- <ImageView
- android:id="@+id/qrcode_view"
- android:layout_width="@dimen/qrcode_size"
- android:layout_height="@dimen/qrcode_size"
- android:src="@android:color/transparent"/>
-
- <TextView
- android:id="@+id/password"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="15sp"
- android:textColor="?android:attr/textColorPrimary"/>
- </LinearLayout>
-
- </LinearLayout>
-
-</LinearLayout>
\ No newline at end of file
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 92e3efd..2f6f04a 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -403,7 +403,6 @@
public static class StylusUsiDetailsActivity extends SettingsActivity { /* empty */ }
public static class BluetoothBroadcastActivity extends SettingsActivity { /* empty */ }
public static class BluetoothFindBroadcastsActivity extends SettingsActivity { /* empty */ }
- public static class AudioStreamConfirmDialogActivity extends SettingsActivity { /* empty */ }
public static class WifiCallingDisclaimerActivity extends SettingsActivity { /* empty */ }
public static class MobileNetworkListActivity extends SettingsActivity {}
public static class PowerMenuSettingsActivity extends SettingsActivity {}
diff --git a/src/com/android/settings/SettingsApplication.java b/src/com/android/settings/SettingsApplication.java
index 528576d..1a53b83 100644
--- a/src/com/android/settings/SettingsApplication.java
+++ b/src/com/android/settings/SettingsApplication.java
@@ -28,11 +28,13 @@
import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.core.instrumentation.ElapsedTimeUtils;
+import com.android.settings.fuelgauge.BatterySettingsStorage;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.FeatureFactoryImpl;
import com.android.settings.spa.SettingsSpaEnvironment;
import com.android.settingslib.applications.AppIconCacheManager;
+import com.android.settingslib.datastore.BackupRestoreStorageManager;
import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory;
import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -54,6 +56,8 @@
public void onCreate() {
super.onCreate();
+ BackupRestoreStorageManager.getInstance(this).add(new BatterySettingsStorage(this));
+
// Add null checking to avoid test case failed.
if (getApplicationContext() != null) {
ElapsedTimeUtils.assignSuwFinishedTimeStamp(getApplicationContext());
@@ -73,6 +77,12 @@
}
}
+ @Override
+ public void onTerminate() {
+ BackupRestoreStorageManager.getInstance(this).removeAll();
+ super.onTerminate();
+ }
+
@NonNull
protected FeatureFactory getFeatureFactory() {
return new FeatureFactoryImpl();
diff --git a/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java b/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java
index 80a03c6..cad2186 100644
--- a/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityHearingAidsFragment.java
@@ -38,7 +38,6 @@
public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPreferenceFragment {
private static final String TAG = "AccessibilityHearingAidsFragment";
private static final String KEY_HEARING_OPTIONS_CATEGORY = "hearing_options_category";
- public static final String KEY_HEARING_DEVICE_ADD_BT_DEVICES = "hearing_device_add_bt_devices";
private static final int SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX = 20;
private String mFeatureName;
diff --git a/src/com/android/settings/accessibility/HearingDevicePairingDetail.java b/src/com/android/settings/accessibility/HearingDevicePairingDetail.java
deleted file mode 100644
index 117a8ed..0000000
--- a/src/com/android/settings/accessibility/HearingDevicePairingDetail.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.accessibility;
-
-import android.app.settings.SettingsEnums;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothUuid;
-import android.bluetooth.le.ScanFilter;
-import android.content.Context;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settings.R;
-import com.android.settings.bluetooth.BluetoothDevicePairingDetailBase;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * HearingDevicePairingDetail is a page to scan hearing devices. This page shows scanning icons and
- * pairing them.
- */
-public class HearingDevicePairingDetail extends BluetoothDevicePairingDetailBase {
-
- private static final String TAG = "HearingDevicePairingDetail";
- @VisibleForTesting
- static final String KEY_AVAILABLE_HEARING_DEVICES = "available_hearing_devices";
-
- public HearingDevicePairingDetail() {
- super();
- final List<ScanFilter> filterList = new ArrayList<>();
- // Filters for ASHA hearing aids
- filterList.add(new ScanFilter.Builder().setServiceUuid(BluetoothUuid.HEARING_AID).build());
- filterList.add(new ScanFilter.Builder()
- .setServiceData(BluetoothUuid.HEARING_AID, new byte[0]).build());
- // Filters for LE audio hearing aids
- filterList.add(new ScanFilter.Builder().setServiceUuid(BluetoothUuid.HAS).build());
- filterList.add(new ScanFilter.Builder()
- .setServiceData(BluetoothUuid.HAS, new byte[0]).build());
- setFilter(filterList);
- }
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- use(ViewAllBluetoothDevicesPreferenceController.class).init(this);
- }
-
- @Override
- public void onStart() {
- super.onStart();
- mAvailableDevicesCategory.setProgress(mBluetoothAdapter.isEnabled());
- }
-
- @Override
- public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
- super.onDeviceBondStateChanged(cachedDevice, bondState);
-
- mAvailableDevicesCategory.setProgress(bondState == BluetoothDevice.BOND_NONE);
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.HEARING_AID_PAIRING;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.hearing_device_pairing_detail;
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- @Override
- public String getDeviceListKey() {
- return KEY_AVAILABLE_HEARING_DEVICES;
- }
-}
diff --git a/src/com/android/settings/backup/SettingsBackupHelper.java b/src/com/android/settings/backup/SettingsBackupHelper.java
index ecf4c71..0861af2 100644
--- a/src/com/android/settings/backup/SettingsBackupHelper.java
+++ b/src/com/android/settings/backup/SettingsBackupHelper.java
@@ -22,10 +22,10 @@
import android.app.backup.SharedPreferencesBackupHelper;
import com.android.settings.flags.Flags;
-import com.android.settings.fuelgauge.BatteryBackupHelper;
import com.android.settings.onboarding.OnboardingFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.shortcut.CreateShortcutPreferenceController;
+import com.android.settingslib.datastore.BackupRestoreStorageManager;
/** Backup agent for Settings APK */
public class SettingsBackupHelper extends BackupAgentHelper {
@@ -35,7 +35,7 @@
@Override
public void onCreate() {
super.onCreate();
- addHelper(BatteryBackupHelper.TAG, new BatteryBackupHelper(this));
+ BackupRestoreStorageManager.getInstance(this).addBackupAgentHelpers(this);
addHelper(PREF_LOCALE_NOTIFICATION,
new SharedPreferencesBackupHelper(this, LOCALE_NOTIFICATION));
if (Flags.enableSoundBackup()) {
@@ -51,6 +51,7 @@
@Override
public void onRestoreFinished() {
super.onRestoreFinished();
+ BackupRestoreStorageManager.getInstance(this).onRestoreFinished();
CreateShortcutPreferenceController.updateRestoredShortcuts(this);
}
}
diff --git a/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java b/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
index 3a16e3e..73c7d73 100644
--- a/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
+++ b/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
@@ -28,11 +28,9 @@
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
-import com.android.settings.accessibility.HearingDevicePairingDetail;
import com.android.settings.accessibility.HearingDevicePairingFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.flags.Flags;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -125,11 +123,8 @@
final int launchPage = getArguments().getInt(KEY_LAUNCH_PAGE);
final boolean launchFromA11y = (launchPage == SettingsEnums.ACCESSIBILITY)
|| (launchPage == SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS);
- final String a11yDestination = Flags.newHearingDevicePairingPage()
- ? HearingDevicePairingFragment.class.getName()
- : HearingDevicePairingDetail.class.getName();
final String destination = launchFromA11y
- ? a11yDestination
+ ? HearingDevicePairingFragment.class.getName()
: BluetoothPairingDetail.class.getName();
new SubSettingLauncher(getActivity())
.setDestination(destination)
diff --git a/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java b/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java
index a0b249d..a023420 100644
--- a/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java
+++ b/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java
@@ -18,6 +18,7 @@
import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.EXTRA_BLUETOOTH_DEVICE_SINK;
import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.EXTRA_BLUETOOTH_SINK_IS_GROUP;
+import static com.android.settingslib.flags.Flags.legacyLeAudioSharing;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
@@ -53,6 +54,10 @@
@Override
protected void handleIntent(Intent intent) {
+ if (!legacyLeAudioSharing()) {
+ finish();
+ }
+
String action = intent != null ? intent.getAction() : null;
if (DEBUG) {
Log.d(TAG, "handleIntent(), action = " + action);
diff --git a/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java b/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
index ef44843..d2bc319 100644
--- a/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
+++ b/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
@@ -15,25 +15,18 @@
*/
package com.android.settings.connecteddevice;
-import static com.android.settings.accessibility.AccessibilityHearingAidsFragment.KEY_HEARING_DEVICE_ADD_BT_DEVICES;
-
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
-import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.accessibility.HearingDevicePairingDetail;
-import com.android.settings.accessibility.HearingDevicePairingFragment;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.flags.Flags;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -83,21 +76,6 @@
}
@Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_ADD_BT_DEVICES)) {
- String destination = Flags.newHearingDevicePairingPage()
- ? HearingDevicePairingFragment.class.getName()
- : HearingDevicePairingDetail.class.getName();
- new SubSettingLauncher(preference.getContext())
- .setDestination(destination)
- .setSourceMetricsCategory(getMetricsCategory())
- .launch();
- return true;
- }
- return super.handlePreferenceTreeClick(preference);
- }
-
- @Override
public int getAvailabilityStatus() {
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
? AVAILABLE
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 6b04d3c..6ef5aa8 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -20,7 +20,6 @@
import android.app.Activity;
import android.app.ActivityManager;
-import android.app.backup.BackupManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
@@ -53,6 +52,7 @@
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.Instrumentable;
+import com.android.settingslib.datastore.ChangeReason;
import com.android.settingslib.widget.LayoutPreference;
import java.util.ArrayList;
@@ -105,7 +105,6 @@
@VisibleForTesting @BatteryOptimizeUtils.OptimizationMode
int mOptimizationMode = BatteryOptimizeUtils.MODE_UNKNOWN;
- @VisibleForTesting BackupManager mBackupManager;
@VisibleForTesting StringBuilder mLogStringBuilder;
// A wrapper class to carry LaunchBatteryDetailPage required arguments.
@@ -293,9 +292,7 @@
@VisibleForTesting
void notifyBackupManager() {
if (mOptimizationMode != mBatteryOptimizeUtils.getAppOptimizationMode()) {
- final BackupManager backupManager =
- mBackupManager != null ? mBackupManager : new BackupManager(getContext());
- backupManager.dataChanged();
+ BatterySettingsStorage.get(getContext()).notifyChange(ChangeReason.UPDATE);
}
}
diff --git a/src/com/android/settings/fuelgauge/BatterySettingsStorage.java b/src/com/android/settings/fuelgauge/BatterySettingsStorage.java
new file mode 100644
index 0000000..ff3223f
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatterySettingsStorage.java
@@ -0,0 +1,370 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.fuelgauge;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import android.app.AppGlobals;
+import android.app.AppOpsManager;
+import android.app.Application;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
+import android.os.Build;
+import android.os.IDeviceIdleController;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.datastore.BackupContext;
+import com.android.settingslib.datastore.BackupRestoreEntity;
+import com.android.settingslib.datastore.BackupRestoreStorageManager;
+import com.android.settingslib.datastore.EntityBackupResult;
+import com.android.settingslib.datastore.ObservableBackupRestoreStorage;
+import com.android.settingslib.datastore.RestoreContext;
+import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/** An implementation to backup and restore battery configurations. */
+public final class BatterySettingsStorage extends ObservableBackupRestoreStorage {
+ public static final String TAG = "BatteryBackupHelper";
+
+ // Definition for the device build information.
+ public static final String KEY_BUILD_BRAND = "device_build_brand";
+ public static final String KEY_BUILD_PRODUCT = "device_build_product";
+ public static final String KEY_BUILD_MANUFACTURER = "device_build_manufacture";
+ public static final String KEY_BUILD_FINGERPRINT = "device_build_fingerprint";
+ // Customized fields for device extra information.
+ public static final String KEY_BUILD_METADATA_1 = "device_build_metadata_1";
+ public static final String KEY_BUILD_METADATA_2 = "device_build_metadata_2";
+
+ private static final String DEVICE_IDLE_SERVICE = "deviceidle";
+ private static final String BATTERY_OPTIMIZE_BACKUP_FILE_NAME =
+ "battery_optimize_backup_historical_logs";
+ private static final int DEVICE_BUILD_INFO_SIZE = 6;
+
+ static final String DELIMITER = ",";
+ static final String DELIMITER_MODE = ":";
+ static final String KEY_OPTIMIZATION_LIST = "optimization_mode_list";
+
+ @Nullable private byte[] mOptimizationModeBytes;
+
+ private final Application mApplication;
+ // Device information map from restore.
+ private final ArrayMap<String, String> mDeviceBuildInfoMap =
+ new ArrayMap<>(DEVICE_BUILD_INFO_SIZE);
+
+ /**
+ * Returns the {@link BatterySettingsStorage} registered to {@link BackupRestoreStorageManager}.
+ */
+ public static @NonNull BatterySettingsStorage get(@NonNull Context context) {
+ return (BatterySettingsStorage)
+ BackupRestoreStorageManager.getInstance(context).getOrThrow(TAG);
+ }
+
+ public BatterySettingsStorage(@NonNull Context context) {
+ mApplication = (Application) context.getApplicationContext();
+ }
+
+ @NonNull
+ @Override
+ public String getName() {
+ return TAG;
+ }
+
+ @Override
+ public boolean enableBackup(@NonNull BackupContext backupContext) {
+ return isOwner();
+ }
+
+ @Override
+ public boolean enableRestore() {
+ return isOwner();
+ }
+
+ static boolean isOwner() {
+ return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
+ }
+
+ @NonNull
+ @Override
+ public List<BackupRestoreEntity> createBackupRestoreEntities() {
+ List<String> allowlistedApps = getFullPowerList();
+ if (allowlistedApps == null) {
+ return Collections.emptyList();
+ }
+ PowerUsageFeatureProvider provider =
+ FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider();
+ return Arrays.asList(
+ new StringEntity(KEY_BUILD_BRAND, Build.BRAND),
+ new StringEntity(KEY_BUILD_PRODUCT, Build.PRODUCT),
+ new StringEntity(KEY_BUILD_MANUFACTURER, Build.MANUFACTURER),
+ new StringEntity(KEY_BUILD_FINGERPRINT, Build.FINGERPRINT),
+ new StringEntity(KEY_BUILD_METADATA_1, provider.getBuildMetadata1(mApplication)),
+ new StringEntity(KEY_BUILD_METADATA_2, provider.getBuildMetadata2(mApplication)),
+ new OptimizationModeEntity(allowlistedApps));
+ }
+
+ private @Nullable List<String> getFullPowerList() {
+ final long timestamp = System.currentTimeMillis();
+ String[] allowlistedApps;
+ try {
+ IDeviceIdleController deviceIdleController =
+ IDeviceIdleController.Stub.asInterface(
+ ServiceManager.getService(DEVICE_IDLE_SERVICE));
+ allowlistedApps = deviceIdleController.getFullPowerWhitelist();
+ } catch (RemoteException e) {
+ Log.e(TAG, "backupFullPowerList() failed", e);
+ return null;
+ }
+ // Ignores unexpected empty result case.
+ if (allowlistedApps == null || allowlistedApps.length == 0) {
+ Log.w(TAG, "no data found in the getFullPowerList()");
+ return Collections.emptyList();
+ }
+ Log.d(
+ TAG,
+ String.format(
+ "getFullPowerList() size=%d in %d/ms",
+ allowlistedApps.length, (System.currentTimeMillis() - timestamp)));
+ return Arrays.asList(allowlistedApps);
+ }
+
+ @Override
+ public void writeNewStateDescription(@NonNull ParcelFileDescriptor newState) {
+ BatterySettingsMigrateChecker.verifySaverConfiguration(mApplication);
+ performRestoreIfNeeded();
+ }
+
+ private void performRestoreIfNeeded() {
+ byte[] bytes = mOptimizationModeBytes;
+ mOptimizationModeBytes = null; // clear data
+ if (bytes == null || bytes.length == 0) {
+ return;
+ }
+ final PowerUsageFeatureProvider provider =
+ FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider();
+ if (!provider.isValidToRestoreOptimizationMode(mDeviceBuildInfoMap)) {
+ return;
+ }
+ // Start to restore the app optimization mode data.
+ final int restoreCount = restoreOptimizationMode(bytes);
+ if (restoreCount > 0) {
+ BatterySettingsMigrateChecker.verifyBatteryOptimizeModes(mApplication);
+ }
+ }
+
+ int restoreOptimizationMode(byte[] dataBytes) {
+ final long timestamp = System.currentTimeMillis();
+ final String dataContent = new String(dataBytes, UTF_8);
+ if (dataContent.isEmpty()) {
+ Log.w(TAG, "no data found in the restoreOptimizationMode()");
+ return 0;
+ }
+ final String[] appConfigurations = dataContent.split(BatteryBackupHelper.DELIMITER);
+ if (appConfigurations.length == 0) {
+ Log.w(TAG, "no data found from the split() processing");
+ return 0;
+ }
+ int restoreCount = 0;
+ for (String appConfiguration : appConfigurations) {
+ final String[] results = appConfiguration.split(BatteryBackupHelper.DELIMITER_MODE);
+ // Example format: com.android.systemui:2 we should have length=2
+ if (results.length != 2) {
+ Log.w(TAG, "invalid raw data found:" + appConfiguration);
+ continue;
+ }
+ final String packageName = results[0];
+ final int uid = BatteryUtils.getInstance(mApplication).getPackageUid(packageName);
+ // Ignores system/default apps.
+ if (isSystemOrDefaultApp(packageName, uid)) {
+ Log.w(TAG, "ignore from isSystemOrDefaultApp():" + packageName);
+ continue;
+ }
+ @BatteryOptimizeUtils.OptimizationMode int optimizationMode;
+ try {
+ optimizationMode = Integer.parseInt(results[1]);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "failed to parse the optimization mode: " + appConfiguration, e);
+ continue;
+ }
+ restoreOptimizationMode(packageName, optimizationMode);
+ restoreCount++;
+ }
+ Log.d(
+ TAG,
+ String.format(
+ "restoreOptimizationMode() count=%d in %d/ms",
+ restoreCount, (System.currentTimeMillis() - timestamp)));
+ return restoreCount;
+ }
+
+ private void restoreOptimizationMode(
+ String packageName, @BatteryOptimizeUtils.OptimizationMode int mode) {
+ final BatteryOptimizeUtils batteryOptimizeUtils =
+ newBatteryOptimizeUtils(mApplication, packageName);
+ if (batteryOptimizeUtils == null) {
+ return;
+ }
+ batteryOptimizeUtils.setAppUsageState(
+ mode, BatteryOptimizeHistoricalLogEntry.Action.RESTORE);
+ Log.d(TAG, String.format("restore:%s mode=%d", packageName, mode));
+ }
+
+ @Nullable
+ static BatteryOptimizeUtils newBatteryOptimizeUtils(Context context, String packageName) {
+ final int uid = BatteryUtils.getInstance(context).getPackageUid(packageName);
+ return uid == BatteryUtils.UID_NULL
+ ? null
+ : new BatteryOptimizeUtils(context, uid, packageName);
+ }
+
+ private boolean isSystemOrDefaultApp(String packageName, int uid) {
+ return BatteryOptimizeUtils.isSystemOrDefaultApp(
+ mApplication, PowerAllowlistBackend.getInstance(mApplication), packageName, uid);
+ }
+
+ private class StringEntity implements BackupRestoreEntity {
+ private final String mKey;
+ private final String mValue;
+
+ StringEntity(String key, String value) {
+ this.mKey = key;
+ this.mValue = value;
+ }
+
+ @NonNull
+ @Override
+ public String getKey() {
+ return mKey;
+ }
+
+ @Override
+ public @NonNull EntityBackupResult backup(
+ @NonNull BackupContext backupContext, @NonNull OutputStream outputStream)
+ throws IOException {
+ Log.d(TAG, String.format("backup:%s:%s", mKey, mValue));
+ outputStream.write(mValue.getBytes(UTF_8));
+ return EntityBackupResult.UPDATE;
+ }
+
+ @Override
+ public void restore(
+ @NonNull RestoreContext restoreContext, @NonNull InputStream inputStream)
+ throws IOException {
+ String dataContent = new String(inputStream.readAllBytes(), UTF_8);
+ mDeviceBuildInfoMap.put(mKey, dataContent);
+ Log.d(TAG, String.format("restore:%s:%s", mKey, dataContent));
+ }
+ }
+
+ private class OptimizationModeEntity implements BackupRestoreEntity {
+ private final List<String> mAllowlistedApps;
+
+ private OptimizationModeEntity(List<String> allowlistedApps) {
+ this.mAllowlistedApps = allowlistedApps;
+ }
+
+ @NonNull
+ @Override
+ public String getKey() {
+ return KEY_OPTIMIZATION_LIST;
+ }
+
+ @Override
+ public @NonNull EntityBackupResult backup(
+ @NonNull BackupContext backupContext, @NonNull OutputStream outputStream)
+ throws IOException {
+ final long timestamp = System.currentTimeMillis();
+ final ArraySet<ApplicationInfo> applications = getInstalledApplications();
+ if (applications == null || applications.isEmpty()) {
+ Log.w(TAG, "no data found in the getInstalledApplications()");
+ return EntityBackupResult.DELETE;
+ }
+ int backupCount = 0;
+ final StringBuilder builder = new StringBuilder();
+ final AppOpsManager appOps = mApplication.getSystemService(AppOpsManager.class);
+ final SharedPreferences sharedPreferences = getSharedPreferences(mApplication);
+ // Converts application into the AppUsageState.
+ for (ApplicationInfo info : applications) {
+ final int mode = BatteryOptimizeUtils.getMode(appOps, info.uid, info.packageName);
+ @BatteryOptimizeUtils.OptimizationMode
+ final int optimizationMode =
+ BatteryOptimizeUtils.getAppOptimizationMode(
+ mode, mAllowlistedApps.contains(info.packageName));
+ // Ignores default optimized/unknown state or system/default apps.
+ if (optimizationMode == BatteryOptimizeUtils.MODE_OPTIMIZED
+ || optimizationMode == BatteryOptimizeUtils.MODE_UNKNOWN
+ || isSystemOrDefaultApp(info.packageName, info.uid)) {
+ continue;
+ }
+ final String packageOptimizeMode =
+ info.packageName + DELIMITER_MODE + optimizationMode;
+ builder.append(packageOptimizeMode).append(DELIMITER);
+ Log.d(TAG, "backupOptimizationMode: " + packageOptimizeMode);
+ BatteryOptimizeLogUtils.writeLog(
+ sharedPreferences,
+ Action.BACKUP,
+ info.packageName,
+ /* actionDescription */ "mode: " + optimizationMode);
+ backupCount++;
+ }
+
+ outputStream.write(builder.toString().getBytes(UTF_8));
+ Log.d(
+ TAG,
+ String.format(
+ "backup getInstalledApplications():%d count=%d in %d/ms",
+ applications.size(),
+ backupCount,
+ (System.currentTimeMillis() - timestamp)));
+ return EntityBackupResult.UPDATE;
+ }
+
+ private @Nullable ArraySet<ApplicationInfo> getInstalledApplications() {
+ return BatteryOptimizeUtils.getInstalledApplications(
+ mApplication, AppGlobals.getPackageManager());
+ }
+
+ static @NonNull SharedPreferences getSharedPreferences(Context context) {
+ return context.getSharedPreferences(
+ BATTERY_OPTIMIZE_BACKUP_FILE_NAME, Context.MODE_PRIVATE);
+ }
+
+ @Override
+ public void restore(
+ @NonNull RestoreContext restoreContext, @NonNull InputStream inputStream)
+ throws IOException {
+ mOptimizationModeBytes = inputStream.readAllBytes();
+ }
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetail.java b/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetail.java
index 2067456..56702cf 100644
--- a/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetail.java
@@ -19,7 +19,6 @@
import static com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
import android.app.Activity;
-import android.app.backup.BackupManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
@@ -42,6 +41,7 @@
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.datastore.ChangeReason;
import com.android.settingslib.widget.FooterPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.widget.MainSwitchPreference;
@@ -78,7 +78,6 @@
@VisibleForTesting SelectorWithWidgetPreference mUnrestrictedPreference;
@VisibleForTesting MainSwitchPreference mMainSwitchPreference;
@VisibleForTesting FooterPreference mFooterPreference;
- @VisibleForTesting BackupManager mBackupManager;
@VisibleForTesting StringBuilder mLogStringBuilder;
@VisibleForTesting @BatteryOptimizeUtils.OptimizationMode
@@ -187,9 +186,7 @@
@VisibleForTesting
void notifyBackupManager() {
if (mOptimizationMode != mBatteryOptimizeUtils.getAppOptimizationMode()) {
- final BackupManager backupManager =
- mBackupManager != null ? mBackupManager : new BackupManager(getContext());
- backupManager.dataChanged();
+ BatterySettingsStorage.get(getContext()).notifyChange(ChangeReason.UPDATE);
}
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
index 1482117..29839e9 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
@@ -274,8 +274,7 @@
if (!isResumed() || anomalyEventList == null) {
return;
}
- Log.d(TAG, "anomalyEventList = " + anomalyEventList);
-
+ logPowerAnomalyEventList(anomalyEventList);
final Set<String> dismissedPowerAnomalyKeys =
DatabaseUtils.getDismissedPowerAnomalyKeys(getContext());
Log.d(TAG, "dismissedPowerAnomalyKeys = " + dismissedPowerAnomalyKeys);
@@ -429,10 +428,19 @@
.filter(predicate)
.max(Comparator.comparing(PowerAnomalyEvent::getScore))
.orElse(null);
- Log.d(TAG, "filterAnomalyEvent = " + filterAnomalyEvent);
+ Log.d(TAG, "filterAnomalyEvent = "
+ + (filterAnomalyEvent == null ? null : filterAnomalyEvent.getEventId()));
return filterAnomalyEvent;
}
+ private static void logPowerAnomalyEventList(PowerAnomalyEventList anomalyEventList) {
+ final StringBuilder stringBuilder = new StringBuilder();
+ for (PowerAnomalyEvent anomalyEvent : anomalyEventList.getPowerAnomalyEventsList()) {
+ stringBuilder.append(anomalyEvent.getEventId()).append(", ");
+ }
+ Log.d(TAG, "anomalyEventList = [" + stringBuilder + "]");
+ }
+
private static BatteryDiffData getAllBatteryDiffData(
Map<Integer, Map<Integer, BatteryDiffData>> batteryUsageMap) {
return batteryUsageMap == null
diff --git a/src/com/android/settings/network/telephony/SubscriptionRepository.kt b/src/com/android/settings/network/telephony/SubscriptionRepository.kt
index 9a46272..e44b577 100644
--- a/src/com/android/settings/network/telephony/SubscriptionRepository.kt
+++ b/src/com/android/settings/network/telephony/SubscriptionRepository.kt
@@ -17,8 +17,10 @@
package com.android.settings.network.telephony
import android.content.Context
+import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.util.Log
+import com.android.settings.network.SubscriptionUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.channels.awaitClose
@@ -36,6 +38,10 @@
subscriptionManager?.isSubscriptionEnabled(subId) ?: false
}.flowOn(Dispatchers.Default)
+fun Context.phoneNumberFlow(subscriptionInfo: SubscriptionInfo) = subscriptionsChangedFlow().map {
+ SubscriptionUtil.getFormattedPhoneNumber(this, subscriptionInfo)
+}.flowOn(Dispatchers.Default)
+
fun Context.subscriptionsChangedFlow() = callbackFlow {
val subscriptionManager = getSystemService(SubscriptionManager::class.java)!!
diff --git a/src/com/android/settings/spa/network/SimsSection.kt b/src/com/android/settings/spa/network/SimsSection.kt
index cc8a5d1..334ca61 100644
--- a/src/com/android/settings/spa/network/SimsSection.kt
+++ b/src/com/android/settings/spa/network/SimsSection.kt
@@ -33,6 +33,7 @@
import com.android.settings.network.SubscriptionUtil
import com.android.settings.network.telephony.MobileNetworkUtils
import com.android.settings.network.telephony.isSubscriptionEnabledFlow
+import com.android.settings.network.telephony.phoneNumberFlow
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
import com.android.settingslib.spa.widget.preference.TwoTargetSwitchPreference
@@ -57,11 +58,14 @@
val checked = remember(subInfo.subscriptionId) {
context.isSubscriptionEnabledFlow(subInfo.subscriptionId)
}.collectAsStateWithLifecycle(initialValue = false)
+ val phoneNumber = remember(subInfo) {
+ context.phoneNumberFlow(subInfo)
+ }.collectAsStateWithLifecycle(initialValue = null)
//TODO: Add the Restricted TwoTargetSwitchPreference in SPA
TwoTargetSwitchPreference(
object : SwitchPreferenceModel {
override val title = subInfo.displayName.toString()
- override val summary = { subInfo.number }
+ override val summary = { phoneNumber.value ?: "" }
override val checked = { checked.value }
override val onCheckedChange = { newChecked: Boolean ->
SubscriptionUtil.startToggleSubscriptionDialogActivity(
diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
index bd57e9d..d082b1f 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
@@ -32,10 +32,6 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
-import android.platform.test.annotations.RequiresFlagsDisabled;
-import android.platform.test.annotations.RequiresFlagsEnabled;
-import android.platform.test.flag.junit.CheckFlagsRule;
-import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
@@ -47,7 +43,6 @@
import com.android.settings.bluetooth.BluetoothPairingDetail;
import com.android.settings.bluetooth.HearingAidPairingDialogFragment;
import com.android.settings.bluetooth.Utils;
-import com.android.settings.flags.Flags;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -82,9 +77,6 @@
@Rule
public final MockitoRule mockito = MockitoJUnit.rule();
- @Rule
- public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
-
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
private static final int TEST_LAUNCH_PAGE = SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY;
@@ -137,8 +129,7 @@
}
@Test
- @RequiresFlagsEnabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
- public void dialogPositiveButtonClick_intentToNewA11yPairingPage() {
+ public void dialogPositiveButtonClick_intentToA11yPairingPage() {
setupDialog(SettingsEnums.ACCESSIBILITY);
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
dialog.show();
@@ -151,20 +142,6 @@
}
@Test
- @RequiresFlagsDisabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
- public void dialogPositiveButtonClick_intentToOldA11yPairingPage() {
- setupDialog(SettingsEnums.ACCESSIBILITY);
- final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
- dialog.show();
-
- dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
-
- final Intent intent = shadowOf(mActivity).getNextStartedActivity();
- assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
- .isEqualTo(HearingDevicePairingDetail.class.getName());
- }
-
- @Test
public void dialogNegativeButtonClick_dismissDialog() {
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
dialog.show();
diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingDetailTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingDetailTest.java
deleted file mode 100644
index e1651d9..0000000
--- a/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingDetailTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.accessibility;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.content.Context;
-
-import androidx.test.core.app.ApplicationProvider;
-
-import com.android.settings.bluetooth.BluetoothProgressCategory;
-import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoRule;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-import org.robolectric.shadow.api.Shadow;
-
-/** Tests for {@link HearingDevicePairingDetail}. */
-@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowBluetoothAdapter.class})
-public class HearingDevicePairingDetailTest {
-
- @Rule
- public final MockitoRule mockito = MockitoJUnit.rule();
-
- private final Context mContext = ApplicationProvider.getApplicationContext();
-
- @Mock
- private CachedBluetoothDevice mCachedBluetoothDevice;
- private BluetoothProgressCategory mProgressCategory;
- private TestHearingDevicePairingDetail mFragment;
-
- @Before
- public void setUp() {
- final BluetoothAdapter bluetoothAdapter = spy(BluetoothAdapter.getDefaultAdapter());
- final ShadowBluetoothAdapter shadowBluetoothAdapter = Shadow.extract(
- BluetoothAdapter.getDefaultAdapter());
- shadowBluetoothAdapter.setEnabled(true);
-
- mProgressCategory = spy(new BluetoothProgressCategory(mContext));
- mFragment = spy(new TestHearingDevicePairingDetail());
- when(mFragment.getContext()).thenReturn(mContext);
- when(mFragment.findPreference(
- HearingDevicePairingDetail.KEY_AVAILABLE_HEARING_DEVICES)).thenReturn(
- mProgressCategory);
- mFragment.setBluetoothAdapter(bluetoothAdapter);
-
- }
-
- @Test
- public void getDeviceListKey_expectedKey() {
- assertThat(mFragment.getDeviceListKey()).isEqualTo(
- HearingDevicePairingDetail.KEY_AVAILABLE_HEARING_DEVICES);
- }
-
- @Test
- public void onDeviceBondStateChanged_bondNone_setProgressFalse() {
- mFragment.initPreferencesFromPreferenceScreen();
-
- mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_NONE);
-
- verify(mProgressCategory).setProgress(true);
- }
-
- @Test
- public void onDeviceBondStateChanged_bonding_setProgressTrue() {
- mFragment.initPreferencesFromPreferenceScreen();
-
- mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDING);
-
- verify(mProgressCategory).setProgress(false);
- }
-
- private static class TestHearingDevicePairingDetail extends HearingDevicePairingDetail {
- TestHearingDevicePairingDetail() {
- super();
- }
-
- public void setBluetoothAdapter(BluetoothAdapter bluetoothAdapter) {
- this.mBluetoothAdapter = bluetoothAdapter;
- }
-
- public void enableScanning() {
- super.enableScanning();
- }
- }
-}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java
index 1f9fbeb..b368a22 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java
@@ -56,7 +56,7 @@
private final String TEST_KEY = "test_key";
@Spy
- private HearingDevicePairingDetail mFragment = new HearingDevicePairingDetail();
+ private HearingDevicePairingFragment mFragment = new HearingDevicePairingFragment();
private FragmentActivity mActivity;
@Mock
private PreferenceScreen mScreen;
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
index 63fa88d..70c73a6 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
@@ -15,16 +15,12 @@
*/
package com.android.settings.connecteddevice;
-import static com.android.settings.accessibility.AccessibilityHearingAidsFragment.KEY_HEARING_DEVICE_ADD_BT_DEVICES;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
@@ -33,27 +29,17 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.platform.test.annotations.RequiresFlagsDisabled;
-import android.platform.test.annotations.RequiresFlagsEnabled;
-import android.platform.test.flag.junit.CheckFlagsRule;
-import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.text.TextUtils;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
-import com.android.settings.accessibility.HearingDevicePairingDetail;
-import com.android.settings.accessibility.HearingDevicePairingFragment;
-import com.android.settings.flags.Flags;
import com.android.settingslib.RestrictedPreference;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
@@ -65,10 +51,6 @@
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowApplicationPackageManager.class)
public class AddDevicePreferenceControllerTest {
-
- @Rule
- public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
-
@Mock
private PreferenceScreen mScreen;
@Mock
@@ -100,8 +82,6 @@
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
when(mScreen.findPreference(key)).thenReturn(mAddDevicePreference);
mAddDevicePreferenceController.displayPreference(mScreen);
-
- doNothing().when(mContext).startActivity(any(Intent.class));
}
@Test
@@ -157,30 +137,4 @@
assertThat(mAddDevicePreferenceController.getAvailabilityStatus())
.isEqualTo(UNSUPPORTED_ON_DEVICE);
}
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
- public void handlePreferenceClick_A11yPreference_redirectToNewPairingPage() {
- mAddDevicePreference.setKey(KEY_HEARING_DEVICE_ADD_BT_DEVICES);
- final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
-
- mAddDevicePreferenceController.handlePreferenceTreeClick(mAddDevicePreference);
-
- verify(mContext).startActivity(intentCaptor.capture());
- assertThat(intentCaptor.getValue().getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
- .isEqualTo(HearingDevicePairingFragment.class.getName());
- }
-
- @Test
- @RequiresFlagsDisabled(Flags.FLAG_NEW_HEARING_DEVICE_PAIRING_PAGE)
- public void handlePreferenceClick_A11yPreference_redirectToOldPairingPage() {
- mAddDevicePreference.setKey(KEY_HEARING_DEVICE_ADD_BT_DEVICES);
- final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
-
- mAddDevicePreferenceController.handlePreferenceTreeClick(mAddDevicePreference);
-
- verify(mContext).startActivity(intentCaptor.capture());
- assertThat(intentCaptor.getValue().getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
- .isEqualTo(HearingDevicePairingDetail.class.getName());
- }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 583db5e..0648de4 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -33,7 +33,6 @@
import static org.mockito.Mockito.when;
import android.app.AppOpsManager;
-import android.app.backup.BackupManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
@@ -61,8 +60,12 @@
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.datastore.ChangeReason;
+import com.android.settingslib.datastore.Observer;
import com.android.settingslib.widget.LayoutPreference;
+import com.google.common.util.concurrent.MoreExecutors;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -116,9 +119,10 @@
@Mock private AppOpsManager mAppOpsManager;
@Mock private LoaderManager mLoaderManager;
@Mock private BatteryOptimizeUtils mBatteryOptimizeUtils;
- @Mock private BackupManager mBackupManager;
+ @Mock private Observer mObserver;
private Context mContext;
+ private BatterySettingsStorage mBatterySettingsStorage;
private PrimarySwitchPreference mAllowBackgroundUsagePreference;
private AdvancedPowerUsageDetail mFragment;
private SettingsActivity mTestActivity;
@@ -130,6 +134,7 @@
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
+ mBatterySettingsStorage = BatterySettingsStorage.get(mContext);
when(mContext.getPackageName()).thenReturn("foo");
mFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
@@ -200,7 +205,6 @@
mFragment.mHeaderPreference = mHeaderPreference;
mFragment.mState = mState;
mFragment.mBatteryOptimizeUtils = mBatteryOptimizeUtils;
- mFragment.mBackupManager = mBackupManager;
mFragment.mLogStringBuilder = new StringBuilder();
mAppEntry.info = mock(ApplicationInfo.class);
@@ -447,23 +451,25 @@
@Test
public void notifyBackupManager_optimizationModeIsNotChanged_notInvokeDataChanged() {
+ mBatterySettingsStorage.addObserver(mObserver, MoreExecutors.directExecutor());
final int mode = BatteryOptimizeUtils.MODE_RESTRICTED;
mFragment.mOptimizationMode = mode;
when(mBatteryOptimizeUtils.getAppOptimizationMode()).thenReturn(mode);
mFragment.notifyBackupManager();
- verifyNoInteractions(mBackupManager);
+ verifyNoInteractions(mObserver);
}
@Test
public void notifyBackupManager_optimizationModeIsChanged_invokeDataChanged() {
+ mBatterySettingsStorage.addObserver(mObserver, MoreExecutors.directExecutor());
mFragment.mOptimizationMode = BatteryOptimizeUtils.MODE_RESTRICTED;
when(mBatteryOptimizeUtils.getAppOptimizationMode())
.thenReturn(BatteryOptimizeUtils.MODE_UNRESTRICTED);
mFragment.notifyBackupManager();
- verify(mBackupManager).dataChanged();
+ verify(mObserver).onChanged(ChangeReason.UPDATE);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetailTest.java
index b6caa7f..9061117 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerBackgroundUsageDetailTest.java
@@ -33,7 +33,6 @@
import static org.mockito.Mockito.when;
import android.app.AppOpsManager;
-import android.app.backup.BackupManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
@@ -119,7 +118,6 @@
@Mock private LoaderManager mLoaderManager;
@Mock private ApplicationsState.AppEntry mAppEntry;
@Mock private BatteryEntry mBatteryEntry;
- @Mock private BackupManager mBackupManager;
@Mock private PackageManager mPackageManager;
@Mock private AppOpsManager mAppOpsManager;
@Mock private CompoundButton mMockSwitch;
@@ -174,7 +172,6 @@
mFragment.mHeaderPreference = mHeaderPreference;
mFragment.mState = mState;
mFragment.mBatteryOptimizeUtils = mBatteryOptimizeUtils;
- mFragment.mBackupManager = mBackupManager;
mAppEntry.info = mock(ApplicationInfo.class);
mTestActivity = spy(new SettingsActivity());
diff --git a/tests/unit/src/com/android/settings/wifi/RequestToggleWiFiActivityTest.java b/tests/unit/src/com/android/settings/wifi/RequestToggleWiFiActivityTest.java
index 3d2d9a8..d84d5ad 100644
--- a/tests/unit/src/com/android/settings/wifi/RequestToggleWiFiActivityTest.java
+++ b/tests/unit/src/com/android/settings/wifi/RequestToggleWiFiActivityTest.java
@@ -34,6 +34,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,6 +43,7 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
+@Ignore
@RunWith(AndroidJUnit4.class)
public class RequestToggleWiFiActivityTest {
diff --git a/tests/unit/src/com/android/settings/wifi/WifiDialog2Test.kt b/tests/unit/src/com/android/settings/wifi/WifiDialog2Test.kt
index ef50433..0b14790 100644
--- a/tests/unit/src/com/android/settings/wifi/WifiDialog2Test.kt
+++ b/tests/unit/src/com/android/settings/wifi/WifiDialog2Test.kt
@@ -23,6 +23,7 @@
import com.android.settings.wifi.WifiDialog2.WifiDialog2Listener
import com.android.wifitrackerlib.WifiEntry
import com.google.common.truth.Truth.assertThat
+import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -30,6 +31,7 @@
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
+@Ignore
@RunWith(AndroidJUnit4::class)
class WifiDialog2Test {
@get:Rule
diff --git a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
index 2826310..d5d4c7f 100644
--- a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
+++ b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
@@ -35,6 +35,7 @@
import com.android.wifitrackerlib.WifiEntry;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -143,6 +144,7 @@
null /* scanResult */);
}
+ @Ignore
@Test
public void checkShowWifiHotspot_allReady_returnTrue() {
assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isTrue();