Snap for 11558480 from b9895a2438 to 24Q3-release
Change-Id: I9b010d65d75bc8eb5223ba389240e30243b900c2
This commit is contained in:
@@ -153,6 +153,7 @@
|
|||||||
android:requiredForAllUsers="true"
|
android:requiredForAllUsers="true"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:backupAgent="com.android.settings.backup.SettingsBackupHelper"
|
android:backupAgent="com.android.settings.backup.SettingsBackupHelper"
|
||||||
|
android:restoreAnyVersion="true"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
android:defaultToDeviceProtectedStorage="true"
|
android:defaultToDeviceProtectedStorage="true"
|
||||||
android:directBootAware="true"
|
android:directBootAware="true"
|
||||||
|
|||||||
@@ -150,14 +150,14 @@
|
|||||||
<string name="bluetooth_pair_other_ear_dialog_right_ear_positive_button">Pair right ear</string>
|
<string name="bluetooth_pair_other_ear_dialog_right_ear_positive_button">Pair right ear</string>
|
||||||
<!-- Connected devices settings. Positive button of the dialog to help user to pair left ear of the hearing aid device. Dialog shows when only one of the hearing aid device set is connected. [CHAR LIMIT=20] -->
|
<!-- Connected devices settings. Positive button of the dialog to help user to pair left ear of the hearing aid device. Dialog shows when only one of the hearing aid device set is connected. [CHAR LIMIT=20] -->
|
||||||
<string name="bluetooth_pair_other_ear_dialog_left_ear_positive_button">Pair left ear</string>
|
<string name="bluetooth_pair_other_ear_dialog_left_ear_positive_button">Pair left ear</string>
|
||||||
<!-- Title for all hearing devices related controls section. [CHAR LIMIT=60] -->
|
<!-- Connected devices settings. Title of the preference to show the entrance of the hearing device settings page. [CHAR LIMIT=65 BACKUP_MESSAGE_ID=1895676556354697234] -->
|
||||||
<string name="bluetooth_device_controls_general">For all available hearing devices</string>
|
<string name="bluetooth_hearing_device_settings_title">Hearing device settings</string>
|
||||||
<!-- Connected devices settings. Title of the preference to show the entrance of the hearing device settings related page. [CHAR LIMIT=65] -->
|
<!-- Connected devices settings. Summary of the preference to show the entrance of the hearing device settings page. [CHAR LIMIT=65 BACKUP_MESSAGE_ID=8115767735418425663] -->
|
||||||
<string name="bluetooth_device_controls_title">More hearing device settings</string>
|
<string name="bluetooth_hearing_device_settings_summary">Shortcut, hearing aid compatibility</string>
|
||||||
<!-- Connected devices settings. Summary of the preference to show the item in the hearing device settings related page. [CHAR LIMIT=120] -->
|
<!-- Connected devices settings. Title for hearing aids presets. A preset is a set of hearing aid settings. User can apply different settings in different environments (e.g. Outdoor, Restaurant, Home) [CHAR LIMIT=60] -->
|
||||||
<string name="bluetooth_device_controls_summary">Change cross-device settings like shortcut, and telecoil controls</string>
|
<string name="bluetooth_hearing_aids_presets">Presets</string>
|
||||||
<!-- Title for this device specific controls section. [CHAR LIMIT=30] -->
|
<!-- Message when selecting hearing aids presets failed. [CHAR LIMIT=NONE] -->
|
||||||
<string name="bluetooth_device_controls_specific">For this device</string>
|
<string name="bluetooth_hearing_aids_presets_error">Couldn\u2019t update preset</string>
|
||||||
<!-- Connected devices settings. Title of the preference to show the entrance of the audio output page. It can change different types of audio are played on phone or other bluetooth devices. [CHAR LIMIT=35] -->
|
<!-- Connected devices settings. Title of the preference to show the entrance of the audio output page. It can change different types of audio are played on phone or other bluetooth devices. [CHAR LIMIT=35] -->
|
||||||
<string name="bluetooth_audio_routing_title">Audio output</string>
|
<string name="bluetooth_audio_routing_title">Audio output</string>
|
||||||
<!-- Title for bluetooth audio routing page footer. [CHAR LIMIT=30] -->
|
<!-- Title for bluetooth audio routing page footer. [CHAR LIMIT=30] -->
|
||||||
@@ -1847,11 +1847,6 @@
|
|||||||
<!-- Bluetooth developer settings: Maximum number of connected audio devices -->
|
<!-- Bluetooth developer settings: Maximum number of connected audio devices -->
|
||||||
<string name="bluetooth_max_connected_audio_devices_dialog_title">Select maximum number of connected Bluetooth audio devices</string>
|
<string name="bluetooth_max_connected_audio_devices_dialog_title">Select maximum number of connected Bluetooth audio devices</string>
|
||||||
|
|
||||||
<!-- Nfc developer settings: The title of the setting. [CHAR LIMIT=60] -->
|
|
||||||
<string name="nfc_stack_debuglog_title">NFC stack debug log</string>
|
|
||||||
<!-- Nfc developer settings: The description of the setting. -->
|
|
||||||
<string name="nfc_stack_debuglog_summary">Increase NFC stack logging level</string>
|
|
||||||
|
|
||||||
<!-- Nfc developer settings: The title of the setting to enable nfc verbose vendor log. [CHAR LIMIT=60] -->
|
<!-- Nfc developer settings: The title of the setting to enable nfc verbose vendor log. [CHAR LIMIT=60] -->
|
||||||
<string name="nfc_verbose_vendor_log_title">NFC verbose vendor debug log</string>
|
<string name="nfc_verbose_vendor_log_title">NFC verbose vendor debug log</string>
|
||||||
<!-- Nfc developer settings: The description of the setting to enable nfc verbose vendor log. [CHAR_LIMIT=NONE] -->
|
<!-- Nfc developer settings: The description of the setting to enable nfc verbose vendor log. [CHAR_LIMIT=NONE] -->
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
android:key="device_companion_apps"/>
|
android:key="device_companion_apps"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="device_controls_general" />
|
android:key="hearing_device_group" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="bluetooth_audio_device_type_group"/>
|
android:key="bluetooth_audio_device_type_group"/>
|
||||||
|
|||||||
@@ -469,11 +469,6 @@
|
|||||||
android:entries="@array/bluetooth_max_connected_audio_devices"
|
android:entries="@array/bluetooth_max_connected_audio_devices"
|
||||||
android:entryValues="@array/bluetooth_max_connected_audio_devices_values" />
|
android:entryValues="@array/bluetooth_max_connected_audio_devices_values" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:key="nfc_stack_debuglog_enabled"
|
|
||||||
android:title="@string/nfc_stack_debuglog_title"
|
|
||||||
android:summary="@string/nfc_stack_debuglog_summary" />
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:key="nfc_verbose_vendor_log"
|
android:key="nfc_verbose_vendor_log"
|
||||||
android:title="@string/nfc_verbose_vendor_log_title"
|
android:title="@string/nfc_verbose_vendor_log_title"
|
||||||
|
|||||||
@@ -0,0 +1,308 @@
|
|||||||
|
/*
|
||||||
|
* 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.bluetooth;
|
||||||
|
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.KEY_HEARING_DEVICE_GROUP;
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.ORDER_HEARING_AIDS_PRESETS;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothCsipSetCoordinator;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothHapClient;
|
||||||
|
import android.bluetooth.BluetoothHapPresetInfo;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.bluetooth.HapClientProfile;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The controller of the hearing aid presets.
|
||||||
|
*/
|
||||||
|
public class BluetoothDetailsHearingAidsPresetsController extends
|
||||||
|
BluetoothDetailsController implements Preference.OnPreferenceChangeListener,
|
||||||
|
BluetoothHapClient.Callback, OnResume, OnPause {
|
||||||
|
|
||||||
|
private static final boolean DEBUG = true;
|
||||||
|
private static final String TAG = "BluetoothDetailsHearingAidsPresetsController";
|
||||||
|
static final String KEY_HEARING_AIDS_PRESETS = "hearing_aids_presets";
|
||||||
|
|
||||||
|
private final HapClientProfile mHapClientProfile;
|
||||||
|
@Nullable
|
||||||
|
private ListPreference mPreference;
|
||||||
|
|
||||||
|
public BluetoothDetailsHearingAidsPresetsController(@NonNull Context context,
|
||||||
|
@NonNull PreferenceFragmentCompat fragment,
|
||||||
|
@NonNull LocalBluetoothManager manager,
|
||||||
|
@NonNull CachedBluetoothDevice device,
|
||||||
|
@NonNull Lifecycle lifecycle) {
|
||||||
|
super(context, fragment, device, lifecycle);
|
||||||
|
mHapClientProfile = manager.getProfileManager().getHapClientProfile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (mHapClientProfile != null) {
|
||||||
|
mHapClientProfile.registerCallback(ThreadUtils.getBackgroundExecutor(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
if (mHapClientProfile != null) {
|
||||||
|
mHapClientProfile.unregisterCallback(this);
|
||||||
|
}
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(@NonNull Preference preference, @Nullable Object newValue) {
|
||||||
|
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
|
if (newValue instanceof final String value
|
||||||
|
&& preference instanceof final ListPreference listPreference) {
|
||||||
|
final int index = listPreference.findIndexOfValue(value);
|
||||||
|
final String presetName = listPreference.getEntries()[index].toString();
|
||||||
|
final int presetIndex = Integer.parseInt(
|
||||||
|
listPreference.getEntryValues()[index].toString());
|
||||||
|
listPreference.setSummary(presetName);
|
||||||
|
boolean supportSynchronizedPresets = mHapClientProfile.supportsSynchronizedPresets(
|
||||||
|
mCachedDevice.getDevice());
|
||||||
|
int hapGroupId = mHapClientProfile.getHapGroup(mCachedDevice.getDevice());
|
||||||
|
if (supportSynchronizedPresets
|
||||||
|
&& hapGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onPreferenceChange, selectPresetForGroup "
|
||||||
|
+ ", presetName: " + presetName
|
||||||
|
+ ", presetIndex: " + presetIndex
|
||||||
|
+ ", hapGroupId: " + hapGroupId
|
||||||
|
+ ", device: " + mCachedDevice.getAddress());
|
||||||
|
}
|
||||||
|
mHapClientProfile.selectPresetForGroup(hapGroupId, presetIndex);
|
||||||
|
} else {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onPreferenceChange, selectPreset "
|
||||||
|
+ ", presetName: " + presetName
|
||||||
|
+ ", presetIndex: " + presetIndex
|
||||||
|
+ ", device: " + mCachedDevice.getAddress());
|
||||||
|
}
|
||||||
|
mHapClientProfile.selectPreset(mCachedDevice.getDevice(), presetIndex);
|
||||||
|
final CachedBluetoothDevice subDevice = mCachedDevice.getSubDevice();
|
||||||
|
if (subDevice != null) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onPreferenceChange, selectPreset for subDevice"
|
||||||
|
+ ", device: " + subDevice.getAddress());
|
||||||
|
}
|
||||||
|
mHapClientProfile.selectPreset(subDevice.getDevice(), presetIndex);
|
||||||
|
}
|
||||||
|
for (final CachedBluetoothDevice memberDevice :
|
||||||
|
mCachedDevice.getMemberDevice()) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onPreferenceChange, selectPreset for memberDevice"
|
||||||
|
+ ", device: " + memberDevice.getAddress());
|
||||||
|
}
|
||||||
|
mHapClientProfile.selectPreset(memberDevice.getDevice(), presetIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_HEARING_AIDS_PRESETS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init(PreferenceScreen screen) {
|
||||||
|
PreferenceCategory deviceControls = screen.findPreference(KEY_HEARING_DEVICE_GROUP);
|
||||||
|
if (deviceControls != null) {
|
||||||
|
mPreference = createPresetPreference(deviceControls.getContext());
|
||||||
|
deviceControls.addPreference(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void refresh() {
|
||||||
|
if (!isAvailable() || mPreference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mPreference.setEnabled(mCachedDevice.isConnectedHapClientDevice());
|
||||||
|
|
||||||
|
loadAllPresetInfo();
|
||||||
|
if (mPreference.getEntries().length == 0) {
|
||||||
|
mPreference.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
int activePresetIndex = mHapClientProfile.getActivePresetIndex(
|
||||||
|
mCachedDevice.getDevice());
|
||||||
|
if (activePresetIndex != BluetoothHapClient.PRESET_INDEX_UNAVAILABLE) {
|
||||||
|
mPreference.setValue(Integer.toString(activePresetIndex));
|
||||||
|
mPreference.setSummary(mPreference.getEntry());
|
||||||
|
} else {
|
||||||
|
mPreference.setSummary(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (mHapClientProfile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mCachedDevice.getProfiles().stream().anyMatch(
|
||||||
|
profile -> profile instanceof HapClientProfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPresetSelected(@NonNull BluetoothDevice device, int presetIndex, int reason) {
|
||||||
|
if (device.equals(mCachedDevice.getDevice())) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onPresetSelected, device: " + device.getAddress()
|
||||||
|
+ ", presetIndex: " + presetIndex + ", reason: " + reason);
|
||||||
|
}
|
||||||
|
mContext.getMainExecutor().execute(this::refresh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPresetSelectionFailed(@NonNull BluetoothDevice device, int reason) {
|
||||||
|
if (device.equals(mCachedDevice.getDevice())) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG,
|
||||||
|
"onPresetSelectionFailed, device: " + device.getAddress()
|
||||||
|
+ ", reason: " + reason);
|
||||||
|
}
|
||||||
|
mContext.getMainExecutor().execute(() -> {
|
||||||
|
refresh();
|
||||||
|
showErrorToast();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPresetSelectionForGroupFailed(int hapGroupId, int reason) {
|
||||||
|
if (hapGroupId == mHapClientProfile.getHapGroup(mCachedDevice.getDevice())) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onPresetSelectionForGroupFailed, group: " + hapGroupId
|
||||||
|
+ ", reason: " + reason);
|
||||||
|
}
|
||||||
|
mContext.getMainExecutor().execute(() -> {
|
||||||
|
refresh();
|
||||||
|
showErrorToast();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPresetInfoChanged(@NonNull BluetoothDevice device,
|
||||||
|
@NonNull List<BluetoothHapPresetInfo> presetInfoList, int reason) {
|
||||||
|
if (device.equals(mCachedDevice.getDevice())) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onPresetInfoChanged, device: " + device.getAddress()
|
||||||
|
+ ", reason: " + reason
|
||||||
|
+ ", infoList: " + presetInfoList);
|
||||||
|
}
|
||||||
|
mContext.getMainExecutor().execute(this::refresh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSetPresetNameFailed(@NonNull BluetoothDevice device, int reason) {
|
||||||
|
if (device.equals(mCachedDevice.getDevice())) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG,
|
||||||
|
"onSetPresetNameFailed, device: " + device.getAddress()
|
||||||
|
+ ", reason: " + reason);
|
||||||
|
}
|
||||||
|
mContext.getMainExecutor().execute(() -> {
|
||||||
|
refresh();
|
||||||
|
showErrorToast();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSetPresetNameForGroupFailed(int hapGroupId, int reason) {
|
||||||
|
if (hapGroupId == mHapClientProfile.getHapGroup(mCachedDevice.getDevice())) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onSetPresetNameForGroupFailed, group: " + hapGroupId
|
||||||
|
+ ", reason: " + reason);
|
||||||
|
}
|
||||||
|
mContext.getMainExecutor().execute(() -> {
|
||||||
|
refresh();
|
||||||
|
showErrorToast();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ListPreference createPresetPreference(Context context) {
|
||||||
|
ListPreference preference = new ListPreference(context);
|
||||||
|
preference.setKey(KEY_HEARING_AIDS_PRESETS);
|
||||||
|
preference.setOrder(ORDER_HEARING_AIDS_PRESETS);
|
||||||
|
preference.setTitle(context.getString(R.string.bluetooth_hearing_aids_presets));
|
||||||
|
preference.setOnPreferenceChangeListener(this);
|
||||||
|
return preference;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAllPresetInfo() {
|
||||||
|
if (mPreference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<BluetoothHapPresetInfo> infoList = mHapClientProfile.getAllPresetInfo(
|
||||||
|
mCachedDevice.getDevice());
|
||||||
|
CharSequence[] presetNames = new CharSequence[infoList.size()];
|
||||||
|
CharSequence[] presetIndexes = new CharSequence[infoList.size()];
|
||||||
|
for (int i = 0; i < infoList.size(); i++) {
|
||||||
|
presetNames[i] = infoList.get(i).getName();
|
||||||
|
presetIndexes[i] = Integer.toString(infoList.get(i).getIndex());
|
||||||
|
}
|
||||||
|
mPreference.setEntries(presetNames);
|
||||||
|
mPreference.setEntryValues(presetIndexes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
@Nullable
|
||||||
|
ListPreference getPreference() {
|
||||||
|
return mPreference;
|
||||||
|
}
|
||||||
|
|
||||||
|
void showErrorToast() {
|
||||||
|
Toast.makeText(mContext, R.string.bluetooth_hearing_aids_presets_error,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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.bluetooth;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.accessibility.Flags;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The controller of the hearing device controls.
|
||||||
|
*
|
||||||
|
* <p><b>Note:</b> It is responsible for creating the sub-controllers inside this preference
|
||||||
|
* category controller.
|
||||||
|
*/
|
||||||
|
public class BluetoothDetailsHearingDeviceController extends BluetoothDetailsController {
|
||||||
|
|
||||||
|
public static final int ORDER_HEARING_DEVICE_SETTINGS = 1;
|
||||||
|
public static final int ORDER_HEARING_AIDS_PRESETS = 2;
|
||||||
|
static final String KEY_HEARING_DEVICE_GROUP = "hearing_device_group";
|
||||||
|
|
||||||
|
private final List<BluetoothDetailsController> mControllers = new ArrayList<>();
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
private LocalBluetoothManager mManager;
|
||||||
|
|
||||||
|
public BluetoothDetailsHearingDeviceController(@NonNull Context context,
|
||||||
|
@NonNull PreferenceFragmentCompat fragment,
|
||||||
|
@NonNull LocalBluetoothManager manager,
|
||||||
|
@NonNull CachedBluetoothDevice device,
|
||||||
|
@NonNull Lifecycle lifecycle) {
|
||||||
|
super(context, fragment, device, lifecycle);
|
||||||
|
mManager = manager;
|
||||||
|
mLifecycle = lifecycle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setSubControllers(
|
||||||
|
BluetoothDetailsHearingDeviceSettingsController hearingDeviceSettingsController,
|
||||||
|
BluetoothDetailsHearingAidsPresetsController presetsController) {
|
||||||
|
mControllers.clear();
|
||||||
|
mControllers.add(hearingDeviceSettingsController);
|
||||||
|
mControllers.add(presetsController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mControllers.stream().anyMatch(BluetoothDetailsController::isAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_HEARING_DEVICE_GROUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init(PreferenceScreen screen) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void refresh() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiates the sub controllers controlled by this group controller.
|
||||||
|
*
|
||||||
|
* <p><b>Note:</b> The caller must call this method when creating this class.
|
||||||
|
*
|
||||||
|
* @param isLaunchFromHearingDevicePage a boolean that determines if the caller is launch from
|
||||||
|
* hearing device page
|
||||||
|
*/
|
||||||
|
void initSubControllers(boolean isLaunchFromHearingDevicePage) {
|
||||||
|
mControllers.clear();
|
||||||
|
// Don't need to show the entrance to hearing device page when launched from the same page
|
||||||
|
if (!isLaunchFromHearingDevicePage) {
|
||||||
|
mControllers.add(new BluetoothDetailsHearingDeviceSettingsController(mContext,
|
||||||
|
mFragment, mCachedDevice, mLifecycle));
|
||||||
|
}
|
||||||
|
if (Flags.enableHearingAidPresetControl()) {
|
||||||
|
mControllers.add(new BluetoothDetailsHearingAidsPresetsController(mContext, mFragment,
|
||||||
|
mManager, mCachedDevice, mLifecycle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public List<BluetoothDetailsController> getSubControllers() {
|
||||||
|
return mControllers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.KEY_HEARING_DEVICE_GROUP;
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.ORDER_HEARING_DEVICE_SETTINGS;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@@ -36,15 +39,13 @@ import com.google.common.annotations.VisibleForTesting;
|
|||||||
/**
|
/**
|
||||||
* The controller of the hearing device settings to launch Hearing device page.
|
* The controller of the hearing device settings to launch Hearing device page.
|
||||||
*/
|
*/
|
||||||
public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDetailsController
|
public class BluetoothDetailsHearingDeviceSettingsController extends BluetoothDetailsController
|
||||||
implements Preference.OnPreferenceClickListener {
|
implements Preference.OnPreferenceClickListener {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String KEY_DEVICE_CONTROLS_GENERAL_GROUP = "device_controls_general";
|
static final String KEY_HEARING_DEVICE_SETTINGS = "hearing_device_settings";
|
||||||
@VisibleForTesting
|
|
||||||
static final String KEY_HEARING_DEVICE_CONTROLS = "hearing_device_controls";
|
|
||||||
|
|
||||||
public BluetoothDetailsHearingDeviceControlsController(Context context,
|
public BluetoothDetailsHearingDeviceSettingsController(Context context,
|
||||||
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||||
super(context, fragment, device, lifecycle);
|
super(context, fragment, device, lifecycle);
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
@@ -57,37 +58,40 @@ public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init(PreferenceScreen screen) {
|
protected void init(PreferenceScreen screen) {
|
||||||
if (!mCachedDevice.isHearingAidDevice()) {
|
if (!isAvailable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final PreferenceCategory group = screen.findPreference(KEY_HEARING_DEVICE_GROUP);
|
||||||
final PreferenceCategory prefCategory = screen.findPreference(getPreferenceKey());
|
final Preference pref = createHearingDeviceSettingsPreference(group.getContext());
|
||||||
final Preference pref = createHearingDeviceControlsPreference(prefCategory.getContext());
|
group.addPreference(pref);
|
||||||
prefCategory.addPreference(pref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refresh() {}
|
protected void refresh() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_DEVICE_CONTROLS_GENERAL_GROUP;
|
return KEY_HEARING_DEVICE_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_CONTROLS)) {
|
if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_SETTINGS)) {
|
||||||
launchAccessibilityHearingDeviceSettings();
|
launchAccessibilityHearingDeviceSettings();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Preference createHearingDeviceControlsPreference(Context context) {
|
private Preference createHearingDeviceSettingsPreference(Context context) {
|
||||||
final ArrowPreference preference = new ArrowPreference(context);
|
final ArrowPreference preference = new ArrowPreference(context);
|
||||||
preference.setKey(KEY_HEARING_DEVICE_CONTROLS);
|
preference.setKey(KEY_HEARING_DEVICE_SETTINGS);
|
||||||
preference.setTitle(context.getString(R.string.bluetooth_device_controls_title));
|
preference.setOrder(ORDER_HEARING_DEVICE_SETTINGS);
|
||||||
preference.setSummary(context.getString(R.string.bluetooth_device_controls_summary));
|
preference.setTitle(context.getString(R.string.bluetooth_hearing_device_settings_title));
|
||||||
|
preference.setSummary(
|
||||||
|
context.getString(R.string.bluetooth_hearing_device_settings_summary));
|
||||||
preference.setOnPreferenceClickListener(this);
|
preference.setOnPreferenceClickListener(this);
|
||||||
|
|
||||||
return preference;
|
return preference;
|
||||||
@@ -326,16 +326,16 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
|||||||
lifecycle));
|
lifecycle));
|
||||||
controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
|
controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
|
||||||
lifecycle));
|
lifecycle));
|
||||||
// Don't need to show hearing device again when launched from the same page.
|
controllers.add(new BluetoothDetailsDataSyncController(context, this, mCachedDevice,
|
||||||
if (!isLaunchFromHearingDevicePage()) {
|
lifecycle));
|
||||||
controllers.add(new BluetoothDetailsHearingDeviceControlsController(context, this,
|
controllers.add(new BluetoothDetailsExtraOptionsController(context, this, mCachedDevice,
|
||||||
mCachedDevice, lifecycle));
|
lifecycle));
|
||||||
}
|
BluetoothDetailsHearingDeviceController hearingDeviceController =
|
||||||
controllers.add(new BluetoothDetailsDataSyncController(context, this,
|
new BluetoothDetailsHearingDeviceController(context, this, mManager,
|
||||||
mCachedDevice, lifecycle));
|
mCachedDevice, lifecycle);
|
||||||
controllers.add(
|
controllers.add(hearingDeviceController);
|
||||||
new BluetoothDetailsExtraOptionsController(
|
hearingDeviceController.initSubControllers(isLaunchFromHearingDevicePage());
|
||||||
context, this, mCachedDevice, lifecycle));
|
controllers.addAll(hearingDeviceController.getSubControllers());
|
||||||
}
|
}
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ import com.android.settingslib.applications.AppUtils;
|
|||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.instrumentation.Instrumentable;
|
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||||
import com.android.settingslib.datastore.ChangeReason;
|
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -272,7 +271,6 @@ public class AdvancedPowerUsageDetail extends DashboardFragment
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
notifyBackupManager();
|
|
||||||
final int currentOptimizeMode = mBatteryOptimizeUtils.getAppOptimizationMode();
|
final int currentOptimizeMode = mBatteryOptimizeUtils.getAppOptimizationMode();
|
||||||
mLogStringBuilder.append(", onPause mode = ").append(currentOptimizeMode);
|
mLogStringBuilder.append(", onPause mode = ").append(currentOptimizeMode);
|
||||||
logMetricCategory(currentOptimizeMode);
|
logMetricCategory(currentOptimizeMode);
|
||||||
@@ -289,13 +287,6 @@ public class AdvancedPowerUsageDetail extends DashboardFragment
|
|||||||
Log.d(TAG, "Leave with mode: " + currentOptimizeMode);
|
Log.d(TAG, "Leave with mode: " + currentOptimizeMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void notifyBackupManager() {
|
|
||||||
if (mOptimizationMode != mBatteryOptimizeUtils.getAppOptimizationMode()) {
|
|
||||||
BatterySettingsStorage.get(getContext()).notifyChange(ChangeReason.UPDATE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void initHeader() {
|
void initHeader() {
|
||||||
final View appSnippet = mHeaderPreference.findViewById(R.id.entity_header);
|
final View appSnippet = mHeaderPreference.findViewById(R.id.entity_header);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
|
import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
|
||||||
|
import com.android.settingslib.datastore.ChangeReason;
|
||||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@@ -222,6 +223,10 @@ public class BatteryOptimizeUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// App preferences are already clear when code reach here, and there may be no
|
||||||
|
// setAppUsageStateInternal call to notifyChange. So always trigger notifyChange here.
|
||||||
|
BatterySettingsStorage.get(context).notifyChange(ChangeReason.DELETE);
|
||||||
|
|
||||||
allowlistBackend.refreshList();
|
allowlistBackend.refreshList();
|
||||||
// Resets optimization mode for each application.
|
// Resets optimization mode for each application.
|
||||||
for (ApplicationInfo info : applications) {
|
for (ApplicationInfo info : applications) {
|
||||||
@@ -351,6 +356,9 @@ public class BatteryOptimizeUtils {
|
|||||||
}
|
}
|
||||||
BatteryOptimizeLogUtils.writeLog(
|
BatteryOptimizeLogUtils.writeLog(
|
||||||
context, action, packageNameKey, createLogEvent(appStandbyMode, allowListed));
|
context, action, packageNameKey, createLogEvent(appStandbyMode, allowListed));
|
||||||
|
if (action != Action.RESET) { // reset has been notified in resetAppOptimizationMode
|
||||||
|
BatterySettingsStorage.get(context).notifyChange(toChangeReason(action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String createLogEvent(int appStandbyMode, boolean allowListed) {
|
private static String createLogEvent(int appStandbyMode, boolean allowListed) {
|
||||||
@@ -362,4 +370,8 @@ public class BatteryOptimizeUtils {
|
|||||||
allowListed,
|
allowListed,
|
||||||
getAppOptimizationMode(appStandbyMode, allowListed));
|
getAppOptimizationMode(appStandbyMode, allowListed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static @ChangeReason int toChangeReason(Action action) {
|
||||||
|
return action == Action.RESTORE ? ChangeReason.RESTORE : ChangeReason.UPDATE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import com.android.settingslib.HelpUtils;
|
|||||||
import com.android.settingslib.applications.AppUtils;
|
import com.android.settingslib.applications.AppUtils;
|
||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.datastore.ChangeReason;
|
|
||||||
import com.android.settingslib.widget.FooterPreference;
|
import com.android.settingslib.widget.FooterPreference;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
import com.android.settingslib.widget.MainSwitchPreference;
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
@@ -116,7 +115,6 @@ public class PowerBackgroundUsageDetail extends DashboardFragment
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
notifyBackupManager();
|
|
||||||
final int currentOptimizeMode = mBatteryOptimizeUtils.getAppOptimizationMode();
|
final int currentOptimizeMode = mBatteryOptimizeUtils.getAppOptimizationMode();
|
||||||
mLogStringBuilder.append(", onPause mode = ").append(currentOptimizeMode);
|
mLogStringBuilder.append(", onPause mode = ").append(currentOptimizeMode);
|
||||||
logMetricCategory(currentOptimizeMode);
|
logMetricCategory(currentOptimizeMode);
|
||||||
@@ -183,13 +181,6 @@ public class PowerBackgroundUsageDetail extends DashboardFragment
|
|||||||
onRadioButtonClicked(isEnabled ? mOptimizePreference : null);
|
onRadioButtonClicked(isEnabled ? mOptimizePreference : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void notifyBackupManager() {
|
|
||||||
if (mOptimizationMode != mBatteryOptimizeUtils.getAppOptimizationMode()) {
|
|
||||||
BatterySettingsStorage.get(getContext()).notifyChange(ChangeReason.UPDATE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
int getSelectedPreference() {
|
int getSelectedPreference() {
|
||||||
if (!mMainSwitchPreference.isChecked()) {
|
if (!mMainSwitchPreference.isChecked()) {
|
||||||
|
|||||||
@@ -16,16 +16,22 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.input.InputSettings;
|
import android.hardware.input.InputSettings;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
public class TrackpadTapDraggingPreferenceController extends TogglePreferenceController {
|
public class TrackpadTapDraggingPreferenceController extends TogglePreferenceController {
|
||||||
|
|
||||||
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
public TrackpadTapDraggingPreferenceController(Context context, String key) {
|
public TrackpadTapDraggingPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
|
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,7 +42,8 @@ public class TrackpadTapDraggingPreferenceController extends TogglePreferenceCon
|
|||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
InputSettings.setTouchpadTapDragging(mContext, isChecked);
|
InputSettings.setTouchpadTapDragging(mContext, isChecked);
|
||||||
// TODO(b/321978150): add a metric for tap dragging settings changes.
|
mMetricsFeatureProvider.action(
|
||||||
|
mContext, SettingsEnums.ACTION_GESTURE_TAP_DRAGGING_CHANGED, isChecked);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.network.SubscriptionInfoListViewModel
|
import com.android.settings.network.SubscriptionInfoListViewModel
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils
|
import com.android.settings.network.telephony.MobileNetworkUtils
|
||||||
|
import com.android.settings.spa.network.PrimarySimRepository.PrimarySimInfo
|
||||||
import com.android.settings.wifi.WifiPickerTrackerHelper
|
import com.android.settings.wifi.WifiPickerTrackerHelper
|
||||||
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
|
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
|
||||||
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
||||||
import com.android.settingslib.spa.framework.common.createSettingsPage
|
import com.android.settingslib.spa.framework.common.createSettingsPage
|
||||||
import com.android.settingslib.spa.framework.compose.navigator
|
import com.android.settingslib.spa.framework.compose.navigator
|
||||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||||
import com.android.settingslib.spa.widget.preference.ListPreferenceOption
|
|
||||||
import com.android.settingslib.spa.widget.preference.Preference
|
import com.android.settingslib.spa.widget.preference.Preference
|
||||||
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
||||||
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
||||||
@@ -173,16 +173,12 @@ fun PageImpl(
|
|||||||
) {
|
) {
|
||||||
val selectableSubscriptionInfoList by selectableSubscriptionInfoListFlow
|
val selectableSubscriptionInfoList by selectableSubscriptionInfoListFlow
|
||||||
.collectAsStateWithLifecycle(initialValue = emptyList())
|
.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||||
val activeSubscriptionInfoList: List<SubscriptionInfo> =
|
|
||||||
selectableSubscriptionInfoList.filter { subscriptionInfo ->
|
|
||||||
subscriptionInfo.simSlotIndex != -1
|
|
||||||
}
|
|
||||||
|
|
||||||
val stringSims = stringResource(R.string.provider_network_settings_title)
|
val stringSims = stringResource(R.string.provider_network_settings_title)
|
||||||
RegularScaffold(title = stringSims) {
|
RegularScaffold(title = stringSims) {
|
||||||
SimsSection(selectableSubscriptionInfoList)
|
SimsSection(selectableSubscriptionInfoList)
|
||||||
PrimarySimSectionImpl(
|
PrimarySimSectionImpl(
|
||||||
activeSubscriptionInfoList,
|
selectableSubscriptionInfoListFlow,
|
||||||
defaultVoiceSubId,
|
defaultVoiceSubId,
|
||||||
defaultSmsSubId,
|
defaultSmsSubId,
|
||||||
defaultDataSubId,
|
defaultDataSubId,
|
||||||
@@ -193,7 +189,7 @@ fun PageImpl(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PrimarySimImpl(
|
fun PrimarySimImpl(
|
||||||
subscriptionInfoList: List<SubscriptionInfo>,
|
primarySimInfo: PrimarySimInfo,
|
||||||
callsSelectedId: MutableIntState,
|
callsSelectedId: MutableIntState,
|
||||||
textsSelectedId: MutableIntState,
|
textsSelectedId: MutableIntState,
|
||||||
mobileDataSelectedId: MutableIntState,
|
mobileDataSelectedId: MutableIntState,
|
||||||
@@ -237,40 +233,6 @@ fun PrimarySimImpl(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
var state = rememberSaveable { mutableStateOf(false) }
|
|
||||||
var callsAndSmsList = remember {
|
|
||||||
mutableListOf(ListPreferenceOption(id = -1, text = "Loading"))
|
|
||||||
}
|
|
||||||
var dataList = remember {
|
|
||||||
mutableListOf(ListPreferenceOption(id = -1, text = "Loading"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subscriptionInfoList.size >= 2) {
|
|
||||||
state.value = true
|
|
||||||
callsAndSmsList.clear()
|
|
||||||
dataList.clear()
|
|
||||||
for (info in subscriptionInfoList) {
|
|
||||||
var item = ListPreferenceOption(
|
|
||||||
id = info.subscriptionId,
|
|
||||||
text = "${info.displayName}",
|
|
||||||
summary = "${info.number}"
|
|
||||||
)
|
|
||||||
callsAndSmsList.add(item)
|
|
||||||
dataList.add(item)
|
|
||||||
}
|
|
||||||
callsAndSmsList.add(
|
|
||||||
ListPreferenceOption(
|
|
||||||
id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
|
|
||||||
text = stringResource(id = R.string.sim_calls_ask_first_prefs_title)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// hide the primary sim
|
|
||||||
state.value = false
|
|
||||||
Log.d(NetworkCellularGroupProvider.name, "Hide primary sim")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.value) {
|
|
||||||
val telephonyManagerForNonDds: TelephonyManager? =
|
val telephonyManagerForNonDds: TelephonyManager? =
|
||||||
context.getSystemService(TelephonyManager::class.java)
|
context.getSystemService(TelephonyManager::class.java)
|
||||||
?.createForSubscriptionId(nonDds.intValue)
|
?.createForSubscriptionId(nonDds.intValue)
|
||||||
@@ -280,21 +242,21 @@ fun PrimarySimImpl(
|
|||||||
|
|
||||||
CreatePrimarySimListPreference(
|
CreatePrimarySimListPreference(
|
||||||
stringResource(id = R.string.primary_sim_calls_title),
|
stringResource(id = R.string.primary_sim_calls_title),
|
||||||
callsAndSmsList,
|
primarySimInfo.callsAndSmsList,
|
||||||
callsSelectedId,
|
callsSelectedId,
|
||||||
ImageVector.vectorResource(R.drawable.ic_phone),
|
ImageVector.vectorResource(R.drawable.ic_phone),
|
||||||
actionSetCalls
|
actionSetCalls
|
||||||
)
|
)
|
||||||
CreatePrimarySimListPreference(
|
CreatePrimarySimListPreference(
|
||||||
stringResource(id = R.string.primary_sim_texts_title),
|
stringResource(id = R.string.primary_sim_texts_title),
|
||||||
callsAndSmsList,
|
primarySimInfo.callsAndSmsList,
|
||||||
textsSelectedId,
|
textsSelectedId,
|
||||||
Icons.AutoMirrored.Outlined.Message,
|
Icons.AutoMirrored.Outlined.Message,
|
||||||
actionSetTexts
|
actionSetTexts
|
||||||
)
|
)
|
||||||
CreatePrimarySimListPreference(
|
CreatePrimarySimListPreference(
|
||||||
stringResource(id = R.string.mobile_data_settings_title),
|
stringResource(id = R.string.mobile_data_settings_title),
|
||||||
dataList,
|
primarySimInfo.dataList,
|
||||||
mobileDataSelectedId,
|
mobileDataSelectedId,
|
||||||
Icons.Outlined.DataUsage,
|
Icons.Outlined.DataUsage,
|
||||||
actionSetMobileData
|
actionSetMobileData
|
||||||
@@ -325,20 +287,29 @@ fun PrimarySimImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PrimarySimSectionImpl(
|
fun PrimarySimSectionImpl(
|
||||||
subscriptionInfoList: List<SubscriptionInfo>,
|
subscriptionInfoListFlow: Flow<List<SubscriptionInfo>>,
|
||||||
callsSelectedId: MutableIntState,
|
callsSelectedId: MutableIntState,
|
||||||
textsSelectedId: MutableIntState,
|
textsSelectedId: MutableIntState,
|
||||||
mobileDataSelectedId: MutableIntState,
|
mobileDataSelectedId: MutableIntState,
|
||||||
nonDds: MutableIntState,
|
nonDds: MutableIntState,
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val primarySimInfo = remember(subscriptionInfoListFlow) {
|
||||||
|
subscriptionInfoListFlow
|
||||||
|
.map { subscriptionInfoList ->
|
||||||
|
subscriptionInfoList.filter { subInfo -> subInfo.simSlotIndex != -1 }
|
||||||
|
}
|
||||||
|
.map(PrimarySimRepository(context)::getPrimarySimInfo)
|
||||||
|
.flowOn(Dispatchers.Default)
|
||||||
|
}.collectAsStateWithLifecycle(initialValue = null).value ?: return
|
||||||
|
|
||||||
Category(title = stringResource(id = R.string.primary_sim_title)) {
|
Category(title = stringResource(id = R.string.primary_sim_title)) {
|
||||||
PrimarySimImpl(
|
PrimarySimImpl(
|
||||||
subscriptionInfoList,
|
primarySimInfo,
|
||||||
callsSelectedId,
|
callsSelectedId,
|
||||||
textsSelectedId,
|
textsSelectedId,
|
||||||
mobileDataSelectedId,
|
mobileDataSelectedId,
|
||||||
|
|||||||
62
src/com/android/settings/spa/network/PrimarySimRepository.kt
Normal file
62
src/com/android/settings/spa/network/PrimarySimRepository.kt
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.spa.network
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.telephony.SubscriptionInfo
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
|
import android.util.Log
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.android.settings.network.SubscriptionUtil
|
||||||
|
import com.android.settingslib.spa.widget.preference.ListPreferenceOption
|
||||||
|
|
||||||
|
class PrimarySimRepository(private val context: Context) {
|
||||||
|
|
||||||
|
data class PrimarySimInfo(
|
||||||
|
val callsAndSmsList: List<ListPreferenceOption>,
|
||||||
|
val dataList: List<ListPreferenceOption>,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getPrimarySimInfo(selectableSubscriptionInfoList: List<SubscriptionInfo>): PrimarySimInfo? {
|
||||||
|
if (selectableSubscriptionInfoList.size < 2) {
|
||||||
|
Log.d(TAG, "Hide primary sim")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val callsAndSmsList = mutableListOf<ListPreferenceOption>()
|
||||||
|
val dataList = mutableListOf<ListPreferenceOption>()
|
||||||
|
for (info in selectableSubscriptionInfoList) {
|
||||||
|
val item = ListPreferenceOption(
|
||||||
|
id = info.subscriptionId,
|
||||||
|
text = "${info.displayName}",
|
||||||
|
summary = SubscriptionUtil.getFormattedPhoneNumber(context, info) ?: "",
|
||||||
|
)
|
||||||
|
callsAndSmsList += item
|
||||||
|
dataList += item
|
||||||
|
}
|
||||||
|
callsAndSmsList += ListPreferenceOption(
|
||||||
|
id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
|
||||||
|
text = context.getString(R.string.sim_calls_ask_first_prefs_title),
|
||||||
|
)
|
||||||
|
|
||||||
|
return PrimarySimInfo(callsAndSmsList, dataList)
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
private const val TAG = "PrimarySimRepository"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,10 +24,13 @@ import androidx.compose.material.icons.outlined.SignalCellularAlt
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.MutableIntState
|
import androidx.compose.runtime.MutableIntState
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.network.SimOnboardingService
|
import com.android.settings.network.SimOnboardingService
|
||||||
import com.android.settingslib.spa.framework.theme.SettingsDimension
|
import com.android.settingslib.spa.framework.theme.SettingsDimension
|
||||||
@@ -38,6 +41,9 @@ import com.android.settingslib.spa.widget.scaffold.BottomAppBarButton
|
|||||||
import com.android.settingslib.spa.widget.scaffold.SuwScaffold
|
import com.android.settingslib.spa.widget.scaffold.SuwScaffold
|
||||||
import com.android.settingslib.spa.widget.ui.SettingsBody
|
import com.android.settingslib.spa.widget.ui.SettingsBody
|
||||||
import com.android.settingslib.spa.widget.ui.SettingsIcon
|
import com.android.settingslib.spa.widget.ui.SettingsIcon
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the sim onboarding primary sim compose
|
* the sim onboarding primary sim compose
|
||||||
@@ -77,13 +83,19 @@ fun SimOnboardingPrimarySimImpl(
|
|||||||
SettingsBody(stringResource(id = R.string.sim_onboarding_primary_sim_msg))
|
SettingsBody(stringResource(id = R.string.sim_onboarding_primary_sim_msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedSubscriptionInfoList =
|
val context = LocalContext.current
|
||||||
|
val primarySimInfo = remember {
|
||||||
|
flow {
|
||||||
|
val selectableSubInfoList =
|
||||||
onboardingService.getSelectedSubscriptionInfoListWithRenaming()
|
onboardingService.getSelectedSubscriptionInfoListWithRenaming()
|
||||||
|
emit(PrimarySimRepository(context).getPrimarySimInfo(selectableSubInfoList))
|
||||||
|
}.flowOn(Dispatchers.Default)
|
||||||
|
}.collectAsStateWithLifecycle(initialValue = null).value ?: return@SuwScaffold
|
||||||
callsSelectedId.intValue = onboardingService.targetPrimarySimCalls
|
callsSelectedId.intValue = onboardingService.targetPrimarySimCalls
|
||||||
textsSelectedId.intValue = onboardingService.targetPrimarySimTexts
|
textsSelectedId.intValue = onboardingService.targetPrimarySimTexts
|
||||||
mobileDataSelectedId.intValue = onboardingService.targetPrimarySimMobileData
|
mobileDataSelectedId.intValue = onboardingService.targetPrimarySimMobileData
|
||||||
PrimarySimImpl(
|
PrimarySimImpl(
|
||||||
subscriptionInfoList = selectedSubscriptionInfoList,
|
primarySimInfo = primarySimInfo,
|
||||||
callsSelectedId = callsSelectedId,
|
callsSelectedId = callsSelectedId,
|
||||||
textsSelectedId = textsSelectedId,
|
textsSelectedId = textsSelectedId,
|
||||||
mobileDataSelectedId = mobileDataSelectedId,
|
mobileDataSelectedId = mobileDataSelectedId,
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ import com.android.settings.network.telephony.isSubscriptionEnabledFlow
|
|||||||
import com.android.settings.network.telephony.phoneNumberFlow
|
import com.android.settings.network.telephony.phoneNumberFlow
|
||||||
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
||||||
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
|
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
|
||||||
import com.android.settingslib.spa.widget.preference.TwoTargetSwitchPreference
|
|
||||||
import com.android.settingslib.spa.widget.ui.SettingsIcon
|
import com.android.settingslib.spa.widget.ui.SettingsIcon
|
||||||
import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
|
import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
|
||||||
import com.android.settingslib.spaprivileged.template.preference.RestrictedPreference
|
import com.android.settingslib.spaprivileged.template.preference.RestrictedPreference
|
||||||
|
import com.android.settingslib.spaprivileged.template.preference.RestrictedTwoTargetSwitchPreference
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SimsSection(subscriptionInfoList: List<SubscriptionInfo>) {
|
fun SimsSection(subscriptionInfoList: List<SubscriptionInfo>) {
|
||||||
@@ -61,9 +61,8 @@ private fun SimPreference(subInfo: SubscriptionInfo) {
|
|||||||
val phoneNumber = remember(subInfo) {
|
val phoneNumber = remember(subInfo) {
|
||||||
context.phoneNumberFlow(subInfo)
|
context.phoneNumberFlow(subInfo)
|
||||||
}.collectAsStateWithLifecycle(initialValue = null)
|
}.collectAsStateWithLifecycle(initialValue = null)
|
||||||
//TODO: Add the Restricted TwoTargetSwitchPreference in SPA
|
RestrictedTwoTargetSwitchPreference(
|
||||||
TwoTargetSwitchPreference(
|
model = object : SwitchPreferenceModel {
|
||||||
object : SwitchPreferenceModel {
|
|
||||||
override val title = subInfo.displayName.toString()
|
override val title = subInfo.displayName.toString()
|
||||||
override val summary = { phoneNumber.value ?: "" }
|
override val summary = { phoneNumber.value ?: "" }
|
||||||
override val checked = { checked.value }
|
override val checked = { checked.value }
|
||||||
@@ -74,7 +73,8 @@ private fun SimPreference(subInfo: SubscriptionInfo) {
|
|||||||
newChecked,
|
newChecked,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
restrictions = Restrictions(keys = listOf(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)),
|
||||||
) {
|
) {
|
||||||
MobileNetworkUtils.launchMobileNetworkSettings(context, subInfo)
|
MobileNetworkUtils.launchMobileNetworkSettings(context, subInfo)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.settings.applications;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -48,12 +49,13 @@ import com.android.settingslib.widget.LayoutPreference;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
@@ -62,6 +64,8 @@ import org.robolectric.util.ReflectionHelpers;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowEntityHeaderController.class, ShadowSettingsLibUtils.class})
|
@Config(shadows = {ShadowEntityHeaderController.class, ShadowSettingsLibUtils.class})
|
||||||
public class AppInfoWithHeaderTest {
|
public class AppInfoWithHeaderTest {
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private EntityHeaderController mHeaderController;
|
private EntityHeaderController mHeaderController;
|
||||||
@@ -71,7 +75,6 @@ public class AppInfoWithHeaderTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mFactory = FakeFeatureFactory.setupForTest();
|
mFactory = FakeFeatureFactory.setupForTest();
|
||||||
when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
|
when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
|
||||||
.thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
|
.thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
|
||||||
@@ -120,7 +123,6 @@ public class AppInfoWithHeaderTest {
|
|||||||
assertThat(mAppInfoWithHeader.mPackageRemovedCalled).isTrue();
|
assertThat(mAppInfoWithHeader.mPackageRemovedCalled).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("b/315135755")
|
|
||||||
@Test
|
@Test
|
||||||
public void noExtraUserHandleInIntent_retrieveAppEntryWithMyUserId()
|
public void noExtraUserHandleInIntent_retrieveAppEntryWithMyUserId()
|
||||||
throws PackageManager.NameNotFoundException {
|
throws PackageManager.NameNotFoundException {
|
||||||
@@ -133,10 +135,8 @@ public class AppInfoWithHeaderTest {
|
|||||||
|
|
||||||
when(mAppInfoWithHeader.mState.getEntry(packageName,
|
when(mAppInfoWithHeader.mState.getEntry(packageName,
|
||||||
UserHandle.myUserId())).thenReturn(entry);
|
UserHandle.myUserId())).thenReturn(entry);
|
||||||
when(mAppInfoWithHeader.mPm.getPackageInfoAsUser(entry.info.packageName,
|
when(mAppInfoWithHeader.mPm.getPackageInfoAsUser(eq(entry.info.packageName),
|
||||||
PackageManager.MATCH_DISABLED_COMPONENTS |
|
any(), eq(UserHandle.myUserId()))).thenReturn(
|
||||||
PackageManager.GET_SIGNING_CERTIFICATES |
|
|
||||||
PackageManager.GET_PERMISSIONS, UserHandle.myUserId())).thenReturn(
|
|
||||||
mAppInfoWithHeader.mPackageInfo);
|
mAppInfoWithHeader.mPackageInfo);
|
||||||
|
|
||||||
mAppInfoWithHeader.retrieveAppEntry();
|
mAppInfoWithHeader.retrieveAppEntry();
|
||||||
@@ -146,7 +146,6 @@ public class AppInfoWithHeaderTest {
|
|||||||
assertThat(mAppInfoWithHeader.mAppEntry).isNotNull();
|
assertThat(mAppInfoWithHeader.mAppEntry).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("b/315135755")
|
|
||||||
@Test
|
@Test
|
||||||
public void extraUserHandleInIntent_retrieveAppEntryWithMyUserId()
|
public void extraUserHandleInIntent_retrieveAppEntryWithMyUserId()
|
||||||
throws PackageManager.NameNotFoundException {
|
throws PackageManager.NameNotFoundException {
|
||||||
@@ -161,10 +160,8 @@ public class AppInfoWithHeaderTest {
|
|||||||
entry.info.packageName = packageName;
|
entry.info.packageName = packageName;
|
||||||
|
|
||||||
when(mAppInfoWithHeader.mState.getEntry(packageName, USER_ID)).thenReturn(entry);
|
when(mAppInfoWithHeader.mState.getEntry(packageName, USER_ID)).thenReturn(entry);
|
||||||
when(mAppInfoWithHeader.mPm.getPackageInfoAsUser(entry.info.packageName,
|
when(mAppInfoWithHeader.mPm.getPackageInfoAsUser(eq(entry.info.packageName),
|
||||||
PackageManager.MATCH_DISABLED_COMPONENTS |
|
any(), eq(USER_ID))).thenReturn(
|
||||||
PackageManager.GET_SIGNING_CERTIFICATES |
|
|
||||||
PackageManager.GET_PERMISSIONS, USER_ID)).thenReturn(
|
|
||||||
mAppInfoWithHeader.mPackageInfo);
|
mAppInfoWithHeader.mPackageInfo);
|
||||||
|
|
||||||
mAppInfoWithHeader.retrieveAppEntry();
|
mAppInfoWithHeader.retrieveAppEntry();
|
||||||
@@ -232,6 +229,8 @@ public class AppInfoWithHeaderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Intent getIntent() { return mIntent; }
|
protected Intent getIntent() {
|
||||||
|
return mIntent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,270 @@
|
|||||||
|
/*
|
||||||
|
* 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.bluetooth;
|
||||||
|
|
||||||
|
import static android.bluetooth.BluetoothCsipSetCoordinator.GROUP_ID_INVALID;
|
||||||
|
import static android.bluetooth.BluetoothHapClient.PRESET_INDEX_UNAVAILABLE;
|
||||||
|
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.KEY_HEARING_DEVICE_GROUP;
|
||||||
|
import static com.android.settings.bluetooth.BluetoothDetailsHearingAidsPresetsController.KEY_HEARING_AIDS_PRESETS;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothHapClient;
|
||||||
|
import android.bluetooth.BluetoothHapPresetInfo;
|
||||||
|
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.bluetooth.HapClientProfile;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||||
|
|
||||||
|
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 java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
/** Tests for {@link BluetoothDetailsHearingAidsPresetsController}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class BluetoothDetailsHearingAidsPresetsControllerTest extends
|
||||||
|
BluetoothDetailsControllerTestBase {
|
||||||
|
|
||||||
|
private static final int TEST_PRESET_INDEX = 1;
|
||||||
|
private static final String TEST_PRESET_NAME = "test_preset";
|
||||||
|
private static final int TEST_HAP_GROUP_ID = 1;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private LocalBluetoothManager mLocalManager;
|
||||||
|
@Mock
|
||||||
|
private LocalBluetoothProfileManager mProfileManager;
|
||||||
|
@Mock
|
||||||
|
private HapClientProfile mHapClientProfile;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedChildDevice;
|
||||||
|
@Mock
|
||||||
|
private BluetoothDevice mChildDevice;
|
||||||
|
|
||||||
|
private BluetoothDetailsHearingAidsPresetsController mController;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() {
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
when(mLocalManager.getProfileManager()).thenReturn(mProfileManager);
|
||||||
|
when(mProfileManager.getHapClientProfile()).thenReturn(mHapClientProfile);
|
||||||
|
when(mCachedDevice.getProfiles()).thenReturn(List.of(mHapClientProfile));
|
||||||
|
when(mCachedDevice.isConnectedHapClientDevice()).thenReturn(true);
|
||||||
|
when(mCachedChildDevice.getDevice()).thenReturn(mChildDevice);
|
||||||
|
PreferenceCategory deviceControls = new PreferenceCategory(mContext);
|
||||||
|
deviceControls.setKey(KEY_HEARING_DEVICE_GROUP);
|
||||||
|
mScreen.addPreference(deviceControls);
|
||||||
|
mController = new BluetoothDetailsHearingAidsPresetsController(mContext, mFragment,
|
||||||
|
mLocalManager, mCachedDevice, mLifecycle);
|
||||||
|
mController.init(mScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_supportHap_returnTrue() {
|
||||||
|
when(mCachedDevice.getProfiles()).thenReturn(List.of(mHapClientProfile));
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_notSupportHap_returnFalse() {
|
||||||
|
when(mCachedDevice.getProfiles()).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onResume_registerCallback() {
|
||||||
|
mController.onResume();
|
||||||
|
|
||||||
|
verify(mHapClientProfile).registerCallback(any(Executor.class),
|
||||||
|
any(BluetoothHapClient.Callback.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPause_unregisterCallback() {
|
||||||
|
mController.onPause();
|
||||||
|
|
||||||
|
verify(mHapClientProfile).unregisterCallback(any(BluetoothHapClient.Callback.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_keyMatched_verifyStatusUpdated() {
|
||||||
|
final ListPreference presetPreference = getTestPresetPreference(KEY_HEARING_AIDS_PRESETS);
|
||||||
|
|
||||||
|
boolean handled = mController.onPreferenceChange(presetPreference,
|
||||||
|
String.valueOf(TEST_PRESET_INDEX));
|
||||||
|
|
||||||
|
assertThat(handled).isTrue();
|
||||||
|
verify(presetPreference).setSummary(TEST_PRESET_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_keyNotMatched_doNothing() {
|
||||||
|
final ListPreference presetPreference = getTestPresetPreference("wrong_key");
|
||||||
|
|
||||||
|
boolean handled = mController.onPreferenceChange(
|
||||||
|
presetPreference, String.valueOf(TEST_PRESET_INDEX));
|
||||||
|
|
||||||
|
assertThat(handled).isFalse();
|
||||||
|
verify(presetPreference, never()).setSummary(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_supportGroupOperation_validGroupId_verifySelectPresetForGroup() {
|
||||||
|
final ListPreference presetPreference = getTestPresetPreference(KEY_HEARING_AIDS_PRESETS);
|
||||||
|
when(mHapClientProfile.supportsSynchronizedPresets(mDevice)).thenReturn(true);
|
||||||
|
when(mHapClientProfile.getHapGroup(mDevice)).thenReturn(TEST_HAP_GROUP_ID);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(presetPreference, String.valueOf(TEST_PRESET_INDEX));
|
||||||
|
|
||||||
|
verify(mHapClientProfile).selectPresetForGroup(TEST_HAP_GROUP_ID, TEST_PRESET_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_notSupportGroupOperation_verifySelectPreset() {
|
||||||
|
final ListPreference presetPreference = getTestPresetPreference(KEY_HEARING_AIDS_PRESETS);
|
||||||
|
when(mHapClientProfile.supportsSynchronizedPresets(mDevice)).thenReturn(false);
|
||||||
|
when(mHapClientProfile.getHapGroup(mDevice)).thenReturn(TEST_HAP_GROUP_ID);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(presetPreference, String.valueOf(TEST_PRESET_INDEX));
|
||||||
|
|
||||||
|
verify(mHapClientProfile).selectPreset(mDevice, TEST_PRESET_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_invalidGroupId_verifySelectPreset() {
|
||||||
|
final ListPreference presetPreference = getTestPresetPreference(KEY_HEARING_AIDS_PRESETS);
|
||||||
|
when(mHapClientProfile.supportsSynchronizedPresets(mDevice)).thenReturn(true);
|
||||||
|
when(mHapClientProfile.getHapGroup(mDevice)).thenReturn(GROUP_ID_INVALID);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(presetPreference, String.valueOf(TEST_PRESET_INDEX));
|
||||||
|
|
||||||
|
verify(mHapClientProfile).selectPreset(mDevice, TEST_PRESET_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_notSupportGroupOperation_hasSubDevice_verifyStatusUpdated() {
|
||||||
|
final ListPreference presetPreference = getTestPresetPreference(KEY_HEARING_AIDS_PRESETS);
|
||||||
|
when(mHapClientProfile.supportsSynchronizedPresets(mDevice)).thenReturn(false);
|
||||||
|
when(mCachedDevice.getSubDevice()).thenReturn(mCachedChildDevice);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(presetPreference, String.valueOf(TEST_PRESET_INDEX));
|
||||||
|
|
||||||
|
verify(mHapClientProfile).selectPreset(mDevice, TEST_PRESET_INDEX);
|
||||||
|
verify(mHapClientProfile).selectPreset(mChildDevice, TEST_PRESET_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_notSupportGroupOperation_hasMemberDevice_verifyStatusUpdated() {
|
||||||
|
final ListPreference presetPreference = getTestPresetPreference(KEY_HEARING_AIDS_PRESETS);
|
||||||
|
when(mHapClientProfile.supportsSynchronizedPresets(mDevice)).thenReturn(false);
|
||||||
|
when(mCachedDevice.getMemberDevice()).thenReturn(Set.of(mCachedChildDevice));
|
||||||
|
|
||||||
|
mController.onPreferenceChange(presetPreference, String.valueOf(TEST_PRESET_INDEX));
|
||||||
|
|
||||||
|
verify(mHapClientProfile).selectPreset(mDevice, TEST_PRESET_INDEX);
|
||||||
|
verify(mHapClientProfile).selectPreset(mChildDevice, TEST_PRESET_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void refresh_emptyPresetInfo_preferenceDisabled() {
|
||||||
|
when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
|
mController.refresh();
|
||||||
|
|
||||||
|
assertThat(mController.getPreference()).isNotNull();
|
||||||
|
assertThat(mController.getPreference().isEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void refresh_validPresetInfo_preferenceEnabled() {
|
||||||
|
BluetoothHapPresetInfo info = getTestPresetInfo();
|
||||||
|
when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));
|
||||||
|
|
||||||
|
mController.refresh();
|
||||||
|
|
||||||
|
assertThat(mController.getPreference()).isNotNull();
|
||||||
|
assertThat(mController.getPreference().isEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void refresh_invalidActivePresetIndex_summaryIsNull() {
|
||||||
|
BluetoothHapPresetInfo info = getTestPresetInfo();
|
||||||
|
when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));
|
||||||
|
when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(PRESET_INDEX_UNAVAILABLE);
|
||||||
|
|
||||||
|
mController.refresh();
|
||||||
|
|
||||||
|
assertThat(mController.getPreference()).isNotNull();
|
||||||
|
assertThat(mController.getPreference().getSummary()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void refresh_validActivePresetIndex_summaryIsNotNull() {
|
||||||
|
BluetoothHapPresetInfo info = getTestPresetInfo();
|
||||||
|
when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));
|
||||||
|
when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(TEST_PRESET_INDEX);
|
||||||
|
|
||||||
|
mController.refresh();
|
||||||
|
|
||||||
|
assertThat(mController.getPreference()).isNotNull();
|
||||||
|
assertThat(mController.getPreference().getSummary()).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
private BluetoothHapPresetInfo getTestPresetInfo() {
|
||||||
|
BluetoothHapPresetInfo info = mock(BluetoothHapPresetInfo.class);
|
||||||
|
when(info.getName()).thenReturn(TEST_PRESET_NAME);
|
||||||
|
when(info.getIndex()).thenReturn(TEST_PRESET_INDEX);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ListPreference getTestPresetPreference(String key) {
|
||||||
|
final ListPreference presetPreference = spy(new ListPreference(mContext));
|
||||||
|
when(presetPreference.findIndexOfValue(String.valueOf(TEST_PRESET_INDEX))).thenReturn(0);
|
||||||
|
when(presetPreference.getEntries()).thenReturn(new CharSequence[]{TEST_PRESET_NAME});
|
||||||
|
when(presetPreference.getEntryValues()).thenReturn(
|
||||||
|
new CharSequence[]{String.valueOf(TEST_PRESET_INDEX)});
|
||||||
|
presetPreference.setKey(key);
|
||||||
|
return presetPreference;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* 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.bluetooth;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
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 com.android.settings.accessibility.Flags;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/** Tests for {@link BluetoothDetailsHearingDeviceController}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class BluetoothDetailsHearingDeviceControllerTest extends
|
||||||
|
BluetoothDetailsControllerTestBase {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private LocalBluetoothManager mLocalManager;
|
||||||
|
@Mock
|
||||||
|
private LocalBluetoothProfileManager mProfileManager;
|
||||||
|
@Mock
|
||||||
|
private BluetoothDetailsHearingDeviceController mHearingDeviceController;
|
||||||
|
@Mock
|
||||||
|
private BluetoothDetailsHearingAidsPresetsController mPresetsController;
|
||||||
|
@Mock
|
||||||
|
private BluetoothDetailsHearingDeviceSettingsController mHearingDeviceSettingsController;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() {
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
when(mLocalManager.getProfileManager()).thenReturn(mProfileManager);
|
||||||
|
mHearingDeviceController = new BluetoothDetailsHearingDeviceController(mContext,
|
||||||
|
mFragment, mLocalManager, mCachedDevice, mLifecycle);
|
||||||
|
mHearingDeviceController.setSubControllers(mHearingDeviceSettingsController,
|
||||||
|
mPresetsController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_hearingDeviceSettingsAvailable_returnTrue() {
|
||||||
|
when(mHearingDeviceSettingsController.isAvailable()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mHearingDeviceController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_presetsControlsAvailable_returnTrue() {
|
||||||
|
when(mPresetsController.isAvailable()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mHearingDeviceController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_noControllersAvailable_returnFalse() {
|
||||||
|
when(mHearingDeviceSettingsController.isAvailable()).thenReturn(false);
|
||||||
|
when(mPresetsController.isAvailable()).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mHearingDeviceController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initSubControllers_launchFromHearingDevicePage_hearingDeviceSettingsNotExist() {
|
||||||
|
mHearingDeviceController.initSubControllers(true);
|
||||||
|
|
||||||
|
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||||
|
c -> c instanceof BluetoothDetailsHearingDeviceSettingsController)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initSubControllers_notLaunchFromHearingDevicePage_hearingDeviceSettingsExist() {
|
||||||
|
mHearingDeviceController.initSubControllers(false);
|
||||||
|
|
||||||
|
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||||
|
c -> c instanceof BluetoothDetailsHearingDeviceSettingsController)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HEARING_AID_PRESET_CONTROL)
|
||||||
|
public void initSubControllers_flagEnabled_presetControllerExist() {
|
||||||
|
mHearingDeviceController.initSubControllers(false);
|
||||||
|
|
||||||
|
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||||
|
c -> c instanceof BluetoothDetailsHearingAidsPresetsController)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsDisabled(Flags.FLAG_ENABLE_HEARING_AID_PRESET_CONTROL)
|
||||||
|
public void initSubControllers_flagDisabled_presetControllerNotExist() {
|
||||||
|
mHearingDeviceController.initSubControllers(false);
|
||||||
|
|
||||||
|
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||||
|
c -> c instanceof BluetoothDetailsHearingAidsPresetsController)).isFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,23 +39,24 @@ import org.mockito.junit.MockitoJUnit;
|
|||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
/** Tests for {@link BluetoothDetailsHearingDeviceControlsController}. */
|
/** Tests for {@link BluetoothDetailsHearingDeviceSettingsController}. */
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class BluetoothDetailsHearingDeviceControlsControllerTest extends
|
public class BluetoothDetailsHearingDeviceSettingsControllerTest extends
|
||||||
BluetoothDetailsControllerTestBase {
|
BluetoothDetailsControllerTestBase {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
|
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<Intent> mIntentArgumentCaptor;
|
private ArgumentCaptor<Intent> mIntentArgumentCaptor;
|
||||||
private BluetoothDetailsHearingDeviceControlsController mController;
|
private BluetoothDetailsHearingDeviceSettingsController mController;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
FakeFeatureFactory.setupForTest();
|
FakeFeatureFactory.setupForTest();
|
||||||
mController = new BluetoothDetailsHearingDeviceControlsController(mActivity, mFragment,
|
mController = new BluetoothDetailsHearingDeviceSettingsController(mActivity, mFragment,
|
||||||
mCachedDevice, mLifecycle);
|
mCachedDevice, mLifecycle);
|
||||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||||
}
|
}
|
||||||
@@ -75,12 +76,12 @@ public class BluetoothDetailsHearingDeviceControlsControllerTest extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onPreferenceClick_hearingDeviceControlsKey_LaunchExpectedFragment() {
|
public void onPreferenceClick_hearingDeviceSettingsKey_launchExpectedFragment() {
|
||||||
final Preference hearingControlsKeyPreference = new Preference(mContext);
|
final Preference hearingDeviceSettingsPreference = new Preference(mContext);
|
||||||
hearingControlsKeyPreference.setKey(
|
hearingDeviceSettingsPreference.setKey(
|
||||||
BluetoothDetailsHearingDeviceControlsController.KEY_HEARING_DEVICE_CONTROLS);
|
BluetoothDetailsHearingDeviceSettingsController.KEY_HEARING_DEVICE_SETTINGS);
|
||||||
|
|
||||||
mController.onPreferenceClick(hearingControlsKeyPreference);
|
mController.onPreferenceClick(hearingDeviceSettingsPreference);
|
||||||
|
|
||||||
assertStartActivityWithExpectedFragment(mActivity,
|
assertStartActivityWithExpectedFragment(mActivity,
|
||||||
AccessibilityHearingAidsFragment.class.getName());
|
AccessibilityHearingAidsFragment.class.getName());
|
||||||
@@ -18,7 +18,7 @@ package com.android.settings.bluetooth;
|
|||||||
|
|
||||||
import static android.bluetooth.BluetoothDevice.BOND_NONE;
|
import static android.bluetooth.BluetoothDevice.BOND_NONE;
|
||||||
|
|
||||||
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceControlsController.KEY_DEVICE_CONTROLS_GENERAL_GROUP;
|
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceSettingsController.KEY_HEARING_DEVICE_SETTINGS;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ public class BluetoothDeviceDetailsFragmentTest {
|
|||||||
|
|
||||||
assertThat(controllerList.stream()
|
assertThat(controllerList.stream()
|
||||||
.anyMatch(controller -> controller.getPreferenceKey().equals(
|
.anyMatch(controller -> controller.getPreferenceKey().equals(
|
||||||
KEY_DEVICE_CONTROLS_GENERAL_GROUP))).isFalse();
|
KEY_HEARING_DEVICE_SETTINGS))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -253,7 +253,7 @@ public class BluetoothDeviceDetailsFragmentTest {
|
|||||||
|
|
||||||
assertThat(controllerList.stream()
|
assertThat(controllerList.stream()
|
||||||
.anyMatch(controller -> controller.getPreferenceKey().equals(
|
.anyMatch(controller -> controller.getPreferenceKey().equals(
|
||||||
KEY_DEVICE_CONTROLS_GENERAL_GROUP))).isTrue();
|
KEY_HEARING_DEVICE_SETTINGS))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputDevice createInputDeviceWithMatchingBluetoothAddress() {
|
private InputDevice createInputDeviceWithMatchingBluetoothAddress() {
|
||||||
|
|||||||
@@ -60,12 +60,8 @@ import com.android.settingslib.applications.AppUtils;
|
|||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
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.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -119,10 +115,8 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
@Mock private AppOpsManager mAppOpsManager;
|
@Mock private AppOpsManager mAppOpsManager;
|
||||||
@Mock private LoaderManager mLoaderManager;
|
@Mock private LoaderManager mLoaderManager;
|
||||||
@Mock private BatteryOptimizeUtils mBatteryOptimizeUtils;
|
@Mock private BatteryOptimizeUtils mBatteryOptimizeUtils;
|
||||||
@Mock private Observer mObserver;
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BatterySettingsStorage mBatterySettingsStorage;
|
|
||||||
private PrimarySwitchPreference mAllowBackgroundUsagePreference;
|
private PrimarySwitchPreference mAllowBackgroundUsagePreference;
|
||||||
private AdvancedPowerUsageDetail mFragment;
|
private AdvancedPowerUsageDetail mFragment;
|
||||||
private SettingsActivity mTestActivity;
|
private SettingsActivity mTestActivity;
|
||||||
@@ -134,7 +128,6 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
mBatterySettingsStorage = BatterySettingsStorage.get(mContext);
|
|
||||||
when(mContext.getPackageName()).thenReturn("foo");
|
when(mContext.getPackageName()).thenReturn("foo");
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||||
@@ -448,28 +441,4 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
TimeUnit.SECONDS.sleep(1);
|
TimeUnit.SECONDS.sleep(1);
|
||||||
verifyNoInteractions(mMetricsFeatureProvider);
|
verifyNoInteractions(mMetricsFeatureProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(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(mObserver).onChanged(ChangeReason.UPDATE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,12 @@ import android.os.UserManager;
|
|||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
|
import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
|
||||||
|
import com.android.settingslib.datastore.ChangeReason;
|
||||||
|
import com.android.settingslib.datastore.Observer;
|
||||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -74,14 +78,18 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
@Mock private PowerAllowlistBackend mMockBackend;
|
@Mock private PowerAllowlistBackend mMockBackend;
|
||||||
@Mock private IPackageManager mMockIPackageManager;
|
@Mock private IPackageManager mMockIPackageManager;
|
||||||
@Mock private UserManager mMockUserManager;
|
@Mock private UserManager mMockUserManager;
|
||||||
|
@Mock private Observer mObserver;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BatteryOptimizeUtils mBatteryOptimizeUtils;
|
private BatteryOptimizeUtils mBatteryOptimizeUtils;
|
||||||
|
private BatterySettingsStorage mBatterySettingsStorage;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
mBatterySettingsStorage = BatterySettingsStorage.get(mContext);
|
||||||
|
mBatterySettingsStorage.addObserver(mObserver, MoreExecutors.directExecutor());
|
||||||
mBatteryOptimizeUtils = spy(new BatteryOptimizeUtils(mContext, UID, PACKAGE_NAME));
|
mBatteryOptimizeUtils = spy(new BatteryOptimizeUtils(mContext, UID, PACKAGE_NAME));
|
||||||
mBatteryOptimizeUtils.mAppOpsManager = mMockAppOpsManager;
|
mBatteryOptimizeUtils.mAppOpsManager = mMockAppOpsManager;
|
||||||
mBatteryOptimizeUtils.mBatteryUtils = mMockBatteryUtils;
|
mBatteryOptimizeUtils.mBatteryUtils = mMockBatteryUtils;
|
||||||
@@ -156,6 +164,7 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
TimeUnit.SECONDS.sleep(1);
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
|
||||||
verifySetAppOptimizationMode(AppOpsManager.MODE_IGNORED, /* allowListed */ false);
|
verifySetAppOptimizationMode(AppOpsManager.MODE_IGNORED, /* allowListed */ false);
|
||||||
|
verify(mObserver).onChanged(ChangeReason.UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -169,6 +178,7 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
TimeUnit.SECONDS.sleep(1);
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
|
||||||
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ true);
|
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ true);
|
||||||
|
verify(mObserver).onChanged(ChangeReason.UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -182,6 +192,7 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
TimeUnit.SECONDS.sleep(1);
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
|
||||||
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ false);
|
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ false);
|
||||||
|
verify(mObserver).onChanged(ChangeReason.UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -197,6 +208,7 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
verify(mMockBatteryUtils, never()).setForceAppStandby(anyInt(), anyString(), anyInt());
|
verify(mMockBatteryUtils, never()).setForceAppStandby(anyInt(), anyString(), anyInt());
|
||||||
verify(mMockBackend, never()).addApp(anyString());
|
verify(mMockBackend, never()).addApp(anyString());
|
||||||
verify(mMockBackend, never()).removeApp(anyString());
|
verify(mMockBackend, never()).removeApp(anyString());
|
||||||
|
verifyNoInteractions(mObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -288,6 +300,7 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
inOrder.verify(mMockBackend).isAllowlisted(PACKAGE_NAME, UID);
|
inOrder.verify(mMockBackend).isAllowlisted(PACKAGE_NAME, UID);
|
||||||
inOrder.verify(mMockBackend).isSysAllowlisted(PACKAGE_NAME);
|
inOrder.verify(mMockBackend).isSysAllowlisted(PACKAGE_NAME);
|
||||||
verifyNoMoreInteractions(mMockBackend);
|
verifyNoMoreInteractions(mMockBackend);
|
||||||
|
verify(mObserver).onChanged(ChangeReason.DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -298,6 +311,7 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
/* isSystemOrDefaultApp */ false);
|
/* isSystemOrDefaultApp */ false);
|
||||||
|
|
||||||
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ false);
|
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ false);
|
||||||
|
verify(mObserver).onChanged(ChangeReason.DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -308,6 +322,7 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
/* isSystemOrDefaultApp */ false);
|
/* isSystemOrDefaultApp */ false);
|
||||||
|
|
||||||
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ false);
|
verifySetAppOptimizationMode(AppOpsManager.MODE_ALLOWED, /* allowListed */ false);
|
||||||
|
verify(mObserver).onChanged(ChangeReason.DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runTestForResetWithMode(
|
private void runTestForResetWithMode(
|
||||||
|
|||||||
Reference in New Issue
Block a user