Merge "Import translations. DO NOT MERGE ANYWHERE" into sc-dev
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index b94da0d..9c79bab 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -4013,4 +4013,36 @@
column="5"/>
</issue>
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <item android:offset="0" android:color="#FF4285F4"/>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/drawable/one_handed_guideline.xml"
+ line="34"
+ column="36"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <item android:offset="1" android:color="#004385F5"/>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/drawable/one_handed_guideline.xml"
+ line="35"
+ column="36"/>
+ </issue>
+
</issues>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7ad7fe1..7e10006 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3188,6 +3188,10 @@
<string name="status_prl_version">PRL version</string>
<!-- About phone screen, title for MEID for multi-sim devices -->
<string name="meid_multi_sim">MEID (sim slot %1$d)</string>
+ <!-- The status text when (Wi-Fi or Bluetooth) scanning is on. [CHAR LIMIT=100] -->
+ <string name="scanning_status_text_on">On</string>
+ <!-- The status text when (Wi-Fi or Bluetooth) scanning is off. [CHAR LIMIT=100] -->
+ <string name="scanning_status_text_off">Off</string>
<!-- The status text when both Wi-Fi scanning and Bluetooth scanning are on. [CHAR LIMIT=100] -->
<string name="scanning_status_text_wifi_on_ble_on">Both Wi\u2011Fi and Bluetooth scanning are on</string>
<!-- The status text when Wi-Fi scanning is on and Bluetooth scanning are off. [CHAR LIMIT=100] -->
@@ -5027,27 +5031,27 @@
<!-- Title for the accessibility preference screen to enable screen magnification. [CHAR LIMIT=35] -->
<string name="accessibility_screen_magnification_title">Magnification</string>
<!-- Title for the accessibility preference screen to edit magnification area. [CHAR LIMIT=35] -->
- <string name="accessibility_magnification_mode_title">Magnification area</string>
+ <string name="accessibility_magnification_mode_title">Choose how to magnify</string>
<!-- Message for the accessibility preference screen to edit magnification area dialog. [CHAR LIMIT=none] -->
- <string name="accessibility_magnification_area_settings_message">Choose the magnification area(s) you want to use when magnifying the screen</string>
+ <string name="accessibility_magnification_area_settings_message">Magnify your full screen, a specific area, or switch between both options</string>
<!-- Summary for the accessibility preference screen to edit full screen. [CHAR LIMIT=none] -->
<string name="accessibility_magnification_area_settings_full_screen_summary">Full screen</string>
- <!-- Summary for the accessibility preference screen to edit window screen. [CHAR LIMIT=none] -->
- <string name="accessibility_magnification_area_settings_window_screen_summary">Part of screen</string>
- <!-- Summary for the accessibility preference screen to edit entire screen. [CHAR LIMIT=none] -->
- <string name="accessibility_magnification_area_settings_all_summary">Full screen & part of screen</string>
- <!-- Message for the accessibility preference screen to edit entire screen. [CHAR LIMIT=none] -->
- <string name="accessibility_magnification_area_settings_full_screen">Magnify entire screen</string>
+ <!-- Summary for the accessibility preference screen to edit partial screen. [CHAR LIMIT=none] -->
+ <string name="accessibility_magnification_area_settings_window_screen_summary">Partial screen</string>
+ <!-- Summary for the accessibility preference screen to edit full and partial screen. [CHAR LIMIT=none] -->
+ <string name="accessibility_magnification_area_settings_all_summary">Switch between full and partial screen</string>
+ <!-- Message for the accessibility preference screen to edit the full screen. [CHAR LIMIT=none] -->
+ <string name="accessibility_magnification_area_settings_full_screen">Magnify full screen</string>
<!-- Message for the accessibility preference screen to edit part of screen. [CHAR LIMIT=none] -->
<string name="accessibility_magnification_area_settings_window_screen">Magnify part of screen</string>
<!-- Title for the accessibility magnification switch shortcut dialog. [CHAR LIMIT=48] -->
<string name="accessibility_magnification_switch_shortcut_title">Switch to accessibility button?</string>
<!-- Message for the accessibility magnification switch shortcut dialog. [CHAR LIMIT=none] -->
- <string name="accessibility_magnification_switch_shortcut_message">Using triple tap to magnify part of the screen will cause typing and other actions to be delayed.\n\nDo you want to switch to using accessibility button to magnify?</string>
+ <string name="accessibility_magnification_switch_shortcut_message">Using triple-tap to magnify part of the screen causes typing and other delays.\n\nThe accessibility button floats on your screen over other apps. Tap it to magnify.</string>
<!-- Title for the switch shortcut button in accessibility switch shortcut dialog to change the config shortcut value. [CHAR LIMIT=45] -->
<string name="accessibility_magnification_switch_shortcut_positive_button">Switch to accessibility button</string>
<!-- Title for the cancel button in accessibility switch shortcut dialog to keep the config shortcut value. [CHAR LIMIT=54] -->
- <string name="accessibility_magnification_switch_shortcut_negative_button">Keep triple tap to magnify</string>
+ <string name="accessibility_magnification_switch_shortcut_negative_button">Use triple-tap</string>
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
<string name="accessibility_magnification_service_settings_title">Magnification settings</string>
<!-- Title for the accessibility preference screen to enable triple-tap gesture screen magnification. [CHAR LIMIT=35] -->
@@ -5068,7 +5072,7 @@
<string name="accessibility_screen_magnification_navbar_short_summary">Tap a button to zoom</string>
<!-- Summary for the accessibility preference screen to enable screen magnification gestures. [CHAR LIMIT=none] -->
<string name="accessibility_screen_magnification_summary">
- <![CDATA[Quickly zoom in on the screen to display content more clearly.<br/><br/>
+ <![CDATA[Quickly zoom in on the screen to make content larger.<br/><br/>
<b>To zoom in:</b><br/>
1. Use shortcut to start magnification<br/>
2. Tap the screen<br/>
@@ -12785,36 +12789,36 @@
<!-- Title for bluetooth main switch. [CHAR LIMIT=50] -->
<string name="bluetooth_main_switch_title">Use Bluetooth</string>
- <!-- Do not translate. Title for prevent ringing main switch. [CHAR LIMIT=50] -->
- <string name="prevent_ringing_main_switch_title" translatable="false">Use prevent ringing</string>
- <!-- Do not translate. Title for use wifi hotspot main switch [CHAR LIMIT=50]-->
- <string name="use_wifi_hotsopt_main_switch_title" translatable="false">Use Wi\u2011Fi hotspot</string>
- <!-- Do not translate. Title for app pinning main switch. [CHAR LIMIT=50] -->
- <string name="app_pinning_main_switch_title" translatable="false">Use app pinning</string>
- <!-- Do not translate. Title for developer options main switch. [CHAR LIMIT=50] -->
- <string name="developer_options_main_switch_title" translatable="false">Use developer options</string>
- <!-- Do not translate. Title for default print service main switch. [CHAR LIMIT=50] -->
- <string name="default_print_service_main_switch_title" translatable="false">Use default print service</string>
- <!-- Do not translate. Title for multiple users main switch. [CHAR LIMIT=50] -->
- <string name="multiple_users_main_switch_title" translatable="false">Use multiple users</string>
- <!-- Do not translate. Title for wireless debugging main switch. [CHAR LIMIT=50] -->
- <string name="wireless_debugging_main_switch_title" translatable="false">Use wireless debugging</string>
- <!-- Do not translate. Title for graphics driver main switch. [CHAR LIMIT=50] -->
- <string name="graphics_driver_main_switch_title" translatable="false">Use graphics driver preferences</string>
- <!-- Do not translate. Title for battery saver main switch preferences. [CHAR LIMIT=50] -->
- <string name="battery_saver_main_switch_title" translatable="false">Use battery saver</string>
- <!-- Do not translate. Title for Do Not Disturb main switch preferences. [CHAR LIMIT=50] -->
- <string name="do_not_disturb_main_switch_title" translatable="false">Use Do Not Disturb</string>
- <!-- Do not translate. Title for Night Light main switch preferences. [CHAR LIMIT=50] -->
- <string name="night_light_main_switch_title" translatable="false">Use Night Light</string>
- <!-- Do not translate. Title for NFC main switch preferences. [CHAR LIMIT=50] -->
- <string name="nfc_main_switch_title" translatable="false">Use NFC</string>
- <!-- Do not translate. Title for Adaptive Battery main switch preferences. [CHAR LIMIT=50] -->
- <string name="adaptive_battery_main_switch_title" translatable="false">Use adaptive battery</string>
- <!-- Do not translate. Title for adaptive brightness main switch preferences. [CHAR LIMIT=50] -->
- <string name="adaptive_brightness_main_switch_title" translatable="false">Use adaptive brightness</string>
- <!-- Do not translate. Title for wifi calling main switch preferences. [CHAR LIMIT=50] -->
- <string name="wifi_calling_main_switch_title" translatable="false">Use Wi-Fi calling</string>
+ <!-- Title for prevent ringing main switch. [CHAR LIMIT=50] -->
+ <string name="prevent_ringing_main_switch_title">Use prevent ringing</string>
+ <!-- Title for use wifi hotspot main switch [CHAR LIMIT=50]-->
+ <string name="use_wifi_hotsopt_main_switch_title">Use Wi\u2011Fi hotspot</string>
+ <!-- Title for app pinning main switch. [CHAR LIMIT=50] -->
+ <string name="app_pinning_main_switch_title">Use app pinning</string>
+ <!-- Title for developer options main switch. [CHAR LIMIT=50] -->
+ <string name="developer_options_main_switch_title">Use developer options</string>
+ <!-- Title for default print service main switch. [CHAR LIMIT=50] -->
+ <string name="default_print_service_main_switch_title">Use default print service</string>
+ <!-- Title for multiple users main switch. [CHAR LIMIT=50] -->
+ <string name="multiple_users_main_switch_title">Use multiple users</string>
+ <!-- Title for wireless debugging main switch. [CHAR LIMIT=50] -->
+ <string name="wireless_debugging_main_switch_title">Use wireless debugging</string>
+ <!-- Title for graphics driver main switch. [CHAR LIMIT=50] -->
+ <string name="graphics_driver_main_switch_title">Use graphics driver preferences</string>
+ <!-- Title for battery saver main switch preferences. [CHAR LIMIT=50] -->
+ <string name="battery_saver_main_switch_title">Use battery saver</string>
+ <!-- Title for Do Not Disturb main switch preferences. [CHAR LIMIT=50] -->
+ <string name="do_not_disturb_main_switch_title">Use Do Not Disturb</string>
+ <!-- Title for Night Light main switch preferences. [CHAR LIMIT=50] -->
+ <string name="night_light_main_switch_title">Use Night Light</string>
+ <!-- Title for NFC main switch preferences. [CHAR LIMIT=50] -->
+ <string name="nfc_main_switch_title">Use NFC</string>
+ <!-- Title for Adaptive Battery main switch preferences. [CHAR LIMIT=50] -->
+ <string name="adaptive_battery_main_switch_title">Use adaptive battery</string>
+ <!-- Title for adaptive brightness main switch preferences. [CHAR LIMIT=50] -->
+ <string name="adaptive_brightness_main_switch_title">Use adaptive brightness</string>
+ <!-- Title for wifi calling main switch preferences. [CHAR LIMIT=50] -->
+ <string name="wifi_calling_main_switch_title">Use Wi‑Fi calling</string>
<!-- Default preference title for showing all apps on device [CHAR_LIMIT=50]-->
<string name="default_see_all_apps_title">See all apps</string>
diff --git a/res/xml/location_services.xml b/res/xml/location_services.xml
index ef94886..516491c 100644
--- a/res/xml/location_services.xml
+++ b/res/xml/location_services.xml
@@ -18,21 +18,21 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/location_services_screen_title">
- <SwitchPreference
- android:title="@string/location_scanning_wifi_always_scanning_title"
- android:summary="@string/location_scanning_wifi_always_scanning_description"
- android:defaultValue="true"
- android:key="wifi_always_scanning" />
-
- <SwitchPreference
- android:title="@string/location_scanning_bluetooth_always_scanning_title"
- android:summary="@string/location_scanning_bluetooth_always_scanning_description"
- android:defaultValue="true"
- android:key="bluetooth_always_scanning" />
-
<PreferenceCategory
android:key="location_services"
android:layout="@layout/preference_category_no_label"
settings:controller="com.android.settings.location.LocationInjectedServicesPreferenceController"/>
+ <Preference
+ android:fragment="com.android.settings.location.WifiScanningFragment"
+ android:key="location_services_wifi_scanning"
+ android:title="@string/location_scanning_wifi_always_scanning_title"
+ settings:controller="com.android.settings.location.LocationServicesWifiScanningPreferenceController"/>
+
+ <Preference
+ android:fragment="com.android.settings.location.BluetoothScanningFragment"
+ android:key="location_services_bluetooth_scanning"
+ android:title="@string/location_scanning_bluetooth_always_scanning_title"
+ settings:controller="com.android.settings.location.LocationServicesBluetoothScanningPreferenceController"/>
+
</PreferenceScreen>
diff --git a/res/xml/location_services_bluetooth_scanning.xml b/res/xml/location_services_bluetooth_scanning.xml
new file mode 100644
index 0000000..fb522f0
--- /dev/null
+++ b/res/xml/location_services_bluetooth_scanning.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="@string/location_scanning_bluetooth_always_scanning_title">
+
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="bluetooth_always_scanning_switch"
+ android:title="@string/location_scanning_bluetooth_always_scanning_title"
+ settings:controller="com.android.settings.location.BluetoothScanningMainSwitchPreferenceController"/>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="bluetooth_always_scanning_footer"
+ android:title="@string/location_scanning_bluetooth_always_scanning_description"
+ android:selectable="false"
+ settings:searchable="false"/>
+
+</PreferenceScreen>
diff --git a/res/xml/location_services_wifi_scanning.xml b/res/xml/location_services_wifi_scanning.xml
new file mode 100644
index 0000000..a436fac
--- /dev/null
+++ b/res/xml/location_services_wifi_scanning.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="@string/location_scanning_wifi_always_scanning_title">
+
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="wifi_always_scanning_switch"
+ android:title="@string/location_scanning_wifi_always_scanning_title"
+ settings:controller="com.android.settings.location.WifiScanningMainSwitchPreferenceController"/>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="wifi_always_scanning_footer"
+ android:title="@string/location_scanning_wifi_always_scanning_description"
+ android:selectable="false"
+ settings:searchable="false"/>
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
index 7f8ade1..096c2c5 100644
--- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -29,9 +29,10 @@
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
-import android.provider.DeviceConfig;
import android.provider.MediaStore;
+import android.text.TextUtils;
import android.util.Log;
+import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@@ -43,7 +44,6 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.fuelgauge.BatteryMeterView;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -84,6 +84,7 @@
private static final int LEFT_DEVICE_ID = 1;
private static final int RIGHT_DEVICE_ID = 2;
private static final int CASE_DEVICE_ID = 3;
+ private static final int MAIN_DEVICE_ID = 4;
@VisibleForTesting
LayoutPreference mLayoutPreference;
@@ -115,13 +116,11 @@
@Override
public int getAvailabilityStatus() {
- final boolean advancedEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
- SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, true);
- final boolean untetheredHeadset = mCachedDevice != null
- && BluetoothUtils.getBooleanMetaData(
- mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
- Log.d(TAG, "getAvailabilityStatus() is untethered : " + untetheredHeadset);
- return advancedEnabled && untetheredHeadset ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ if (mCachedDevice == null) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ return Utils.isAdvancedDetailsHeader(mCachedDevice.getDevice())
+ ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
@@ -182,27 +181,45 @@
updateDisconnectLayout();
return;
}
+ final BluetoothDevice device = mCachedDevice.getDevice();
+ final String deviceType = BluetoothUtils.getStringMetaData(device,
+ BluetoothDevice.METADATA_DEVICE_TYPE);
+ if (TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_WATCH)
+ || TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_DEFAULT)) {
+ mLayoutPreference.findViewById(R.id.layout_left).setVisibility(View.GONE);
+ mLayoutPreference.findViewById(R.id.layout_right).setVisibility(View.GONE);
- updateSubLayout(mLayoutPreference.findViewById(R.id.layout_left),
- BluetoothDevice.METADATA_UNTETHERED_LEFT_ICON,
- BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY,
- BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING,
- R.string.bluetooth_left_name,
- LEFT_DEVICE_ID);
+ updateSubLayout(mLayoutPreference.findViewById(R.id.layout_middle),
+ BluetoothDevice.METADATA_MAIN_ICON,
+ BluetoothDevice.METADATA_MAIN_BATTERY,
+ BluetoothDevice.METADATA_MAIN_CHARGING,
+ /* titleResId */ 0,
+ MAIN_DEVICE_ID);
+ } else if (TextUtils.equals(deviceType,
+ BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET)
+ || BluetoothUtils.getBooleanMetaData(device,
+ BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) {
+ updateSubLayout(mLayoutPreference.findViewById(R.id.layout_left),
+ BluetoothDevice.METADATA_UNTETHERED_LEFT_ICON,
+ BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY,
+ BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING,
+ R.string.bluetooth_left_name,
+ LEFT_DEVICE_ID);
- updateSubLayout(mLayoutPreference.findViewById(R.id.layout_middle),
- BluetoothDevice.METADATA_UNTETHERED_CASE_ICON,
- BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY,
- BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING,
- R.string.bluetooth_middle_name,
- CASE_DEVICE_ID);
+ updateSubLayout(mLayoutPreference.findViewById(R.id.layout_middle),
+ BluetoothDevice.METADATA_UNTETHERED_CASE_ICON,
+ BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY,
+ BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING,
+ R.string.bluetooth_middle_name,
+ CASE_DEVICE_ID);
- updateSubLayout(mLayoutPreference.findViewById(R.id.layout_right),
- BluetoothDevice.METADATA_UNTETHERED_RIGHT_ICON,
- BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY,
- BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING,
- R.string.bluetooth_right_name,
- RIGHT_DEVICE_ID);
+ updateSubLayout(mLayoutPreference.findViewById(R.id.layout_right),
+ BluetoothDevice.METADATA_UNTETHERED_RIGHT_ICON,
+ BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY,
+ BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING,
+ R.string.bluetooth_right_name,
+ RIGHT_DEVICE_ID);
+ }
}
}
@@ -226,17 +243,21 @@
}
private void updateSubLayout(LinearLayout linearLayout, int iconMetaKey, int batteryMetaKey,
- int chargeMetaKey, int titleResId, int batteryId) {
+ int chargeMetaKey, int titleResId, int deviceId) {
if (linearLayout == null) {
return;
}
final BluetoothDevice bluetoothDevice = mCachedDevice.getDevice();
final String iconUri = BluetoothUtils.getStringMetaData(bluetoothDevice, iconMetaKey);
+ final ImageView imageView = linearLayout.findViewById(R.id.header_icon);
if (iconUri != null) {
- final ImageView imageView = linearLayout.findViewById(R.id.header_icon);
updateIcon(imageView, iconUri);
+ } else {
+ final Pair<Drawable, String> pair =
+ BluetoothUtils.getBtRainbowDrawableWithDescription(mContext, mCachedDevice);
+ imageView.setImageDrawable(pair.first);
+ imageView.setContentDescription(pair.second);
}
-
final int batteryLevel = BluetoothUtils.getIntMetaData(bluetoothDevice, batteryMetaKey);
final boolean charging = BluetoothUtils.getBooleanMetaData(bluetoothDevice, chargeMetaKey);
if (DEBUG) {
@@ -244,24 +265,35 @@
+ ", charge : " + chargeMetaKey + ", batteryLevel : " + batteryLevel
+ ", charging : " + charging + ", iconUri : " + iconUri);
}
-
- if (batteryId != CASE_DEVICE_ID) {
- showBatteryPredictionIfNecessary(linearLayout, batteryId, batteryLevel);
+ if (deviceId == LEFT_DEVICE_ID || deviceId == RIGHT_DEVICE_ID) {
+ showBatteryPredictionIfNecessary(linearLayout, deviceId, batteryLevel);
}
+ final TextView batterySummaryView = linearLayout.findViewById(R.id.bt_battery_summary);
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
linearLayout.setVisibility(View.VISIBLE);
- final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
- textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
- textView.setVisibility(View.VISIBLE);
+ batterySummaryView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
+ batterySummaryView.setVisibility(View.VISIBLE);
showBatteryIcon(linearLayout, batteryLevel, charging, batteryMetaKey);
} else {
- // Hide it if it doesn't have battery information
- linearLayout.setVisibility(View.GONE);
+ if (deviceId == MAIN_DEVICE_ID) {
+ linearLayout.setVisibility(View.VISIBLE);
+ batterySummaryView.setText(com.android.settings.Utils.formatPercentage(
+ bluetoothDevice.getBatteryLevel()));
+ batterySummaryView.setVisibility(View.VISIBLE);
+ linearLayout.findViewById(R.id.bt_battery_icon).setVisibility(View.GONE);
+ } else {
+ // Hide it if it doesn't have battery information
+ linearLayout.setVisibility(View.GONE);
+ }
}
final TextView textView = linearLayout.findViewById(R.id.header_title);
- textView.setText(titleResId);
- textView.setVisibility(View.VISIBLE);
+ if (deviceId == MAIN_DEVICE_ID) {
+ textView.setVisibility(View.GONE);
+ } else {
+ textView.setText(titleResId);
+ textView.setVisibility(View.VISIBLE);
+ }
}
private void showBatteryPredictionIfNecessary(LinearLayout linearLayout, int batteryId,
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
index fc74004..9f5e78e 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
@@ -16,10 +16,8 @@
package com.android.settings.bluetooth;
-import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.drawable.Drawable;
-import android.provider.DeviceConfig;
import android.text.TextUtils;
import android.util.Pair;
@@ -27,7 +25,6 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -56,11 +53,7 @@
@Override
public boolean isAvailable() {
- final boolean advancedEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
- SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, true);
- return !advancedEnabled
- || !BluetoothUtils.getBooleanMetaData(mCachedDevice.getDevice(),
- BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
+ return !Utils.isAdvancedDetailsHeader(mCachedDevice.getDevice());
}
@Override
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
index e40e30d..cd36ce8 100644
--- a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
@@ -16,6 +16,8 @@
package com.android.settings.bluetooth;
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -23,6 +25,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
+import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
@@ -30,11 +33,14 @@
import androidx.preference.Preference;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.settings.R;
-
-import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+import com.android.settings.password.PasswordUtils;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
/**
* BluetoothPermissionActivity shows a dialog for accepting incoming
@@ -51,8 +57,13 @@
private TextView messageView;
private Button mOkButton;
private BluetoothDevice mDevice;
- private String mReturnPackage = null;
- private String mReturnClass = null;
+
+ @VisibleForTesting
+ String mReturnPackage = null;
+ @VisibleForTesting
+ String mReturnClass = null;
+ @VisibleForTesting
+ String mCallingAppPackageName;
private int mRequestType = 0;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -80,6 +91,7 @@
getWindow().addPrivateFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
Intent i = getIntent();
+ mCallingAppPackageName = PasswordUtils.getCallingAppPackageName(getActivityToken());
String action = i.getAction();
if (!action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST)) {
Log.e(TAG, "Error: this activity may be started only with intent "
@@ -94,6 +106,22 @@
mRequestType = i.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
+ // Even if the user has already made the choice, Bluetooth still may not know that if
+ // the user preference data have not been migrated from Settings app's shared
+ // preferences to Bluetooth app's. In that case, Bluetooth app broadcasts an
+ // ACTION_CONNECTION_ACCESS_REQUEST intent to ask to Settings app.
+ //
+ // If that happens, 'checkUserChoice()' here will do migration because it finds or
+ // creates a 'CachedBluetoothDevice' object for the device.
+ //
+ // After migration is done, 'checkUserChoice()' replies to the request by sending an
+ // ACTION_CONNECTION_ACCESS_REPLY intent. And we don't need to start permission activity
+ // dialog or notification.
+ if (checkUserChoice()) {
+ finish();
+ return;
+ }
+
if(DEBUG) Log.i(TAG, "onCreate() Request type: " + mRequestType);
if (mRequestType == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION) {
@@ -202,7 +230,14 @@
sendReplyIntentToReceiver(false, true);
}
- private void sendReplyIntentToReceiver(final boolean allowed, final boolean always) {
+ @VisibleForTesting
+ void sendReplyIntentToReceiver(final boolean allowed, final boolean always) {
+ if (!TextUtils.equals(mCallingAppPackageName, mReturnPackage)) {
+ Log.w(TAG, "sendReplyIntentToReceiver() return package name is not equivalent"
+ + " to calling package name!");
+ return;
+ }
+
Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
if (mReturnPackage != null && mReturnClass != null) {
@@ -246,4 +281,76 @@
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
+
+ /**
+ * @return true user had made a choice, this method replies to the request according
+ * to user's previous decision
+ * false user hadnot made any choice on this device
+ */
+ private boolean checkUserChoice() {
+ boolean processed = false;
+
+ // ignore if it is something else than phonebook/message settings it wants us to remember
+ if (mRequestType != BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS
+ && mRequestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS
+ && mRequestType != BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
+ Log.d(TAG, "checkUserChoice(): Unknown RequestType " + mRequestType);
+ return processed;
+ }
+
+ final LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(this);
+ final CachedBluetoothDeviceManager cachedDeviceManager =
+ bluetoothManager.getCachedDeviceManager();
+ CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
+ if (cachedDevice == null) {
+ cachedDevice = cachedDeviceManager.addDevice(mDevice);
+ }
+
+ if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
+ final int phonebookPermission = mDevice.getPhonebookAccessPermission();
+
+ if (phonebookPermission == BluetoothDevice.ACCESS_UNKNOWN) {
+ // Leave 'processed' as false.
+ } else if (phonebookPermission == BluetoothDevice.ACCESS_ALLOWED) {
+ sendReplyIntentToReceiver(true, true);
+ processed = true;
+ } else if (phonebookPermission == BluetoothDevice.ACCESS_REJECTED) {
+ sendReplyIntentToReceiver(false, true);
+ processed = true;
+ } else {
+ Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
+ }
+ } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
+ final int messagePermission = mDevice.getMessageAccessPermission();
+
+ if (messagePermission == BluetoothDevice.ACCESS_UNKNOWN) {
+ // Leave 'processed' as false.
+ } else if (messagePermission == BluetoothDevice.ACCESS_ALLOWED) {
+ sendReplyIntentToReceiver(true, true);
+ processed = true;
+ } else if (messagePermission == BluetoothDevice.ACCESS_REJECTED) {
+ sendReplyIntentToReceiver(false, true);
+ processed = true;
+ } else {
+ Log.e(TAG, "Bad messagePermission: " + messagePermission);
+ }
+ } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
+ final int simPermission = mDevice.getSimAccessPermission();
+
+ if (simPermission == BluetoothDevice.ACCESS_UNKNOWN) {
+ // Leave 'processed' as false.
+ } else if (simPermission == BluetoothDevice.ACCESS_ALLOWED) {
+ sendReplyIntentToReceiver(true, true);
+ processed = true;
+ } else if (simPermission == BluetoothDevice.ACCESS_REJECTED) {
+ sendReplyIntentToReceiver(false, true);
+ processed = true;
+ } else {
+ Log.e(TAG, "Bad simPermission: " + simPermission);
+ }
+ }
+
+ Log.d(TAG, "checkUserChoice(): returning " + processed);
+ return processed;
+ }
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
index 7fac4991c..c606e31 100644
--- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
@@ -29,9 +29,6 @@
import android.util.Log;
import com.android.settings.R;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
/**
* BluetoothPermissionRequest is a receiver to receive Bluetooth connection
@@ -83,21 +80,6 @@
if (DEBUG) Log.d(TAG, "onReceive request type: " + mRequestType + " return "
+ mReturnPackage + "," + mReturnClass);
- // Even if the user has already made the choice, Bluetooth still may not know that if
- // the user preference data have not been migrated from Settings app's shared
- // preferences to Bluetooth app's. In that case, Bluetooth app broadcasts an
- // ACTION_CONNECTION_ACCESS_REQUEST intent to ask to Settings app.
- //
- // If that happens, 'checkUserChoice()' here will do migration because it finds or
- // creates a 'CachedBluetoothDevice' object for the device.
- //
- // After migration is done, 'checkUserChoice()' replies to the request by sending an
- // ACTION_CONNECTION_ACCESS_REPLY intent. And we don't need to start permission activity
- // dialog or notification.
- if (checkUserChoice()) {
- return;
- }
-
Intent connectionAccessIntent = new Intent(action);
connectionAccessIntent.setClass(context, BluetoothPermissionActivity.class);
// We use the FLAG_ACTIVITY_MULTIPLE_TASK since we can have multiple concurrent access
@@ -212,92 +194,4 @@
}
return null;
}
-
- /**
- * @return true user had made a choice, this method replies to the request according
- * to user's previous decision
- * false user hadnot made any choice on this device
- */
- private boolean checkUserChoice() {
- boolean processed = false;
-
- // ignore if it is something else than phonebook/message settings it wants us to remember
- if (mRequestType != BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS
- && mRequestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS
- && mRequestType != BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
- if (DEBUG) Log.d(TAG, "checkUserChoice(): Unknown RequestType " + mRequestType);
- return processed;
- }
-
- LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(mContext);
- CachedBluetoothDeviceManager cachedDeviceManager =
- bluetoothManager.getCachedDeviceManager();
- CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
- if (cachedDevice == null) {
- cachedDevice = cachedDeviceManager.addDevice(mDevice);
- }
-
- String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
-
- if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
- int phonebookPermission = mDevice.getPhonebookAccessPermission();
-
- if (phonebookPermission == BluetoothDevice.ACCESS_UNKNOWN) {
- // Leave 'processed' as false.
- } else if (phonebookPermission == BluetoothDevice.ACCESS_ALLOWED) {
- sendReplyIntentToReceiver(true);
- processed = true;
- } else if (phonebookPermission == BluetoothDevice.ACCESS_REJECTED) {
- sendReplyIntentToReceiver(false);
- processed = true;
- } else {
- Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
- }
- } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
- int messagePermission = mDevice.getMessageAccessPermission();
-
- if (messagePermission == BluetoothDevice.ACCESS_UNKNOWN) {
- // Leave 'processed' as false.
- } else if (messagePermission == BluetoothDevice.ACCESS_ALLOWED) {
- sendReplyIntentToReceiver(true);
- processed = true;
- } else if (messagePermission == BluetoothDevice.ACCESS_REJECTED) {
- sendReplyIntentToReceiver(false);
- processed = true;
- } else {
- Log.e(TAG, "Bad messagePermission: " + messagePermission);
- }
- } else if(mRequestType == BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
- int simPermission = mDevice.getSimAccessPermission();
-
- if (simPermission == BluetoothDevice.ACCESS_UNKNOWN) {
- // Leave 'processed' as false.
- } else if (simPermission == BluetoothDevice.ACCESS_ALLOWED) {
- sendReplyIntentToReceiver(true);
- processed = true;
- } else if (simPermission == BluetoothDevice.ACCESS_REJECTED) {
- sendReplyIntentToReceiver(false);
- processed = true;
- } else {
- Log.e(TAG, "Bad simPermission: " + simPermission);
- }
- }
- if (DEBUG) Log.d(TAG,"checkUserChoice(): returning " + processed);
- return processed;
- }
-
- private void sendReplyIntentToReceiver(final boolean allowed) {
- Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
-
- if (mReturnPackage != null && mReturnClass != null) {
- intent.setClassName(mReturnPackage, mReturnClass);
- }
-
- intent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
- allowed ? BluetoothDevice.CONNECTION_ACCESS_YES
- : BluetoothDevice.CONNECTION_ACCESS_NO);
- intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
- intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
- mContext.sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN);
- }
}
diff --git a/src/com/android/settings/bluetooth/DevicePickerFragment.java b/src/com/android/settings/bluetooth/DevicePickerFragment.java
index ab8eea5..214c590 100644
--- a/src/com/android/settings/bluetooth/DevicePickerFragment.java
+++ b/src/com/android/settings/bluetooth/DevicePickerFragment.java
@@ -27,12 +27,15 @@
import android.content.Intent;
import android.os.Bundle;
import android.os.UserManager;
+import android.text.TextUtils;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
+import com.android.settings.password.PasswordUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -48,10 +51,16 @@
@VisibleForTesting
BluetoothProgressCategory mAvailableDevicesCategory;
+ @VisibleForTesting
+ String mLaunchPackage;
+ @VisibleForTesting
+ String mLaunchClass;
+ @VisibleForTesting
+ String mCallingAppPackageName;
+ @VisibleForTesting
+ Context mContext;
private boolean mNeedAuth;
- private String mLaunchPackage;
- private String mLaunchClass;
private boolean mScanAllowed;
public DevicePickerFragment() {
@@ -85,6 +94,9 @@
getActivity().setTitle(getString(R.string.device_picker));
UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
mScanAllowed = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH);
+ mCallingAppPackageName = PasswordUtils.getCallingAppPackageName(
+ getActivity().getActivityToken());
+ mContext = getContext();
setHasOptionsMenu(true);
}
@@ -188,11 +200,17 @@
}
private void sendDevicePickedIntent(BluetoothDevice device) {
+ if (!TextUtils.equals(mCallingAppPackageName, mLaunchPackage)) {
+ Log.w(TAG, "sendDevicePickedIntent() launch package name is not equivalent to"
+ + " calling package name!");
+ return;
+ }
+
Intent intent = new Intent(BluetoothDevicePicker.ACTION_DEVICE_SELECTED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
if (mLaunchPackage != null && mLaunchClass != null) {
intent.setClassName(mLaunchPackage, mLaunchClass);
}
- getActivity().sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN);
+ mContext.sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN);
}
}
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 48c7212..ca8f9d3 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -21,14 +21,18 @@
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.DialogInterface;
+import android.provider.DeviceConfig;
import android.provider.Settings;
+import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
+import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
+import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
@@ -153,4 +157,36 @@
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
}
+
+ /**
+ * Check if the Bluetooth device supports advanced details header
+ *
+ * @param bluetoothDevice the BluetoothDevice to get metadata
+ * @return true if it supports advanced details header, false otherwise.
+ */
+ public static boolean isAdvancedDetailsHeader(@NonNull BluetoothDevice bluetoothDevice) {
+ final boolean advancedEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
+ SettingsUIDeviceConfig.BT_ADVANCED_HEADER_ENABLED, true);
+ if (!advancedEnabled) {
+ Log.d(TAG, "isAdvancedDetailsHeader: advancedEnabled is false");
+ return false;
+ }
+ // The metadata is for Android R
+ final boolean untetheredHeadset = BluetoothUtils.getBooleanMetaData(bluetoothDevice,
+ BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
+ if (untetheredHeadset) {
+ Log.d(TAG, "isAdvancedDetailsHeader: untetheredHeadset is true");
+ return true;
+ }
+ // The metadata is for Android S
+ final String deviceType = BluetoothUtils.getStringMetaData(bluetoothDevice,
+ BluetoothDevice.METADATA_DEVICE_TYPE);
+ if (TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET)
+ || TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_WATCH)
+ || TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_DEFAULT)) {
+ Log.d(TAG, "isAdvancedDetailsHeader: deviceType is " + deviceType);
+ return true;
+ }
+ return false;
+ }
}
diff --git a/src/com/android/settings/location/BluetoothScanningFragment.java b/src/com/android/settings/location/BluetoothScanningFragment.java
new file mode 100644
index 0000000..553f975
--- /dev/null
+++ b/src/com/android/settings/location/BluetoothScanningFragment.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2021 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.location;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A page that configures the Bluetooth scanning setting.
+ */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class BluetoothScanningFragment extends DashboardFragment {
+ private static final String TAG = "BluetoothScanningFragment";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.LOCATION_SERVICES;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.location_services_bluetooth_scanning;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ }
+
+ private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ controllers.add(new BluetoothScanningPreferenceController(context));
+ return controllers;
+ }
+
+ /**
+ * For Search.
+ */
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.location_services_bluetooth_scanning) {
+
+ @Override
+ public List<AbstractPreferenceController> createPreferenceControllers(Context
+ context) {
+ return buildPreferenceControllers(context);
+ }
+ };
+}
diff --git a/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java b/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java
new file mode 100644
index 0000000..051fd8d
--- /dev/null
+++ b/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2021 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.location;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.widget.Switch;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
+
+/**
+ * Preference controller for Bluetooth scanning main switch.
+ */
+public class BluetoothScanningMainSwitchPreferenceController extends TogglePreferenceController
+ implements OnMainSwitchChangeListener {
+
+ private static final String KEY_BLUETOOTH_SCANNING_SWITCH = "bluetooth_always_scanning_switch";
+
+ public BluetoothScanningMainSwitchPreferenceController(Context context) {
+ super(context, KEY_BLUETOOTH_SCANNING_SWITCH);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ MainSwitchPreference pref = screen.findPreference(getPreferenceKey());
+ pref.addOnSwitchChangeListener(this);
+ pref.updateStatus(isChecked());
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, isChecked ? 1 : 0);
+ // Returning true means the underlying setting is updated.
+ return true;
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ if (isChecked != isChecked()) {
+ setChecked(isChecked);
+ }
+ }
+}
diff --git a/src/com/android/settings/location/LocationServicesBluetoothScanningPreferenceController.java b/src/com/android/settings/location/LocationServicesBluetoothScanningPreferenceController.java
new file mode 100644
index 0000000..9913848
--- /dev/null
+++ b/src/com/android/settings/location/LocationServicesBluetoothScanningPreferenceController.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2021 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.location;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * Preference controller for Bluetooth scanning in Location Services.
+ */
+public class LocationServicesBluetoothScanningPreferenceController extends
+ BasePreferenceController {
+
+ public LocationServicesBluetoothScanningPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ final boolean bleScanOn = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+ int resId =
+ bleScanOn ? R.string.scanning_status_text_on : R.string.scanning_status_text_off;
+ return mContext.getString(resId);
+ }
+
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+}
diff --git a/src/com/android/settings/location/LocationServicesWifiScanningPreferenceController.java b/src/com/android/settings/location/LocationServicesWifiScanningPreferenceController.java
new file mode 100644
index 0000000..080a023
--- /dev/null
+++ b/src/com/android/settings/location/LocationServicesWifiScanningPreferenceController.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2021 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.location;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * Preference controller for Wi-Fi scanning in Location Services.
+ */
+public class LocationServicesWifiScanningPreferenceController extends BasePreferenceController {
+
+ private final WifiManager mWifiManager;
+
+ public LocationServicesWifiScanningPreferenceController(Context context, String key) {
+ super(context, key);
+ mWifiManager = context.getSystemService(WifiManager.class);
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ final boolean wifiScanOn = mWifiManager.isScanAlwaysAvailable();
+ int resId =
+ wifiScanOn ? R.string.scanning_status_text_on : R.string.scanning_status_text_off;
+ return mContext.getString(resId);
+ }
+
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+}
diff --git a/src/com/android/settings/location/WifiScanningFragment.java b/src/com/android/settings/location/WifiScanningFragment.java
new file mode 100644
index 0000000..f5cb0ae
--- /dev/null
+++ b/src/com/android/settings/location/WifiScanningFragment.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2021 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.location;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A page that configures the Wi-Fi scanning setting.
+ */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class WifiScanningFragment extends DashboardFragment {
+ private static final String TAG = "WifiScanningFragment";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.LOCATION_SERVICES;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.location_services_wifi_scanning;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ }
+
+ private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ controllers.add(new WifiScanningPreferenceController(context));
+ return controllers;
+ }
+
+ /**
+ * For Search.
+ */
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.location_services_wifi_scanning) {
+
+ @Override
+ public List<AbstractPreferenceController> createPreferenceControllers(Context
+ context) {
+ return buildPreferenceControllers(context);
+ }
+ };
+}
diff --git a/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java b/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java
new file mode 100644
index 0000000..a69fdb8
--- /dev/null
+++ b/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2021 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.location;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+import android.widget.Switch;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
+
+/**
+ * Preference controller for Wi-Fi scanning main switch.
+ */
+public class WifiScanningMainSwitchPreferenceController extends TogglePreferenceController
+ implements OnMainSwitchChangeListener {
+
+ private static final String KEY_WIFI_SCANNING_SWITCH = "wifi_always_scanning_switch";
+ private final WifiManager mWifiManager;
+
+ public WifiScanningMainSwitchPreferenceController(Context context) {
+ super(context, KEY_WIFI_SCANNING_SWITCH);
+ mWifiManager = context.getSystemService(WifiManager.class);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ MainSwitchPreference pref = screen.findPreference(getPreferenceKey());
+ pref.addOnSwitchChangeListener(this);
+ pref.updateStatus(isChecked());
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mWifiManager.isScanAlwaysAvailable();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ mWifiManager.setScanAlwaysAvailable(isChecked);
+ // Returning true means the underlying setting is updated.
+ return true;
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ if (isChecked != isChecked()) {
+ setChecked(isChecked);
+ }
+ }
+}
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index 4878f31..ea29a1d 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -15,7 +15,6 @@
*/
package com.android.settings.network;
-import static android.net.ConnectivityManager.PRIVATE_DNS_DEFAULT_MODE_FALLBACK;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
@@ -28,6 +27,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.net.ConnectivityManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -84,14 +84,6 @@
@VisibleForTesting
static final String HOSTNAME_KEY = Settings.Global.PRIVATE_DNS_SPECIFIER;
- public static String getModeFromSettings(ContentResolver cr) {
- String mode = Settings.Global.getString(cr, MODE_KEY);
- if (!PRIVATE_DNS_MAP.containsKey(mode)) {
- mode = Settings.Global.getString(cr, Settings.Global.PRIVATE_DNS_DEFAULT_MODE);
- }
- return PRIVATE_DNS_MAP.containsKey(mode) ? mode : PRIVATE_DNS_DEFAULT_MODE_FALLBACK;
- }
-
public static String getHostnameFromSettings(ContentResolver cr) {
return Settings.Global.getString(cr, HOSTNAME_KEY);
}
@@ -168,7 +160,7 @@
final Context context = getContext();
final ContentResolver contentResolver = context.getContentResolver();
- mMode = getModeFromSettings(context.getContentResolver());
+ mMode = ConnectivityManager.getPrivateDnsMode(contentResolver);
mEditText = view.findViewById(R.id.private_dns_mode_provider_hostname);
mEditText.addTextChangedListener(this);
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
index 84cae88..3136040 100644
--- a/src/com/android/settings/network/PrivateDnsPreferenceController.java
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -118,7 +118,7 @@
public CharSequence getSummary() {
final Resources res = mContext.getResources();
final ContentResolver cr = mContext.getContentResolver();
- final String mode = PrivateDnsModeDialogPreference.getModeFromSettings(cr);
+ final String mode = ConnectivityManager.getPrivateDnsMode(cr);
final LinkProperties lp = mLatestLinkProperties;
final List<InetAddress> dnses = (lp == null) ? null : lp.getValidatedPrivateDnsServers();
final boolean dnsesResolved = !ArrayUtils.isEmpty(dnses);
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 0f3695a..dcba273 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -127,20 +127,23 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- final PreferenceScreen screen = getPreferenceScreen();
- final Bundle arguments = getArguments();
+ // TODO(b/182237530): This method should be removed when this flag is deprecated.
+ if (!FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
+ final PreferenceScreen screen = getPreferenceScreen();
+ final Bundle arguments = getArguments();
- if (screen == null) {
- return;
- }
- if (arguments != null) {
- final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
- if (!TextUtils.isEmpty(highlightKey)) {
- final PreferenceCategory advancedCategory =
- screen.findPreference(KEY_ADVANCED_CATEGORY);
- // Has highlight row - expand everything
- advancedCategory.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
- scrollToPreference(advancedCategory);
+ if (screen == null) {
+ return;
+ }
+ if (arguments != null) {
+ final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
+ if (!TextUtils.isEmpty(highlightKey)) {
+ final PreferenceCategory advancedCategory =
+ screen.findPreference(KEY_ADVANCED_CATEGORY);
+ // Has highlight row - expand everything
+ advancedCategory.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
+ scrollToPreference(advancedCategory);
+ }
}
}
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
index 4d2ad36..c8891e5 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
@@ -109,8 +109,61 @@
}
@Test
+ public void refresh_connectedWatch_behaveAsExpected() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
+ BluetoothDevice.DEVICE_TYPE_WATCH.getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
+ String.valueOf(false).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_MAIN_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
+ when(mCachedDevice.isConnected()).thenReturn(true);
+
+ mController.refresh();
+
+ assertThat(mLayoutPreference.findViewById(R.id.layout_left).getVisibility()).isEqualTo(
+ View.GONE);
+ assertThat(mLayoutPreference.findViewById(R.id.layout_right).getVisibility()).isEqualTo(
+ View.GONE);
+ assertThat(mLayoutPreference.findViewById(R.id.layout_middle).getVisibility()).isEqualTo(
+ View.VISIBLE);
+ assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN);
+ }
+
+ @Test
+ public void refresh_connectedUntetheredHeadset_behaveAsExpected() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
+ BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
+ String.valueOf(false).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_LEFT).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_RIGHT).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
+ when(mCachedDevice.isConnected()).thenReturn(true);
+
+ mController.refresh();
+
+ assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_left), BATTERY_LEVEL_LEFT);
+ assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_right), BATTERY_LEVEL_RIGHT);
+ assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN);
+ }
+
+ @Test
public void refresh_connected_updateCorrectInfo() {
when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
+ String.valueOf(true).getBytes());
+ when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)).thenReturn(
String.valueOf(BATTERY_LEVEL_LEFT).getBytes());
when(mBluetoothDevice.getMetadata(
@@ -151,6 +204,9 @@
@Test
public void refresh_withLowBatteryAndUncharged_showAlertIcon() {
when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
+ String.valueOf(true).getBytes());
+ when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)).thenReturn(
String.valueOf(LOW_BATTERY_LEVEL).getBytes());
when(mBluetoothDevice.getMetadata(
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPermissionActivityTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPermissionActivityTest.java
new file mode 100644
index 0000000..4dd568b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPermissionActivityTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2021 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.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.content.Intent;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(RobolectricTestRunner.class)
+public class BluetoothPermissionActivityTest {
+
+ private BluetoothPermissionActivity mActivity;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mActivity = new BluetoothPermissionActivity();
+ }
+
+ @Test
+ public void callingPackageIsEqualToReturnPackage_sendBroadcastToReturnPackage() {
+ mActivity.mReturnPackage = "com.android.settings";
+ mActivity.mReturnClass = "com.android.settings.bluetooth.BluetoothPermissionActivity";
+ mActivity.mCallingAppPackageName = "com.android.settings";
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ ReflectionHelpers.setField(mActivity, "mBase", mContext);
+
+ mActivity.sendReplyIntentToReceiver(true, true);
+
+ verify(mContext).sendBroadcast(intentCaptor.capture(),
+ eq("android.permission.BLUETOOTH_ADMIN"));
+ assertThat(intentCaptor.getValue().getComponent().getPackageName())
+ .isEqualTo("com.android.settings");
+ }
+
+ @Test
+ public void callingPackageIsNotEqualToReturnPackage_broadcastNotSend() {
+ mActivity.mReturnPackage = "com.fake.settings";
+ mActivity.mReturnClass = "com.android.settings.bluetooth.BluetoothPermissionActivity";
+ mActivity.mCallingAppPackageName = "com.android.settings";
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ ReflectionHelpers.setField(mActivity, "mBase", mContext);
+
+ mActivity.sendReplyIntentToReceiver(true, true);
+
+ verify(mContext, never()).sendBroadcast(intentCaptor.capture(),
+ eq("android.permission.BLUETOOTH_ADMIN"));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java
index feaf683..f5635a9 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/DevicePickerFragmentTest.java
@@ -16,28 +16,46 @@
package com.android.settings.bluetooth;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.eq;
+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.content.Context;
+import android.content.Intent;
+
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class DevicePickerFragmentTest {
@Mock
private BluetoothProgressCategory mAvailableDevicesCategory;
+
private DevicePickerFragment mFragment;
+ private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFragment = new DevicePickerFragment();
-
+ mContext = spy(RuntimeEnvironment.application);
+ mFragment.mContext = mContext;
mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
}
@@ -49,4 +67,40 @@
verify(mAvailableDevicesCategory).setProgress(true);
}
+
+ @Test
+ public void callingPackageIsEqualToLaunchPackage_sendBroadcastToLaunchPackage() {
+ final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
+ final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ when(cachedDevice.getDevice()).thenReturn(bluetoothDevice);
+ mFragment.mSelectedDevice = bluetoothDevice;
+ mFragment.mLaunchPackage = "com.android.settings";
+ mFragment.mLaunchClass = "com.android.settings.bluetooth.BluetoothPermissionActivity";
+ mFragment.mCallingAppPackageName = "com.android.settings";
+
+ mFragment.onDeviceBondStateChanged(cachedDevice, BluetoothDevice.BOND_BONDED);
+
+ verify(mContext).sendBroadcast(intentCaptor.capture(),
+ eq("android.permission.BLUETOOTH_ADMIN"));
+ assertThat(intentCaptor.getValue().getComponent().getPackageName())
+ .isEqualTo(mFragment.mLaunchPackage);
+ }
+
+ @Test
+ public void callingPackageIsNotEqualToLaunchPackage_broadcastNotSend() {
+ final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
+ final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ when(cachedDevice.getDevice()).thenReturn(bluetoothDevice);
+ mFragment.mSelectedDevice = bluetoothDevice;
+ mFragment.mLaunchPackage = "com.fake.settings";
+ mFragment.mLaunchClass = "com.android.settings.bluetooth.BluetoothPermissionActivity";
+ mFragment.mCallingAppPackageName = "com.android.settings";
+
+ mFragment.onDeviceBondStateChanged(cachedDevice, BluetoothDevice.BOND_BONDED);
+
+ verify(mContext, never()).sendBroadcast(intentCaptor.capture(),
+ eq("android.permission.BLUETOOTH_ADMIN"));
+ }
}