Merge "[Audiosharing] Save user preferred primary headset to SettingsProvider" into main
diff --git a/res/layout/dialog_a11y_bounce_key.xml b/res/layout/dialog_a11y_bounce_key.xml
index 7e23692..da3ebde 100644
--- a/res/layout/dialog_a11y_bounce_key.xml
+++ b/res/layout/dialog_a11y_bounce_key.xml
@@ -56,28 +56,79 @@
android:id="@+id/bounce_key_value_200"
android:text="@string/bounce_keys_dialog_option_200"
android:paddingStart="12dp"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
+ android:layout_gravity="start|center_vertical"
android:background="@null"/>
<RadioButton
android:id="@+id/bounce_key_value_400"
android:text="@string/bounce_keys_dialog_option_400"
android:paddingStart="12dp"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginTop="16dp"
+ android:layout_gravity="start|center_vertical"
+ android:layout_marginTop="12dp"
android:background="@null"/>
<RadioButton
android:id="@+id/bounce_key_value_600"
android:text="@string/bounce_keys_dialog_option_600"
android:paddingStart="12dp"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginTop="16dp"
+ android:layout_gravity="start|center_vertical"
+ android:layout_marginTop="12dp"
android:background="@null"/>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginVertical="12dp">
+ <RadioButton
+ android:id="@+id/bounce_key_value_custom"
+ android:paddingStart="12dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:background="@null"/>
+ <LinearLayout
+ android:id="@+id/custom_value_option"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:gravity="center_vertical"
+ android:paddingEnd="16dp">
+ <TextView
+ android:id="@+id/bounce_key_value_custom_title"
+ android:text="Custom"
+ android:textColor="?android:attr/textColorPrimary"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+ <TextView
+ android:id="@+id/bounce_key_value_custom_value"
+ android:text="custom value"
+ android:textColor="?android:attr/textColorPrimary"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginTop="8dp"
+ android:visibility="gone"/>
+ <SeekBar
+ android:id="@+id/bounce_key_value_custom_slider"
+ android:paddingStart="8dp"
+ android:paddingEnd="36dp"
+ android:min="1"
+ android:max="50"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginTop="8dp"
+ android:visibility="gone"
+ android:background="@null"/>
+ </LinearLayout>
+ </LinearLayout>
</RadioGroup>
</LinearLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5326fa5..c6d44c1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4696,6 +4696,10 @@
<string name="keyboard_a11y_settings">Physical keyboard accessibility</string>
<!-- Summary for the button to trigger the 'Physical keyboard accessibility' page. [CHAR LIMIT=NONE] -->
<string name="keyboard_a11y_settings_summary">Sticky keys, Bounce keys, Mouse keys</string>
+ <!-- Title for the keyboard repeat key option. [CHAR LIMIT=60] -->
+ <string name="keyboard_repeat_key_title">Repeat Keys</string>
+ <!-- Summary for the keyboard repeat key option. [CHAR LIMIT=NONE] -->
+ <string name="keyboard_repeat_key_summary">Hold down a key to repeat its character until the key is released</string>
<!-- Title text for per IME subtype keyboard layout. [CHAR LIMIT=35] -->
<string name="ime_label_title"><xliff:g id="ime_label" example="Gboard">%s</xliff:g> layout</string>
@@ -5635,7 +5639,7 @@
<!-- Title for the preference to change video caption locale. [CHAR LIMIT=35] -->
<string name="captioning_locale">Language</string>
<!-- Title for the preference to change video caption text size. [CHAR LIMIT=35] -->
- <string name="captioning_text_size">Text size</string>
+ <string name="captioning_text_size">Caption size</string>
<!-- Title for the preference category containing video caption property presets. [CHAR LIMIT=35] -->
<string name="captioning_preset">Caption style</string>
<!-- Title for the preference catgeory containing custom video caption properties. [CHAR LIMIT=35] -->
diff --git a/res/xml/physical_keyboard_settings.xml b/res/xml/physical_keyboard_settings.xml
index 1527ff5..5d2c5fc 100644
--- a/res/xml/physical_keyboard_settings.xml
+++ b/res/xml/physical_keyboard_settings.xml
@@ -15,6 +15,7 @@
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/physical_keyboard_title">
<!-- Additional preference screens are inserted here programmatically
with low order values to set the key map of each attached keyboard. -->
@@ -31,6 +32,14 @@
android:title="@string/modifier_keys_settings"
android:summary="@string/modifier_keys_settings_summary"
android:fragment="com.android.settings.inputmethod.ModifierKeysSettings" />
+
+ <SwitchPreferenceCompat
+ android:key="physical_keyboard_repeat_key"
+ android:title="@string/keyboard_repeat_key_title"
+ android:summary="@string/keyboard_repeat_key_summary"
+ android:defaultValue="false"
+ settings:controller="com.android.settings.inputmethod.KeyboardRepeatKeysController" />
+
<Preference
android:key="physical_keyboard_a11y"
android:title="@string/keyboard_a11y_settings"
diff --git a/res/xml/storage_dashboard_fragment.xml b/res/xml/storage_dashboard_fragment.xml
index f14f4ad..6c2b8d4 100644
--- a/res/xml/storage_dashboard_fragment.xml
+++ b/res/xml/storage_dashboard_fragment.xml
@@ -101,7 +101,8 @@
android:key="pref_system"
android:title="@string/storage_os_name"
android:icon="@drawable/ic_android_vd_theme_24"
- android:order="202"/>
+ android:order="202"
+ settings:searchable="false"/>
<com.android.settings.deviceinfo.StorageItemPreference
android:key="temporary_files"
android:title="@string/storage_temporary_files"
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index d2fc6cc..747efaa 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -25,6 +25,7 @@
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
+import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
@@ -38,6 +39,7 @@
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SettingsMainSwitchPreference;
import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.search.SearchIndexableRaw;
import java.util.ArrayList;
import java.util.List;
@@ -53,6 +55,11 @@
private static final String KEY_PROTANOMALY = "daltonizer_mode_protanomaly";
private static final String KEY_TRITANOMEALY = "daltonizer_mode_tritanomaly";
private static final String KEY_GRAYSCALE = "daltonizer_mode_grayscale";
+
+ @VisibleForTesting
+ static final String KEY_SHORTCUT_PREFERENCE = "daltonizer_shortcut_key";
+ @VisibleForTesting
+ static final String KEY_SWITCH_PREFERENCE = "daltonizer_switch_preference_key";
@VisibleForTesting
static final String KEY_SATURATION = "daltonizer_saturation";
@@ -171,6 +178,11 @@
}
@Override
+ protected String getUseServicePreferenceKey() {
+ return KEY_SWITCH_PREFERENCE;
+ }
+
+ @Override
protected CharSequence getShortcutTitle() {
return getText(R.string.accessibility_daltonizer_shortcut_title);
}
@@ -203,5 +215,27 @@
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider(R.xml.accessibility_daltonizer_settings);
+ new BaseSearchIndexProvider(R.xml.accessibility_daltonizer_settings) {
+ @Override
+ public List<SearchIndexableRaw> getRawDataToIndex(Context context,
+ boolean enabled) {
+ final List<SearchIndexableRaw> rawData =
+ super.getRawDataToIndex(context, enabled);
+
+ if (Flags.fixA11ySettingsSearch()) {
+ SearchIndexableRaw shortcutRaw = new SearchIndexableRaw(context);
+ shortcutRaw.key = KEY_SHORTCUT_PREFERENCE;
+ shortcutRaw.title = context.getString(
+ R.string.accessibility_daltonizer_shortcut_title);
+ rawData.add(shortcutRaw);
+
+ SearchIndexableRaw mainSwitchRaw = new SearchIndexableRaw(context);
+ mainSwitchRaw.key = KEY_SWITCH_PREFERENCE;
+ mainSwitchRaw.title = context.getString(
+ R.string.accessibility_daltonizer_primary_switch_title);
+ rawData.add(mainSwitchRaw);
+ }
+ return rawData;
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
index b5d5099..fb5a9f3 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
@@ -169,6 +169,7 @@
}
if (packageName != null && hideBackgroundUsageTimeSet.contains(packageName)) {
entry.mBackgroundUsageTimeInMs = 0;
+ entry.mForegroundServiceUsageTimeInMs = 0;
}
}
}
diff --git a/src/com/android/settings/inputmethod/KeyboardAccessibilityBounceKeysController.java b/src/com/android/settings/inputmethod/KeyboardAccessibilityBounceKeysController.java
index 559b2e4..1652f00 100644
--- a/src/com/android/settings/inputmethod/KeyboardAccessibilityBounceKeysController.java
+++ b/src/com/android/settings/inputmethod/KeyboardAccessibilityBounceKeysController.java
@@ -21,7 +21,11 @@
import android.net.Uri;
import android.provider.Settings;
import android.text.TextUtils;
+import android.view.View;
+import android.widget.RadioButton;
import android.widget.RadioGroup;
+import android.widget.SeekBar;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -33,9 +37,13 @@
import com.android.settings.R;
import com.android.settingslib.PrimarySwitchPreference;
+import java.util.concurrent.TimeUnit;
+
public class KeyboardAccessibilityBounceKeysController extends
InputSettingPreferenceController implements
LifecycleObserver {
+ private static final int CUSTOM_PROGRESS_INTERVAL = 100;
+ private static final long MILLISECOND_IN_SECONDS = TimeUnit.SECONDS.toMillis(1);
public static final int BOUNCE_KEYS_THRESHOLD = 500;
private AlertDialog mAlertDialog;
@@ -62,7 +70,7 @@
}
@Override
- public boolean handlePreferenceTreeClick(Preference preference) {
+ public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return false;
}
@@ -105,23 +113,87 @@
(dialog, which) -> {
RadioGroup radioGroup =
mAlertDialog.findViewById(R.id.bounce_key_value_group);
- int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
- int threshold = checkedRadioButtonId == R.id.bounce_key_value_600 ? 600
- : checkedRadioButtonId == R.id.bounce_key_value_400 ? 400
- : checkedRadioButtonId == R.id.bounce_key_value_200
- ? 200 : 0;
+ SeekBar seekbar = mAlertDialog.findViewById(
+ R.id.bounce_key_value_custom_slider);
+ RadioButton customRadioButton = mAlertDialog.findViewById(
+ R.id.bounce_key_value_custom);
+ int threshold;
+ if (customRadioButton.isChecked()) {
+ threshold = seekbar.getProgress() * CUSTOM_PROGRESS_INTERVAL;
+ } else {
+ int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
+ threshold = checkedRadioButtonId == R.id.bounce_key_value_600 ? 600
+ : checkedRadioButtonId == R.id.bounce_key_value_400 ? 400
+ : checkedRadioButtonId == R.id.bounce_key_value_200
+ ? 200 : 0;
+ }
InputSettings.setAccessibilityBounceKeysThreshold(context, threshold);
})
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
.create();
mAlertDialog.setOnShowListener(dialog -> {
- RadioGroup radioGroup = mAlertDialog.findViewById(R.id.bounce_key_value_group);
- int bounceKeysThreshold = InputSettings.getAccessibilityBounceKeysThreshold(context);
- switch (bounceKeysThreshold) {
- case 600 -> radioGroup.check(R.id.bounce_key_value_600);
- case 400 -> radioGroup.check(R.id.bounce_key_value_400);
- default -> radioGroup.check(R.id.bounce_key_value_200);
- }
+ RadioGroup cannedValueRadioGroup = mAlertDialog.findViewById(
+ R.id.bounce_key_value_group);
+ RadioButton customRadioButton = mAlertDialog.findViewById(R.id.bounce_key_value_custom);
+ TextView customValueTextView = mAlertDialog.findViewById(
+ R.id.bounce_key_value_custom_value);
+ SeekBar customProgressBar = mAlertDialog.findViewById(
+ R.id.bounce_key_value_custom_slider);
+ customProgressBar.incrementProgressBy(CUSTOM_PROGRESS_INTERVAL);
+ customProgressBar.setProgress(1);
+ View customValueView = mAlertDialog.findViewById(R.id.custom_value_option);
+ customValueView.setOnClickListener(l -> customRadioButton.performClick());
+ customRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ if (isChecked) {
+ cannedValueRadioGroup.clearCheck();
+ }
+ customValueTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+ customValueTextView.setText(
+ progressToThresholdInSecond(customProgressBar.getProgress()));
+ customProgressBar.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+ buttonView.setChecked(isChecked);
+ });
+ cannedValueRadioGroup.setOnCheckedChangeListener(
+ (group, checkedId) -> customRadioButton.setChecked(false));
+ customProgressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ customValueTextView.setText(progressToThresholdInSecond(progress));
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+ initStateBasedOnThreshold(cannedValueRadioGroup, customRadioButton, customValueTextView,
+ customProgressBar);
});
}
+
+ private static String progressToThresholdInSecond(int progress) {
+ return String.valueOf((double) progress * CUSTOM_PROGRESS_INTERVAL
+ / MILLISECOND_IN_SECONDS);
+ }
+
+ private void initStateBasedOnThreshold(RadioGroup cannedValueRadioGroup,
+ RadioButton customRadioButton, TextView customValueTextView,
+ SeekBar customProgressBar) {
+ int bounceKeysThreshold = InputSettings.getAccessibilityBounceKeysThreshold(mContext);
+ switch (bounceKeysThreshold) {
+ case 600 -> cannedValueRadioGroup.check(R.id.bounce_key_value_600);
+ case 400 -> cannedValueRadioGroup.check(R.id.bounce_key_value_400);
+ case 0, 200 -> cannedValueRadioGroup.check(R.id.bounce_key_value_200);
+ default -> {
+ customValueTextView.setText(
+ String.valueOf(
+ (double) bounceKeysThreshold / MILLISECOND_IN_SECONDS));
+ customProgressBar.setProgress(bounceKeysThreshold / CUSTOM_PROGRESS_INTERVAL);
+ customRadioButton.setChecked(true);
+ }
+ }
+ }
}
diff --git a/src/com/android/settings/inputmethod/KeyboardRepeatKeysController.java b/src/com/android/settings/inputmethod/KeyboardRepeatKeysController.java
new file mode 100644
index 0000000..a232098
--- /dev/null
+++ b/src/com/android/settings/inputmethod/KeyboardRepeatKeysController.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 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.inputmethod;
+
+import android.content.Context;
+import android.hardware.input.InputSettings;
+import android.net.Uri;
+import android.provider.Settings;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreferenceCompat;
+
+public class KeyboardRepeatKeysController extends
+ InputSettingPreferenceController implements
+ LifecycleObserver {
+
+ @Nullable
+ private SwitchPreferenceCompat mSwitchPreferenceCompat;
+
+ public KeyboardRepeatKeysController(@NonNull Context context,
+ @NonNull String key) {
+ super(context, key);
+ }
+
+ @Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSwitchPreferenceCompat = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return InputSettings.isRepeatKeysFeatureFlagEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return InputSettings.isRepeatKeysEnabled(mContext);
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ InputSettings.setRepeatKeysEnabled(mContext, isChecked);
+ return true;
+ }
+
+ @Override
+ protected void onInputSettingUpdated() {
+ if (mSwitchPreferenceCompat != null) {
+ mSwitchPreferenceCompat.setChecked(InputSettings.isRepeatKeysEnabled(mContext));
+ }
+ }
+
+ @Override
+ protected Uri getSettingUri() {
+ return Settings.Secure.getUriFor(
+ Settings.Secure.KEY_REPEAT_ENABLED);
+ }
+}
diff --git a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
index a000f9e..48100a3 100644
--- a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
+++ b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
@@ -48,8 +48,8 @@
import com.android.internal.util.Preconditions;
import com.android.settings.R;
import com.android.settings.Settings;
-import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.keyboard.Flags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -65,7 +65,7 @@
// TODO(b/327638540): Update implementation of preference here and reuse key preferences and
// controllers between here and A11y Setting page.
@SearchIndexable
-public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
+public final class PhysicalKeyboardFragment extends DashboardFragment
implements InputManager.InputDeviceListener,
KeyboardLayoutDialogFragment.OnSetupKeyboardLayoutsListener {
@@ -79,6 +79,7 @@
private static final String KEYBOARD_SHORTCUTS_HELPER = "keyboard_shortcuts_helper";
private static final String MODIFIER_KEYS_SETTINGS = "modifier_keys_settings";
private static final String EXTRA_AUTO_SELECTION = "auto_selection";
+ private static final String TAG = "KeyboardAndTouchA11yFragment";
private static final Uri sVirtualKeyboardSettingsUri = Secure.getUriFor(
Secure.SHOW_IME_WITH_HARD_KEYBOARD);
private static final Uri sAccessibilityBounceKeysUri = Secure.getUriFor(
@@ -119,6 +120,16 @@
private String mBluetoothAddress;
@Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.physical_keyboard_settings;
+ }
+
+ @Override
public void onSaveInstanceState(Bundle outState) {
outState.putParcelable(EXTRA_AUTO_SELECTION, mAutoInputDeviceIdentifier);
super.onSaveInstanceState(outState);
@@ -126,6 +137,7 @@
@Override
public void onCreatePreferences(Bundle bundle, String s) {
+ super.onCreatePreferences(bundle, s);
Activity activity = Preconditions.checkNotNull(getActivity());
addPreferencesFromResource(R.xml.physical_keyboard_settings);
mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
diff --git a/src/com/android/settings/network/CellularSecurityPreferenceController.java b/src/com/android/settings/network/CellularSecurityPreferenceController.java
index f43805e..0b0c2a7 100644
--- a/src/com/android/settings/network/CellularSecurityPreferenceController.java
+++ b/src/com/android/settings/network/CellularSecurityPreferenceController.java
@@ -88,10 +88,10 @@
} catch (UnsupportedOperationException e) {
Log.i(LOG_TAG, "Null cipher enablement is unsupported, hiding divider: "
+ e.getMessage());
- } catch (Exception e) {
+ } catch (IllegalStateException e) {
Log.e(LOG_TAG,
"Failed isNullCipherAndIntegrityEnabled. Setting availability to "
- + "CONDITIONALLY_UNAVAILABLE. Exception: "
+ + "UNSUPPORTED_ON_DEVICE. Exception: "
+ e.getMessage());
}
@@ -104,6 +104,12 @@
} catch (UnsupportedOperationException e) {
Log.i(LOG_TAG, "Cellular security notifications are unsupported, hiding divider: "
+ e.getMessage());
+ } catch (IllegalStateException e) {
+ Log.e(LOG_TAG,
+ "Failed isNullCipherNotificationsEnabled, "
+ + "isCellularIdentifierDisclosureNotificationsEnabled. "
+ + "Setting availability to UNSUPPORTED_ON_DEVICE. Exception: "
+ + e.getMessage());
}
if (isNullCipherDisablementAvailable || areCellSecNotificationsAvailable) {
diff --git a/src/com/android/settings/spa/search/SpaSearchLandingActivity.kt b/src/com/android/settings/spa/search/SpaSearchLandingActivity.kt
index 2c0955b..b94f52c 100644
--- a/src/com/android/settings/spa/search/SpaSearchLandingActivity.kt
+++ b/src/com/android/settings/spa/search/SpaSearchLandingActivity.kt
@@ -38,9 +38,17 @@
finish()
}
- private fun isValidCall() =
- PasswordUtils.getCallingAppPackageName(activityToken) ==
+ private fun isValidCall(): Boolean {
+ val callingAppPackageName = PasswordUtils.getCallingAppPackageName(activityToken)
+ if (callingAppPackageName == packageName) {
+ // SettingsIntelligence sometimes starts SearchResultTrampoline first, in this case,
+ // SearchResultTrampoline checks if the call is valid, then SearchResultTrampoline will
+ // start this activity, allow this use case.
+ return true
+ }
+ return callingAppPackageName ==
featureFactory.searchFeatureProvider.getSettingsIntelligencePkgName(this)
+ }
companion object {
@VisibleForTesting
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragmentTest.java
index fd82994..a33fefb 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragmentTest.java
@@ -18,6 +18,8 @@
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+import static com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.KEY_SHORTCUT_PREFERENCE;
+import static com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.KEY_SWITCH_PREFERENCE;
import static com.google.common.truth.Truth.assertThat;
@@ -26,9 +28,9 @@
import android.content.Intent;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
-import android.view.accessibility.Flags;
import android.widget.PopupWindow;
import androidx.fragment.app.Fragment;
@@ -38,6 +40,7 @@
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.widget.SettingsMainSwitchPreference;
+import com.android.settingslib.search.SearchIndexableRaw;
import org.junit.Before;
import org.junit.Rule;
@@ -48,6 +51,7 @@
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
import java.util.List;
/** Tests for {@link ToggleDaltonizerPreferenceFragment} */
@@ -103,7 +107,7 @@
}
@Test
- @DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
+ @DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, OFF);
@@ -168,6 +172,37 @@
assertThat(keys).containsAtLeastElementsIn(niks);
}
+ @Test
+ @DisableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
+ public void getRawDataToIndex_flagOff_returnEmptyData() {
+ List<SearchIndexableRaw> rawData = ToggleDaltonizerPreferenceFragment
+ .SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext, /* enabled= */ true);
+
+ assertThat(rawData).isEmpty();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
+ public void getRawDataToIndex_flagOn_returnAllIndexablePreferences() {
+ String[] expectedKeys = {KEY_SHORTCUT_PREFERENCE, KEY_SWITCH_PREFERENCE};
+ String[] expectedTitles = {
+ mContext.getString(R.string.accessibility_daltonizer_shortcut_title),
+ mContext.getString(R.string.accessibility_daltonizer_primary_switch_title)};
+ List<String> keysResultList = new ArrayList<>();
+ List<String> titlesResultList = new ArrayList<>();
+ List<SearchIndexableRaw> rawData = ToggleDaltonizerPreferenceFragment
+ .SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext, /* enabled= */ true);
+
+ for (SearchIndexableRaw rawDataItem : rawData) {
+ keysResultList.add(rawDataItem.key);
+ titlesResultList.add(rawDataItem.title);
+ }
+
+ assertThat(rawData).hasSize(2);
+ assertThat(keysResultList).containsExactly(expectedKeys);
+ assertThat(titlesResultList).containsExactly(expectedTitles);
+ }
+
private static PopupWindow getLatestPopupWindow() {
final ShadowApplication shadowApplication =
Shadow.extract(ApplicationProvider.getApplicationContext());
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
index ae4c56d..1f3067e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
@@ -903,6 +903,7 @@
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
0L,
0L,
+ 0L,
false)),
batteryHistoryKeys[1],
Map.of(
@@ -920,6 +921,7 @@
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
0L,
0L,
+ 0L,
false)),
batteryHistoryKeys[2],
Map.of(
@@ -937,6 +939,7 @@
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
0L,
0L,
+ 0L,
false)));
final BatteryLevelData batteryLevelData = generateBatteryLevelData(batteryHistoryKeys);
final Map<Integer, Map<Integer, Map<Long, Map<String, List<AppUsagePeriod>>>>>
@@ -993,6 +996,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
// Adds the index = 0 data.
@@ -1010,6 +1014,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1034,6 +1039,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 15L,
+ /* foregroundServiceUsageTimeInMs= */ 20L,
/* backgroundUsageTimeInMs= */ 25L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1054,6 +1060,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 25L,
+ /* foregroundServiceUsageTimeInMs= */ 30L,
/* backgroundUsageTimeInMs= */ 35L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1070,6 +1077,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY,
/* foregroundUsageTimeInMs= */ 40L,
+ /* foregroundServiceUsageTimeInMs= */ 45L,
/* backgroundUsageTimeInMs= */ 50L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1086,6 +1094,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 5L,
+ /* foregroundServiceUsageTimeInMs= */ 5L,
/* backgroundUsageTimeInMs= */ 5L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1106,6 +1115,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 30L,
+ /* foregroundServiceUsageTimeInMs= */ 35L,
/* backgroundUsageTimeInMs= */ 40L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1122,6 +1132,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY,
/* foregroundUsageTimeInMs= */ 50L,
+ /* foregroundServiceUsageTimeInMs= */ 55L,
/* backgroundUsageTimeInMs= */ 60L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1138,6 +1149,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 5L,
+ /* foregroundServiceUsageTimeInMs= */ 5L,
/* backgroundUsageTimeInMs= */ 5L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1195,6 +1207,7 @@
/* backgroundUsageConsumePower= */ 9,
/* cachedUsageConsumePower= */ 8,
/* foregroundUsageTimeInMs= */ 30,
+ /* foregroundServiceUsageTimeInMs= */ 35,
/* backgroundUsageTimeInMs= */ 40,
/* screenOnTimeInMs= */ 12);
assertBatteryDiffEntry(
@@ -1208,6 +1221,7 @@
/* backgroundUsageConsumePower= */ 8,
/* cachedUsageConsumePower= */ 8,
/* foregroundUsageTimeInMs= */ 5,
+ /* foregroundServiceUsageTimeInMs= */ 5,
/* backgroundUsageTimeInMs= */ 5,
/* screenOnTimeInMs= */ 0);
assertBatteryDiffEntry(
@@ -1221,6 +1235,7 @@
/* backgroundUsageConsumePower= */ 5,
/* cachedUsageConsumePower= */ 5,
/* foregroundUsageTimeInMs= */ 16,
+ /* foregroundServiceUsageTimeInMs= */ 55,
/* backgroundUsageTimeInMs= */ 60,
/* screenOnTimeInMs= */ 9);
resultDiffData = resultMap.get(0).get(DataProcessor.SELECTED_INDEX_ALL);
@@ -1235,6 +1250,7 @@
/* backgroundUsageConsumePower= */ 5,
/* cachedUsageConsumePower= */ 5,
/* foregroundUsageTimeInMs= */ 15,
+ /* foregroundServiceUsageTimeInMs= */ 20,
/* backgroundUsageTimeInMs= */ 25,
/* screenOnTimeInMs= */ 5);
resultDiffData = resultMap.get(1).get(DataProcessor.SELECTED_INDEX_ALL);
@@ -1249,6 +1265,7 @@
/* backgroundUsageConsumePower= */ 8,
/* cachedUsageConsumePower= */ 8,
/* foregroundUsageTimeInMs= */ 5,
+ /* foregroundServiceUsageTimeInMs= */ 5,
/* backgroundUsageTimeInMs= */ 5,
/* screenOnTimeInMs= */ 0);
assertBatteryDiffEntry(
@@ -1262,6 +1279,7 @@
/* backgroundUsageConsumePower= */ 4,
/* cachedUsageConsumePower= */ 3,
/* foregroundUsageTimeInMs= */ 15,
+ /* foregroundServiceUsageTimeInMs= */ 15,
/* backgroundUsageTimeInMs= */ 15,
/* screenOnTimeInMs= */ 7);
assertBatteryDiffEntry(
@@ -1275,6 +1293,7 @@
/* backgroundUsageConsumePower= */ 5,
/* cachedUsageConsumePower= */ 5,
/* foregroundUsageTimeInMs= */ 16,
+ /* foregroundServiceUsageTimeInMs= */ 55,
/* backgroundUsageTimeInMs= */ 60,
/* screenOnTimeInMs= */ 9);
}
@@ -1308,6 +1327,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1324,6 +1344,7 @@
currentUserId + 1,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1340,6 +1361,7 @@
currentUserId + 2,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 20L,
+ /* foregroundServiceUsageTimeInMs= */ 25L,
/* backgroundUsageTimeInMs= */ 30L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1359,6 +1381,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 20L,
+ /* foregroundServiceUsageTimeInMs= */ 25L,
/* backgroundUsageTimeInMs= */ 30L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1375,6 +1398,7 @@
currentUserId + 1,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1391,6 +1415,7 @@
currentUserId + 2,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 30L,
+ /* foregroundServiceUsageTimeInMs= */ 30L,
/* backgroundUsageTimeInMs= */ 30L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1410,6 +1435,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 20L,
+ /* foregroundServiceUsageTimeInMs= */ 25L,
/* backgroundUsageTimeInMs= */ 30L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1426,6 +1452,7 @@
currentUserId + 1,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 20L,
+ /* foregroundServiceUsageTimeInMs= */ 20L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1442,6 +1469,7 @@
currentUserId + 2,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 30L,
+ /* foregroundServiceUsageTimeInMs= */ 30L,
/* backgroundUsageTimeInMs= */ 30L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1477,6 +1505,7 @@
/* backgroundUsageConsumePower= */ 5,
/* cachedUsageConsumePower= */ 5,
/* foregroundUsageTimeInMs= */ 10,
+ /* foregroundServiceUsageTimeInMs= */ 10,
/* backgroundUsageTimeInMs= */ 10,
/* screenOnTimeInMs= */ 0);
assertThat(resultDiffData.getSystemDiffEntryList()).isEmpty();
@@ -1509,6 +1538,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1528,6 +1558,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1547,6 +1578,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 3600000L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 7200000L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1587,6 +1619,7 @@
final BatteryDiffEntry resultEntry = resultDiffData.getAppDiffEntryList().get(0);
assertThat(resultEntry.mForegroundUsageTimeInMs)
.isEqualTo(Math.round(entry.mForegroundUsageTimeInMs * ratio));
+ assertThat(resultEntry.mForegroundServiceUsageTimeInMs).isEqualTo(0);
assertThat(resultEntry.mBackgroundUsageTimeInMs).isEqualTo(0);
assertThat(resultEntry.mConsumePower).isEqualTo(entry.mConsumePower * ratio);
assertThat(resultEntry.mForegroundUsageConsumePower)
@@ -1627,6 +1660,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1643,6 +1677,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1662,6 +1697,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1678,6 +1714,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1697,6 +1734,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1713,6 +1751,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1748,6 +1787,7 @@
/* backgroundUsageConsumePower= */ 5,
/* cachedUsageConsumePower= */ 5,
/* foregroundUsageTimeInMs= */ 10,
+ /* foregroundServiceUsageTimeInMs= */ 15,
/* backgroundUsageTimeInMs= */ 20,
/* screenOnTimeInMs= */ 0);
}
@@ -1777,6 +1817,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1793,6 +1834,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1812,6 +1854,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1828,6 +1871,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 0L,
+ /* foregroundServiceUsageTimeInMs= */ 0L,
/* backgroundUsageTimeInMs= */ 0L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1847,6 +1891,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1863,6 +1908,7 @@
currentUserId,
ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
/* foregroundUsageTimeInMs= */ 10L,
+ /* foregroundServiceUsageTimeInMs= */ 15L,
/* backgroundUsageTimeInMs= */ 20L,
/* isHidden= */ false);
entryMap.put(entry.getKey(), entry);
@@ -1892,6 +1938,7 @@
assertThat(resultEntry.mBackgroundUsageTimeInMs).isEqualTo(20);
resultEntry = resultDiffData.getAppDiffEntryList().get(1);
assertThat(resultEntry.mBackgroundUsageTimeInMs).isEqualTo(0);
+ assertThat(resultEntry.mForegroundServiceUsageTimeInMs).isEqualTo(0);
}
@Test
@@ -1921,6 +1968,7 @@
doReturn(0.0).when(mMockBatteryEntry1).getConsumedPowerInBackground();
doReturn(0.0).when(mMockBatteryEntry1).getConsumedPowerInCached();
doReturn(30L).when(mMockBatteryEntry1).getTimeInForegroundMs();
+ doReturn(35L).when(mMockBatteryEntry1).getTimeInForegroundServiceMs();
doReturn(40L).when(mMockBatteryEntry1).getTimeInBackgroundMs();
doReturn(1).when(mMockBatteryEntry1).getUid();
doReturn(ConvertUtils.CONSUMER_TYPE_UID_BATTERY).when(mMockBatteryEntry1).getConsumerType();
@@ -1930,6 +1978,7 @@
doReturn(0.0).when(mMockBatteryEntry2).getConsumedPowerInBackground();
doReturn(0.0).when(mMockBatteryEntry2).getConsumedPowerInCached();
doReturn(20L).when(mMockBatteryEntry2).getTimeInForegroundMs();
+ doReturn(20L).when(mMockBatteryEntry2).getTimeInForegroundServiceMs();
doReturn(20L).when(mMockBatteryEntry2).getTimeInBackgroundMs();
doReturn(2).when(mMockBatteryEntry2).getUid();
doReturn(ConvertUtils.CONSUMER_TYPE_UID_BATTERY).when(mMockBatteryEntry2).getConsumerType();
@@ -1939,6 +1988,7 @@
doReturn(0.0).when(mMockBatteryEntry3).getConsumedPowerInBackground();
doReturn(0.0).when(mMockBatteryEntry3).getConsumedPowerInCached();
doReturn(0L).when(mMockBatteryEntry3).getTimeInForegroundMs();
+ doReturn(0L).when(mMockBatteryEntry3).getTimeInForegroundServiceMs();
doReturn(0L).when(mMockBatteryEntry3).getTimeInBackgroundMs();
doReturn(3).when(mMockBatteryEntry3).getUid();
doReturn(ConvertUtils.CONSUMER_TYPE_UID_BATTERY).when(mMockBatteryEntry3).getConsumerType();
@@ -1948,6 +1998,7 @@
doReturn(0.3).when(mMockBatteryEntry4).getConsumedPowerInBackground();
doReturn(0.1).when(mMockBatteryEntry4).getConsumedPowerInCached();
doReturn(10L).when(mMockBatteryEntry4).getTimeInForegroundMs();
+ doReturn(10L).when(mMockBatteryEntry4).getTimeInForegroundServiceMs();
doReturn(10L).when(mMockBatteryEntry4).getTimeInBackgroundMs();
doReturn(4).when(mMockBatteryEntry4).getUid();
doReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY)
@@ -1978,6 +2029,7 @@
/* backgroundUsageConsumePower= */ 0,
/* cachedUsageConsumePower= */ 0,
/* foregroundUsageTimeInMs= */ 20,
+ /* foregroundServiceUsageTimeInMs= */ 20,
/* backgroundUsageTimeInMs= */ 20,
/* screenOnTimeInMs= */ 0);
assertBatteryDiffEntry(
@@ -1991,6 +2043,7 @@
/* backgroundUsageConsumePower= */ 0,
/* cachedUsageConsumePower= */ 0,
/* foregroundUsageTimeInMs= */ 30,
+ /* foregroundServiceUsageTimeInMs= */ 35,
/* backgroundUsageTimeInMs= */ 40,
/* screenOnTimeInMs= */ 0);
assertBatteryDiffEntry(
@@ -2004,6 +2057,7 @@
/* backgroundUsageConsumePower= */ 0.3,
/* cachedUsageConsumePower= */ 0.1,
/* foregroundUsageTimeInMs= */ 10,
+ /* foregroundServiceUsageTimeInMs= */ 10,
/* backgroundUsageTimeInMs= */ 10,
/* screenOnTimeInMs= */ 0);
}
@@ -2390,6 +2444,7 @@
final long userId,
final int consumerType,
final long foregroundUsageTimeInMs,
+ final long foregroundServiceUsageTimeInMs,
final long backgroundUsageTimeInMs,
final boolean isHidden) {
// Only insert required fields.
@@ -2402,6 +2457,7 @@
.setBackgroundUsageConsumePower(backgroundUsageConsumePower)
.setCachedUsageConsumePower(cachedUsageConsumePower)
.setForegroundUsageTimeInMs(foregroundUsageTimeInMs)
+ .setForegroundServiceUsageTimeInMs(foregroundServiceUsageTimeInMs)
.setBackgroundUsageTimeInMs(backgroundUsageTimeInMs)
.setIsHidden(isHidden)
.build();
@@ -2531,6 +2587,7 @@
final double backgroundUsageConsumePower,
final double cachedUsageConsumePower,
final long foregroundUsageTimeInMs,
+ final long foregroundServiceUsageTimeInMs,
final long backgroundUsageTimeInMs,
final long screenOnTimeInMs) {
assertThat(entry.mUserId).isEqualTo(userId);
@@ -2543,6 +2600,8 @@
assertThat(entry.mBackgroundUsageConsumePower).isEqualTo(backgroundUsageConsumePower);
assertThat(entry.mCachedUsageConsumePower).isEqualTo(cachedUsageConsumePower);
assertThat(entry.mForegroundUsageTimeInMs).isEqualTo(foregroundUsageTimeInMs);
+ assertThat(entry.mForegroundServiceUsageTimeInMs)
+ .isEqualTo(foregroundServiceUsageTimeInMs);
assertThat(entry.mBackgroundUsageTimeInMs).isEqualTo(backgroundUsageTimeInMs);
assertThat(entry.mScreenOnTimeInMs).isEqualTo(screenOnTimeInMs);
}
diff --git a/tests/robotests/src/com/android/settings/inputmethod/KeyboardRepeatKeysControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/KeyboardRepeatKeysControllerTest.java
new file mode 100644
index 0000000..e1b4ffd
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/inputmethod/KeyboardRepeatKeysControllerTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 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.inputmethod;
+
+import static com.android.input.flags.Flags.FLAG_KEYBOARD_REPEAT_KEYS;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.hardware.input.InputSettings;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import com.android.settings.core.BasePreferenceController;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {
+ com.android.settings.testutils.shadow.ShadowFragment.class,
+})
+public class KeyboardRepeatKeysControllerTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ private Context mContext;
+
+ private KeyboardRepeatKeysController mKeyboardRepeatKeysController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mKeyboardRepeatKeysController = new KeyboardRepeatKeysController(mContext,
+ "physical_keyboard_repeat_key");
+ }
+
+ @Test
+ @EnableFlags(FLAG_KEYBOARD_REPEAT_KEYS)
+ public void getAvailabilityStatus_flagIsEnabled_isAvailable() {
+ assertThat(mKeyboardRepeatKeysController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ @DisableFlags(FLAG_KEYBOARD_REPEAT_KEYS)
+ public void getAvailabilityStatus_flagIsDisabled_notSupport() {
+ assertThat(mKeyboardRepeatKeysController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void isChecked_sameWithInputSettingValue() {
+ boolean isRepeatKeysEnabled = InputSettings.isRepeatKeysEnabled(mContext);
+ assertThat(mKeyboardRepeatKeysController.isChecked()).isEqualTo(isRepeatKeysEnabled);
+ }
+
+ @Test
+ public void setChecked_updatesInputSettingValue() {
+ mKeyboardRepeatKeysController.setChecked(false);
+
+ assertThat(InputSettings.isRepeatKeysEnabled(mContext)).isEqualTo(false);
+ }
+}