Snap for 8112519 from 17979a4d32 to tm-release
Change-Id: I3f7ff2892b0db1c52be2b925746a6da82cf6af8d
This commit is contained in:
@@ -114,6 +114,7 @@
|
|||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.READ_APP_SPECIFIC_LOCALES" />
|
<uses-permission android:name="android.permission.READ_APP_SPECIFIC_LOCALES" />
|
||||||
<uses-permission android:name="android.permission.QUERY_ADMIN_POLICY" />
|
<uses-permission android:name="android.permission.QUERY_ADMIN_POLICY" />
|
||||||
|
<uses-permission android:name="android.permission.READ_SAFETY_CENTER_STATUS" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".SettingsApplication"
|
android:name=".SettingsApplication"
|
||||||
|
|||||||
@@ -22,15 +22,6 @@
|
|||||||
android:height="@dimen/accessibility_icon_size"
|
android:height="@dimen/accessibility_icon_size"
|
||||||
android:color="@color/accessibility_feature_background"/>
|
android:color="@color/accessibility_feature_background"/>
|
||||||
</item>
|
</item>
|
||||||
<item android:gravity="center">
|
<item android:gravity="center"
|
||||||
<vector
|
android:drawable="@drawable/ic_font_download"/>
|
||||||
android:width="@dimen/accessibility_icon_foreground_size"
|
|
||||||
android:height="@dimen/accessibility_icon_foreground_size"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M6.4,18h2.1l1.1,-3.05h4.8L15.5,18h2.1L13.05,6h-2.1zM10.2,13.2l1.75,-4.95h0.1l1.75,4.95zM4,22q-0.825,0 -1.413,-0.587Q2,20.825 2,20L2,4q0,-0.825 0.587,-1.413Q3.175,2 4,2h16q0.825,0 1.413,0.587Q22,3.175 22,4v16q0,0.825 -0.587,1.413Q20.825,22 20,22zM4,20h16L20,4L4,4v16zM4,4v16L4,4z"/>
|
|
||||||
</vector>
|
|
||||||
</item>
|
|
||||||
</layer-list>
|
</layer-list>
|
||||||
26
res/drawable/ic_font_download.xml
Normal file
26
res/drawable/ic_font_download.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2022 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="@dimen/accessibility_icon_foreground_size"
|
||||||
|
android:height="@dimen/accessibility_icon_foreground_size"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M6.4,18h2.1l1.1,-3.05h4.8L15.5,18h2.1L13.05,6h-2.1zM10.2,13.2l1.75,-4.95h0.1l1.75,4.95zM4,22q-0.825,0 -1.413,-0.587Q2,20.825 2,20L2,4q0,-0.825 0.587,-1.413Q3.175,2 4,2h16q0.825,0 1.413,0.587Q22,3.175 22,4v16q0,0.825 -0.587,1.413Q20.825,22 20,22zM4,20h16L20,4L4,4v16zM4,4v16L4,4z"/>
|
||||||
|
</vector>
|
||||||
@@ -583,4 +583,7 @@
|
|||||||
-->
|
-->
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- The ratio to use when using the two-pane settings layout -->
|
||||||
|
<item name="config_activity_embed_split_ratio" format="float" type="dimen">0.5</item>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import com.android.settings.enterprise.EnterprisePrivacySettings;
|
|||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.security.SecuritySettingsFeatureProvider;
|
import com.android.settings.security.SecuritySettingsFeatureProvider;
|
||||||
|
|
||||||
import com.google.android.setupdesign.util.ThemeHelper;
|
import com.google.android.setupdesign.util.ThemeHelper;
|
||||||
@@ -152,7 +152,7 @@ public class Settings extends SettingsActivity {
|
|||||||
/** Redirects to SafetyCenter if enabled. */
|
/** Redirects to SafetyCenter if enabled. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void handleSafetyCenterRedirection() {
|
public void handleSafetyCenterRedirection() {
|
||||||
if (SafetyCenterStatus.isEnabled()) {
|
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||||
try {
|
try {
|
||||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||||
finish();
|
finish();
|
||||||
@@ -213,7 +213,7 @@ public class Settings extends SettingsActivity {
|
|||||||
/** Redirects to SafetyCenter if enabled. */
|
/** Redirects to SafetyCenter if enabled. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void handleSafetyCenterRedirection() {
|
public void handleSafetyCenterRedirection() {
|
||||||
if (SafetyCenterStatus.isEnabled()) {
|
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||||
try {
|
try {
|
||||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
|
/** Provides utility methods to accessibility quick settings only. */
|
||||||
|
final class AccessibilityQuickSettingUtils {
|
||||||
|
|
||||||
|
private static final String ACCESSIBILITY_PERF = "accessibility_prefs";
|
||||||
|
private static final String KEY_TILE_SERVICE_SHOWN = "tile_service_shown";
|
||||||
|
private static final char COMPONENT_NAME_SEPARATOR = ':';
|
||||||
|
private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
|
||||||
|
new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opts in component name into {@link AccessibilityQuickSettingUtils#KEY_TILE_SERVICE_SHOWN}
|
||||||
|
* colon-separated string in {@link SharedPreferences}.
|
||||||
|
*
|
||||||
|
* @param context The current context.
|
||||||
|
* @param componentName The component name that need to be opted in SharedPreferences.
|
||||||
|
*/
|
||||||
|
public static void optInValueToSharedPreferences(Context context,
|
||||||
|
@NonNull ComponentName componentName) {
|
||||||
|
final String targetString = getFromSharedPreferences(context);
|
||||||
|
if (hasValueInSharedPreferences(targetString, componentName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||||
|
if (!TextUtils.isEmpty(targetString)) {
|
||||||
|
joiner.add(targetString);
|
||||||
|
}
|
||||||
|
joiner.add(componentName.flattenToString());
|
||||||
|
|
||||||
|
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||||
|
editor.putString(KEY_TILE_SERVICE_SHOWN, joiner.toString()).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if component name existed in {@link
|
||||||
|
* AccessibilityQuickSettingUtils#KEY_TILE_SERVICE_SHOWN} string in {@link SharedPreferences}.
|
||||||
|
*
|
||||||
|
* @param context The current context.
|
||||||
|
* @param componentName The component name that need to be checked existed in SharedPreferences.
|
||||||
|
* @return {@code true} if componentName existed in SharedPreferences.
|
||||||
|
*/
|
||||||
|
public static boolean hasValueInSharedPreferences(Context context,
|
||||||
|
@NonNull ComponentName componentName) {
|
||||||
|
final String targetString = getFromSharedPreferences(context);
|
||||||
|
return hasValueInSharedPreferences(targetString, componentName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasValueInSharedPreferences(String targetString,
|
||||||
|
@NonNull ComponentName componentName) {
|
||||||
|
if (TextUtils.isEmpty(targetString)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sStringColonSplitter.setString(targetString);
|
||||||
|
|
||||||
|
while (sStringColonSplitter.hasNext()) {
|
||||||
|
final String name = sStringColonSplitter.next();
|
||||||
|
if (TextUtils.equals(componentName.flattenToString(), name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFromSharedPreferences(Context context) {
|
||||||
|
return getSharedPreferences(context).getString(KEY_TILE_SERVICE_SHOWN, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SharedPreferences getSharedPreferences(Context context) {
|
||||||
|
return context.getSharedPreferences(ACCESSIBILITY_PERF, Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AccessibilityQuickSettingUtils(){}
|
||||||
|
}
|
||||||
@@ -17,9 +17,11 @@
|
|||||||
package com.android.settings.activityembedding;
|
package com.android.settings.activityembedding;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.LayoutDirection;
|
import android.util.LayoutDirection;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -35,9 +37,11 @@ import com.android.settings.Settings;
|
|||||||
import com.android.settings.SubSettings;
|
import com.android.settings.SubSettings;
|
||||||
import com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling;
|
import com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling;
|
||||||
import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroduction;
|
import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroduction;
|
||||||
|
import com.android.settings.core.FeatureFlags;
|
||||||
import com.android.settings.homepage.DeepLinkHomepageActivity;
|
import com.android.settings.homepage.DeepLinkHomepageActivity;
|
||||||
import com.android.settings.homepage.SettingsHomepageActivity;
|
import com.android.settings.homepage.SettingsHomepageActivity;
|
||||||
import com.android.settings.homepage.SliceDeepLinkHomepageActivity;
|
import com.android.settings.homepage.SliceDeepLinkHomepageActivity;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -92,7 +96,7 @@ public class ActivityEmbeddingRulesController {
|
|||||||
clearTop,
|
clearTop,
|
||||||
ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthPx(context),
|
ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthPx(context),
|
||||||
ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthPx(context),
|
ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthPx(context),
|
||||||
ActivityEmbeddingUtils.SPLIT_RATIO,
|
ActivityEmbeddingUtils.getSplitRatio(context),
|
||||||
LayoutDirection.LOCALE));
|
LayoutDirection.LOCALE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +202,7 @@ public class ActivityEmbeddingRulesController {
|
|||||||
SplitRule.FINISH_ADJACENT,
|
SplitRule.FINISH_ADJACENT,
|
||||||
ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthPx(mContext),
|
ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthPx(mContext),
|
||||||
ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthPx(mContext),
|
ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthPx(mContext),
|
||||||
ActivityEmbeddingUtils.SPLIT_RATIO,
|
ActivityEmbeddingUtils.getSplitRatio(mContext),
|
||||||
LayoutDirection.LOCALE);
|
LayoutDirection.LOCALE);
|
||||||
|
|
||||||
mSplitController.registerRule(placeholderRule);
|
mSplitController.registerRule(placeholderRule);
|
||||||
@@ -206,11 +210,22 @@ public class ActivityEmbeddingRulesController {
|
|||||||
|
|
||||||
private void registerAlwaysExpandRule() {
|
private void registerAlwaysExpandRule() {
|
||||||
final Set<ActivityFilter> activityFilters = new HashSet<>();
|
final Set<ActivityFilter> activityFilters = new HashSet<>();
|
||||||
|
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SETTINGS_SEARCH_ALWAYS_EXPAND)) {
|
||||||
|
final Intent searchIntent = FeatureFactory.getFactory(mContext)
|
||||||
|
.getSearchFeatureProvider()
|
||||||
|
.buildSearchIntent(mContext, SettingsEnums.SETTINGS_HOMEPAGE);
|
||||||
|
addActivityFilter(activityFilters, searchIntent);
|
||||||
|
}
|
||||||
addActivityFilter(activityFilters, FingerprintEnrollIntroduction.class);
|
addActivityFilter(activityFilters, FingerprintEnrollIntroduction.class);
|
||||||
addActivityFilter(activityFilters, FingerprintEnrollEnrolling.class);
|
addActivityFilter(activityFilters, FingerprintEnrollEnrolling.class);
|
||||||
mSplitController.registerRule(new ActivityRule(activityFilters, true /* alwaysExpand */));
|
mSplitController.registerRule(new ActivityRule(activityFilters, true /* alwaysExpand */));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addActivityFilter(Set<ActivityFilter> activityFilters, Intent intent) {
|
||||||
|
activityFilters.add(new ActivityFilter(new ComponentName("*" /* pkg */, "*" /* cls */),
|
||||||
|
intent.getAction()));
|
||||||
|
}
|
||||||
|
|
||||||
private void addActivityFilter(Set<ActivityFilter> activityFilters,
|
private void addActivityFilter(Set<ActivityFilter> activityFilters,
|
||||||
Class<? extends Activity> activityClass) {
|
Class<? extends Activity> activityClass) {
|
||||||
activityFilters.add(new ActivityFilter(new ComponentName(mContext, activityClass),
|
activityFilters.add(new ActivityFilter(new ComponentName(mContext, activityClass),
|
||||||
|
|||||||
@@ -24,9 +24,10 @@ import android.util.TypedValue;
|
|||||||
|
|
||||||
import androidx.window.embedding.SplitController;
|
import androidx.window.embedding.SplitController;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
/** An util class collecting all common methods for the embedding activity features. */
|
/** An util class collecting all common methods for the embedding activity features. */
|
||||||
public class ActivityEmbeddingUtils {
|
public class ActivityEmbeddingUtils {
|
||||||
public static final float SPLIT_RATIO = 0.5f;
|
|
||||||
// The smallest value of current width of the window when the split should be used.
|
// The smallest value of current width of the window when the split should be used.
|
||||||
private static final float MIN_CURRENT_SCREEN_SPLIT_WIDTH_DP = 720f;
|
private static final float MIN_CURRENT_SCREEN_SPLIT_WIDTH_DP = 720f;
|
||||||
// The smallest value of the smallest-width (sw) of the window in any rotation when
|
// The smallest value of the smallest-width (sw) of the window in any rotation when
|
||||||
@@ -51,6 +52,14 @@ public class ActivityEmbeddingUtils {
|
|||||||
TypedValue.COMPLEX_UNIT_DIP, MIN_SMALLEST_SCREEN_SPLIT_WIDTH_DP, dm);
|
TypedValue.COMPLEX_UNIT_DIP, MIN_SMALLEST_SCREEN_SPLIT_WIDTH_DP, dm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ratio to use when splitting windows. This should be a float which describes
|
||||||
|
* the percentage of the screen which the first window should occupy.
|
||||||
|
*/
|
||||||
|
public static float getSplitRatio(Context context) {
|
||||||
|
return context.getResources().getFloat(R.dimen.config_activity_embed_split_ratio);
|
||||||
|
}
|
||||||
|
|
||||||
/** Whether to support embedding activity feature. */
|
/** Whether to support embedding activity feature. */
|
||||||
public static boolean isEmbeddingActivityEnabled(Context context) {
|
public static boolean isEmbeddingActivityEnabled(Context context) {
|
||||||
final boolean isFlagEnabled = FeatureFlagUtils.isEnabled(context,
|
final boolean isFlagEnabled = FeatureFlagUtils.isEnabled(context,
|
||||||
|
|||||||
@@ -28,4 +28,6 @@ public class FeatureFlags {
|
|||||||
public static final String CONDITIONAL_CARDS = "settings_conditionals";
|
public static final String CONDITIONAL_CARDS = "settings_conditionals";
|
||||||
public static final String TETHER_ALL_IN_ONE = "settings_tether_all_in_one";
|
public static final String TETHER_ALL_IN_ONE = "settings_tether_all_in_one";
|
||||||
public static final String CONTEXTUAL_HOME = "settings_contextual_home";
|
public static final String CONTEXTUAL_HOME = "settings_contextual_home";
|
||||||
|
public static final String SETTINGS_SEARCH_ALWAYS_EXPAND =
|
||||||
|
"settings_search_always_expand";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ public class UserAdapter implements SpinnerAdapter, ListAdapter {
|
|||||||
Drawable icon;
|
Drawable icon;
|
||||||
if (userInfo.isManagedProfile()) {
|
if (userInfo.isManagedProfile()) {
|
||||||
mName = context.getString(R.string.managed_user_title);
|
mName = context.getString(R.string.managed_user_title);
|
||||||
icon = context.getDrawable(
|
icon = context.getPackageManager().getUserBadgeForDensityNoBackground(
|
||||||
com.android.internal.R.drawable.ic_corp_badge);
|
userHandle, /* density= */ 0);
|
||||||
} else {
|
} else {
|
||||||
mName = userInfo.name;
|
mName = userInfo.name;
|
||||||
final int userId = userInfo.id;
|
final int userId = userInfo.id;
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ public final class BatteryBackupHelper implements BackupHelper {
|
|||||||
static final String KEY_FULL_POWER_LIST = "full_power_list";
|
static final String KEY_FULL_POWER_LIST = "full_power_list";
|
||||||
static final String KEY_OPTIMIZATION_LIST = "optimization_mode_list";
|
static final String KEY_OPTIMIZATION_LIST = "optimization_mode_list";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
List<ApplicationInfo> mTestApplicationInfoList = null;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PowerAllowlistBackend mPowerAllowlistBackend;
|
PowerAllowlistBackend mPowerAllowlistBackend;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -267,6 +270,9 @@ public final class BatteryBackupHelper implements BackupHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<ApplicationInfo> getInstalledApplications() {
|
private List<ApplicationInfo> getInstalledApplications() {
|
||||||
|
if (mTestApplicationInfoList != null) {
|
||||||
|
return mTestApplicationInfoList;
|
||||||
|
}
|
||||||
final List<ApplicationInfo> applications = new ArrayList<>();
|
final List<ApplicationInfo> applications = new ArrayList<>();
|
||||||
final UserManager um = mContext.getSystemService(UserManager.class);
|
final UserManager um = mContext.getSystemService(UserManager.class);
|
||||||
for (UserInfo userInfo : um.getProfiles(UserHandle.myUserId())) {
|
for (UserInfo userInfo : um.getProfiles(UserHandle.myUserId())) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import android.content.Context;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
@@ -93,7 +93,7 @@ public class PrivacyDashboardFragment extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
return !SafetyCenterStatus.isEnabled();
|
return !SafetyCenterStatusHolder.get().isEnabled(context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import android.annotation.NonNull;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
|
|
||||||
/** The preference controller for the top level privacy tile. */
|
/** The preference controller for the top level privacy tile. */
|
||||||
public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceController {
|
public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceController {
|
||||||
@@ -31,7 +31,7 @@ public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (!SafetyCenterStatus.isEnabled()) {
|
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.safetycenter;
|
|
||||||
|
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
|
|
||||||
/** Knows whether safety center is enabled or disabled. */
|
|
||||||
public class SafetyCenterStatus {
|
|
||||||
|
|
||||||
/** Whether SafetyCenter page is enabled. */
|
|
||||||
@VisibleForTesting
|
|
||||||
public static final String SAFETY_CENTER_IS_ENABLED = "safety_center_is_enabled";
|
|
||||||
|
|
||||||
/** Returns true is SafetyCenter page is enabled, false otherwise. */
|
|
||||||
public static boolean isEnabled() {
|
|
||||||
// TODO(b/208625216): use SafetyManager API instead
|
|
||||||
return DeviceConfig.getBoolean(
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY, SAFETY_CENTER_IS_ENABLED, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.safetycenter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.safetycenter.SafetyCenterManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
/** Knows whether safety center is enabled or disabled. */
|
||||||
|
public class SafetyCenterStatusHolder {
|
||||||
|
|
||||||
|
private static final String TAG = "SafetyCenterStatusHolder";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public static SafetyCenterStatusHolder sInstance;
|
||||||
|
|
||||||
|
private SafetyCenterStatusHolder() {}
|
||||||
|
|
||||||
|
/** Returns an instance of {@link SafetyCenterStatusHolder}. */
|
||||||
|
public static SafetyCenterStatusHolder get() {
|
||||||
|
if (sInstance == null) {
|
||||||
|
sInstance = new SafetyCenterStatusHolder();
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true is SafetyCenter page is enabled, false otherwise. */
|
||||||
|
public boolean isEnabled(Context context) {
|
||||||
|
if (context == null) {
|
||||||
|
Log.e(TAG, "Context is null at SafetyCenterStatusHolder#isEnabled");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SafetyCenterManager safetyCenterManager =
|
||||||
|
context.getSystemService(SafetyCenterManager.class);
|
||||||
|
if (safetyCenterManager == null) {
|
||||||
|
Log.w(TAG, "System service SAFETY_CENTER_SERVICE (SafetyCenterManager) is null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return safetyCenterManager.isSafetyCenterEnabled();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Log.e(TAG, "Calling isSafetyCenterEnabled failed.", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ public class TopLevelSafetyCenterEntryPreferenceController extends BasePreferenc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (SafetyCenterStatus.isEnabled()) {
|
if (SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
@@ -32,6 +33,7 @@ import com.android.settings.SettingsApplication;
|
|||||||
import com.android.settings.SubSettings;
|
import com.android.settings.SubSettings;
|
||||||
import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
|
import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
|
||||||
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||||
|
import com.android.settings.core.FeatureFlags;
|
||||||
import com.android.settings.homepage.SettingsHomepageActivity;
|
import com.android.settings.homepage.SettingsHomepageActivity;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
@@ -97,8 +99,13 @@ public class SearchResultTrampoline extends Activity {
|
|||||||
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
|
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else if (isSettingsIntelligence(callingActivity)) {
|
} else if (isSettingsIntelligence(callingActivity)) {
|
||||||
// Register SplitPairRule for SubSettings, set clearTop false to prevent unexpected back
|
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SETTINGS_SEARCH_ALWAYS_EXPAND)) {
|
||||||
// navigation behavior.
|
startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS));
|
||||||
|
} else {
|
||||||
|
// Register SplitPairRule for SubSettings, set clearTop false to prevent unexpected
|
||||||
|
// back navigation behavior.
|
||||||
ActivityEmbeddingRulesController.registerSubSettingsPairRule(this,
|
ActivityEmbeddingRulesController.registerSubSettingsPairRule(this,
|
||||||
false /* clearTop */);
|
false /* clearTop */);
|
||||||
|
|
||||||
@@ -112,6 +119,7 @@ public class SearchResultTrampoline extends Activity {
|
|||||||
homeActivity.getMainFragment().setHighlightMenuKey(highlightMenuKey,
|
homeActivity.getMainFragment().setHighlightMenuKey(highlightMenuKey,
|
||||||
/* scrollNeeded= */ true);
|
/* scrollNeeded= */ true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Two-pane case
|
// Two-pane case
|
||||||
startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey)
|
startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey)
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.SettingsApplication;
|
import com.android.settings.SettingsApplication;
|
||||||
|
import com.android.settings.core.FeatureFlags;
|
||||||
import com.android.settings.homepage.SettingsHomepageActivity;
|
import com.android.settings.homepage.SettingsHomepageActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,6 +38,11 @@ public class SearchStateReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (FeatureFlagUtils.isEnabled(context, FeatureFlags.SETTINGS_SEARCH_ALWAYS_EXPAND)) {
|
||||||
|
// Not needed to show/hide the highlight when search is full screen
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
Log.w(TAG, "Null intent");
|
Log.w(TAG, "Null intent");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import com.android.settings.biometrics.face.FaceProfileStatusPreferenceControlle
|
|||||||
import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
|
import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||||
import com.android.settings.widget.PreferenceCategoryController;
|
import com.android.settings.widget.PreferenceCategoryController;
|
||||||
@@ -60,11 +60,14 @@ public class SecurityAdvancedSettings extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategoryKey() {
|
public String getCategoryKey() {
|
||||||
if (SafetyCenterStatus.isEnabled()) {
|
final Context context = getContext();
|
||||||
|
if (context == null) {
|
||||||
|
return CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS;
|
||||||
|
} else if (SafetyCenterStatusHolder.get().isEnabled(context)) {
|
||||||
return CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS;
|
return CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS;
|
||||||
} else {
|
} else {
|
||||||
final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
|
final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
|
||||||
FeatureFactory.getFactory(getContext())
|
FeatureFactory.getFactory(context)
|
||||||
.getSecuritySettingsFeatureProvider();
|
.getSecuritySettingsFeatureProvider();
|
||||||
|
|
||||||
if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) {
|
if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import com.android.settings.biometrics.face.FaceStatusPreferenceController;
|
|||||||
import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
|
import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||||
import com.android.settings.widget.PreferenceCategoryController;
|
import com.android.settings.widget.PreferenceCategoryController;
|
||||||
@@ -129,7 +129,7 @@ public class SecuritySettings extends DashboardFragment {
|
|||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
return !FeatureFactory.getFactory(context).getSecuritySettingsFeatureProvider()
|
return !FeatureFactory.getFactory(context).getSecuritySettingsFeatureProvider()
|
||||||
.hasAlternativeSecuritySettingsFragment()
|
.hasAlternativeSecuritySettingsFragment()
|
||||||
&& !SafetyCenterStatus.isEnabled();
|
&& !SafetyCenterStatusHolder.get().isEnabled(context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import androidx.preference.Preference;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
|
|
||||||
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
|
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ public class TopLevelSecurityEntryPreferenceController extends BasePreferenceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (!SafetyCenterStatus.isEnabled()) {
|
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
|
|||||||
@@ -414,6 +414,9 @@ public class AddAppNetworksFragment extends InstrumentedFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateSingleNetworkSignalIcon(int level) {
|
private void updateSingleNetworkSignalIcon(int level) {
|
||||||
|
if (level == WifiEntry.WIFI_LEVEL_UNREACHABLE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// TODO: Check level of the network to show signal icon.
|
// TODO: Check level of the network to show signal icon.
|
||||||
final Drawable wifiIcon = mActivity.getDrawable(
|
final Drawable wifiIcon = mActivity.getDrawable(
|
||||||
Utils.getWifiIconResource(level)).mutate();
|
Utils.getWifiIconResource(level)).mutate();
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
/** Tests for {@link AccessibilityQuickSettingUtils}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public final class AccessibilityQuickSettingUtilsTest {
|
||||||
|
private static final String DUMMY_PACKAGE_NAME = "com.mock.example";
|
||||||
|
private static final String DUMMY_CLASS_NAME = DUMMY_PACKAGE_NAME + ".mock_a11y_service";
|
||||||
|
private static final String DUMMY_CLASS_NAME2 = DUMMY_PACKAGE_NAME + ".mock_a11y_service2";
|
||||||
|
private static final ComponentName DUMMY_COMPONENT_NAME = new ComponentName(DUMMY_PACKAGE_NAME,
|
||||||
|
DUMMY_CLASS_NAME);
|
||||||
|
private static final ComponentName DUMMY_COMPONENT_NAME2 = new ComponentName(DUMMY_PACKAGE_NAME,
|
||||||
|
DUMMY_CLASS_NAME2);
|
||||||
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void optInValueToSharedPreferences_optInValue_haveMatchString() {
|
||||||
|
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext,
|
||||||
|
DUMMY_COMPONENT_NAME);
|
||||||
|
|
||||||
|
assertThat(AccessibilityQuickSettingUtils.hasValueInSharedPreferences(mContext,
|
||||||
|
DUMMY_COMPONENT_NAME)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void optInValueToSharedPreferences_optInTwoValues_haveMatchString() {
|
||||||
|
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext,
|
||||||
|
DUMMY_COMPONENT_NAME);
|
||||||
|
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext,
|
||||||
|
DUMMY_COMPONENT_NAME2);
|
||||||
|
|
||||||
|
assertThat(AccessibilityQuickSettingUtils.hasValueInSharedPreferences(mContext,
|
||||||
|
DUMMY_COMPONENT_NAME)).isTrue();
|
||||||
|
assertThat(AccessibilityQuickSettingUtils.hasValueInSharedPreferences(mContext,
|
||||||
|
DUMMY_COMPONENT_NAME2)).isTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
|||||||
import com.android.settingslib.dream.DreamBackend;
|
import com.android.settingslib.dream.DreamBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
@@ -38,6 +39,7 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Ignore
|
||||||
public class WhenToDreamPickerTest {
|
public class WhenToDreamPickerTest {
|
||||||
|
|
||||||
private WhenToDreamPicker mPicker;
|
private WhenToDreamPicker mPicker;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.android.settingslib.dream.DreamBackend;
|
|||||||
import com.android.settingslib.dream.DreamBackend.WhenToDream;
|
import com.android.settingslib.dream.DreamBackend.WhenToDream;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
@@ -37,6 +38,7 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Ignore
|
||||||
public class WhenToDreamPreferenceControllerTest {
|
public class WhenToDreamPreferenceControllerTest {
|
||||||
|
|
||||||
private WhenToDreamPreferenceController mController;
|
private WhenToDreamPreferenceController mController;
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
@@ -202,7 +201,6 @@ public final class BatteryBackupHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void backupOptimizationMode_backupOptimizationMode() throws Exception {
|
public void backupOptimizationMode_backupOptimizationMode() throws Exception {
|
||||||
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
||||||
createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
|
createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
|
||||||
@@ -215,7 +213,6 @@ public final class BatteryBackupHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void backupOptimizationMode_backupOptimizationModeAndIgnoreSystemApp()
|
public void backupOptimizationMode_backupOptimizationModeAndIgnoreSystemApp()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
||||||
@@ -232,7 +229,6 @@ public final class BatteryBackupHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void backupOptimizationMode_backupOptimizationModeAndIgnoreDefaultApp()
|
public void backupOptimizationMode_backupOptimizationModeAndIgnoreDefaultApp()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
||||||
@@ -387,6 +383,8 @@ public final class BatteryBackupHelperTest {
|
|||||||
AppOpsManager.OP_RUN_ANY_IN_BACKGROUND,
|
AppOpsManager.OP_RUN_ANY_IN_BACKGROUND,
|
||||||
applicationInfo2.uid,
|
applicationInfo2.uid,
|
||||||
applicationInfo2.packageName);
|
applicationInfo2.packageName);
|
||||||
|
mBatteryBackupHelper.mTestApplicationInfoList =
|
||||||
|
Arrays.asList(applicationInfo1, applicationInfo2, applicationInfo3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implements(UserHandle.class)
|
@Implements(UserHandle.class)
|
||||||
|
|||||||
@@ -1,179 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 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.fuelgauge;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.util.SparseLongArray;
|
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
|
|
||||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
|
||||||
import com.android.settings.testutils.DatabaseTestUtils;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
@Ignore
|
|
||||||
public class BatteryDatabaseManagerTest {
|
|
||||||
private static String PACKAGE_NAME_NEW = "com.android.app1";
|
|
||||||
private static int UID_NEW = 345;
|
|
||||||
private static int TYPE_NEW = 1;
|
|
||||||
private static String PACKAGE_NAME_OLD = "com.android.app2";
|
|
||||||
private static int UID_OLD = 543;
|
|
||||||
private static int TYPE_OLD = 2;
|
|
||||||
private static long NOW = System.currentTimeMillis();
|
|
||||||
private static long ONE_DAY_BEFORE = NOW - DateUtils.DAY_IN_MILLIS;
|
|
||||||
private static long TWO_DAYS_BEFORE = NOW - 2 * DateUtils.DAY_IN_MILLIS;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BatteryDatabaseManager mBatteryDatabaseManager;
|
|
||||||
private AppInfo mNewAppInfo;
|
|
||||||
private AppInfo mOldAppInfo;
|
|
||||||
private AppInfo mCombinedAppInfo;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mBatteryDatabaseManager = spy(BatteryDatabaseManager.getInstance(mContext));
|
|
||||||
|
|
||||||
mNewAppInfo = new AppInfo.Builder()
|
|
||||||
.setUid(UID_NEW)
|
|
||||||
.setPackageName(PACKAGE_NAME_NEW)
|
|
||||||
.addAnomalyType(TYPE_NEW)
|
|
||||||
.build();
|
|
||||||
mOldAppInfo = new AppInfo.Builder()
|
|
||||||
.setUid(UID_OLD)
|
|
||||||
.setPackageName(PACKAGE_NAME_OLD)
|
|
||||||
.addAnomalyType(TYPE_OLD)
|
|
||||||
.build();
|
|
||||||
mCombinedAppInfo = new AppInfo.Builder()
|
|
||||||
.setUid(UID_NEW)
|
|
||||||
.setPackageName(PACKAGE_NAME_NEW)
|
|
||||||
.addAnomalyType(TYPE_NEW)
|
|
||||||
.addAnomalyType(TYPE_OLD)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void cleanUp() {
|
|
||||||
DatabaseTestUtils.clearDb(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allAnomalyFunctions() {
|
|
||||||
mBatteryDatabaseManager.insertAnomaly(UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW,
|
|
||||||
AnomalyDatabaseHelper.State.NEW, NOW);
|
|
||||||
mBatteryDatabaseManager.insertAnomaly(UID_OLD, PACKAGE_NAME_OLD, TYPE_OLD,
|
|
||||||
AnomalyDatabaseHelper.State.NEW, TWO_DAYS_BEFORE);
|
|
||||||
|
|
||||||
// In database, it contains two record
|
|
||||||
List<AppInfo> totalAppInfos = mBatteryDatabaseManager.queryAllAnomalies(0 /* timeMsAfter */,
|
|
||||||
AnomalyDatabaseHelper.State.NEW);
|
|
||||||
assertThat(totalAppInfos).containsExactly(mNewAppInfo, mOldAppInfo);
|
|
||||||
|
|
||||||
// Only one record shows up if we query by timestamp
|
|
||||||
List<AppInfo> appInfos = mBatteryDatabaseManager.queryAllAnomalies(ONE_DAY_BEFORE,
|
|
||||||
AnomalyDatabaseHelper.State.NEW);
|
|
||||||
assertThat(appInfos).containsExactly(mNewAppInfo);
|
|
||||||
|
|
||||||
mBatteryDatabaseManager.deleteAllAnomaliesBeforeTimeStamp(ONE_DAY_BEFORE);
|
|
||||||
|
|
||||||
// The obsolete record is removed from database
|
|
||||||
List<AppInfo> appInfos1 = mBatteryDatabaseManager.queryAllAnomalies(0 /* timeMsAfter */,
|
|
||||||
AnomalyDatabaseHelper.State.NEW);
|
|
||||||
assertThat(appInfos1).containsExactly(mNewAppInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateAnomalies_updateSuccessfully() {
|
|
||||||
mBatteryDatabaseManager.insertAnomaly(UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW,
|
|
||||||
AnomalyDatabaseHelper.State.NEW, NOW);
|
|
||||||
mBatteryDatabaseManager.insertAnomaly(UID_OLD, PACKAGE_NAME_OLD, TYPE_OLD,
|
|
||||||
AnomalyDatabaseHelper.State.NEW, NOW);
|
|
||||||
final AppInfo appInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME_OLD).build();
|
|
||||||
final List<AppInfo> updateAppInfos = new ArrayList<>();
|
|
||||||
updateAppInfos.add(appInfo);
|
|
||||||
|
|
||||||
// Change state of PACKAGE_NAME_OLD to handled
|
|
||||||
mBatteryDatabaseManager.updateAnomalies(updateAppInfos,
|
|
||||||
AnomalyDatabaseHelper.State.HANDLED);
|
|
||||||
|
|
||||||
// The state of PACKAGE_NAME_NEW is still new
|
|
||||||
List<AppInfo> newAppInfos = mBatteryDatabaseManager.queryAllAnomalies(ONE_DAY_BEFORE,
|
|
||||||
AnomalyDatabaseHelper.State.NEW);
|
|
||||||
assertThat(newAppInfos).containsExactly(mNewAppInfo);
|
|
||||||
|
|
||||||
// The state of PACKAGE_NAME_OLD is changed to handled
|
|
||||||
List<AppInfo> handledAppInfos = mBatteryDatabaseManager.queryAllAnomalies(ONE_DAY_BEFORE,
|
|
||||||
AnomalyDatabaseHelper.State.HANDLED);
|
|
||||||
assertThat(handledAppInfos).containsExactly(mOldAppInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void queryAnomalies_removeDuplicateByUid() {
|
|
||||||
mBatteryDatabaseManager.insertAnomaly(UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW,
|
|
||||||
AnomalyDatabaseHelper.State.NEW, NOW);
|
|
||||||
mBatteryDatabaseManager.insertAnomaly(UID_NEW, PACKAGE_NAME_NEW, TYPE_OLD,
|
|
||||||
AnomalyDatabaseHelper.State.NEW, NOW);
|
|
||||||
|
|
||||||
// Only contain one AppInfo with multiple types
|
|
||||||
List<AppInfo> newAppInfos = mBatteryDatabaseManager.queryAllAnomalies(ONE_DAY_BEFORE,
|
|
||||||
AnomalyDatabaseHelper.State.NEW);
|
|
||||||
assertThat(newAppInfos).containsExactly(mCombinedAppInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allActionFunctions() {
|
|
||||||
final long timestamp = System.currentTimeMillis();
|
|
||||||
mBatteryDatabaseManager.insertAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_OLD,
|
|
||||||
PACKAGE_NAME_OLD, 0);
|
|
||||||
mBatteryDatabaseManager.insertAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_OLD,
|
|
||||||
PACKAGE_NAME_OLD, 1);
|
|
||||||
mBatteryDatabaseManager.insertAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_NEW,
|
|
||||||
PACKAGE_NAME_NEW, timestamp);
|
|
||||||
|
|
||||||
final SparseLongArray timeArray = mBatteryDatabaseManager.queryActionTime(
|
|
||||||
AnomalyDatabaseHelper.ActionType.RESTRICTION);
|
|
||||||
assertThat(timeArray.size()).isEqualTo(2);
|
|
||||||
assertThat(timeArray.get(UID_OLD)).isEqualTo(1);
|
|
||||||
assertThat(timeArray.get(UID_NEW)).isEqualTo(timestamp);
|
|
||||||
|
|
||||||
mBatteryDatabaseManager.deleteAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_NEW,
|
|
||||||
PACKAGE_NAME_NEW);
|
|
||||||
final SparseLongArray recentTimeArray = mBatteryDatabaseManager.queryActionTime(
|
|
||||||
AnomalyDatabaseHelper.ActionType.RESTRICTION);
|
|
||||||
assertThat(recentTimeArray.size()).isEqualTo(1);
|
|
||||||
assertThat(timeArray.get(UID_OLD)).isEqualTo(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
|||||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -75,12 +74,11 @@ public class ContextualCardsFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void onStart_shouldRegisterBothReceivers() {
|
public void onStart_shouldRegisterBothReceivers() {
|
||||||
mFragment.onStart();
|
mFragment.onStart();
|
||||||
|
|
||||||
verify(mActivity).registerReceiver(eq(mFragment.mKeyEventReceiver),
|
verify(mActivity).registerReceiver(eq(mFragment.mKeyEventReceiver),
|
||||||
any(IntentFilter.class));
|
any(IntentFilter.class), eq(Context.RECEIVER_EXPORTED));
|
||||||
verify(mActivity).registerReceiver(eq(mFragment.mScreenOffReceiver),
|
verify(mActivity).registerReceiver(eq(mFragment.mScreenOffReceiver),
|
||||||
any(IntentFilter.class));
|
any(IntentFilter.class));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,19 +26,25 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.slice.builders.ListBuilder;
|
||||||
|
import androidx.slice.builders.SliceAction;
|
||||||
import androidx.slice.Slice;
|
import androidx.slice.Slice;
|
||||||
import androidx.slice.SliceProvider;
|
import androidx.slice.SliceProvider;
|
||||||
import androidx.slice.widget.SliceLiveData;
|
import androidx.slice.widget.SliceLiveData;
|
||||||
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||||
import com.android.settings.homepage.contextualcards.ContextualCardsFragment;
|
import com.android.settings.homepage.contextualcards.ContextualCardsFragment;
|
||||||
@@ -46,7 +52,6 @@ import com.android.settings.homepage.contextualcards.ControllerRendererPool;
|
|||||||
import com.android.settings.wifi.slice.ContextualWifiSlice;
|
import com.android.settings.wifi.slice.ContextualWifiSlice;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -56,7 +61,6 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.android.controller.ActivityController;
|
import org.robolectric.android.controller.ActivityController;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Ignore
|
|
||||||
public class SliceContextualCardRendererTest {
|
public class SliceContextualCardRendererTest {
|
||||||
|
|
||||||
private static final Uri TEST_SLICE_URI = Uri.parse("content://test/test");
|
private static final Uri TEST_SLICE_URI = Uri.parse("content://test/test");
|
||||||
@@ -287,7 +291,7 @@ public class SliceContextualCardRendererTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ContextualCard buildContextualCard(Uri sliceUri) {
|
private ContextualCard buildContextualCard(Uri sliceUri) {
|
||||||
final Slice slice = new ContextualWifiSlice(mActivity).getSlice();
|
final Slice slice = buildSlice();
|
||||||
return new ContextualCard.Builder()
|
return new ContextualCard.Builder()
|
||||||
.setName("test_name")
|
.setName("test_name")
|
||||||
.setCardType(ContextualCard.CardType.SLICE)
|
.setCardType(ContextualCard.CardType.SLICE)
|
||||||
@@ -296,4 +300,23 @@ public class SliceContextualCardRendererTest {
|
|||||||
.setSlice(slice)
|
.setSlice(slice)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Slice buildSlice() {
|
||||||
|
final String title = "test_title";
|
||||||
|
final IconCompat icon = IconCompat.createWithResource(mActivity, R.drawable.empty_icon);
|
||||||
|
final PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||||
|
mActivity,
|
||||||
|
title.hashCode() /* requestCode */,
|
||||||
|
new Intent("test action"),
|
||||||
|
PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
final SliceAction action
|
||||||
|
= SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, title);
|
||||||
|
return new ListBuilder(mActivity, TEST_SLICE_URI, ListBuilder.INFINITY)
|
||||||
|
.addRow(new ListBuilder.RowBuilder()
|
||||||
|
.addEndItem(icon, ListBuilder.ICON_IMAGE)
|
||||||
|
.setTitle(title)
|
||||||
|
.setPrimaryAction(action))
|
||||||
|
.addAction(SliceAction.createToggle(pendingIntent, null /* actionTitle */, true))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ package com.android.settings.wifi;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
@@ -34,7 +38,6 @@ import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
|
|||||||
import com.android.settingslib.wifi.WifiStatusTracker;
|
import com.android.settingslib.wifi.WifiStatusTracker;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -54,15 +57,18 @@ public class WifiSummaryUpdaterTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||||
|
doReturn(mock(Intent.class)).when(mContext).registerReceiver(any(), any(), anyInt());
|
||||||
|
doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class));
|
||||||
|
|
||||||
mSummaryUpdater = new WifiSummaryUpdater(mContext, mListener, mWifiTracker);
|
mSummaryUpdater = new WifiSummaryUpdater(mContext, mListener, mWifiTracker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void register_true_shouldRegisterListenerAndTracker() {
|
public void register_true_shouldRegisterListenerAndTracker() {
|
||||||
mSummaryUpdater.register(true);
|
mSummaryUpdater.register(true);
|
||||||
|
|
||||||
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
|
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class),
|
||||||
|
anyInt());
|
||||||
verify(mWifiTracker).setListening(true);
|
verify(mWifiTracker).setListening(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +81,6 @@ public class WifiSummaryUpdaterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void register_false_shouldUnregisterListenerAndTracker() {
|
public void register_false_shouldUnregisterListenerAndTracker() {
|
||||||
mSummaryUpdater.register(true);
|
mSummaryUpdater.register(true);
|
||||||
mSummaryUpdater.register(false);
|
mSummaryUpdater.register(false);
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
|
|||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -68,7 +67,7 @@ public class WifiP2pSettingsTest {
|
|||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private FragmentActivity mActivity;
|
private FragmentActivity mActivity;
|
||||||
private WifiP2pSettings mFragment;
|
private TestWifiP2pSettings mFragment;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
public WifiP2pManager mWifiP2pManager;
|
public WifiP2pManager mWifiP2pManager;
|
||||||
@@ -86,8 +85,10 @@ public class WifiP2pSettingsTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
TestWifiP2pSettings.sMockWifiP2pManager = mWifiP2pManager;
|
||||||
|
|
||||||
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||||
mFragment = new WifiP2pSettings();
|
mFragment = new TestWifiP2pSettings();
|
||||||
mFragment.mWifiP2pManager = mWifiP2pManager;
|
mFragment.mWifiP2pManager = mWifiP2pManager;
|
||||||
doReturn(mChannel).when(mWifiP2pManager).initialize(any(), any(), any());
|
doReturn(mChannel).when(mWifiP2pManager).initialize(any(), any(), any());
|
||||||
FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
|
FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
|
||||||
@@ -504,7 +505,6 @@ public class WifiP2pSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void onActivityCreate_withNullP2pManager_shouldGetP2pManagerAgain() {
|
public void onActivityCreate_withNullP2pManager_shouldGetP2pManagerAgain() {
|
||||||
mFragment.mChannel = null; // Reset channel to re-test onActivityCreated flow
|
mFragment.mChannel = null; // Reset channel to re-test onActivityCreated flow
|
||||||
mFragment.mWifiP2pManager = null;
|
mFragment.mWifiP2pManager = null;
|
||||||
@@ -542,4 +542,13 @@ public class WifiP2pSettingsTest {
|
|||||||
wifiP2pDevice.deviceName = "testName";
|
wifiP2pDevice.deviceName = "testName";
|
||||||
mWifiP2pPeer.device = wifiP2pDevice;
|
mWifiP2pPeer.device = wifiP2pDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TestWifiP2pSettings extends WifiP2pSettings {
|
||||||
|
static WifiP2pManager sMockWifiP2pManager;
|
||||||
|
@Override
|
||||||
|
protected Object getSystemService(final String name) {
|
||||||
|
if (Context.WIFI_P2P_SERVICE.equals(name)) return sMockWifiP2pManager;
|
||||||
|
return getActivity().getSystemService(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,34 +23,39 @@ import static org.mockito.Mockito.doNothing;
|
|||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
import com.android.settings.Settings;
|
import com.android.settings.Settings;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class PrivacyDashboardActivityTest {
|
public class PrivacyDashboardActivityTest {
|
||||||
|
|
||||||
private static final String DEFAULT_FRAGMENT_CLASSNAME = "DefaultFragmentClassname";
|
private static final String DEFAULT_FRAGMENT_CLASSNAME = "DefaultFragmentClassname";
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
private Settings.PrivacyDashboardActivity mActivity;
|
private Settings.PrivacyDashboardActivity mActivity;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
MockitoAnnotations.initMocks(this);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setAction(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
|
intent.setAction(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
|
||||||
intent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
intent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
||||||
@@ -71,19 +76,9 @@ public class PrivacyDashboardActivityTest {
|
|||||||
doNothing().when(mActivity).startActivity(any(Intent.class));
|
doNothing().when(mActivity).startActivity(any(Intent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
@@ -94,12 +89,7 @@ public class PrivacyDashboardActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
verify(mActivity, times(0)).startActivity(any());
|
verify(mActivity, times(0)).startActivity(any());
|
||||||
|
|||||||
@@ -18,20 +18,22 @@ package com.android.settings.privacy;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import android.provider.DeviceConfig;
|
import static org.mockito.Mockito.when;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.security.TopLevelSecurityEntryPreferenceController;
|
import com.android.settings.security.TopLevelSecurityEntryPreferenceController;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class TopLevelPrivacyEntryPreferenceControllerTest {
|
public class TopLevelPrivacyEntryPreferenceControllerTest {
|
||||||
@@ -41,30 +43,21 @@ public class TopLevelPrivacyEntryPreferenceControllerTest {
|
|||||||
private TopLevelPrivacyEntryPreferenceController mTopLevelPrivacyEntryPreferenceController;
|
private TopLevelPrivacyEntryPreferenceController mTopLevelPrivacyEntryPreferenceController;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
MockitoAnnotations.initMocks(this);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
mTopLevelPrivacyEntryPreferenceController =
|
mTopLevelPrivacyEntryPreferenceController =
|
||||||
new TopLevelPrivacyEntryPreferenceController(mContext, PREFERENCE_KEY);
|
new TopLevelPrivacyEntryPreferenceController(
|
||||||
}
|
ApplicationProvider.getApplicationContext(), PREFERENCE_KEY);
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
@@ -72,11 +65,7 @@ public class TopLevelPrivacyEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.safetycenter;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.safetycenter.SafetyCenterManager;
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class SafetyCenterStatusHolderTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isEnabled_whenContextNull_returnsFalse() {
|
||||||
|
assertThat(SafetyCenterStatusHolder.get().isEnabled(null)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isEnabled_whenSystemServiceNull_returnsFalse() {
|
||||||
|
when(mContext.getSystemService(SafetyCenterManager.class)).thenReturn(null);
|
||||||
|
|
||||||
|
assertThat(SafetyCenterStatusHolder.get().isEnabled(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.safetycenter;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class SafetyCenterStatusTest {
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isEnabled_whenFlagTrue_returnsTrue() {
|
|
||||||
DeviceConfig.setProperty(
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(SafetyCenterStatus.isEnabled()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isEnabled_whenFlagFalse_returnsFalse() {
|
|
||||||
DeviceConfig.setProperty(
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(SafetyCenterStatus.isEnabled()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,18 +22,16 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -50,12 +48,16 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
mTopLevelSafetyCenterEntryPreferenceController;
|
mTopLevelSafetyCenterEntryPreferenceController;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
||||||
mPreference.setKey(PREFERENCE_KEY);
|
mPreference.setKey(PREFERENCE_KEY);
|
||||||
@@ -63,14 +65,6 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
doNothing().when(mContext).startActivity(any(Intent.class));
|
doNothing().when(mContext).startActivity(any(Intent.class));
|
||||||
mTopLevelSafetyCenterEntryPreferenceController =
|
mTopLevelSafetyCenterEntryPreferenceController =
|
||||||
new TopLevelSafetyCenterEntryPreferenceController(mContext, PREFERENCE_KEY);
|
new TopLevelSafetyCenterEntryPreferenceController(mContext, PREFERENCE_KEY);
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -110,11 +104,7 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsUnavailable() {
|
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsUnavailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
@@ -122,11 +112,7 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsAvailable() {
|
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsAvailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.AVAILABLE);
|
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.AVAILABLE);
|
||||||
|
|||||||
@@ -18,17 +18,18 @@ package com.android.settings.security;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
|
|
||||||
import androidx.test.annotation.UiThreadTest;
|
import androidx.test.annotation.UiThreadTest;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
@@ -36,6 +37,8 @@ import com.android.settingslib.drawer.CategoryKey;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SecurityAdvancedSettingsTest {
|
public class SecurityAdvancedSettingsTest {
|
||||||
@@ -47,16 +50,22 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SecurityAdvancedSettings mSecurityAdvancedSettings;
|
private SecurityAdvancedSettings mSecurityAdvancedSettings;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
if (Looper.myLooper() == null) {
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
mSecurityAdvancedSettings = new SecurityAdvancedSettings();
|
mSecurityAdvancedSettings = spy(new SecurityAdvancedSettings());
|
||||||
|
when(mSecurityAdvancedSettings.getContext()).thenReturn(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -67,7 +76,7 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCategoryKey_whenSafetyCenterIsEnabled_returnsSecurity() {
|
public void getCategoryKey_whenSafetyCenterIsEnabled_returnsSecurity() {
|
||||||
setSafetyCenterEnabled(true);
|
when(mSafetyCenterStatusHolder.isEnabled(any())).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||||
.isEqualTo(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
.isEqualTo(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||||
@@ -75,7 +84,7 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCategoryKey_whenAlternativeFragmentPresented_returnsAlternative() {
|
public void getCategoryKey_whenAlternativeFragmentPresented_returnsAlternative() {
|
||||||
setSafetyCenterEnabled(false);
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
setupAlternativeFragment(true, ALTERNATIVE_CATEGORY_KEY);
|
setupAlternativeFragment(true, ALTERNATIVE_CATEGORY_KEY);
|
||||||
|
|
||||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||||
@@ -84,7 +93,7 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCategoryKey_whenNoAlternativeFragmentPresented_returnsLegacy() {
|
public void getCategoryKey_whenNoAlternativeFragmentPresented_returnsLegacy() {
|
||||||
setSafetyCenterEnabled(false);
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
setupAlternativeFragment(false, null);
|
setupAlternativeFragment(false, null);
|
||||||
|
|
||||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||||
@@ -95,14 +104,6 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
|
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSafetyCenterEnabled(boolean isEnabled) {
|
|
||||||
DeviceConfig.setProperty(
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(isEnabled),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupAlternativeFragment(boolean hasAlternativeFragment,
|
private void setupAlternativeFragment(boolean hasAlternativeFragment,
|
||||||
String alternativeCategoryKey) {
|
String alternativeCategoryKey) {
|
||||||
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
|||||||
@@ -25,22 +25,22 @@ import static org.mockito.Mockito.times;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
import com.android.settings.Settings;
|
import com.android.settings.Settings;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@@ -52,13 +52,16 @@ public class SecurityDashboardActivityTest {
|
|||||||
private Settings.SecurityDashboardActivity mActivity;
|
private Settings.SecurityDashboardActivity mActivity;
|
||||||
private Intent mDefaultIntent;
|
private Intent mDefaultIntent;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
FakeFeatureFactory mFeatureFactory = FakeFeatureFactory.setupForTest();
|
FakeFeatureFactory mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
mDefaultIntent = new Intent();
|
mDefaultIntent = new Intent();
|
||||||
mDefaultIntent.setAction(android.provider.Settings.ACTION_SECURITY_SETTINGS);
|
mDefaultIntent.setAction(android.provider.Settings.ACTION_SECURITY_SETTINGS);
|
||||||
mDefaultIntent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
mDefaultIntent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
||||||
@@ -79,12 +82,6 @@ public class SecurityDashboardActivityTest {
|
|||||||
doNothing().when(mActivity).startActivity(any(Intent.class));
|
doNothing().when(mActivity).startActivity(any(Intent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noAvailableAlternativeFragmentAvailable_defaultFragmentSet() {
|
public void noAvailableAlternativeFragmentAvailable_defaultFragmentSet() {
|
||||||
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
||||||
@@ -125,11 +122,7 @@ public class SecurityDashboardActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
@@ -140,11 +133,7 @@ public class SecurityDashboardActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
|
|||||||
@@ -25,18 +25,15 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -57,15 +54,15 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
|
|
||||||
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
||||||
mPreference.setKey(PREFERENCE_KEY);
|
mPreference.setKey(PREFERENCE_KEY);
|
||||||
@@ -75,12 +72,6 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
new TopLevelSecurityEntryPreferenceController(mContext, PREFERENCE_KEY);
|
new TopLevelSecurityEntryPreferenceController(mContext, PREFERENCE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick_forDifferentPreferenceKey_isNotHandled() {
|
public void handlePreferenceTreeClick_forDifferentPreferenceKey_isNotHandled() {
|
||||||
Preference preference = new Preference(ApplicationProvider.getApplicationContext());
|
Preference preference = new Preference(ApplicationProvider.getApplicationContext());
|
||||||
@@ -137,11 +128,7 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
@@ -149,11 +136,7 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
||||||
|
|||||||
Reference in New Issue
Block a user