Add summary text for more top level setting tiles
- Connected devices - App & notifs - Battery Bug: 110405144 Test: robotests Change-Id: Ife44f7c5165483a1bad903ce90a241108ab5da25
This commit is contained in:
@@ -34,12 +34,13 @@
|
||||
android:title="@string/connected_devices_dashboard_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:icon="@drawable/ic_homepage_connected_device"
|
||||
android:fragment="com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment"/>
|
||||
android:fragment="com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment"
|
||||
settings:controller="com.android.settings.connecteddevice.TopLevelConnectedDevicesPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_apps_and_notifs"
|
||||
android:title="@string/app_and_notification_dashboard_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:summary="@string/app_and_notification_dashboard_summary"
|
||||
android:icon="@drawable/ic_homepage_apps"
|
||||
android:fragment="com.android.settings.applications.AppAndNotificationDashboardFragment"/>
|
||||
|
||||
@@ -48,19 +49,20 @@
|
||||
android:title="@string/power_usage_summary_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:icon="@drawable/ic_homepage_battery"
|
||||
android:fragment="com.android.settings.fuelgauge.PowerUsageSummary"/>
|
||||
android:fragment="com.android.settings.fuelgauge.PowerUsageSummary"
|
||||
settings:controller="com.android.settings.fuelgauge.TopLevelBatteryPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_display"
|
||||
android:title="@string/display_settings"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:summary="@string/display_dashboard_summary"
|
||||
android:icon="@drawable/ic_homepage_display"
|
||||
android:fragment="com.android.settings.DisplaySettings"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_sound"
|
||||
android:title="@string/sound_settings"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:summary="@string/sound_dashboard_summary"
|
||||
android:icon="@drawable/ic_homepage_sound"
|
||||
android:fragment="com.android.settings.notification.SoundSettings"/>
|
||||
|
||||
@@ -69,33 +71,36 @@
|
||||
android:title="@string/storage_settings"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:icon="@drawable/ic_homepage_storage"
|
||||
android:fragment="com.android.settings.deviceinfo.StorageSettings"/>
|
||||
android:fragment="com.android.settings.deviceinfo.StorageSettings"
|
||||
settings:controller="com.android.settings.deviceinfo.TopLevelStoragePreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_security"
|
||||
android:title="@string/security_settings_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:icon="@drawable/ic_homepage_security"
|
||||
android:fragment="com.android.settings.security.SecuritySettings"/>
|
||||
android:fragment="com.android.settings.security.SecuritySettings"
|
||||
settings:controller="com.android.settings.security.TopLevelSecurityEntryPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_accounts"
|
||||
android:title="@string/account_dashboard_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:icon="@drawable/ic_homepage_accounts"
|
||||
android:fragment="com.android.settings.accounts.AccountDashboardFragment"/>
|
||||
android:fragment="com.android.settings.accounts.AccountDashboardFragment"
|
||||
settings:controller="com.android.settings.accounts.TopLevelAccountEntryPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_accessibility"
|
||||
android:title="@string/accessibility_settings"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:summary="@string/accessibility_settings_summary"
|
||||
android:icon="@drawable/ic_homepage_accessibility"
|
||||
android:fragment="com.android.settings.accessibility.AccessibilitySettings"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_system"
|
||||
android:title="@string/header_category_system"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:summary="@string/system_dashboard_summary"
|
||||
android:icon="@drawable/ic_homepage_system_dashboard"
|
||||
android:fragment="com.android.settings.system.SystemDashboardFragment"/>
|
||||
|
||||
|
@@ -121,7 +121,6 @@ public class Settings extends SettingsActivity {
|
||||
}
|
||||
public static class DirectoryAccessSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
|
||||
public static class TopLevelSettings extends SettingsActivity { /* empty */ }
|
||||
public static class ApnSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class WifiCallingSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class MemorySettingsActivity extends SettingsActivity { /* empty */ }
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.accounts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.os.UserHandle;
|
||||
import android.text.BidiFormatter;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TopLevelAccountEntryPreferenceController extends BasePreferenceController {
|
||||
public TopLevelAccountEntryPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final AuthenticatorHelper authHelper = new AuthenticatorHelper(mContext,
|
||||
UserHandle.of(UserHandle.myUserId()), null /* OnAccountsUpdateListener */);
|
||||
final String[] types = authHelper.getEnabledAccountTypes();
|
||||
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
|
||||
final List<CharSequence> summaries = new ArrayList<>();
|
||||
|
||||
if (types == null || types.length == 0) {
|
||||
summaries.add(mContext.getString(R.string.account_dashboard_default_summary));
|
||||
} else {
|
||||
// Show up to 3 account types, ignore any null value
|
||||
int accountToAdd = Math.min(3, types.length);
|
||||
|
||||
for (int i = 0; i < types.length && accountToAdd > 0; i++) {
|
||||
final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
|
||||
if (TextUtils.isEmpty(label)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
summaries.add(bidiFormatter.unicodeWrap(label));
|
||||
accountToAdd--;
|
||||
}
|
||||
}
|
||||
return ListFormatter.getInstance().format(summaries);
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.connecteddevice;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class TopLevelConnectedDevicesPreferenceController extends BasePreferenceController {
|
||||
|
||||
public TopLevelConnectedDevicesPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mContext.getText(
|
||||
AdvancedConnectedDeviceController.getConnectedDevicesSummaryResourceId(mContext));
|
||||
}
|
||||
}
|
@@ -26,6 +26,11 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
@@ -46,11 +51,12 @@ import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
/**
|
||||
* Deprecated in favor of {@link com.android.settings.homepage.TopLevelSettings}
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public class DashboardSummary extends InstrumentedFragment
|
||||
implements CategoryListener, ConditionListener,
|
||||
FocusListener, SuggestionControllerMixinCompat.SuggestionControllerHost {
|
||||
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.deviceinfo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
||||
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class TopLevelStoragePreferenceController extends BasePreferenceController {
|
||||
|
||||
private final StorageManager mStorageManager;
|
||||
private final StorageManagerVolumeProvider mStorageManagerVolumeProvider;
|
||||
|
||||
public TopLevelStoragePreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mStorageManager = mContext.getSystemService(StorageManager.class);
|
||||
mStorageManagerVolumeProvider = new StorageManagerVolumeProvider(mStorageManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
// TODO: Register listener.
|
||||
final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
|
||||
final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
|
||||
mStorageManagerVolumeProvider);
|
||||
double privateUsedBytes = info.totalBytes - info.freeBytes;
|
||||
return mContext.getString(R.string.storage_summary,
|
||||
percentageFormat.format(privateUsedBytes / info.totalBytes),
|
||||
Formatter.formatFileSize(mContext, info.freeBytes));
|
||||
}
|
||||
}
|
@@ -17,13 +17,13 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
|
||||
import static com.android.settings.fuelgauge.TopLevelBatteryPreferenceController.getDashboardLabel;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.BidiFormatter;
|
||||
import android.text.format.Formatter;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -32,6 +32,11 @@ import android.view.View;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.app.LoaderManager.LoaderCallbacks;
|
||||
import androidx.loader.content.Loader;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
@@ -51,11 +56,6 @@ import com.android.settingslib.utils.StringUtil;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.app.LoaderManager.LoaderCallbacks;
|
||||
import androidx.loader.content.Loader;
|
||||
|
||||
/**
|
||||
* Displays a list of apps and subsystems that consume power, ordered by how much power was
|
||||
* consumed since the last time it was unplugged.
|
||||
@@ -147,9 +147,9 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
|
||||
protected void updateViews(List<BatteryInfo> batteryInfos) {
|
||||
final BatteryMeterView batteryView = mBatteryLayoutPref
|
||||
.findViewById(R.id.battery_header_icon);
|
||||
.findViewById(R.id.battery_header_icon);
|
||||
final TextView percentRemaining =
|
||||
mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
||||
mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
||||
final TextView summary1 = mBatteryLayoutPref.findViewById(R.id.summary1);
|
||||
final TextView summary2 = mBatteryLayoutPref.findViewById(R.id.summary2);
|
||||
BatteryInfo oldInfo = batteryInfos.get(0);
|
||||
@@ -160,13 +160,13 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
// can sometimes say 0 time remaining because battery stats requires the phone
|
||||
// be unplugged for a period of time before being willing ot make an estimate.
|
||||
summary1.setText(mPowerFeatureProvider.getOldEstimateDebugString(
|
||||
Formatter.formatShortElapsedTime(getContext(),
|
||||
PowerUtil.convertUsToMs(oldInfo.remainingTimeUs))));
|
||||
Formatter.formatShortElapsedTime(getContext(),
|
||||
PowerUtil.convertUsToMs(oldInfo.remainingTimeUs))));
|
||||
|
||||
// for this one we can just set the string directly
|
||||
summary2.setText(mPowerFeatureProvider.getEnhancedEstimateDebugString(
|
||||
Formatter.formatShortElapsedTime(getContext(),
|
||||
PowerUtil.convertUsToMs(newInfo.remainingTimeUs))));
|
||||
Formatter.formatShortElapsedTime(getContext(),
|
||||
PowerUtil.convertUsToMs(newInfo.remainingTimeUs))));
|
||||
|
||||
batteryView.setBatteryLevel(oldInfo.batteryLevel);
|
||||
batteryView.setCharging(!oldInfo.discharging);
|
||||
@@ -419,19 +419,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static CharSequence getDashboardLabel(Context context, BatteryInfo info) {
|
||||
CharSequence label;
|
||||
final BidiFormatter formatter = BidiFormatter.getInstance();
|
||||
if (info.remainingLabel == null) {
|
||||
label = info.batteryPercentString;
|
||||
} else {
|
||||
label = context.getString(R.string.power_remaining_settings_home_page,
|
||||
formatter.unicodeWrap(info.batteryPercentString),
|
||||
formatter.unicodeWrap(info.remainingLabel));
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
import android.text.BidiFormatter;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||
private Preference mPreference;
|
||||
private BatteryInfo mBatteryInfo;
|
||||
|
||||
public TopLevelBatteryPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
|
||||
mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
|
||||
BatteryInfo.getBatteryInfo(mContext, info -> {
|
||||
mBatteryInfo = info;
|
||||
updateState(mPreference);
|
||||
}, true /* shortString */);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mBatteryBroadcastReceiver.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mBatteryBroadcastReceiver.unRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return getDashboardLabel(mContext, mBatteryInfo);
|
||||
}
|
||||
|
||||
static CharSequence getDashboardLabel(Context context, BatteryInfo info) {
|
||||
if (info == null || context == null) {
|
||||
return null;
|
||||
}
|
||||
CharSequence label;
|
||||
final BidiFormatter formatter = BidiFormatter.getInstance();
|
||||
if (info.remainingLabel == null) {
|
||||
label = info.batteryPercentString;
|
||||
} else {
|
||||
label = context.getString(R.string.power_remaining_settings_home_page,
|
||||
formatter.unicodeWrap(info.batteryPercentString),
|
||||
formatter.unicodeWrap(info.remainingLabel));
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.security;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
|
||||
|
||||
public TopLevelSecurityEntryPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final FingerprintManager fpm =
|
||||
Utils.getFingerprintManagerOrNull(mContext);
|
||||
final FaceManager faceManager =
|
||||
Utils.getFaceManagerOrNull(mContext);
|
||||
if (faceManager != null && faceManager.isHardwareDetected()) {
|
||||
return mContext.getText(R.string.security_dashboard_summary_face);
|
||||
} else if (fpm != null && fpm.isHardwareDetected()) {
|
||||
return mContext.getText(R.string.security_dashboard_summary);
|
||||
} else {
|
||||
return mContext.getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,40 +15,20 @@
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.LABELS;
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.TYPES;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.Robolectric;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AccountDashboardFragmentTest {
|
||||
|
||||
@@ -59,66 +39,11 @@ public class AccountDashboardFragmentTest {
|
||||
mFragment = new AccountDashboardFragment();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowAuthenticationHelper.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategory_isAccount() {
|
||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowAuthenticationHelper.class
|
||||
})
|
||||
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final FragmentActivity activity = Robolectric.buildActivity(
|
||||
FragmentActivity.class).setup().get();
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1] + ", and " + LABELS[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAuthenticationHelper.class)
|
||||
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
||||
ShadowAuthenticationHelper.setEnabledAccount(null);
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).setup().get();
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
verify(loader).setSummary(provider,
|
||||
activity.getString(R.string.account_dashboard_default_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAuthenticationHelper.class)
|
||||
public void updateSummary_noAccountTypeLabel_shouldNotDisplayNullEntry() {
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).setup().get();
|
||||
final String[] enabledAccounts = {TYPES[0], "unlabeled_account_type", TYPES[1]};
|
||||
ShadowAuthenticationHelper.setEnabledAccount(enabledAccounts);
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
// should only show the 2 accounts with labels
|
||||
verify(loader).setSummary(provider, LABELS[0] + " and " + LABELS[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
@@ -129,43 +54,5 @@ public class AccountDashboardFragmentTest {
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
|
||||
}
|
||||
|
||||
@Implements(AuthenticatorHelper.class)
|
||||
public static class ShadowAuthenticationHelper {
|
||||
|
||||
static final String[] TYPES = {"type1", "type2", "type3", "type4"};
|
||||
static final String[] LABELS = {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
|
||||
private static String[] sEnabledAccount = TYPES;
|
||||
|
||||
public void __constructor__(Context context, UserHandle userHandle,
|
||||
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
||||
}
|
||||
|
||||
private static void setEnabledAccount(String[] enabledAccount) {
|
||||
sEnabledAccount = enabledAccount;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sEnabledAccount = TYPES;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String[] getEnabledAccountTypes() {
|
||||
return sEnabledAccount;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public CharSequence getLabelForType(Context context, final String accountType) {
|
||||
if (TextUtils.equals(accountType, TYPES[0])) {
|
||||
return LABELS[0];
|
||||
} else if (TextUtils.equals(accountType, TYPES[1])) {
|
||||
return LABELS[1];
|
||||
} else if (TextUtils.equals(accountType, TYPES[2])) {
|
||||
return LABELS[2];
|
||||
} else if (TextUtils.equals(accountType, TYPES[3])) {
|
||||
return LABELS[3];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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.accounts;
|
||||
|
||||
import static com.android.settings.accounts.TopLevelAccountEntryPreferenceControllerTest
|
||||
.ShadowAuthenticationHelper.LABELS;
|
||||
import static com.android.settings.accounts.TopLevelAccountEntryPreferenceControllerTest
|
||||
.ShadowAuthenticationHelper.TYPES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {TopLevelAccountEntryPreferenceControllerTest.ShadowAuthenticationHelper.class})
|
||||
public class TopLevelAccountEntryPreferenceControllerTest {
|
||||
|
||||
private TopLevelAccountEntryPreferenceController mController;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new TopLevelAccountEntryPreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowAuthenticationHelper.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(LABELS[0] + ", " + LABELS[1] + ", and " + LABELS[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
||||
ShadowAuthenticationHelper.setEnabledAccount(null);
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.account_dashboard_default_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_noAccountTypeLabel_shouldNotDisplayNullEntry() {
|
||||
final String[] enabledAccounts = {TYPES[0], "unlabeled_account_type", TYPES[1]};
|
||||
ShadowAuthenticationHelper.setEnabledAccount(enabledAccounts);
|
||||
|
||||
|
||||
// should only show the 2 accounts with labels
|
||||
assertThat(mController.getSummary()).isEqualTo(LABELS[0] + " and " + LABELS[1]);
|
||||
}
|
||||
|
||||
@Implements(AuthenticatorHelper.class)
|
||||
public static class ShadowAuthenticationHelper {
|
||||
|
||||
static final String[] TYPES = {"type1", "type2", "type3", "type4"};
|
||||
static final String[] LABELS = {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
|
||||
private static String[] sEnabledAccount = TYPES;
|
||||
|
||||
public void __constructor__(Context context, UserHandle userHandle,
|
||||
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
||||
}
|
||||
|
||||
private static void setEnabledAccount(String[] enabledAccount) {
|
||||
sEnabledAccount = enabledAccount;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sEnabledAccount = TYPES;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String[] getEnabledAccountTypes() {
|
||||
return sEnabledAccount;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public CharSequence getLabelForType(Context context, final String accountType) {
|
||||
if (TextUtils.equals(accountType, TYPES[0])) {
|
||||
return LABELS[0];
|
||||
} else if (TextUtils.equals(accountType, TYPES[1])) {
|
||||
return LABELS[1];
|
||||
} else if (TextUtils.equals(accountType, TYPES[2])) {
|
||||
return LABELS[2];
|
||||
} else if (TextUtils.equals(accountType, TYPES[3])) {
|
||||
return LABELS[3];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.connecteddevice;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class TopLevelConnectedDevicesPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private TopLevelConnectedDevicesPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new TopLevelConnectedDevicesPreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAdvancedConnectedDeviceController.class)
|
||||
public void getSummary_shouldCallAdvancedConnectedDeviceController() {
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.settings_label_launcher));
|
||||
}
|
||||
|
||||
@Implements(AdvancedConnectedDeviceController.class)
|
||||
private static class ShadowAdvancedConnectedDeviceController {
|
||||
|
||||
@Implementation
|
||||
public static int getConnectedDevicesSummaryResourceId(Context context) {
|
||||
return R.string.settings_label_launcher;
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -25,14 +24,9 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.usage.StorageStatsManager;
|
||||
import android.content.Intent;
|
||||
import android.icu.text.NumberFormat;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||
|
||||
@@ -41,8 +35,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -65,34 +57,6 @@ public class StorageSettingsTest {
|
||||
when(mStorageManagerVolumeProvider.getVolumes()).thenReturn(mVolumes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() throws Exception {
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
StorageSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
|
||||
final VolumeInfo volumeInfo = mVolumes.get(0);
|
||||
when(volumeInfo.isMountedReadable()).thenReturn(true);
|
||||
when(volumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getTotalBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(500L);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getFreeBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(0L);
|
||||
|
||||
ReflectionHelpers
|
||||
.setField(provider, "mStorageManagerVolumeProvider", mStorageManagerVolumeProvider);
|
||||
ReflectionHelpers.setField(provider, "mContext", RuntimeEnvironment.application);
|
||||
|
||||
provider.setListening(true);
|
||||
|
||||
final String percentage = NumberFormat.getPercentInstance().format(1);
|
||||
final String freeSpace = Formatter.formatFileSize(RuntimeEnvironment.application, 0);
|
||||
verify(loader).setSummary(provider,
|
||||
RuntimeEnvironment.application.getString(
|
||||
R.string.storage_summary, percentage, freeSpace));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePublicVolumeClick_startsANonNullActivityWhenVolumeHasNoBrowse() {
|
||||
VolumeInfo volumeInfo = mock(VolumeInfo.class, RETURNS_DEEP_STUBS);
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.usage.StorageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.icu.text.NumberFormat;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class TopLevelStoragePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private StorageManagerVolumeProvider mStorageManagerVolumeProvider;
|
||||
|
||||
private Context mContext;
|
||||
private TopLevelStoragePreferenceController mController;
|
||||
private List<VolumeInfo> mVolumes;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mVolumes = new ArrayList<>();
|
||||
mVolumes.add(mock(VolumeInfo.class, RETURNS_DEEP_STUBS));
|
||||
when(mStorageManagerVolumeProvider.getVolumes()).thenReturn(mVolumes);
|
||||
|
||||
mController = new TopLevelStoragePreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() throws Exception {
|
||||
final VolumeInfo volumeInfo = mVolumes.get(0);
|
||||
when(volumeInfo.isMountedReadable()).thenReturn(true);
|
||||
when(volumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getTotalBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(500L);
|
||||
when(mStorageManagerVolumeProvider
|
||||
.getFreeBytes(nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
|
||||
.thenReturn(0L);
|
||||
|
||||
ReflectionHelpers.setField(mController,
|
||||
"mStorageManagerVolumeProvider", mStorageManagerVolumeProvider);
|
||||
|
||||
final String percentage = NumberFormat.getPercentInstance().format(1);
|
||||
final String freeSpace = Formatter.formatFileSize(RuntimeEnvironment.application, 0);
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
RuntimeEnvironment.application.getString(
|
||||
R.string.storage_summary, percentage, freeSpace));
|
||||
}
|
||||
}
|
@@ -16,7 +16,9 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_ADVANCED_BATTERY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
@@ -40,6 +42,8 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.loader.app.LoaderManager;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.R;
|
||||
@@ -50,7 +54,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -69,8 +72,6 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.loader.app.LoaderManager;
|
||||
|
||||
// TODO: Improve this test class so that it starts up the real activity and fragment.
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
@@ -343,18 +344,6 @@ public class PowerUsageSummaryTest {
|
||||
verify(mFragment).restartBatteryTipLoader();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDashboardLabel_returnsCorrectLabel() {
|
||||
BatteryInfo info = new BatteryInfo();
|
||||
info.batteryPercentString = "3%";
|
||||
assertThat(PowerUsageSummary.getDashboardLabel(mRealContext, info))
|
||||
.isEqualTo(info.batteryPercentString);
|
||||
|
||||
info.remainingLabel = "Phone will shut down soon";
|
||||
assertThat(PowerUsageSummary.getDashboardLabel(mRealContext, info))
|
||||
.isEqualTo("3% - Phone will shut down soon");
|
||||
}
|
||||
|
||||
public static class TestFragment extends PowerUsageSummary {
|
||||
private Context mContext;
|
||||
|
||||
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.android.settings.fuelgauge.TopLevelBatteryPreferenceController.getDashboardLabel;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class TopLevelBatteryPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDashboardLabel_returnsCorrectLabel() {
|
||||
BatteryInfo info = new BatteryInfo();
|
||||
info.batteryPercentString = "3%";
|
||||
assertThat(getDashboardLabel(mContext, info))
|
||||
.isEqualTo(info.batteryPercentString);
|
||||
|
||||
info.remainingLabel = "Phone will shut down soon";
|
||||
assertThat(getDashboardLabel(mContext, info))
|
||||
.isEqualTo("3% - Phone will shut down soon");
|
||||
}
|
||||
}
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.security;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -26,7 +25,6 @@ import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -37,17 +35,15 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SecuritySettingsTest {
|
||||
public class TopLevelSecurityPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
@Mock
|
||||
private FaceManager mFaceManager;
|
||||
private SecuritySettings.SummaryProvider mSummaryProvider;
|
||||
private TopLevelSecurityEntryPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -56,87 +52,80 @@ public class SecuritySettingsTest {
|
||||
.thenReturn(mFingerprintManager);
|
||||
when(mContext.getSystemService(Context.FACE_SERVICE))
|
||||
.thenReturn(mFaceManager);
|
||||
mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
|
||||
mController = new TopLevelSecurityEntryPreferenceController(mContext, "test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_notListening() {
|
||||
mSummaryProvider.setListening(false);
|
||||
|
||||
verifyNoMoreInteractions(mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_hasFace_hasStaticSummary() {
|
||||
public void geSummary_hasFace_hasStaticSummary() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_face);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_face);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
|
||||
public void geSummary_hasFingerPrint_hasStaticSummary() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFpFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFpHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFaceFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFaceFeature_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFaceHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
public void geSummary_noFaceHardware_shouldSetSummaryWithNoBiometrics() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(true);
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
mController.getSummary();
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
verify(mContext).getText(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user