Snap for 7243396 from 11eabdf3e8 to sc-v2-release
Change-Id: Iaf2608c07118eca57fcb0b0cb4adbb29278e3c32
This commit is contained in:
@@ -1490,6 +1490,7 @@
|
||||
<activity android:name=".applications.specialaccess.deviceadmin.DeviceAdminAdd"
|
||||
android:label="@string/device_admin_add_title"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.SubSettings"
|
||||
android:clearTaskOnLaunch="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.app.action.ADD_DEVICE_ADMIN" />
|
||||
|
||||
95
res/layout-land/udfps_enroll_enrolling_land.xml
Normal file
95
res/layout-land/udfps_enroll_enrolling_land.xml
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<com.google.android.setupdesign.GlifLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/setup_wizard_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout="@layout/sud_glif_blank_template"
|
||||
style="?attr/fingerprint_layout_theme">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false">
|
||||
|
||||
<!-- Both texts are kept as separate text views so it doesn't jump around in portrait.
|
||||
See layouts/fingerprint_enroll_enrolling_base.xml. -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="?attr/sudMarginStart"
|
||||
android:layout_marginBottom="@dimen/sud_content_frame_padding_bottom"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sud_layout_icon"
|
||||
style="@style/SudGlifIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="?attr/sudGlifHeaderGravity"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:src="@drawable/ic_fingerprint_header" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suc_layout_title"
|
||||
style="@style/SudGlifHeaderTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp" />
|
||||
|
||||
<TextView
|
||||
style="@style/SudDescription.Glif"
|
||||
android:id="@+id/sud_layout_subtitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.setupdesign.GlifLayout>
|
||||
94
res/layout-land/udfps_enroll_find_sensor_land.xml
Normal file
94
res/layout-land/udfps_enroll_find_sensor_land.xml
Normal file
@@ -0,0 +1,94 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<com.google.android.setupdesign.GlifLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/setup_wizard_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout="@layout/sud_glif_blank_template"
|
||||
style="?attr/fingerprint_layout_theme">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="?attr/sudMarginStart"
|
||||
android:layout_marginBottom="@dimen/sud_content_frame_padding_bottom"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sud_layout_icon"
|
||||
style="@style/SudGlifIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="?attr/sudGlifHeaderGravity"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:src="@drawable/ic_fingerprint_header" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suc_layout_title"
|
||||
style="@style/SudGlifHeaderTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sud_layout_subtitle"
|
||||
style="@style/SudDescription.Glif"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.setupdesign.GlifLayout>
|
||||
@@ -5843,6 +5843,8 @@
|
||||
<string name="history_details_title">History details</string>
|
||||
<!-- Preference title for advanced battery usage [CHAR LIMIT=40] -->
|
||||
<string name="advanced_battery_preference_title">View battery usage</string>
|
||||
<!-- Preference summary for advanced battery usage [CHAR LIMIT=40] -->
|
||||
<string name="advanced_battery_preference_summary">View usage for past 24 hours</string>
|
||||
|
||||
<!-- Activity title for battery usage details for an app. or power consumer -->
|
||||
<string name="battery_details_title">Battery usage</string>
|
||||
@@ -5979,7 +5981,7 @@
|
||||
<string name="battery_auto_restriction_summary">Detect when apps drain battery</string>
|
||||
|
||||
<!-- Summary for battery manager when it is on -->
|
||||
<string name="battery_manager_on" product="default">On / Detecting when apps drain battery</string>
|
||||
<string name="battery_manager_summary">Detecting when apps drain battery</string>
|
||||
|
||||
<!-- Summary for battery manager when it is off -->
|
||||
<string name="battery_manager_off">Off</string>
|
||||
@@ -6245,6 +6247,9 @@
|
||||
<!-- Battery saver: Label for preference to indicate there is a routine based schedule [CHAR_LIMIT=40] -->
|
||||
<string name="battery_saver_auto_routine">Based on your routine</string>
|
||||
|
||||
<!-- Battery saver: Summary for preference to indicate there is a routine based schedule [CHAR_LIMIT=40] -->
|
||||
<string name="battery_saver_pref_auto_routine_summary">Will turn on based on your routine</string>
|
||||
|
||||
<!-- Battery saver: Label for preference to indicate there is a percentage based schedule [CHAR_LIMIT=40] -->
|
||||
<string name="battery_saver_auto_percentage">Based on percentage</string>
|
||||
|
||||
@@ -6612,7 +6617,7 @@
|
||||
|
||||
<!-- Message displayed to let the user know that some of the options are disabled by admin. [CHAR LIMIT=NONE] -->
|
||||
<string name="admin_disabled_other_options">Other options are disabled by your admin</string>
|
||||
<string name="admin_more_details">More details</string>
|
||||
<string name="admin_more_details">Learn more</string>
|
||||
<string name="notification_log_title">Notification log</string>
|
||||
|
||||
<string name="notification_history_title">Notification history</string>
|
||||
@@ -12804,6 +12809,12 @@
|
||||
<!-- Power menu setting privacy no secure screen lock set [CHAR_LIMIT=NONE] -->
|
||||
<string name="power_menu_privacy_not_secure">To use, first set a screen lock</string>
|
||||
|
||||
<!-- Power menu setting use long press power to invoke assistant. [CHAR_LIMIT=NONE] -->
|
||||
<string name="power_menu_long_press_for_assist">Hold for Assistant</string>
|
||||
|
||||
<!-- Power menu setting use log press power to invoke assistant summary. [CHAR_LIMIT=NONE] -->
|
||||
<string name="power_menu_long_press_for_assist_summary">Trigger the Assistant by holding the power button</string>
|
||||
|
||||
<!-- Device controls toggle name [CHAR LIMIT=60] -->
|
||||
<string name="device_controls_setting_toggle">Show device controls</string>
|
||||
|
||||
|
||||
@@ -20,6 +20,13 @@
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/power_menu_setting_name">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="gesture_power_menu_long_press_for_assist"
|
||||
android:title="@string/power_menu_long_press_for_assist"
|
||||
android:summary="@string/power_menu_long_press_for_assist_summary"
|
||||
settings:controller="com.android.settings.gestures.LongPressPowerButtonPreferenceController"
|
||||
/>
|
||||
|
||||
<Preference
|
||||
android:key="gesture_global_actions_panel_summary"
|
||||
android:title="@string/cards_passes_sentence"
|
||||
|
||||
@@ -49,9 +49,9 @@
|
||||
android:summary="@string/ethernet_tethering_subtext"
|
||||
settings:keywords="@string/keywords_hotspot_tethering" />
|
||||
|
||||
<Preference
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="disabled_on_data_saver"
|
||||
android:summary="@string/tether_settings_disabled_on_data_saver"
|
||||
android:title="@string/tether_settings_disabled_on_data_saver"
|
||||
android:selectable="false"
|
||||
settings:allowDividerAbove="true" />
|
||||
settings:searchable="false"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -34,19 +34,19 @@ import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** A customized {@link DialogFragment} with a progress bar. */
|
||||
public class ProgressDialogFragment extends DialogFragment {
|
||||
/** A customized {@link InstrumentedDialogFragment} with a progress bar. */
|
||||
public class ProgressDialogFragment extends InstrumentedDialogFragment {
|
||||
private static final String TAG = "ProgressDialogFragment";
|
||||
private static final String DLG_ID = "ProgressDialog";
|
||||
private static final int PROGRESS_BAR_STEPPING_TIME = 20;
|
||||
@@ -110,6 +110,11 @@ public class ProgressDialogFragment extends DialogFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* To generate a progress alter dialog and invoke the supported links dialog.
|
||||
*/
|
||||
|
||||
@@ -26,19 +26,19 @@ import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/** A customized {@link DialogFragment} with multiple checkboxes. */
|
||||
public class SupportedLinksDialogFragment extends DialogFragment {
|
||||
/** A customized {@link InstrumentedDialogFragment} with multiple checkboxes. */
|
||||
public class SupportedLinksDialogFragment extends InstrumentedDialogFragment {
|
||||
private static final String TAG = "SupportedLinksDialogFrg";
|
||||
private static final String DLG_ID = "SupportedLinksDialog";
|
||||
|
||||
@@ -54,11 +54,6 @@ public class SupportedLinksDialogFragment extends DialogFragment {
|
||||
mSupportedLinkWrapperList = mViewModel.getSupportedLinkWrapperList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Context context = getActivity();
|
||||
@@ -70,13 +65,17 @@ public class SupportedLinksDialogFragment extends DialogFragment {
|
||||
.setAdapter(adapter, /* listener= */ null)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.app_launch_supported_links_add, (dialog, id) -> {
|
||||
// addSelectedItems(((AlertDialog) dialog).getListView());
|
||||
doSelectedAction();
|
||||
})
|
||||
.setNegativeButton(R.string.app_launch_dialog_cancel, /* listener= */ null);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Display the dialog. */
|
||||
public void showDialog(FragmentManager manager) {
|
||||
show(manager, DLG_ID);
|
||||
|
||||
@@ -71,6 +71,7 @@ import com.android.settings.users.UserDialogs;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
@@ -79,7 +80,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DeviceAdminAdd extends Activity {
|
||||
/**
|
||||
* A confirmation screen for enabling administractor.
|
||||
*/
|
||||
public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {
|
||||
static final String TAG = "DeviceAdminAdd";
|
||||
|
||||
static final int DIALOG_WARNING = 1;
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -241,4 +242,14 @@ public class BiometricUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the screen is going into a landscape mode and the angle is equal to
|
||||
* 270.
|
||||
* @param context Context that we use to get the display this context is associated with
|
||||
* @return True if the angle of the rotation is equal to 270.
|
||||
*/
|
||||
public static boolean isReverseLandscape(@NonNull Context context) {
|
||||
return context.getDisplay().getRotation() == Surface.ROTATION_270;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.biometrics.BiometricEnrollSidecar;
|
||||
import com.android.settings.biometrics.BiometricErrorDialog;
|
||||
import com.android.settings.biometrics.BiometricUtils;
|
||||
import com.android.settings.biometrics.BiometricsEnrollEnrolling;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
|
||||
@@ -98,6 +99,7 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
|
||||
private boolean mCanAssumeUdfps;
|
||||
@Nullable private ProgressBar mProgressBar;
|
||||
private ObjectAnimator mProgressAnim;
|
||||
private TextView mDescriptionText;
|
||||
private TextView mErrorText;
|
||||
private Interpolator mFastOutSlowInInterpolator;
|
||||
private Interpolator mLinearOutSlowInInterpolator;
|
||||
@@ -145,7 +147,11 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
|
||||
mCanAssumeUdfps = props.size() == 1 && props.get(0).isAnyUdfpsType();
|
||||
|
||||
if (mCanAssumeUdfps) {
|
||||
if (BiometricUtils.isReverseLandscape(getApplicationContext())) {
|
||||
setContentView(R.layout.udfps_enroll_enrolling_land);
|
||||
} else {
|
||||
setContentView(R.layout.udfps_enroll_enrolling);
|
||||
}
|
||||
setDescriptionText(R.string.security_settings_udfps_enroll_start_message);
|
||||
} else {
|
||||
setContentView(R.layout.fingerprint_enroll_enrolling);
|
||||
|
||||
@@ -112,8 +112,12 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase {
|
||||
|
||||
protected int getContentView() {
|
||||
if (mCanAssumeUdfps) {
|
||||
if (BiometricUtils.isReverseLandscape(getApplicationContext())) {
|
||||
return R.layout.udfps_enroll_find_sensor_land;
|
||||
} else {
|
||||
return R.layout.udfps_enroll_find_sensor_layout;
|
||||
}
|
||||
}
|
||||
return R.layout.fingerprint_enroll_find_sensor;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ public class AdaptiveSleepPreferenceController {
|
||||
mPreference = new RestrictedSwitchPreference(context);
|
||||
mPreference.setTitle(R.string.adaptive_sleep_title);
|
||||
mPreference.setSummary(R.string.adaptive_sleep_description);
|
||||
mPreference.setIcon(R.drawable.empty_icon);
|
||||
mPreference.setChecked(isChecked());
|
||||
mPreference.setKey(PREFERENCE_KEY);
|
||||
mPreference.setOnPreferenceClickListener(preference -> {
|
||||
|
||||
@@ -164,7 +164,8 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
|
||||
final String textMoreDetails = getResources().getString(R.string.admin_more_details);
|
||||
|
||||
final SpannableString spannableString = new SpannableString(
|
||||
textDisabledByAdmin + System.lineSeparator() + textMoreDetails);
|
||||
textDisabledByAdmin + System.lineSeparator()
|
||||
+ System.lineSeparator() + textMoreDetails);
|
||||
final ClickableSpan clickableSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
@@ -174,7 +175,7 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
|
||||
|
||||
if (textDisabledByAdmin != null && textMoreDetails != null) {
|
||||
spannableString.setSpan(clickableSpan, textDisabledByAdmin.length() + 1,
|
||||
textDisabledByAdmin.length() + textMoreDetails.length() + 1,
|
||||
textDisabledByAdmin.length() + textMoreDetails.length() + 2,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public class BatterySaverController extends BasePreferenceController
|
||||
Utils.formatPercentage(percent)) :
|
||||
mContext.getString(R.string.battery_saver_off_summary);
|
||||
} else {
|
||||
return mContext.getString(R.string.battery_saver_auto_routine);
|
||||
return mContext.getString(R.string.battery_saver_pref_auto_routine_summary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,6 @@ public interface BatterySettingsFeatureProvider {
|
||||
/**
|
||||
* Get replacement activity for a given activity or fragment path.
|
||||
*/
|
||||
String getReplacingActivityName(String activity);
|
||||
String getReplacingActivityName(String originalActivity);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,21 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Feature provider implementation for battery settings usage.
|
||||
*/
|
||||
public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatureProvider {
|
||||
|
||||
protected Context mContext;
|
||||
|
||||
public BatterySettingsFeatureProviderImpl(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReplacingActivityName(String activity) {
|
||||
public String getReplacingActivityName(String originalActivity) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.settings.fuelgauge.batterytip;
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
@@ -34,7 +33,6 @@ import com.android.settings.overlay.FeatureFactory;
|
||||
*/
|
||||
public class BatteryManagerPreferenceController extends BasePreferenceController {
|
||||
private static final String KEY_BATTERY_MANAGER = "smart_battery_manager";
|
||||
private static final int ON = 1;
|
||||
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
private AppOpsManager mAppOpsManager;
|
||||
private UserManager mUserManager;
|
||||
@@ -56,24 +54,17 @@ public class BatteryManagerPreferenceController extends BasePreferenceController
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final int num = BatteryTipUtils.getRestrictedAppsList(mAppOpsManager, mUserManager).size();
|
||||
final String setting = mPowerUsageFeatureProvider.isSmartBatterySupported()
|
||||
? Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED
|
||||
: Settings.Global.APP_AUTO_RESTRICTION_ENABLED;
|
||||
final boolean featureOn =
|
||||
Settings.Global.getInt(mContext.getContentResolver(), setting, ON) == ON;
|
||||
|
||||
updateSummary(preference, featureOn, num);
|
||||
updateSummary(preference, num);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateSummary(Preference preference, boolean featureOn, int num) {
|
||||
void updateSummary(Preference preference, int num) {
|
||||
if (num > 0) {
|
||||
preference.setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.battery_manager_app_restricted, num, num));
|
||||
} else if (featureOn) {
|
||||
preference.setSummary(R.string.battery_manager_on);
|
||||
} else {
|
||||
preference.setSummary(R.string.battery_manager_off);
|
||||
preference.setSummary(R.string.battery_manager_summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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.gestures;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Configures the behaviour of long press power button action.
|
||||
*/
|
||||
public class LongPressPowerButtonPreferenceController extends TogglePreferenceController implements
|
||||
LifecycleObserver {
|
||||
|
||||
private static final String POWER_BUTTON_LONG_PRESS_SETTING =
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS;
|
||||
private static final Uri POWER_BUTTON_LONG_PRESS_SETTING_URI =
|
||||
Settings.Global.getUriFor(POWER_BUTTON_LONG_PRESS_SETTING);
|
||||
|
||||
// Used for fallback to global actions if necessary.
|
||||
@VisibleForTesting
|
||||
static final String CARDS_AVAILABLE_KEY =
|
||||
Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
|
||||
@VisibleForTesting
|
||||
static final String CARDS_ENABLED_KEY = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
|
||||
|
||||
/**
|
||||
* Value used for long press power button behaviour when Assist setting is enabled.
|
||||
*
|
||||
* {@link com.android.server.policy.PhoneWindowManager#LONG_PRESS_POWER_GLOBAL_ACTIONS} for
|
||||
* source of the value.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_SHUT_OFF = 2;
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
|
||||
|
||||
/**
|
||||
* Value used for long press power button behaviour when the Assist setting is disabled.
|
||||
*
|
||||
* If this value matches Assist setting, then it falls back to Global Actions panel or
|
||||
* power menu, depending on their respective settings.
|
||||
*/
|
||||
private static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
|
||||
R.integer.config_longPressOnPowerBehavior;
|
||||
|
||||
@Nullable
|
||||
private SettingObserver mSettingsObserver;
|
||||
|
||||
public LongPressPowerButtonPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mSettingsObserver = new SettingObserver(screen.findPreference(getPreferenceKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the settings pages resumes.
|
||||
*/
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
public void onResume() {
|
||||
if (mSettingsObserver != null) {
|
||||
mSettingsObserver.register();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the settings page pauses.
|
||||
*/
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
public void onPause() {
|
||||
if (mSettingsObserver != null) {
|
||||
mSettingsObserver.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final boolean enabled = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
|
||||
return enabled ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
final int powerButtonValue = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||
mContext.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
|
||||
return powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
if (isChecked) {
|
||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
}
|
||||
|
||||
// We need to determine the right disabled value - we set it to device default
|
||||
// if it's different than Assist, otherwise we fallback to either global actions or power
|
||||
//menu.
|
||||
final int defaultPowerButtonValue = mContext.getResources().getInteger(
|
||||
POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE);
|
||||
if (defaultPowerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
|
||||
final int fallbackValue = isCardsOrControlsAvailable() ? LONG_PRESS_POWER_GLOBAL_ACTIONS
|
||||
: LONG_PRESS_POWER_SHUT_OFF;
|
||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING, fallbackValue);
|
||||
}
|
||||
|
||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING, defaultPowerButtonValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the global actions menu on power button click is enabled via any of the
|
||||
* content options.
|
||||
*/
|
||||
private boolean isCardsOrControlsAvailable() {
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
final boolean cardsAvailable = Settings.Secure.getInt(resolver, CARDS_AVAILABLE_KEY, 0)
|
||||
!= 0;
|
||||
final boolean controlsAvailable = mContext.getPackageManager().hasSystemFeature(
|
||||
PackageManager.FEATURE_CONTROLS);
|
||||
return cardsAvailable || controlsAvailable;
|
||||
}
|
||||
|
||||
private final class SettingObserver extends ContentObserver {
|
||||
|
||||
private final Preference mPreference;
|
||||
|
||||
SettingObserver(Preference preference) {
|
||||
super(new Handler(Looper.getMainLooper()));
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
cr.registerContentObserver(POWER_BUTTON_LONG_PRESS_SETTING_URI, false, this);
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
cr.unregisterContentObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,7 +57,8 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return isCardsAvailable() || isControlsAvailable() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
return isCardsAvailable() || isControlsAvailable() || isAssistInvocationAvailable()
|
||||
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
private boolean isControlsAvailable() {
|
||||
@@ -68,4 +69,9 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_AVAILABLE_SETTING, 0) == 1;
|
||||
}
|
||||
|
||||
private boolean isAssistInvocationAvailable() {
|
||||
return mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public BatterySettingsFeatureProvider getBatterySettingsFeatureProvider(Context context) {
|
||||
if (mBatterySettingsFeatureProvider == null) {
|
||||
mBatterySettingsFeatureProvider = new BatterySettingsFeatureProviderImpl();
|
||||
mBatterySettingsFeatureProvider = new BatterySettingsFeatureProviderImpl(context);
|
||||
}
|
||||
return mBatterySettingsFeatureProvider;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,8 @@ public class BatterySaverControllerTest {
|
||||
Settings.Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||
|
||||
assertThat(mBatterySaverController.getSummary()).isEqualTo("Based on your routine");
|
||||
assertThat(mBatterySaverController.getSummary()).
|
||||
isEqualTo("Will turn on based on your routine");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -63,31 +63,20 @@ public class BatteryManagerPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_smartBatteryOnWithRestrictApps_showSummary() {
|
||||
mController.updateSummary(mPreference, true /* smartBatteryOn */, 2);
|
||||
public void updateState_smartBatteryWithRestrictApps_showSummary() {
|
||||
mController.updateSummary(mPreference, 2);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo("2 apps restricted");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_smartBatteryOnWithoutRestriction_showSummary() {
|
||||
public void updateState_smartBatteryWithoutRestriction_showSummary() {
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo("On / Detecting when apps drain battery");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_smartBatteryOff_showSummary() {
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, OFF);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo("Off");
|
||||
assertThat(mPreference.getSummary()).isEqualTo("Detecting when apps drain battery");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ public class SummaryDetectorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetect_notDisabled_tipVisible() {
|
||||
public void testDetect_notDisabled_tipInvisible() {
|
||||
SummaryDetector detector = new SummaryDetector(mPolicy, AVERAGE_TIME_MS);
|
||||
|
||||
assertThat(detector.detect().isVisible()).isTrue();
|
||||
assertThat(detector.detect().isVisible()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressPowerButtonPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_LONG_PRESS_POWER_BUTTON =
|
||||
"gesture_power_menu_long_press_for_assist";
|
||||
|
||||
private Application mContext;
|
||||
private Resources mResources;
|
||||
private LongPressPowerButtonPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
mController = new LongPressPowerButtonPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_POWER_BUTTON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configIsFalse_shouldReturnFalse() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceChecked_longPressPowerSettingSetToAssistant() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_longPressPowerSettingSetToDefaultValue() {
|
||||
// Value out of range chosen deliberately.
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(8);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_assistDefault_setShutOff() {
|
||||
// Value out of range chosen deliberately.
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_SHUT_OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_assistDefaultGlobalActionsEnabled_setGlobalActions() {
|
||||
// Value out of range chosen deliberately.
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
LongPressPowerButtonPreferenceController.CARDS_AVAILABLE_KEY, 1);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
LongPressPowerButtonPreferenceController.CARDS_ENABLED_KEY, 1);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,13 @@ package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -35,6 +40,7 @@ import org.robolectric.shadows.ShadowPackageManager;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PowerMenuPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private PowerMenuPreferenceController mController;
|
||||
private ShadowPackageManager mShadowPackageManager;
|
||||
|
||||
@@ -44,17 +50,26 @@ public class PowerMenuPreferenceControllerTest {
|
||||
private static final String CARDS_ENABLED = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
|
||||
private static final String CARDS_AVAILABLE = Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mResources = mock(Resources.class);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
||||
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_bothAvailable_available() {
|
||||
public void getAvailabilityStatus_allAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
@@ -64,6 +79,9 @@ public class PowerMenuPreferenceControllerTest {
|
||||
public void getAvailabilityStatus_onlyCardsAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
@@ -73,15 +91,69 @@ public class PowerMenuPreferenceControllerTest {
|
||||
public void getAvailabilityStatus_onlyControlsAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_bothUnavailable_unavailable() {
|
||||
public void getAvailabilityStatus_controlsAndCardsAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_controlsAndAssistAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_cardsAndAssistAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_onlyAssistAvailable_available() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_allUnavailable_unavailable() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
|
||||
mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||
|
||||
Reference in New Issue
Block a user