Snap for 8693414 from 909b62ffa4 to tm-qpr1-release

Change-Id: I2b1455a085d98e2c82e24ccd9cec8d205f5853bd
This commit is contained in:
Android Build Coastguard Worker
2022-06-08 01:26:05 +00:00
22 changed files with 602 additions and 143 deletions

View File

@@ -342,8 +342,8 @@
<!-- UI debug setting: Disable Bluetooth A2DP hardware offload [CHAR LIMIT=none] --> <!-- UI debug setting: Disable Bluetooth A2DP hardware offload [CHAR LIMIT=none] -->
<string name="bluetooth_disable_a2dp_hw_offload">Disable Bluetooth A2DP hardware offload</string> <string name="bluetooth_disable_a2dp_hw_offload">Disable Bluetooth A2DP hardware offload</string>
<!-- UI debug setting: Disable Bluetooth LE AUDIO hardware offload [CHAR LIMIT=none] --> <!-- UI debug setting: Disable Bluetooth LE audio hardware offload [CHAR LIMIT=none] -->
<string name="bluetooth_disable_le_audio_hw_offload">Disable Bluetooth LE AUDIO hardware offload</string> <string name="bluetooth_disable_le_audio_hw_offload">Disable Bluetooth LE audio hardware offload</string>
<!-- UI debug setting: Disable Bluetooth hardware offload [CHAR LIMIT=none] --> <!-- UI debug setting: Disable Bluetooth hardware offload [CHAR LIMIT=none] -->
<string name="bluetooth_disable_hw_offload_dialog_title">Restart Device?</string> <string name="bluetooth_disable_hw_offload_dialog_title">Restart Device?</string>
<!-- UI debug setting: Disable Bluetooth hardware offload [CHAR LIMIT=none] --> <!-- UI debug setting: Disable Bluetooth hardware offload [CHAR LIMIT=none] -->
@@ -353,6 +353,11 @@
<!-- UI debug setting: Disable Bluetooth hardware offload [CHAR LIMIT=none] --> <!-- UI debug setting: Disable Bluetooth hardware offload [CHAR LIMIT=none] -->
<string name="bluetooth_disable_hw_offload_dialog_cancel">Cancel</string> <string name="bluetooth_disable_hw_offload_dialog_cancel">Cancel</string>
<!-- Setting Checkbox title for enabling Bluetooth LE Audio feature. [CHAR LIMIT=40] -->
<string name="bluetooth_enable_leaudio">Enable Bluetooth LE audio</string>
<!-- Summary of checkbox for enabling Bluetooth LE audio [CHAR LIMIT=none]-->
<string name="bluetooth_enable_leaudio_summary">Enables Bluetooth LE audio feature if the device supports LE audio hardware capabilities.</string>
<!-- Title for Bluetooth device group with media capability group [CHAR LIMIT=none]--> <!-- Title for Bluetooth device group with media capability group [CHAR LIMIT=none]-->
<string name="connected_device_media_device_title">Media devices</string> <string name="connected_device_media_device_title">Media devices</string>
<!-- Title for Bluetooth device group with media capability group [CHAR LIMIT=none]--> <!-- Title for Bluetooth device group with media capability group [CHAR LIMIT=none]-->

View File

@@ -320,13 +320,18 @@
android:summary="@string/bluetooth_disable_absolute_volume_summary" /> android:summary="@string/bluetooth_disable_absolute_volume_summary" />
<SwitchPreference <SwitchPreference
android:key="bluetooth_disable_a2dp_hw_offload" android:key="bluetooth_enable_leaudio"
android:title="@string/bluetooth_disable_a2dp_hw_offload" /> android:title="@string/bluetooth_enable_leaudio"
android:summary="@string/bluetooth_enable_leaudio_summary" />
<SwitchPreference <SwitchPreference
android:key="bluetooth_disable_le_audio_hw_offload" android:key="bluetooth_disable_le_audio_hw_offload"
android:title="@string/bluetooth_disable_le_audio_hw_offload" /> android:title="@string/bluetooth_disable_le_audio_hw_offload" />
<SwitchPreference
android:key="bluetooth_disable_a2dp_hw_offload"
android:title="@string/bluetooth_disable_a2dp_hw_offload" />
<ListPreference <ListPreference
android:key="bluetooth_select_avrcp_version" android:key="bluetooth_select_avrcp_version"
android:title="@string/bluetooth_select_avrcp_version_string" android:title="@string/bluetooth_select_avrcp_version_string"

View File

@@ -16,21 +16,20 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/location_services_preference_title"> android:key="location_services"
android:title="@string/location_services_preference_title"
<PreferenceCategory settings:controller="com.android.settings.location.LocationInjectedServicesPreferenceController">
android:key="location_services"
android:layout="@layout/preference_category_no_label"
settings:controller="com.android.settings.location.LocationInjectedServicesPreferenceController"/>
<com.android.settingslib.RestrictedPreference <com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.location.WifiScanningFragment" android:fragment="com.android.settings.location.WifiScanningFragment"
android:order="1000"
android:key="location_services_wifi_scanning" android:key="location_services_wifi_scanning"
android:title="@string/location_scanning_wifi_always_scanning_title" android:title="@string/location_scanning_wifi_always_scanning_title"
settings:controller="com.android.settings.location.LocationServicesWifiScanningPreferenceController"/> settings:controller="com.android.settings.location.LocationServicesWifiScanningPreferenceController"/>
<com.android.settingslib.RestrictedPreference <com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.location.BluetoothScanningFragment" android:fragment="com.android.settings.location.BluetoothScanningFragment"
android:order="1001"
android:key="location_services_bluetooth_scanning" android:key="location_services_bluetooth_scanning"
android:title="@string/location_scanning_bluetooth_always_scanning_title" android:title="@string/location_scanning_bluetooth_always_scanning_title"
settings:controller="com.android.settings.location.LocationServicesBluetoothScanningPreferenceController"/> settings:controller="com.android.settings.location.LocationServicesBluetoothScanningPreferenceController"/>

View File

@@ -16,12 +16,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/location_services_screen_title"> android:title="@string/location_services_screen_title"
android:key="location_services_managed_profile"
<PreferenceCategory settings:controller="com.android.settings.location.LocationInjectedServicesForWorkPreferenceController">
android:title="@string/managed_profile_location_services"
android:layout="@layout/preference_category_no_label"
android:key="location_services_managed_profile"
settings:controller="com.android.settings.location.LocationInjectedServicesForWorkPreferenceController"/>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -99,6 +99,8 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
private ViewGroup mContentView; private ViewGroup mContentView;
private ViewPager2 mViewPager;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@@ -111,12 +113,21 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
final int selectedTab = getTabId(activity, getArguments()); final int selectedTab = getTabId(activity, getArguments());
final View tabContainer = mContentView.findViewById(R.id.tab_container); final View tabContainer = mContentView.findViewById(R.id.tab_container);
final ViewPager2 viewPager = tabContainer.findViewById(R.id.view_pager); mViewPager = tabContainer.findViewById(R.id.view_pager);
viewPager.setAdapter(new ProfileSelectFragment.ViewPagerAdapter(this)); mViewPager.setAdapter(new ProfileSelectFragment.ViewPagerAdapter(this));
final TabLayout tabs = tabContainer.findViewById(R.id.tabs); final TabLayout tabs = tabContainer.findViewById(R.id.tabs);
new TabLayoutMediator(tabs, viewPager, new TabLayoutMediator(tabs, mViewPager,
(tab, position) -> tab.setText(getPageTitle(position)) (tab, position) -> tab.setText(getPageTitle(position))
).attach(); ).attach();
mViewPager.registerOnPageChangeCallback(
new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
updateHeight(position);
}
}
);
tabContainer.setVisibility(View.VISIBLE); tabContainer.setVisibility(View.VISIBLE);
final TabLayout.Tab tab = tabs.getTabAt(selectedTab); final TabLayout.Tab tab = tabs.getTabAt(selectedTab);
tab.select(); tab.select();
@@ -133,6 +144,36 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
return mContentView; return mContentView;
} }
protected boolean forceUpdateHeight() {
return false;
}
private void updateHeight(int position) {
if (!forceUpdateHeight()) {
return;
}
ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter();
if (adapter == null || adapter.getItemCount() <= position) {
return;
}
Fragment fragment = adapter.createFragment(position);
View newPage = fragment.getView();
if (newPage != null) {
int viewWidth = View.MeasureSpec.makeMeasureSpec(newPage.getWidth(),
View.MeasureSpec.EXACTLY);
int viewHeight = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
newPage.measure(viewWidth, viewHeight);
int currentHeight = mViewPager.getLayoutParams().height;
int newHeight = newPage.getMeasuredHeight();
if (newHeight != 0 && currentHeight != newHeight) {
ViewGroup.LayoutParams layoutParams = mViewPager.getLayoutParams();
layoutParams.height = newHeight;
mViewPager.setLayoutParams(layoutParams);
}
}
}
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return METRICS_CATEGORY_UNKNOWN; return METRICS_CATEGORY_UNKNOWN;

View File

@@ -50,4 +50,9 @@ public class ProfileSelectLocationServicesFragment extends ProfileSelectFragment
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
return R.xml.location_services_header; return R.xml.location_services_header;
} }
@Override
protected boolean forceUpdateHeight() {
return true;
}
} }

View File

@@ -53,7 +53,7 @@ public class BluetoothA2dpHwOffloadPreferenceController extends DeveloperOptions
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
BluetoothHwOffloadRebootDialog.show(mFragment); BluetoothRebootDialog.show(mFragment);
mChanged = true; mChanged = true;
return false; return false;
} }
@@ -93,9 +93,9 @@ public class BluetoothA2dpHwOffloadPreferenceController extends DeveloperOptions
} }
/** /**
* Called when the HwOffloadDialog confirm is clicked. * Called when the RebootDialog confirm is clicked.
*/ */
public void onHwOffloadDialogConfirmed() { public void onRebootDialogConfirmed() {
if (!mChanged) { if (!mChanged) {
return; return;
} }
@@ -109,9 +109,9 @@ public class BluetoothA2dpHwOffloadPreferenceController extends DeveloperOptions
} }
/** /**
* Called when the HwOffloadDialog cancel is clicked. * Called when the RebootDialog cancel is clicked.
*/ */
public void onHwOffloadDialogCanceled() { public void onRebootDialogCanceled() {
mChanged = false; mChanged = false;
} }
} }

View File

@@ -18,6 +18,9 @@ package com.android.settings.development;
import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_SUPPORTED_PROPERTY; import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_SUPPORTED_PROPERTY;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context; import android.content.Context;
import android.os.SystemProperties; import android.os.SystemProperties;
@@ -43,6 +46,9 @@ public class BluetoothLeAudioHwOffloadPreferenceController
static final String LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY = static final String LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY =
"ro.bluetooth.leaudio_offload.supported"; "ro.bluetooth.leaudio_offload.supported";
@VisibleForTesting
BluetoothAdapter mBluetoothAdapter;
@VisibleForTesting @VisibleForTesting
boolean mChanged = false; boolean mChanged = false;
@@ -50,6 +56,7 @@ public class BluetoothLeAudioHwOffloadPreferenceController
DevelopmentSettingsDashboardFragment fragment) { DevelopmentSettingsDashboardFragment fragment) {
super(context); super(context);
mFragment = fragment; mFragment = fragment;
mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter();
} }
@Override @Override
@@ -59,17 +66,24 @@ public class BluetoothLeAudioHwOffloadPreferenceController
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
BluetoothHwOffloadRebootDialog.show(mFragment); BluetoothRebootDialog.show(mFragment);
mChanged = true; mChanged = true;
return false; return false;
} }
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
if (mBluetoothAdapter == null) {
return;
}
final boolean leAudioEnabled =
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
final boolean offloadSupported = final boolean offloadSupported =
SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false) SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
&& SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false); && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
if (offloadSupported) { if (leAudioEnabled && offloadSupported) {
final boolean offloadDisabled = final boolean offloadDisabled =
SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true); SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
((SwitchPreference) mPreference).setChecked(offloadDisabled); ((SwitchPreference) mPreference).setChecked(offloadDisabled);
@@ -82,12 +96,20 @@ public class BluetoothLeAudioHwOffloadPreferenceController
@Override @Override
protected void onDeveloperOptionsSwitchDisabled() { protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled(); super.onDeveloperOptionsSwitchDisabled();
if (mBluetoothAdapter == null) {
return;
}
final boolean leAudioEnabled =
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
final boolean offloadSupported = final boolean offloadSupported =
SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false) SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
&& SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false); && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
if (offloadSupported) { if (leAudioEnabled && offloadSupported) {
((SwitchPreference) mPreference).setChecked(true); ((SwitchPreference) mPreference).setChecked(true);
SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, "true"); SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, "true");
} else {
mPreference.setEnabled(false);
} }
} }
@@ -104,9 +126,9 @@ public class BluetoothLeAudioHwOffloadPreferenceController
} }
/** /**
* Called when the HwOffloadDialog confirm is clicked. * Called when the RebootDialog confirm is clicked.
*/ */
public void onHwOffloadDialogConfirmed() { public void onRebootDialogConfirmed() {
if (!mChanged) { if (!mChanged) {
return; return;
} }
@@ -119,9 +141,9 @@ public class BluetoothLeAudioHwOffloadPreferenceController
} }
/** /**
* Called when the HwOffloadDialog cancel is clicked. * Called when the RebootDialog cancel is clicked.
*/ */
public void onHwOffloadDialogCanceled() { public void onRebootDialogCanceled() {
mChanged = false; mChanged = false;
} }
} }

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2022 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.development;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.os.SystemProperties;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
/**
* Preference controller to control Bluetooth LE audio feature
*/
public class BluetoothLeAudioPreferenceController
extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
private static final String PREFERENCE_KEY = "bluetooth_enable_leaudio";
private static final String LE_AUDIO_DYNAMIC_SWITCH_PROPERTY =
"ro.bluetooth.leaudio_switcher.supported";
@VisibleForTesting
static final String LE_AUDIO_DYNAMIC_ENABLED_PROPERTY =
"persist.bluetooth.leaudio_switcher.enabled";
private final DevelopmentSettingsDashboardFragment mFragment;
@VisibleForTesting
BluetoothAdapter mBluetoothAdapter;
@VisibleForTesting
boolean mChanged = false;
public BluetoothLeAudioPreferenceController(Context context,
DevelopmentSettingsDashboardFragment fragment) {
super(context);
mFragment = fragment;
mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter();
}
@Override
public String getPreferenceKey() {
return PREFERENCE_KEY;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
BluetoothRebootDialog.show(mFragment);
mChanged = true;
return false;
}
@Override
public void updateState(Preference preference) {
if (mBluetoothAdapter == null) {
return;
}
final boolean leAudioEnabled =
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
((SwitchPreference) mPreference).setChecked(leAudioEnabled);
final boolean leAudioSwitchSupported =
SystemProperties.getBoolean(LE_AUDIO_DYNAMIC_SWITCH_PROPERTY, false);
if (!leAudioSwitchSupported) {
mPreference.setEnabled(false);
} else {
SystemProperties.set(LE_AUDIO_DYNAMIC_ENABLED_PROPERTY,
Boolean.toString(leAudioEnabled));
}
}
/**
* Called when the RebootDialog confirm is clicked.
*/
public void onRebootDialogConfirmed() {
if (!mChanged || mBluetoothAdapter == null) {
return;
}
final boolean leAudioEnabled =
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
SystemProperties.set(LE_AUDIO_DYNAMIC_ENABLED_PROPERTY,
Boolean.toString(!leAudioEnabled));
}
/**
* Called when the RebootDialog cancel is clicked.
*/
public void onRebootDialogCanceled() {
mChanged = false;
}
}

View File

@@ -29,22 +29,23 @@ import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
/** /**
* The a2dp and LE audio offload switch should reboot the device to take effect, the dialog is * The a2dp/LE audio offload and LE audio feature switch should reboot the device to take effect,
* to ask the user to reboot the device after a2dp or LE audio offload user preference changed * the dialog is to ask the user to reboot the device after a2dp/LE audio offload and LE audio
* feature user preference changed
*/ */
public class BluetoothHwOffloadRebootDialog extends InstrumentedDialogFragment public class BluetoothRebootDialog extends InstrumentedDialogFragment
implements DialogInterface.OnClickListener { implements DialogInterface.OnClickListener {
public static final String TAG = "BluetoothHwOffloadReboot"; public static final String TAG = "BluetoothReboot";
/** /**
* The function to show the HwOffloadReboot Dialog. * The function to show the Reboot Dialog.
*/ */
public static void show(DevelopmentSettingsDashboardFragment host) { public static void show(DevelopmentSettingsDashboardFragment host) {
final FragmentManager manager = host.getActivity().getSupportFragmentManager(); final FragmentManager manager = host.getActivity().getSupportFragmentManager();
if (manager.findFragmentByTag(TAG) == null) { if (manager.findFragmentByTag(TAG) == null) {
final BluetoothHwOffloadRebootDialog dialog = final BluetoothRebootDialog dialog =
new BluetoothHwOffloadRebootDialog(); new BluetoothRebootDialog();
dialog.setTargetFragment(host, 0 /* requestCode */); dialog.setTargetFragment(host, 0 /* requestCode */);
dialog.show(manager, TAG); dialog.show(manager, TAG);
} }
@@ -69,33 +70,33 @@ public class BluetoothHwOffloadRebootDialog extends InstrumentedDialogFragment
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
final OnHwOffloadDialogListener host = final OnRebootDialogListener host =
(OnHwOffloadDialogListener) getTargetFragment(); (OnRebootDialogListener) getTargetFragment();
if (host == null) { if (host == null) {
return; return;
} }
if (which == DialogInterface.BUTTON_POSITIVE) { if (which == DialogInterface.BUTTON_POSITIVE) {
host.onHwOffloadDialogConfirmed(); host.onRebootDialogConfirmed();
PowerManager pm = getContext().getSystemService(PowerManager.class); PowerManager pm = getContext().getSystemService(PowerManager.class);
pm.reboot(null); pm.reboot(null);
} else { } else {
host.onHwOffloadDialogCanceled(); host.onRebootDialogCanceled();
} }
} }
/** /**
* The interface for the HsOffloadDialogListener to provide the action as the * The interface for the RebootDialogListener to provide the action as the
* confirmed or canceled clicked. * confirmed or canceled clicked.
*/ */
public interface OnHwOffloadDialogListener { public interface OnRebootDialogListener {
/** /**
* Called when the user presses reboot on the warning dialog. * Called when the user presses reboot on the warning dialog.
*/ */
void onHwOffloadDialogConfirmed(); void onRebootDialogConfirmed();
/** /**
* Called when the user presses cancel on the warning dialog. * Called when the user presses cancel on the warning dialog.
*/ */
void onHwOffloadDialogCanceled(); void onRebootDialogCanceled();
} }
} }

View File

@@ -80,7 +80,7 @@ import java.util.List;
public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFragment public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFragment
implements OnMainSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost, implements OnMainSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost,
AdbClearKeysDialogHost, LogPersistDialogHost, AdbClearKeysDialogHost, LogPersistDialogHost,
BluetoothHwOffloadRebootDialog.OnHwOffloadDialogListener, BluetoothRebootDialog.OnRebootDialogListener,
AbstractBluetoothPreferenceController.Callback { AbstractBluetoothPreferenceController.Callback {
private static final String TAG = "DevSettingsDashboard"; private static final String TAG = "DevSettingsDashboard";
@@ -362,27 +362,37 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
} }
@Override @Override
public void onHwOffloadDialogConfirmed() { public void onRebootDialogConfirmed() {
final BluetoothA2dpHwOffloadPreferenceController a2dpController = final BluetoothA2dpHwOffloadPreferenceController a2dpController =
getDevelopmentOptionsController(BluetoothA2dpHwOffloadPreferenceController.class); getDevelopmentOptionsController(BluetoothA2dpHwOffloadPreferenceController.class);
a2dpController.onHwOffloadDialogConfirmed(); a2dpController.onRebootDialogConfirmed();
final BluetoothLeAudioHwOffloadPreferenceController leAudioController = final BluetoothLeAudioHwOffloadPreferenceController leAudioController =
getDevelopmentOptionsController( getDevelopmentOptionsController(
BluetoothLeAudioHwOffloadPreferenceController.class); BluetoothLeAudioHwOffloadPreferenceController.class);
leAudioController.onHwOffloadDialogConfirmed(); leAudioController.onRebootDialogConfirmed();
final BluetoothLeAudioPreferenceController leAudioFeatureController =
getDevelopmentOptionsController(
BluetoothLeAudioPreferenceController.class);
leAudioFeatureController.onRebootDialogConfirmed();
} }
@Override @Override
public void onHwOffloadDialogCanceled() { public void onRebootDialogCanceled() {
final BluetoothA2dpHwOffloadPreferenceController a2dpController = final BluetoothA2dpHwOffloadPreferenceController a2dpController =
getDevelopmentOptionsController(BluetoothA2dpHwOffloadPreferenceController.class); getDevelopmentOptionsController(BluetoothA2dpHwOffloadPreferenceController.class);
a2dpController.onHwOffloadDialogCanceled(); a2dpController.onRebootDialogCanceled();
final BluetoothLeAudioHwOffloadPreferenceController leAudioController = final BluetoothLeAudioHwOffloadPreferenceController leAudioController =
getDevelopmentOptionsController( getDevelopmentOptionsController(
BluetoothLeAudioHwOffloadPreferenceController.class); BluetoothLeAudioHwOffloadPreferenceController.class);
leAudioController.onHwOffloadDialogCanceled(); leAudioController.onRebootDialogCanceled();
final BluetoothLeAudioPreferenceController leAudioFeatureController =
getDevelopmentOptionsController(
BluetoothLeAudioPreferenceController.class);
leAudioFeatureController.onRebootDialogCanceled();
} }
@Override @Override
@@ -540,6 +550,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new BluetoothAbsoluteVolumePreferenceController(context)); controllers.add(new BluetoothAbsoluteVolumePreferenceController(context));
controllers.add(new BluetoothAvrcpVersionPreferenceController(context)); controllers.add(new BluetoothAvrcpVersionPreferenceController(context));
controllers.add(new BluetoothMapVersionPreferenceController(context)); controllers.add(new BluetoothMapVersionPreferenceController(context));
controllers.add(new BluetoothLeAudioPreferenceController(context, fragment));
controllers.add(new BluetoothA2dpHwOffloadPreferenceController(context, fragment)); controllers.add(new BluetoothA2dpHwOffloadPreferenceController(context, fragment));
controllers.add(new BluetoothLeAudioHwOffloadPreferenceController(context, fragment)); controllers.add(new BluetoothLeAudioHwOffloadPreferenceController(context, fragment));
controllers.add(new BluetoothMaxConnectedAudioDevicesPreferenceController(context)); controllers.add(new BluetoothMaxConnectedAudioDevicesPreferenceController(context));

View File

@@ -20,7 +20,6 @@ import android.content.Context;
import android.os.UserHandle; import android.os.UserHandle;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.widget.RestrictedAppPreference; import com.android.settings.widget.RestrictedAppPreference;
@@ -41,8 +40,6 @@ public class LocationInjectedServicesForWorkPreferenceController extends
@Override @Override
protected void injectLocationServices(PreferenceScreen screen) { protected void injectLocationServices(PreferenceScreen screen) {
final PreferenceCategory categoryLocationServices =
screen.findPreference(getPreferenceKey());
final Map<Integer, List<Preference>> prefs = getLocationServices(); final Map<Integer, List<Preference>> prefs = getLocationServices();
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) { for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) { for (Preference pref : entry.getValue()) {
@@ -51,7 +48,7 @@ public class LocationInjectedServicesForWorkPreferenceController extends
} }
} }
if (entry.getKey() != UserHandle.myUserId()) { if (entry.getKey() != UserHandle.myUserId()) {
LocationSettings.addPreferencesSorted(entry.getValue(), categoryLocationServices); LocationSettings.addPreferencesSorted(entry.getValue(), screen);
} }
} }
} }

View File

@@ -19,7 +19,6 @@ import android.content.Context;
import android.os.UserHandle; import android.os.UserHandle;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.widget.RestrictedAppPreference; import com.android.settings.widget.RestrictedAppPreference;
@@ -41,8 +40,6 @@ public class LocationInjectedServicesPreferenceController
@Override @Override
protected void injectLocationServices(PreferenceScreen screen) { protected void injectLocationServices(PreferenceScreen screen) {
final PreferenceCategory categoryLocationServices =
screen.findPreference(getPreferenceKey());
final Map<Integer, List<Preference>> prefs = getLocationServices(); final Map<Integer, List<Preference>> prefs = getLocationServices();
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) { for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) { for (Preference pref : entry.getValue()) {
@@ -51,10 +48,7 @@ public class LocationInjectedServicesPreferenceController
} }
} }
if (entry.getKey() == UserHandle.myUserId()) { if (entry.getKey() == UserHandle.myUserId()) {
if (categoryLocationServices != null) { LocationSettings.addPreferencesSorted(entry.getValue(), screen);
LocationSettings.addPreferencesSorted(entry.getValue(),
categoryLocationServices);
}
} }
} }
} }

View File

@@ -22,12 +22,8 @@ import android.content.Context;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
/** /**
* A page that configures the Location Services settings including Wi-Fi scanning, Bluetooth * A page that configures the Location Services settings including Wi-Fi scanning, Bluetooth
* scanning, and injected location services. * scanning, and injected location services.
@@ -51,11 +47,6 @@ public class LocationServices extends DashboardFragment {
return TAG; return TAG;
} }
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context);
}
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
@@ -63,23 +54,9 @@ public class LocationServices extends DashboardFragment {
use(LocationInjectedServicesPreferenceController.class).init(this); use(LocationInjectedServicesPreferenceController.class).init(this);
} }
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new WifiScanningPreferenceController(context));
controllers.add(new BluetoothScanningPreferenceController(context));
return controllers;
}
/** /**
* For Search. * For Search.
*/ */
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.location_services) { new BaseSearchIndexProvider(R.xml.location_services);
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context
context) {
return buildPreferenceControllers(context);
}
};
} }

View File

@@ -22,12 +22,8 @@ import android.content.Context;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
/** /**
* A page that configures the Location Services settings for work profile. * A page that configures the Location Services settings for work profile.
*/ */
@@ -50,32 +46,15 @@ public class LocationServicesForWork extends DashboardFragment {
return TAG; return TAG;
} }
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context);
}
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
use(LocationInjectedServicesForWorkPreferenceController.class).init(this); use(LocationInjectedServicesForWorkPreferenceController.class).init(this);
} }
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
return controllers;
}
/** /**
* For Search. * For Search.
*/ */
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.location_services_workprofile) { new BaseSearchIndexProvider(R.xml.location_services_workprofile);
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context
context) {
return buildPreferenceControllers(context);
}
};
} }

View File

@@ -15,19 +15,21 @@
*/ */
package com.android.settings.wifi; package com.android.settings.wifi;
import static android.content.Context.WIFI_SERVICE; import android.annotation.Nullable;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.util.FeatureFlagUtils; import android.os.UserManager;
import android.util.EventLog;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -43,7 +45,8 @@ import java.util.List;
public class ConfigureWifiSettings extends DashboardFragment { public class ConfigureWifiSettings extends DashboardFragment {
private static final String TAG = "ConfigureWifiSettings"; private static final String TAG = "ConfigureWifiSettings";
private static final String KEY_INSTALL_CREDENTIALS = "install_credentials"; @VisibleForTesting
static final String KEY_INSTALL_CREDENTIALS = "install_credentials";
private static final String ACTION_INSTALL_CERTS = "android.credentials.INSTALL"; private static final String ACTION_INSTALL_CERTS = "android.credentials.INSTALL";
private static final String PACKAGE_INSTALL_CERTS = "com.android.certinstaller"; private static final String PACKAGE_INSTALL_CERTS = "com.android.certinstaller";
private static final String CLASS_INSTALL_CERTS = "com.android.certinstaller.CertInstallerMain"; private static final String CLASS_INSTALL_CERTS = "com.android.certinstaller.CertInstallerMain";
@@ -53,16 +56,26 @@ public class ConfigureWifiSettings extends DashboardFragment {
public static final int WIFI_WAKEUP_REQUEST_CODE = 600; public static final int WIFI_WAKEUP_REQUEST_CODE = 600;
private WifiWakeupPreferenceController mWifiWakeupPreferenceController; private WifiWakeupPreferenceController mWifiWakeupPreferenceController;
private Preference mCertinstallerPreference;
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (isGuestUser(context)) return;
mWifiWakeupPreferenceController = use(WifiWakeupPreferenceController.class);
mWifiWakeupPreferenceController.setFragment(this);
}
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
getActivity().setTitle(R.string.network_and_internet_preferences_title); getActivity().setTitle(R.string.network_and_internet_preferences_title);
mCertinstallerPreference = findPreference(KEY_INSTALL_CREDENTIALS); if (isGuestUser(getContext())) return;
if (mCertinstallerPreference != null) {
mCertinstallerPreference.setOnPreferenceClickListener(preference -> { final Preference installCredentialsPref = findPreference(KEY_INSTALL_CREDENTIALS);
if (installCredentialsPref != null) {
installCredentialsPref.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(ACTION_INSTALL_CERTS); Intent intent = new Intent(ACTION_INSTALL_CERTS);
intent.setFlags( intent.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK); Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -77,6 +90,23 @@ public class ConfigureWifiSettings extends DashboardFragment {
} }
} }
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (!isGuestUser(getContext())) return;
Log.w(TAG, "Displays the restricted UI because the user is a guest.");
EventLog.writeEvent(0x534e4554, "231987122", -1 /* UID */, "User is a guest");
// Restricted UI
final TextView emptyView = getActivity().findViewById(android.R.id.empty);
if (emptyView != null) {
emptyView.setVisibility(View.VISIBLE);
emptyView.setText(R.string.wifi_empty_list_user_restricted);
}
getPreferenceScreen().removeAll();
}
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return SettingsEnums.CONFIGURE_WIFI; return SettingsEnums.CONFIGURE_WIFI;
@@ -94,25 +124,18 @@ public class ConfigureWifiSettings extends DashboardFragment {
@Override @Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); if (isGuestUser(context)) return null;
final WifiManager wifiManager = getSystemService(WifiManager.class);
final List<AbstractPreferenceController> controllers = new ArrayList<>(); final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(), controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(),
wifiManager)); wifiManager));
return controllers; return controllers;
} }
@Override
public void onAttach(Context context) {
super.onAttach(context);
mWifiWakeupPreferenceController = use(WifiWakeupPreferenceController.class);
mWifiWakeupPreferenceController.setFragment(this);
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == WIFI_WAKEUP_REQUEST_CODE) { if (mWifiWakeupPreferenceController != null && requestCode == WIFI_WAKEUP_REQUEST_CODE) {
mWifiWakeupPreferenceController.onActivityResult(requestCode, resultCode); mWifiWakeupPreferenceController.onActivityResult(requestCode, resultCode);
return; return;
} }
@@ -122,8 +145,16 @@ public class ConfigureWifiSettings extends DashboardFragment {
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.wifi_configure_settings) { new BaseSearchIndexProvider(R.xml.wifi_configure_settings) {
protected boolean isPageSearchEnabled(Context context) { protected boolean isPageSearchEnabled(Context context) {
if (isGuestUser(context)) return false;
return context.getResources() return context.getResources()
.getBoolean(R.bool.config_show_wifi_settings); .getBoolean(R.bool.config_show_wifi_settings);
} }
}; };
private static boolean isGuestUser(Context context) {
if (context == null) return false;
final UserManager userManager = context.getSystemService(UserManager.class);
if (userManager == null) return false;
return userManager.isGuestUser();
}
} }

View File

@@ -17,6 +17,7 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import static android.Manifest.permission.ACCESS_FINE_LOCATION; import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@@ -31,6 +32,7 @@ import android.os.Looper;
import android.os.Process; import android.os.Process;
import android.os.SimpleClock; import android.os.SimpleClock;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.EventLog; import android.util.EventLog;
import android.util.Log; import android.util.Log;
@@ -115,6 +117,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!isConfigWifiAllowed()) {
finish();
return;
}
mIsWifiTrackerLib = !TextUtils.isEmpty(mIntent.getStringExtra(KEY_CHOSEN_WIFIENTRY_KEY)); mIsWifiTrackerLib = !TextUtils.isEmpty(mIntent.getStringExtra(KEY_CHOSEN_WIFIENTRY_KEY));
@@ -361,6 +367,19 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
} }
} }
@VisibleForTesting
boolean isConfigWifiAllowed() {
UserManager userManager = getSystemService(UserManager.class);
if (userManager == null) return true;
final boolean isConfigWifiAllowed = !userManager.hasUserRestriction(DISALLOW_CONFIG_WIFI);
if (!isConfigWifiAllowed) {
Log.e(TAG, "The user is not allowed to configure Wi-Fi.");
EventLog.writeEvent(0x534e4554, "226133034", getApplicationContext().getUserId(),
"The user is not allowed to configure Wi-Fi.");
}
return isConfigWifiAllowed;
}
private boolean hasWifiManager() { private boolean hasWifiManager() {
if (mWifiManager != null) return true; if (mWifiManager != null) return true;
mWifiManager = getSystemService(WifiManager.class); mWifiManager = getSystemService(WifiManager.class);

View File

@@ -68,7 +68,7 @@ public class BluetoothA2dpHwOffloadPreferenceControllerTest {
SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false)); SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
mController.mChanged = true; mController.mChanged = true;
mController.onHwOffloadDialogConfirmed(); mController.onRebootDialogConfirmed();
final boolean mode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false); final boolean mode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
assertThat(mode).isTrue(); assertThat(mode).isTrue();
} }
@@ -80,7 +80,7 @@ public class BluetoothA2dpHwOffloadPreferenceControllerTest {
mController.mChanged = true; mController.mChanged = true;
mController.onHwOffloadDialogConfirmed(); mController.onRebootDialogConfirmed();
final boolean a2dpMode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, true); final boolean a2dpMode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, true);
final boolean leAudioMode = SystemProperties final boolean leAudioMode = SystemProperties
.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true); .getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
@@ -93,7 +93,7 @@ public class BluetoothA2dpHwOffloadPreferenceControllerTest {
SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false)); SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
mController.mChanged = true; mController.mChanged = true;
mController.onHwOffloadDialogCanceled(); mController.onRebootDialogCanceled();
final boolean mode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false); final boolean mode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
assertThat(mode).isFalse(); assertThat(mode).isFalse();
} }

View File

@@ -66,7 +66,7 @@ public class BluetoothLeAudioHwOffloadPreferenceControllerTest {
SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false)); SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
mController.mChanged = true; mController.mChanged = true;
mController.onHwOffloadDialogConfirmed(); mController.onRebootDialogConfirmed();
final boolean mode = SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false); final boolean mode = SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false);
assertThat(mode).isTrue(); assertThat(mode).isTrue();
} }
@@ -76,7 +76,7 @@ public class BluetoothLeAudioHwOffloadPreferenceControllerTest {
SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(true)); SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(true));
mController.mChanged = true; mController.mChanged = true;
mController.onHwOffloadDialogConfirmed(); mController.onRebootDialogConfirmed();
final boolean mode2 = SystemProperties.getBoolean( final boolean mode2 = SystemProperties.getBoolean(
LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true); LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
assertThat(mode2).isFalse(); assertThat(mode2).isFalse();
@@ -87,7 +87,7 @@ public class BluetoothLeAudioHwOffloadPreferenceControllerTest {
SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false)); SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
mController.mChanged = true; mController.mChanged = true;
mController.onHwOffloadDialogCanceled(); mController.onRebootDialogCanceled();
final boolean mode = SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false); final boolean mode = SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false);
assertThat(mode).isFalse(); assertThat(mode).isFalse();
} }

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2022 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.development;
import static com.android.settings.development.BluetoothLeAudioPreferenceController
.LE_AUDIO_DYNAMIC_ENABLED_PROPERTY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.os.SystemProperties;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class BluetoothLeAudioPreferenceControllerTest {
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock
private DevelopmentSettingsDashboardFragment mFragment;
@Mock
private BluetoothAdapter mBluetoothAdapter;
private Context mContext;
private SwitchPreference mPreference;
private BluetoothLeAudioPreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mPreference = new SwitchPreference(mContext);
mController = spy(new BluetoothLeAudioPreferenceController(mContext, mFragment));
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.mBluetoothAdapter = mBluetoothAdapter;
mController.displayPreference(mPreferenceScreen);
}
@Test
public void onRebootDialogConfirmedAsLeAudioDisabled_shouldSwitchStatus() {
when(mBluetoothAdapter.isLeAudioSupported())
.thenReturn(BluetoothStatusCodes.FEATURE_NOT_SUPPORTED);
mController.mChanged = true;
mController.onRebootDialogConfirmed();
final boolean status = SystemProperties
.getBoolean(LE_AUDIO_DYNAMIC_ENABLED_PROPERTY, false);
assertThat(status).isTrue();
}
@Test
public void onRebootDialogConfirmedAsLeAudioEnabled_shouldSwitchStatus() {
when(mBluetoothAdapter.isLeAudioSupported())
.thenReturn(BluetoothStatusCodes.FEATURE_SUPPORTED);
mController.mChanged = true;
mController.onRebootDialogConfirmed();
final boolean status = SystemProperties
.getBoolean(LE_AUDIO_DYNAMIC_ENABLED_PROPERTY, false);
assertThat(status).isFalse();
}
@Test
public void onRebootDialogCanceled_shouldNotSwitchStatus() {
when(mBluetoothAdapter.isLeAudioSupported())
.thenReturn(BluetoothStatusCodes.FEATURE_NOT_SUPPORTED);
mController.mChanged = true;
mController.onRebootDialogCanceled();
final boolean status = SystemProperties
.getBoolean(LE_AUDIO_DYNAMIC_ENABLED_PROPERTY, false);
assertThat(status).isFalse();
}
}

View File

@@ -1,41 +1,180 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import static com.android.settings.wifi.ConfigureWifiSettings.KEY_INSTALL_CREDENTIALS;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
import android.view.View;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.XmlTestUtils;
import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Before; import org.junit.Before;
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.Mock;
import org.mockito.Spy;
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.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class ConfigureWifiSettingsTest { public class ConfigureWifiSettingsTest {
private Context mContext; @Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Spy
Context mContext = ApplicationProvider.getApplicationContext();
@Mock
UserManager mUserManager;
@Mock
WifiManager mWifiManager;
@Mock
FragmentActivity mActivity;
@Mock
WifiWakeupPreferenceController mWifiWakeupPreferenceController;
@Mock
Preference mInstallCredentialsPref;
@Mock
PreferenceScreen mPreferenceScreen;
@Mock
TextView mEmptyView;
TestConfigureWifiSettings mSettings;
@Before @Before
public void setUp() { public void setUp() {
mContext = spy(RuntimeEnvironment.application); when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.isGuestUser()).thenReturn(false);
when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
mSettings = spy(new TestConfigureWifiSettings());
when(mSettings.getContext()).thenReturn(mContext);
when(mSettings.getActivity()).thenReturn(mActivity);
when(mSettings.use(WifiWakeupPreferenceController.class))
.thenReturn(mWifiWakeupPreferenceController);
when(mSettings.findPreference(KEY_INSTALL_CREDENTIALS)).thenReturn(mInstallCredentialsPref);
}
@Test
public void onAttach_isNotGuestUser_setupController() {
when(mUserManager.isGuestUser()).thenReturn(false);
mSettings.onAttach(mContext);
verify(mWifiWakeupPreferenceController).setFragment(any());
}
@Test
public void onAttach_isGuestUser_doNotSetupController() {
when(mUserManager.isGuestUser()).thenReturn(true);
mSettings.onAttach(mContext);
verify(mWifiWakeupPreferenceController, never()).setFragment(any());
}
@Test
@Config(shadows = ShadowDashboardFragment.class)
public void onCreate_isNotGuestUser_setupPreference() {
when(mUserManager.isGuestUser()).thenReturn(false);
mSettings.onCreate(null);
verify(mInstallCredentialsPref).setOnPreferenceClickListener(any());
}
@Test
@Config(shadows = ShadowDashboardFragment.class)
public void onCreate_isGuestUser_doNotSetupPreference() {
when(mUserManager.isGuestUser()).thenReturn(true);
mSettings.onCreate(null);
verify(mInstallCredentialsPref, never()).setOnPreferenceClickListener(any());
}
@Test
@Config(shadows = ShadowDashboardFragment.class)
public void onViewCreated_isNotGuestUser_doNotRestrictUi() {
when(mUserManager.isGuestUser()).thenReturn(false);
when(mActivity.findViewById(android.R.id.empty)).thenReturn(mEmptyView);
doReturn(mPreferenceScreen).when(mSettings).getPreferenceScreen();
mSettings.onViewCreated(mock(View.class), null);
verify(mEmptyView, never()).setVisibility(View.VISIBLE);
verify(mPreferenceScreen, never()).removeAll();
}
@Test
@Config(shadows = ShadowDashboardFragment.class)
public void onViewCreated_isGuestUser_restrictUi() {
when(mUserManager.isGuestUser()).thenReturn(true);
when(mActivity.findViewById(android.R.id.empty)).thenReturn(mEmptyView);
doReturn(mPreferenceScreen).when(mSettings).getPreferenceScreen();
mSettings.onViewCreated(mock(View.class), null);
verify(mEmptyView).setVisibility(View.VISIBLE);
verify(mPreferenceScreen).removeAll();
} }
@Test @Test
@Config(qualifiers = "mcc999") @Config(qualifiers = "mcc999")
public void testNonIndexableKeys_ifPageDisabled_shouldNotIndexResource() { public void getNonIndexableKeys_ifPageDisabled_shouldNotIndexResource() {
final List<String> niks = final List<String> niks =
ConfigureWifiSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext); ConfigureWifiSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
final int xmlId = new ConfigureWifiSettings().getPreferenceScreenResId();
final int xmlId = mSettings.getPreferenceScreenResId();
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId); final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId);
assertThat(keys).isNotNull(); assertThat(keys).isNotNull();
assertThat(niks).containsAtLeastElementsIn(keys); assertThat(niks).containsAtLeastElementsIn(keys);
} }
public static class TestConfigureWifiSettings extends ConfigureWifiSettings {
@Override
public <T extends AbstractPreferenceController> T use(Class<T> clazz) {
return super.use(clazz);
}
}
@Implements(DashboardFragment.class)
public static class ShadowDashboardFragment {
@Implementation
public void onCreate(Bundle icicle) {
// do nothing
}
@Implementation
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
// do nothing
}
}
} }

View File

@@ -18,6 +18,7 @@ package com.android.settings.wifi;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION; import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION; import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
import static com.android.settings.wifi.WifiDialogActivity.REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER; import static com.android.settings.wifi.WifiDialogActivity.REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
import static com.android.settings.wifi.WifiDialogActivity.RESULT_CONNECTED; import static com.android.settings.wifi.WifiDialogActivity.RESULT_CONNECTED;
@@ -36,6 +37,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.UserManager;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.AccessPoint;
@@ -44,6 +46,7 @@ import com.android.wifitrackerlib.WifiEntry;
import com.google.android.setupcompat.util.WizardManagerHelper; import com.google.android.setupcompat.util.WizardManagerHelper;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -57,6 +60,8 @@ public class WifiDialogActivityTest {
static final String CALLING_PACKAGE = "calling_package"; static final String CALLING_PACKAGE = "calling_package";
static final int REQUEST_CODE = REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER; static final int REQUEST_CODE = REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
@Mock
UserManager mUserManager;
@Mock @Mock
PackageManager mPackageManager; PackageManager mPackageManager;
@Mock @Mock
@@ -92,6 +97,7 @@ public class WifiDialogActivityTest {
FakeFeatureFactory.setupForTest(); FakeFeatureFactory.setupForTest();
mActivity = spy(Robolectric.setupActivity(WifiDialogActivity.class)); mActivity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
when(mActivity.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager); when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
} }
@@ -211,6 +217,20 @@ public class WifiDialogActivityTest {
verify(mActivity).setResult(RESULT_CONNECTED, mResultData); verify(mActivity).setResult(RESULT_CONNECTED, mResultData);
} }
@Test
public void isConfigWifiAllowed_hasNoUserRestriction_returnTrue() {
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_WIFI)).thenReturn(false);
assertThat(mActivity.isConfigWifiAllowed()).isTrue();
}
@Test
public void isConfigWifiAllowed_hasUserRestriction_returnFalse() {
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_WIFI)).thenReturn(true);
assertThat(mActivity.isConfigWifiAllowed()).isFalse();
}
@Test @Test
public void hasPermissionForResult_noCallingPackage_returnFalse() { public void hasPermissionForResult_noCallingPackage_returnFalse() {
when(mActivity.getCallingPackage()).thenReturn(null); when(mActivity.getCallingPackage()).thenReturn(null);