Snap for 7343210 from 7d3c283e27 to sc-release
Change-Id: Iceb4a76f0d480f8cc0a5345951bd23923eeddbae
This commit is contained in:
@@ -141,7 +141,7 @@
|
||||
|
||||
<activity android:name=".network.telephony.MobileNetworkActivity"
|
||||
android:label="@string/network_settings_title"
|
||||
android:theme="@style/Theme.Settings.Home"
|
||||
android:theme="@style/Theme.SubSettings"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter android:priority="1">
|
||||
@@ -418,6 +418,7 @@
|
||||
android:label="@string/apn_settings"
|
||||
android:launchMode="singleTask"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.SubSettings"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize">
|
||||
<intent-filter android:priority="1">
|
||||
<action android:name="android.settings.APN_SETTINGS" />
|
||||
@@ -1313,7 +1314,7 @@
|
||||
<activity
|
||||
android:name=".notification.history.NotificationHistoryActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.NotificationHistory"
|
||||
android:theme="@style/Theme.SubSettings"
|
||||
android:label="@string/notification_history_title">
|
||||
<intent-filter android:priority="1">
|
||||
<action android:name="android.settings.NOTIFICATION_HISTORY" />
|
||||
@@ -2060,6 +2061,7 @@
|
||||
<activity android:name="Settings$ApnEditorActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.SubSettings"
|
||||
android:label="@string/apn_edit">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
@@ -3000,6 +3002,7 @@
|
||||
<activity
|
||||
android:name="Settings$WifiCallingSettingsActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.SubSettings"
|
||||
android:label="@string/wifi_calling_settings_title">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
android:id="@+id/loading_container"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="450dp"
|
||||
android:visibility="gone"
|
||||
android:gravity="center">
|
||||
|
||||
|
||||
@@ -5121,7 +5121,7 @@
|
||||
<!-- Title for the accessibility preference category of interaction control services and settings. [CHAR LIMIT=50] -->
|
||||
<string name="interaction_control_category_title">Interaction controls</string>
|
||||
<!-- Title for the accessibility tap assistance page. [CHAR LIMIT=50] -->
|
||||
<string name="accessibility_tap_assistance_title">Tap assistance</string>
|
||||
<string name="accessibility_tap_assistance_title">Timing controls</string>
|
||||
<!-- Title for the accessibility system controls page. [CHAR LIMIT=50] -->
|
||||
<string name="accessibility_system_controls_title">System controls</string>
|
||||
<!-- Title for the accessibility preference category of services downloaded by the user. [CHAR LIMIT=50] -->
|
||||
@@ -6088,7 +6088,7 @@
|
||||
<string name="restricted_app_time_summary">Restricted <xliff:g id="time" example="5 days ago">%1$s</xliff:g></string>
|
||||
|
||||
<!-- Footer message for restrict app details page -->
|
||||
<string name="restricted_app_detail_footer">These apps have been using battery in the background. Restricted apps may not work properly and notifications may be delayed.</string>
|
||||
<string name="restricted_app_detail_footer">These apps are restricted from background battery usage. They may not work as expected, and notifications may be delayed.</string>
|
||||
|
||||
<!-- Title for auto restriction toggle -->
|
||||
<string name="battery_auto_restriction_title">Use Battery Manager</string>
|
||||
@@ -6312,7 +6312,7 @@
|
||||
<!-- Title for usage time that full charge lasts. [CHAR LIMIT=60] -->
|
||||
<string name="battery_full_charge_last">Full charge lasts about</string>
|
||||
<!-- Description for text in battery footer. [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_footer_summary">Battery usage data is approximate and can change based on usage</string>
|
||||
<string name="battery_footer_summary">Battery usage data is approximate and can change based on usage.</string>
|
||||
<!-- Title for text that shows the amount of time an app has been running while in the foreground. [CHAR LIMIT=80] -->
|
||||
<string name="battery_detail_foreground">While in active use</string>
|
||||
<!-- Title for text that shows the amount of time an app has been running while in the background. [CHAR LIMIT=80] -->
|
||||
@@ -6417,11 +6417,11 @@
|
||||
<string name="battery_saver_sticky_title_new">Turn off when charged</string>
|
||||
|
||||
<!-- Battery Saver: Description for sticky battery saver preference [CHAR_LIMIT=NONE] -->
|
||||
<string name="battery_saver_sticky_description_new" product="default">Battery Saver turns off when your phone charges above <xliff:g id="percent" example="90%">%1$s</xliff:g></string>
|
||||
<string name="battery_saver_sticky_description_new" product="default">Battery Saver turns off when your phone charges above <xliff:g id="number" example="88">^1</xliff:g><xliff:g id="unit" example="%">%</xliff:g></string>
|
||||
<!-- Battery Saver: Description for sticky battery saver preference [CHAR_LIMIT=NONE] -->
|
||||
<string name="battery_saver_sticky_description_new" product="tablet">Battery Saver turns off when your tablet charges above <xliff:g id="percent" example="90%">%1$s</xliff:g></string>
|
||||
<string name="battery_saver_sticky_description_new" product="tablet">Battery Saver turns off when your tablet charges above <xliff:g id="number" example="88">^1</xliff:g><xliff:g id="unit" example="%">%</xliff:g></string>
|
||||
<!-- Battery Saver: Description for sticky battery saver preference [CHAR_LIMIT=NONE] -->
|
||||
<string name="battery_saver_sticky_description_new" product="device">Battery Saver turns off when your device charges above <xliff:g id="percent" example="90%">%1$s</xliff:g></string>
|
||||
<string name="battery_saver_sticky_description_new" product="device">Battery Saver turns off when your device charges above <xliff:g id="number" example="88">^1</xliff:g><xliff:g id="unit" example="%">%</xliff:g></string>
|
||||
|
||||
<!-- Battery saver: Label for seekbar to change battery saver threshold [CHAR_LIMIT=40] -->
|
||||
<string name="battery_saver_seekbar_title"><xliff:g id="percent">%1$s</xliff:g></string>
|
||||
|
||||
@@ -254,11 +254,4 @@
|
||||
<item name="colorPrimary">@*android:color/primary_device_default_settings_light</item>
|
||||
<item name="colorAccent">@*android:color/accent_device_default_light</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.NotificationHistory" parent="@android:style/Theme.DeviceDefault.DayNight">
|
||||
<item name="android:windowActionBar">false</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -53,11 +53,13 @@
|
||||
settings:keywords="@string/keywords_reduce_bright_colors"
|
||||
settings:controller="com.android.settings.accessibility.ReduceBrightColorsPreferenceController"/>
|
||||
|
||||
<SwitchPreference
|
||||
<com.android.settings.display.darkmode.DarkModePreference
|
||||
android:key="dark_ui_mode_accessibility"
|
||||
android:icon="@drawable/ic_dark_ui"
|
||||
android:persistent="false"
|
||||
android:title="@string/dark_ui_mode"
|
||||
android:fragment="com.android.settings.display.darkmode.DarkModeSettingsFragment"
|
||||
android:widgetLayout="@null"
|
||||
settings:widgetLayout="@null"
|
||||
settings:controller="com.android.settings.display.DarkUIPreferenceController"
|
||||
settings:searchable="false"/>
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
android:key="add_bt_devices"
|
||||
android:title="@string/bluetooth_pairing_pref_title"
|
||||
android:icon="@drawable/ic_add_24dp"
|
||||
android:summary="@string/connected_device_add_device_summary"
|
||||
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
|
||||
settings:allowDividerAbove="true"
|
||||
settings:keywords="@string/keywords_add_bt_device"
|
||||
@@ -48,6 +47,18 @@
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="add_bt_devices_summary"
|
||||
android:title="@string/bluetooth_pairing_pref_title"
|
||||
android:icon="@drawable/ic_add_24dp"
|
||||
android:summary="@string/connected_device_add_device_summary"
|
||||
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
|
||||
settings:allowDividerAbove="true"
|
||||
settings:keywords="@string/keywords_add_bt_device"
|
||||
settings:userRestriction="no_config_bluetooth"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:controller="com.android.settings.connecteddevice.AddDeviceSummaryPreferenceController"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="previously_connected_devices"
|
||||
android:title="@string/connected_device_previously_connected_title"
|
||||
|
||||
@@ -120,7 +120,9 @@ public class SettingsDumpService extends Service {
|
||||
obj.put("cell", array);
|
||||
}
|
||||
if (packageManager.hasSystemFeature(FEATURE_WIFI)) {
|
||||
obj.put("wifi", dumpDataUsage(NetworkTemplate.buildTemplateWifiWildcard(), controller));
|
||||
obj.put("wifi", dumpDataUsage(
|
||||
NetworkTemplate.buildTemplateWifi(
|
||||
NetworkTemplate.WIFI_NETWORKID_ALL, null /* subscriberId */), controller));
|
||||
}
|
||||
|
||||
if (packageManager.hasSystemFeature(FEATURE_ETHERNET)) {
|
||||
|
||||
@@ -30,34 +30,41 @@ import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Fragment for providing open activity button. */
|
||||
public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeaturePreferenceFragment {
|
||||
private static final String TAG = "LaunchA11yActivity";
|
||||
private static final String EMPTY_STRING = "";
|
||||
protected static final String KEY_LAUNCH_PREFERENCE = "launch_preference";
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
mToggleServiceSwitchPreference.hide();
|
||||
}
|
||||
// Init new preference to replace the switch preference instead.
|
||||
initLaunchPreference();
|
||||
removePreference(KEY_USE_SERVICE_PREFERENCE);
|
||||
return view;
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
logAccessibilityServiceEnabled(mComponentName, enabled);
|
||||
launchShortcutTargetActivity(getPrefContext().getDisplayId(), mComponentName);
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,16 +106,6 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
||||
// accessibility service from this page.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
|
||||
final AccessibilityShortcutInfo info = getAccessibilityShortcutInfo();
|
||||
final String switchBarText = (info == null) ? EMPTY_STRING : getString(
|
||||
R.string.accessibility_service_primary_open_title,
|
||||
info.getActivityInfo().loadLabel(getPackageManager()));
|
||||
|
||||
switchPreference.setTitle(switchBarText);
|
||||
}
|
||||
|
||||
// IMPORTANT: Refresh the info since there are dynamically changing capabilities.
|
||||
private AccessibilityShortcutInfo getAccessibilityShortcutInfo() {
|
||||
final List<AccessibilityShortcutInfo> infos = AccessibilityManager.getInstance(
|
||||
@@ -126,6 +123,34 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Customizes the order by preference key. */
|
||||
protected List<String> getPreferenceOrderList() {
|
||||
final List<String> lists = new ArrayList<>();
|
||||
lists.add(KEY_ANIMATED_IMAGE);
|
||||
lists.add(KEY_LAUNCH_PREFERENCE);
|
||||
lists.add(KEY_GENERAL_CATEGORY);
|
||||
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
|
||||
return lists;
|
||||
}
|
||||
|
||||
private void initLaunchPreference() {
|
||||
final Preference launchPreference = new Preference(getPrefContext());
|
||||
launchPreference.setKey(KEY_LAUNCH_PREFERENCE);
|
||||
|
||||
final AccessibilityShortcutInfo info = getAccessibilityShortcutInfo();
|
||||
final String switchBarText = (info == null) ? EMPTY_STRING : getString(
|
||||
R.string.accessibility_service_primary_open_title,
|
||||
info.getActivityInfo().loadLabel(getPackageManager()));
|
||||
launchPreference.setTitle(switchBarText);
|
||||
|
||||
launchPreference.setOnPreferenceClickListener(preference -> {
|
||||
logAccessibilityServiceEnabled(mComponentName, /* enabled= */ true);
|
||||
launchShortcutTargetActivity(getPrefContext().getDisplayId(), mComponentName);
|
||||
return true;
|
||||
});
|
||||
getPreferenceScreen().addPreference(launchPreference);
|
||||
}
|
||||
|
||||
private void launchShortcutTargetActivity(int displayId, ComponentName name) {
|
||||
final Intent intent = new Intent();
|
||||
final Bundle bundle = ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle();
|
||||
|
||||
@@ -139,7 +139,8 @@ public class AppDataUsagePreferenceController extends AppInfoPreferenceControlle
|
||||
return NetworkTemplate.buildTemplateMobileWildcard();
|
||||
}
|
||||
if (DataUsageUtils.hasWifiRadio(context)) {
|
||||
return NetworkTemplate.buildTemplateWifiWildcard();
|
||||
return NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */);
|
||||
}
|
||||
return NetworkTemplate.buildTemplateEthernet();
|
||||
}
|
||||
|
||||
@@ -29,11 +29,10 @@ import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
public class AppHeaderViewPreferenceController extends BasePreferenceController
|
||||
implements AppInfoDashboardFragment.Callback, LifecycleObserver, OnStart {
|
||||
implements AppInfoDashboardFragment.Callback, LifecycleObserver {
|
||||
|
||||
private static final String KEY_HEADER = "header_view";
|
||||
|
||||
@@ -67,19 +66,13 @@ public class AppHeaderViewPreferenceController extends BasePreferenceController
|
||||
final Activity activity = mParent.getActivity();
|
||||
mEntityHeaderController = EntityHeaderController
|
||||
.newInstance(activity, mParent, mHeader.findViewById(R.id.entity_header))
|
||||
.setRecyclerView(mParent.getListView(), mLifecycle)
|
||||
.setPackageName(mPackageName)
|
||||
.setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
|
||||
EntityHeaderController.ActionType.ACTION_NONE)
|
||||
.bindHeaderButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mEntityHeaderController
|
||||
.setRecyclerView(mParent.getListView(), mLifecycle)
|
||||
.styleActionBar(mParent.getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUi() {
|
||||
setAppLabelAndIcon(mParent.getPackageInfo(), mParent.getAppEntry());
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.util.IconDrawableFactory;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -36,7 +35,6 @@ import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
public class HeaderPreferenceController extends BasePreferenceController
|
||||
@@ -127,11 +125,4 @@ public class HeaderPreferenceController extends BasePreferenceController
|
||||
.done(mFragment.getActivity(), mContext);
|
||||
pref.findViewById(R.id.entity_header).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
public void onStart() {
|
||||
if (mHeaderController != null) {
|
||||
mHeaderController.styleActionBar(mFragment.getActivity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@ public class BiometricFaceStatusPreferenceController extends FaceStatusPreferenc
|
||||
|
||||
@Override
|
||||
protected boolean isDeviceSupported() {
|
||||
return Utils.hasFaceHardware(mContext);
|
||||
return Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class BiometricFingerprintStatusPreferenceController extends
|
||||
|
||||
@Override
|
||||
protected boolean isDeviceSupported() {
|
||||
return Utils.hasFingerprintHardware(mContext);
|
||||
return Utils.isMultipleBiometricsSupported(mContext)
|
||||
&& Utils.hasFingerprintHardware(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,9 @@ public class BiometricSettingsAppPreferenceController extends TogglePreferenceCo
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!Utils.isMultipleBiometricsSupported(mContext)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (mFaceManager == null || mFingerprintManager == null) {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
@@ -62,6 +63,9 @@ public class BiometricSettingsKeyguardPreferenceController extends TogglePrefere
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!Utils.isMultipleBiometricsSupported(mContext)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return getRestrictingAdmin() != null ? DISABLED_FOR_USER : AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/**
|
||||
* Controller to maintain the {@link androidx.preference.Preference} for add
|
||||
* device. It monitor Bluetooth's status(on/off) and decide if need to show summary or not.
|
||||
* device without summary at beginning. It monitor Bluetooth's status(on/off) and decide if need
|
||||
* to show summary or not.
|
||||
*/
|
||||
public class AddDevicePreferenceController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
@@ -46,7 +47,8 @@ public class AddDevicePreferenceController extends BasePreferenceController
|
||||
}
|
||||
};
|
||||
private IntentFilter mIntentFilter;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
protected BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
public AddDevicePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
@@ -57,6 +59,7 @@ public class AddDevicePreferenceController extends BasePreferenceController
|
||||
@Override
|
||||
public void onStart() {
|
||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,17 +78,22 @@ public class AddDevicePreferenceController extends BasePreferenceController
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
|
||||
&& isBluetoothEnabled()
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
|
||||
return isBluetoothEnabled()
|
||||
? ""
|
||||
: mContext.getString(R.string.connected_device_add_device_summary);
|
||||
}
|
||||
|
||||
protected boolean isBluetoothEnabled() {
|
||||
return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled();
|
||||
}
|
||||
|
||||
void updateState() {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.connecteddevice;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
/**
|
||||
* Controller to maintain the {@link androidx.preference.Preference} for add
|
||||
* device with summary at beginning. It monitor Bluetooth's status(on/off) and decide if need
|
||||
* to show summary or not.
|
||||
*/
|
||||
public class AddDeviceSummaryPreferenceController extends AddDevicePreferenceController {
|
||||
|
||||
public AddDeviceSummaryPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
|
||||
&& !isBluetoothEnabled()
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,9 @@ public class DataUsageSummary extends DataUsageBaseFragment implements DataUsage
|
||||
void addWifiSection() {
|
||||
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
||||
inflatePreferences(R.xml.data_usage_wifi);
|
||||
category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0, services);
|
||||
category.setTemplate(
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */), 0, services);
|
||||
}
|
||||
|
||||
private void addEthernetSection() {
|
||||
|
||||
@@ -225,7 +225,8 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
static void launchWifiDataUsage(Context context) {
|
||||
final Bundle args = new Bundle(1);
|
||||
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE,
|
||||
NetworkTemplate.buildTemplateWifiWildcard());
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */));
|
||||
args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_WIFI);
|
||||
final SubSettingLauncher launcher = new SubSettingLauncher(context)
|
||||
.setArguments(args)
|
||||
@@ -367,7 +368,9 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
@VisibleForTesting
|
||||
protected long getHistoricalUsageLevel() {
|
||||
final DataUsageController controller = new DataUsageController(getContext());
|
||||
return controller.getHistoricalUsageLevel(NetworkTemplate.buildTemplateWifiWildcard());
|
||||
return controller.getHistoricalUsageLevel(
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -138,7 +138,8 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
mDefaultTemplate = DataUsageLib.getMobileTemplate(context, subscriptionId);
|
||||
} else if (DataUsageUtils.hasWifiRadio(context)) {
|
||||
mDataUsageTemplate = R.string.wifi_data_template;
|
||||
mDefaultTemplate = NetworkTemplate.buildTemplateWifiWildcard();
|
||||
mDefaultTemplate = NetworkTemplate.buildTemplateWifi(
|
||||
NetworkTemplate.WIFI_NETWORKID_ALL, null /* subscriberId */);
|
||||
} else {
|
||||
mDataUsageTemplate = R.string.ethernet_data_template;
|
||||
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, subscriptionId);
|
||||
@@ -178,7 +179,6 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
}
|
||||
RecyclerView view = mFragment.getListView();
|
||||
mEntityHeaderController.setRecyclerView(view, mLifecycle);
|
||||
mEntityHeaderController.styleActionBar((Activity) mContext);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -184,7 +184,8 @@ public final class DataUsageUtils extends com.android.settingslib.net.DataUsageU
|
||||
if (SubscriptionManager.isValidSubscriptionId(defaultSubId) && hasMobileData(context)) {
|
||||
return DataUsageLib.getMobileTemplate(context, defaultSubId);
|
||||
} else if (hasWifiRadio(context)) {
|
||||
return NetworkTemplate.buildTemplateWifiWildcard();
|
||||
return NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */);
|
||||
} else {
|
||||
return NetworkTemplate.buildTemplateEthernet();
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ public class DataUsageLib {
|
||||
|
||||
private static NetworkTemplate getMobileTemplateForSubId(
|
||||
TelephonyManager telephonyManager, int subId) {
|
||||
return NetworkTemplate.buildTemplateMobileAll(telephonyManager.getSubscriberId(subId));
|
||||
return NetworkTemplate.buildTemplateMobileAll(
|
||||
telephonyManager.getSubscriberId(subId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,10 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
||||
|
||||
/** Sets all levels value to draw the trapezoid shape */
|
||||
public void setLevels(int[] levels) {
|
||||
if (levels == null) {
|
||||
mLevels = null;
|
||||
return;
|
||||
}
|
||||
// We should provide trapezoid count + 1 data to draw all trapezoids.
|
||||
mLevels = levels.length == mTrapezoidCount + 1 ? levels : null;
|
||||
setClickable(false);
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.android.settings.fuelgauge;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.os.BatteryConsumer;
|
||||
import android.util.Log;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@@ -310,6 +311,14 @@ public class BatteryHistEntry {
|
||||
lowerHistEntry == null ? 0 : lowerHistEntry.mBackgroundUsageTimeInMs,
|
||||
upperHistEntry.mBackgroundUsageTimeInMs,
|
||||
ratio);
|
||||
// Checks whether there is any abnoaml cases!
|
||||
if (upperHistEntry.mConsumePower < consumePower
|
||||
|| upperHistEntry.mForegroundUsageTimeInMs < foregroundUsageTimeInMs
|
||||
|| upperHistEntry.mBackgroundUsageTimeInMs < backgroundUsageTimeInMs) {
|
||||
Log.w(TAG, String.format(
|
||||
"abnormal interpolation:\nupper:%s\nlower:%s",
|
||||
upperHistEntry, lowerHistEntry));
|
||||
}
|
||||
final double batteryLevel =
|
||||
lowerHistEntry == null
|
||||
? upperHistEntry.mBatteryLevel
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.content.Context;
|
||||
import android.icu.text.NumberFormat;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import com.android.settings.R;
|
||||
@@ -37,13 +39,11 @@ public class BatterySaverStickyPreferenceController extends TogglePreferenceCont
|
||||
@Override
|
||||
protected void refreshSummary(Preference preference) {
|
||||
super.refreshSummary(preference);
|
||||
final double stickyShutoffLevel = Settings.Global.getInt(
|
||||
final int stickyShutoffLevel = Settings.Global.getInt(
|
||||
mContext.getContentResolver(), Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL, 90);
|
||||
final String percentage = NumberFormat
|
||||
.getPercentInstance()
|
||||
.format(stickyShutoffLevel / 100.0);
|
||||
preference.setSummary(
|
||||
mContext.getString(R.string.battery_saver_sticky_description_new, percentage));
|
||||
preference.setSummary(TextUtils.expandTemplate(
|
||||
mContext.getString(R.string.battery_saver_sticky_description_new),
|
||||
NumberFormat.getIntegerInstance().format(stickyShutoffLevel)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -92,8 +92,9 @@ public class PreventRingingParentPreferenceController extends TogglePreferenceCo
|
||||
case VOLUME_HUSH_MUTE:
|
||||
summary = mContext.getText(R.string.prevent_ringing_option_mute_summary);
|
||||
break;
|
||||
// VOLUME_HUSH_OFF
|
||||
default:
|
||||
summary = null;
|
||||
summary = mContext.getText(R.string.switch_off_text);
|
||||
}
|
||||
preference.setSummary(summary);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_DESTROY;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||
|
||||
@@ -191,6 +192,12 @@ public class InternetUpdater implements AirplaneModeEnabler.OnAirplaneModeChange
|
||||
mContext.unregisterReceiver(mWifiStateReceiver);
|
||||
}
|
||||
|
||||
/** @OnLifecycleEvent(ON_DESTROY) */
|
||||
@OnLifecycleEvent(ON_DESTROY)
|
||||
public void onDestroy() {
|
||||
mAirplaneModeEnabler.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
||||
fetchActiveNetwork();
|
||||
|
||||
@@ -279,9 +279,9 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
||||
mAddWifiNetworkPreference = new AddWifiNetworkPreference(getPrefContext());
|
||||
mDataUsagePreference = findPreference(PREF_KEY_DATA_USAGE);
|
||||
mDataUsagePreference.setVisible(DataUsageUtils.hasWifiRadio(getContext()));
|
||||
mDataUsagePreference.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(),
|
||||
0 /*subId*/,
|
||||
null /*service*/);
|
||||
mDataUsagePreference.setTemplate(
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */), 0 /*subId*/, null /*service*/);
|
||||
mResetInternetPreference = findPreference(PREF_KEY_RESET_INTERNET);
|
||||
if (mResetInternetPreference != null) {
|
||||
mResetInternetPreference.setVisible(false);
|
||||
|
||||
@@ -122,9 +122,6 @@ public class ConversationHeaderPreferenceController extends NotificationPreferen
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
public void onStart() {
|
||||
mStarted = true;
|
||||
if (mHeaderController != null) {
|
||||
mHeaderController.styleActionBar(mFragment.getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -121,9 +121,6 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
public void onStart() {
|
||||
mStarted = true;
|
||||
if (mHeaderController != null) {
|
||||
mHeaderController.styleActionBar(mFragment.getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -18,15 +18,12 @@ package com.android.settings.widget;
|
||||
|
||||
import android.annotation.IdRes;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -48,7 +45,6 @@ import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.ActionBarShadowController;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -244,7 +240,6 @@ public class EntityHeaderController {
|
||||
* Done mutating entity header, rebinds everything (optionally skip rebinding buttons).
|
||||
*/
|
||||
public View done(Activity activity, boolean rebindActions) {
|
||||
styleActionBar(activity);
|
||||
ImageView iconView = mHeader.findViewById(R.id.entity_header_icon);
|
||||
if (iconView != null) {
|
||||
iconView.setImageDrawable(mIcon);
|
||||
@@ -302,32 +297,6 @@ public class EntityHeaderController {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Styles the action bar (elevation, scrolling behaviors, color, etc).
|
||||
* <p/>
|
||||
* This method must be called after {@link Fragment#onCreate(Bundle)}.
|
||||
*/
|
||||
public EntityHeaderController styleActionBar(Activity activity) {
|
||||
if (activity == null) {
|
||||
Log.w(TAG, "No activity, cannot style actionbar.");
|
||||
return this;
|
||||
}
|
||||
final ActionBar actionBar = activity.getActionBar();
|
||||
if (actionBar == null) {
|
||||
Log.w(TAG, "No actionbar, cannot style actionbar.");
|
||||
return this;
|
||||
}
|
||||
actionBar.setBackgroundDrawable(
|
||||
new ColorDrawable(
|
||||
Utils.getColorAttrDefaultColor(activity, android.R.attr.colorPrimaryDark)));
|
||||
actionBar.setElevation(0);
|
||||
if (mRecyclerView != null && mLifecycle != null) {
|
||||
ActionBarShadowController.attachToView(mActivity, mLifecycle, mRecyclerView);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Done mutating entity header, rebinds everything.
|
||||
*/
|
||||
|
||||
@@ -261,9 +261,9 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
mStatusMessagePreference = findPreference(PREF_KEY_STATUS_MESSAGE);
|
||||
mDataUsagePreference = findPreference(PREF_KEY_DATA_USAGE);
|
||||
mDataUsagePreference.setVisible(DataUsageUtils.hasWifiRadio(getContext()));
|
||||
mDataUsagePreference.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(),
|
||||
0 /*subId*/,
|
||||
null /*service*/);
|
||||
mDataUsagePreference.setTemplate(
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */), 0 /*subId*/, null /*service*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,23 +16,16 @@
|
||||
|
||||
package com.android.settings.applications.appinfo;
|
||||
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@@ -116,18 +109,4 @@ public class AppHeaderViewPreferenceControllerTest {
|
||||
assertThat(title).isNotNull();
|
||||
assertThat(title.getText()).isEqualTo(appLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldStyleActionBar() {
|
||||
final ActionBar actionBar = mock(ActionBar.class);
|
||||
when(mActivity.getActionBar()).thenReturn(actionBar);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verifyZeroInteractions(actionBar);
|
||||
|
||||
mLifecycle.handleLifecycleEvent(ON_START);
|
||||
|
||||
verify(actionBar).setBackgroundDrawable(any(Drawable.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ public class AddDevicePreferenceControllerTest {
|
||||
String key = mAddDevicePreferenceController.getPreferenceKey();
|
||||
mAddDevicePreference = new RestrictedPreference(mContext);
|
||||
mAddDevicePreference.setKey(key);
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
|
||||
when(mScreen.findPreference(key)).thenReturn(mAddDevicePreference);
|
||||
mAddDevicePreferenceController.displayPreference(mScreen);
|
||||
}
|
||||
@@ -128,4 +129,13 @@ public class AddDevicePreferenceControllerTest {
|
||||
assertThat(mAddDevicePreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_bluetoothIsDisabled_unSupported() {
|
||||
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mAddDevicePreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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.connecteddevice;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
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;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplicationPackageManager;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowApplicationPackageManager.class)
|
||||
public class AddDeviceSummaryPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
private Context mContext;
|
||||
private AddDeviceSummaryPreferenceController mAddDeviceSummaryPreferenceController;
|
||||
private RestrictedPreference mAddDevicePreference;
|
||||
private ShadowApplicationPackageManager mPackageManager;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPackageManager = (ShadowApplicationPackageManager) Shadows.shadowOf(
|
||||
mContext.getPackageManager());
|
||||
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
|
||||
|
||||
mAddDeviceSummaryPreferenceController = new AddDeviceSummaryPreferenceController(mContext,
|
||||
"add_bt_devices");
|
||||
ReflectionHelpers.setField(mAddDeviceSummaryPreferenceController,
|
||||
"mBluetoothAdapter", mBluetoothAdapter);
|
||||
|
||||
String key = mAddDeviceSummaryPreferenceController.getPreferenceKey();
|
||||
mAddDevicePreference = new RestrictedPreference(mContext);
|
||||
mAddDevicePreference.setKey(key);
|
||||
when(mScreen.findPreference(key)).thenReturn(mAddDevicePreference);
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(false);
|
||||
mAddDeviceSummaryPreferenceController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_btOnThenOff_summaryShouldBeShown() {
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
|
||||
|
||||
mAddDeviceSummaryPreferenceController.updateState();
|
||||
|
||||
assertTrue(TextUtils.isEmpty(mAddDevicePreference.getSummary()));
|
||||
|
||||
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
|
||||
BroadcastReceiver receiver = ReflectionHelpers.getField(
|
||||
mAddDeviceSummaryPreferenceController, "mReceiver");
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(false);
|
||||
|
||||
receiver.onReceive(mContext, intent);
|
||||
|
||||
assertThat(mAddDevicePreference.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.connected_device_add_device_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_btOffThenOn_summaryShouldNotBeShown() {
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(false);
|
||||
|
||||
mAddDeviceSummaryPreferenceController.updateState();
|
||||
|
||||
assertThat(mAddDevicePreference.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.connected_device_add_device_summary));
|
||||
|
||||
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
|
||||
BroadcastReceiver receiver = ReflectionHelpers.getField(
|
||||
mAddDeviceSummaryPreferenceController, "mReceiver");
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
|
||||
|
||||
receiver.onReceive(mContext, intent);
|
||||
|
||||
assertTrue(TextUtils.isEmpty(mAddDevicePreference.getSummary()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_notHaveBluetoothFeature_unSupported() {
|
||||
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, false);
|
||||
|
||||
assertThat(mAddDeviceSummaryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_haveBluetoothFeature_supported() {
|
||||
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
|
||||
|
||||
assertThat(mAddDeviceSummaryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_bluetoothIsEnabled_unSupported() {
|
||||
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
|
||||
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mAddDeviceSummaryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.android.settings.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
@@ -309,7 +310,8 @@ public class AppDataUsageTest {
|
||||
ReflectionHelpers.setField(mFragment, "mContext", context);
|
||||
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
|
||||
ReflectionHelpers.setField(mFragment, "mTemplate",
|
||||
NetworkTemplate.buildTemplateWifiWildcard());
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */));
|
||||
final long end = System.currentTimeMillis();
|
||||
final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
|
||||
|
||||
@@ -334,7 +336,8 @@ public class AppDataUsageTest {
|
||||
ReflectionHelpers.setField(mFragment, "mContext", context);
|
||||
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
|
||||
ReflectionHelpers.setField(mFragment, "mTemplate",
|
||||
NetworkTemplate.buildTemplateWifiWildcard());
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */));
|
||||
final long end = System.currentTimeMillis();
|
||||
final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
|
||||
|
||||
@@ -365,7 +368,8 @@ public class AppDataUsageTest {
|
||||
ReflectionHelpers.setField(mFragment, "mCycles", testCycles);
|
||||
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
|
||||
ReflectionHelpers.setField(mFragment, "mTemplate",
|
||||
NetworkTemplate.buildTemplateWifiWildcard());
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */));
|
||||
|
||||
final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
|
||||
mFragment.mUidDataCallbacks.onCreateLoader(0 /* id */, Bundle.EMPTY /* args */);
|
||||
@@ -436,6 +440,9 @@ public class AppDataUsageTest {
|
||||
mFragment.onCreate(Bundle.EMPTY);
|
||||
|
||||
assertThat(mFragment.mTemplate.getMatchRule())
|
||||
.isEqualTo(NetworkTemplate.MATCH_WIFI_WILDCARD);
|
||||
.isEqualTo(NetworkTemplate.MATCH_WIFI);
|
||||
assertNull(mFragment.mTemplate.getSubscriberId());
|
||||
assertThat(mFragment.mTemplate.getNetworkId())
|
||||
.isEqualTo(NetworkTemplate.WIFI_NETWORKID_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -386,7 +385,6 @@ public class DataUsageSummaryPreferenceControllerTest {
|
||||
|
||||
verify(mHeaderController)
|
||||
.setRecyclerView(any(RecyclerView.class), any(Lifecycle.class));
|
||||
verify(mHeaderController).styleActionBar(any(Activity.class));
|
||||
}
|
||||
|
||||
private DataUsageController.DataUsageInfo createTestDataUsageInfo(long now) {
|
||||
|
||||
@@ -17,13 +17,9 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -41,7 +37,6 @@ import android.text.TextUtils;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -283,17 +278,6 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldStyleActionBar() {
|
||||
when(mEntityHeaderController.setRecyclerView(nullable(RecyclerView.class), eq(mLifecycle)))
|
||||
.thenReturn(mEntityHeaderController);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mLifecycle.handleLifecycleEvent(ON_START);
|
||||
|
||||
verify(mEntityHeaderController).styleActionBar(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState() {
|
||||
mController.quickUpdateHeaderPreference();
|
||||
|
||||
@@ -97,7 +97,8 @@ public class PreventRingingParentPreferenceControllerTest {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
|
||||
VOLUME_HUSH_OFF);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(null);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getText(
|
||||
R.string.switch_off_text));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,13 +26,11 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.UserHandle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -302,30 +300,6 @@ public class EntityHeaderControllerTest {
|
||||
.isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void styleActionBar_invalidObjects_shouldNotCrash() {
|
||||
mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
|
||||
mController.styleActionBar(null);
|
||||
|
||||
when(mActivity.getActionBar()).thenReturn(null);
|
||||
mController.styleActionBar(mActivity);
|
||||
|
||||
verify(mActivity).getActionBar();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void styleActionBar_setElevationAndBackground() {
|
||||
final ActionBar actionBar = mActivity.getActionBar();
|
||||
|
||||
mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
|
||||
mController.styleActionBar(mActivity);
|
||||
|
||||
verify(actionBar).setElevation(0);
|
||||
// Enforce a color drawable as background here, as image based drawables might not be
|
||||
// wide enough to cover entire action bar.
|
||||
verify(actionBar).setBackgroundDrawable(any(ColorDrawable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initAppHeaderController_appHeaderNull_useFragmentContext() {
|
||||
mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
|
||||
|
||||
@@ -101,8 +101,8 @@ public class DataUsageInfoControllerTest {
|
||||
}
|
||||
|
||||
private NetworkPolicy getDefaultNetworkPolicy() {
|
||||
NetworkTemplate template =
|
||||
new NetworkTemplate(NetworkTemplate.MATCH_WIFI_WILDCARD, null, null);
|
||||
NetworkTemplate template = NetworkTemplate.buildTemplateWifi(
|
||||
NetworkTemplate.WIFI_NETWORKID_ALL, null /* subscriberId */);
|
||||
int cycleDay = -1;
|
||||
String cycleTimezone = "UTC";
|
||||
long warningBytes = -1;
|
||||
@@ -176,4 +176,4 @@ public class DataUsageInfoControllerTest {
|
||||
|
||||
assertThat(info.limitLevel).isEqualTo(policy.limitBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,11 +531,13 @@ public class DataUsageSummaryPreferenceTest {
|
||||
|
||||
final Bundle expect = new Bundle(1);
|
||||
expect.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE,
|
||||
NetworkTemplate.buildTemplateWifiWildcard());
|
||||
NetworkTemplate.buildTemplateWifi(NetworkTemplate.WIFI_NETWORKID_ALL,
|
||||
null /* subscriberId */));
|
||||
final Bundle actual = startedIntent
|
||||
.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||
assertThat((NetworkTemplate) actual.getParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE))
|
||||
.isEqualTo(NetworkTemplate.buildTemplateWifiWildcard());
|
||||
.isEqualTo(NetworkTemplate.buildTemplateWifi(
|
||||
NetworkTemplate.WIFI_NETWORKID_ALL, null /* subscriberId */));
|
||||
|
||||
assertThat(startedIntent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
|
||||
.isEqualTo(ResourcesUtils.getResourcesId(mContext, "string", "wifi_data_usage"));
|
||||
|
||||
@@ -107,6 +107,13 @@ public class InternetUpdaterTest {
|
||||
any(ConnectivityManager.NetworkCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDestroy_shouldCloseCallback() {
|
||||
mInternetUpdater.onDestroy();
|
||||
|
||||
verify(mAirplaneModeEnabler).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateInternetAvailable_wifiConnectedAndNoValidated_internetUnavailable() {
|
||||
final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.vpn2;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class VpnInfoPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private VpnInfoPreference mVpnInfoPreference;
|
||||
private AttributeSet mAttrs;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private View mWarningButton;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
final int helpUrlId = ResourcesUtils.getResourcesId(
|
||||
mContext, "string", "help_url_insecure_vpn");
|
||||
when(mResources.getString(helpUrlId)).thenReturn("https://www.google.com/");
|
||||
|
||||
mVpnInfoPreference = new VpnInfoPreference(mContext, mAttrs);
|
||||
LayoutInflater inflater = mContext.getSystemService(LayoutInflater.class);
|
||||
|
||||
// The VpnInfoPreference is a RestrictedPreference, which is a TwoTargetPreference
|
||||
final int layoutId = ResourcesUtils.getResourcesId(
|
||||
mContext, "layout", "preference_two_target");
|
||||
View view = inflater.inflate(
|
||||
layoutId,
|
||||
null /* root */, false /* attachToRoot */);
|
||||
mHolder = spy(PreferenceViewHolder.createInstanceForTests(view));
|
||||
final int warningButtonId = ResourcesUtils.getResourcesId(
|
||||
mContext, "id", "warning_button");
|
||||
mWarningButton = spy(new View(mContext));
|
||||
when(mWarningButton.getId()).thenReturn(warningButtonId);
|
||||
when(mHolder.findViewById(warningButtonId)).thenReturn(mWarningButton);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_notInsecureVpn_iconInvisible() {
|
||||
mVpnInfoPreference.setInsecureVpn(false);
|
||||
|
||||
mVpnInfoPreference.onBindViewHolder(mHolder);
|
||||
|
||||
verify(mWarningButton).setVisibility(View.GONE);
|
||||
verify(mWarningButton).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_emptyUrl_iconInvisible() {
|
||||
final int helpUrlId = ResourcesUtils.getResourcesId(
|
||||
mContext, "string", "help_url_insecure_vpn");
|
||||
when(mResources.getString(helpUrlId)).thenReturn("");
|
||||
VpnInfoPreference vpnInfoPreference = new VpnInfoPreference(mContext, mAttrs);
|
||||
|
||||
vpnInfoPreference.setInsecureVpn(true);
|
||||
|
||||
vpnInfoPreference.onBindViewHolder(mHolder);
|
||||
|
||||
verify(mWarningButton).setVisibility(View.GONE);
|
||||
verify(mWarningButton).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_insecureVpn_iconVisible() {
|
||||
mVpnInfoPreference.setInsecureVpn(true);
|
||||
|
||||
mVpnInfoPreference.onBindViewHolder(mHolder);
|
||||
|
||||
verify(mWarningButton).setVisibility(View.VISIBLE);
|
||||
verify(mWarningButton).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_dividerInvisible() {
|
||||
mVpnInfoPreference.onBindViewHolder(mHolder);
|
||||
|
||||
final int dividerId = ResourcesUtils.getResourcesId(mContext, "id", "two_target_divider");
|
||||
final View divider = mHolder.findViewById(dividerId);
|
||||
assertEquals(View.GONE, divider.getVisibility());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user