Snap for 7571067 from d7753f4c23
to sc-release
Change-Id: If6f4253be86afbc7967f9316b122a62f8cd604d5
This commit is contained in:
@@ -47,6 +47,7 @@
|
|||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:text="@string/battery_missing_message"
|
android:text="@string/battery_missing_message"
|
||||||
|
android:textColor="@color/battery_info_error_color_black"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem" />
|
android:textAppearance="?android:attr/textAppearanceListItem" />
|
||||||
|
|
||||||
<TextView android:id="@+id/link_text"
|
<TextView android:id="@+id/link_text"
|
||||||
|
@@ -1529,8 +1529,6 @@
|
|||||||
<!-- An allowlist which packages won't show summary in battery usage screen.
|
<!-- An allowlist which packages won't show summary in battery usage screen.
|
||||||
[CHAR LIMIT=NONE] -->
|
[CHAR LIMIT=NONE] -->
|
||||||
<string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
|
<string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
|
||||||
<!-- Google -->
|
|
||||||
<item>"com.google.android.googlequicksearchbox"</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<!-- An allowlist which packages won't show entry in battery usage screen.
|
<!-- An allowlist which packages won't show entry in battery usage screen.
|
||||||
|
@@ -210,4 +210,7 @@
|
|||||||
|
|
||||||
<!-- Material inverse ripple color, useful for inverted backgrounds. -->
|
<!-- Material inverse ripple color, useful for inverted backgrounds. -->
|
||||||
<color name="ripple_material_inverse">@*android:color/ripple_material_dark</color>
|
<color name="ripple_material_inverse">@*android:color/ripple_material_dark</color>
|
||||||
|
|
||||||
|
<!-- Battery error text color -->
|
||||||
|
<color name="battery_info_error_color_black">@*android:color/primary_text_default_material_light</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -24,6 +24,7 @@ import android.hardware.fingerprint.FingerprintManager;
|
|||||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -35,7 +36,9 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.biometrics.BiometricEnrollIntroduction;
|
import com.android.settings.biometrics.BiometricEnrollIntroduction;
|
||||||
import com.android.settings.biometrics.BiometricUtils;
|
import com.android.settings.biometrics.BiometricUtils;
|
||||||
|
import com.android.settings.biometrics.MultiBiometricEnrollHelper;
|
||||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||||
|
import com.android.settings.password.SetupSkipDialog;
|
||||||
import com.android.settingslib.HelpUtils;
|
import com.android.settingslib.HelpUtils;
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
|
|
||||||
@@ -89,6 +92,32 @@ public class FingerprintEnrollIntroduction extends BiometricEnrollIntroduction {
|
|||||||
footerTitle2.setText(getFooterTitle2());
|
footerTitle2.setText(getFooterTitle2());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
// If user has skipped or finished enrolling, don't restart enrollment.
|
||||||
|
final boolean isEnrollRequest = requestCode == BIOMETRIC_FIND_SENSOR_REQUEST
|
||||||
|
|| requestCode == ENROLL_NEXT_BIOMETRIC_REQUEST;
|
||||||
|
final boolean isResultSkipOrFinished = resultCode == RESULT_SKIP
|
||||||
|
|| resultCode == SetupSkipDialog.RESULT_SKIP || resultCode == RESULT_FINISHED;
|
||||||
|
if (isEnrollRequest && isResultSkipOrFinished) {
|
||||||
|
data = setSkipPendingEnroll(data);
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCancelButtonClick(View view) {
|
||||||
|
// User has explicitly canceled enroll. Don't restart it automatically.
|
||||||
|
Intent data = setSkipPendingEnroll(new Intent());
|
||||||
|
setResult(RESULT_SKIP, data);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSkipButtonClick(View view) {
|
||||||
|
onCancelButtonClick(view);
|
||||||
|
}
|
||||||
|
|
||||||
@StringRes
|
@StringRes
|
||||||
int getNegativeButtonTextId() {
|
int getNegativeButtonTextId() {
|
||||||
return R.string.security_settings_fingerprint_enroll_introduction_no_thanks;
|
return R.string.security_settings_fingerprint_enroll_introduction_no_thanks;
|
||||||
@@ -282,4 +311,13 @@ public class FingerprintEnrollIntroduction extends BiometricEnrollIntroduction {
|
|||||||
protected int getMoreButtonTextRes() {
|
protected int getMoreButtonTextRes() {
|
||||||
return R.string.security_settings_face_enroll_introduction_more;
|
return R.string.security_settings_face_enroll_introduction_more;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected static Intent setSkipPendingEnroll(@Nullable Intent data) {
|
||||||
|
if (data == null) {
|
||||||
|
data = new Intent();
|
||||||
|
}
|
||||||
|
data.putExtra(MultiBiometricEnrollHelper.EXTRA_SKIP_PENDING_ENROLL, true);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,6 @@ import com.android.internal.widget.LockPatternUtils;
|
|||||||
import com.android.settings.SetupWizardUtils;
|
import com.android.settings.SetupWizardUtils;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.biometrics.BiometricUtils;
|
import com.android.settings.biometrics.BiometricUtils;
|
||||||
import com.android.settings.biometrics.MultiBiometricEnrollHelper;
|
|
||||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||||
import com.android.settings.password.SetupChooseLockGeneric;
|
import com.android.settings.password.SetupChooseLockGeneric;
|
||||||
import com.android.settings.password.SetupSkipDialog;
|
import com.android.settings.password.SetupSkipDialog;
|
||||||
@@ -85,16 +84,6 @@ public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntrodu
|
|||||||
data = setFingerprintCount(data);
|
data = setFingerprintCount(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If user has skipped or finished enrolling, don't restart enrollment.
|
|
||||||
final boolean isEnrollRequest = requestCode == BIOMETRIC_FIND_SENSOR_REQUEST
|
|
||||||
|| requestCode == ENROLL_NEXT_BIOMETRIC_REQUEST;
|
|
||||||
final boolean isResultSkipOrFinished = resultCode == RESULT_SKIP
|
|
||||||
|| resultCode == SetupSkipDialog.RESULT_SKIP || resultCode == RESULT_FINISHED;
|
|
||||||
if (isEnrollRequest && isResultSkipOrFinished) {
|
|
||||||
data = setSkipPendingEnroll(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,14 +111,6 @@ public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntrodu
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent setSkipPendingEnroll(Intent data) {
|
|
||||||
if (data == null) {
|
|
||||||
data = new Intent();
|
|
||||||
}
|
|
||||||
data.putExtra(MultiBiometricEnrollHelper.EXTRA_SKIP_PENDING_ENROLL, true);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCancelButtonClick(View view) {
|
protected void onCancelButtonClick(View view) {
|
||||||
final int resultCode;
|
final int resultCode;
|
||||||
@@ -151,11 +132,6 @@ public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntrodu
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSkipButtonClick(View view) {
|
|
||||||
onCancelButtonClick(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Propagate lock screen metrics if the user goes back from the fingerprint setup screen
|
* Propagate lock screen metrics if the user goes back from the fingerprint setup screen
|
||||||
* after having added lock screen to his device.
|
* after having added lock screen to his device.
|
||||||
|
@@ -332,9 +332,12 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
|
|
||||||
mTrapezoidIndex = trapezoidIndex;
|
mTrapezoidIndex = trapezoidIndex;
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
|
final long start = System.currentTimeMillis();
|
||||||
removeAndCacheAllPrefs();
|
removeAndCacheAllPrefs();
|
||||||
addAllPreferences();
|
addAllPreferences();
|
||||||
refreshCategoryTitle();
|
refreshCategoryTitle();
|
||||||
|
Log.d(TAG, String.format("refreshUi is finished in %d/ms",
|
||||||
|
(System.currentTimeMillis() - start)));
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -572,7 +572,8 @@ public class BatteryEntry {
|
|||||||
name = context.getResources().getString(R.string.process_kernel_label);
|
name = context.getResources().getString(R.string.process_kernel_label);
|
||||||
} else if ("mediaserver".equals(name)) {
|
} else if ("mediaserver".equals(name)) {
|
||||||
name = context.getResources().getString(R.string.process_mediaserver_label);
|
name = context.getResources().getString(R.string.process_mediaserver_label);
|
||||||
} else if ("dex2oat".equals(name)) {
|
} else if ("dex2oat".equals(name) || "dex2oat32".equals(name) ||
|
||||||
|
"dex2oat64".equals(name)) {
|
||||||
name = context.getResources().getString(R.string.process_dex2oat_label);
|
name = context.getResources().getString(R.string.process_dex2oat_label);
|
||||||
}
|
}
|
||||||
return new NameAndIcon(name, icon, 0 /* iconId */);
|
return new NameAndIcon(name, icon, 0 /* iconId */);
|
||||||
|
@@ -145,13 +145,17 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
final Map<Uri, SliceBackgroundWorker> mPinnedWorkers = new ArrayMap<>();
|
final Map<Uri, SliceBackgroundWorker> mPinnedWorkers = new ArrayMap<>();
|
||||||
|
|
||||||
private Boolean mNightMode;
|
private Boolean mNightMode;
|
||||||
|
private boolean mFirstSlicePinned;
|
||||||
|
private boolean mFirstSliceBound;
|
||||||
|
|
||||||
public SettingsSliceProvider() {
|
public SettingsSliceProvider() {
|
||||||
super(READ_SEARCH_INDEXABLES);
|
super(READ_SEARCH_INDEXABLES);
|
||||||
|
Log.d(TAG, "init");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateSliceProvider() {
|
public boolean onCreateSliceProvider() {
|
||||||
|
Log.d(TAG, "onCreateSliceProvider");
|
||||||
mSlicesDatabaseAccessor = new SlicesDatabaseAccessor(getContext());
|
mSlicesDatabaseAccessor = new SlicesDatabaseAccessor(getContext());
|
||||||
mSliceWeakDataCache = new WeakHashMap<>();
|
mSliceWeakDataCache = new WeakHashMap<>();
|
||||||
return true;
|
return true;
|
||||||
@@ -159,6 +163,10 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlicePinned(Uri sliceUri) {
|
public void onSlicePinned(Uri sliceUri) {
|
||||||
|
if (!mFirstSlicePinned) {
|
||||||
|
Log.d(TAG, "onSlicePinned: " + sliceUri);
|
||||||
|
mFirstSlicePinned = true;
|
||||||
|
}
|
||||||
if (CustomSliceRegistry.isValidUri(sliceUri)) {
|
if (CustomSliceRegistry.isValidUri(sliceUri)) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final CustomSliceable sliceable = FeatureFactory.getFactory(context)
|
final CustomSliceable sliceable = FeatureFactory.getFactory(context)
|
||||||
@@ -194,6 +202,9 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Slice onBindSlice(Uri sliceUri) {
|
public Slice onBindSlice(Uri sliceUri) {
|
||||||
|
if (!mFirstSliceBound) {
|
||||||
|
Log.d(TAG, "onBindSlice start: " + sliceUri);
|
||||||
|
}
|
||||||
final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
|
final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
|
||||||
try {
|
try {
|
||||||
if (!ThreadUtils.isMainThread()) {
|
if (!ThreadUtils.isMainThread()) {
|
||||||
@@ -261,6 +272,10 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
return SliceBuilderUtils.buildSlice(getContext(), cachedSliceData);
|
return SliceBuilderUtils.buildSlice(getContext(), cachedSliceData);
|
||||||
} finally {
|
} finally {
|
||||||
StrictMode.setThreadPolicy(oldPolicy);
|
StrictMode.setThreadPolicy(oldPolicy);
|
||||||
|
if (!mFirstSliceBound) {
|
||||||
|
Log.v(TAG, "onBindSlice end");
|
||||||
|
mFirstSliceBound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
|
|
||||||
@@ -72,11 +73,14 @@ public class BatteryAppListPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
final Resources resources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(resources);
|
||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
|
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
|
||||||
|
when(resources.getTextArray(R.array.allowlist_hide_summary_in_battery_usage))
|
||||||
|
.thenReturn(new String[] {"com.android.googlequicksearchbox"});
|
||||||
FakeFeatureFactory.setupForTest();
|
FakeFeatureFactory.setupForTest();
|
||||||
|
|
||||||
mPreference = new PowerGaugePreference(mContext);
|
mPreference = new PowerGaugePreference(mContext);
|
||||||
@@ -119,7 +123,7 @@ public class BatteryAppListPreferenceControllerTest {
|
|||||||
public void testSetUsageSummary_timeMoreThanOneMinute_GoogleApp_shouldNotSetScreenSummary() {
|
public void testSetUsageSummary_timeMoreThanOneMinute_GoogleApp_shouldNotSetScreenSummary() {
|
||||||
when(mBatteryEntry.getTimeInForegroundMs()).thenReturn(2 * DateUtils.MINUTE_IN_MILLIS);
|
when(mBatteryEntry.getTimeInForegroundMs()).thenReturn(2 * DateUtils.MINUTE_IN_MILLIS);
|
||||||
when(mBatteryEntry.getDefaultPackageName())
|
when(mBatteryEntry.getDefaultPackageName())
|
||||||
.thenReturn("com.google.android.googlequicksearchbox");
|
.thenReturn("com.android.googlequicksearchbox");
|
||||||
doReturn(mContext.getText(R.string.battery_used_for)).when(mFragment).getText(
|
doReturn(mContext.getText(R.string.battery_used_for)).when(mFragment).getText(
|
||||||
R.string.battery_used_for);
|
R.string.battery_used_for);
|
||||||
doReturn(mContext).when(mFragment).getContext();
|
doReturn(mContext).when(mFragment).getContext();
|
||||||
|
@@ -101,8 +101,11 @@ public final class BatteryChartPreferenceControllerTest {
|
|||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mContext.getResources().getConfiguration().setLocales(
|
final Resources resources = spy(mContext.getResources());
|
||||||
new LocaleList(new Locale("en_US")));
|
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
|
||||||
|
doReturn(resources).when(mContext).getResources();
|
||||||
|
doReturn(new String[] {"com.android.googlequicksearchbox"})
|
||||||
|
.when(resources).getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
|
||||||
mBatteryChartPreferenceController = createController();
|
mBatteryChartPreferenceController = createController();
|
||||||
mBatteryChartPreferenceController.mPrefContext = mContext;
|
mBatteryChartPreferenceController.mPrefContext = mContext;
|
||||||
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
|
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
|
||||||
@@ -467,7 +470,7 @@ public final class BatteryChartPreferenceControllerTest {
|
|||||||
spy(createBatteryDiffEntry(
|
spy(createBatteryDiffEntry(
|
||||||
/*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
|
/*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
|
||||||
/*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
|
/*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
|
||||||
doReturn("com.google.android.googlequicksearchbox").when(batteryDiffEntry)
|
doReturn("com.android.googlequicksearchbox").when(batteryDiffEntry)
|
||||||
.getPackageName();
|
.getPackageName();
|
||||||
|
|
||||||
mBatteryChartPreferenceController.setPreferenceSummary(pref, batteryDiffEntry);
|
mBatteryChartPreferenceController.setPreferenceSummary(pref, batteryDiffEntry);
|
||||||
@@ -678,7 +681,7 @@ public final class BatteryChartPreferenceControllerTest {
|
|||||||
|
|
||||||
// Verifies the item which is defined in the array list.
|
// Verifies the item which is defined in the array list.
|
||||||
assertThat(mBatteryChartPreferenceController
|
assertThat(mBatteryChartPreferenceController
|
||||||
.isValidToShowSummary("com.google.android.googlequicksearchbox"))
|
.isValidToShowSummary("com.android.googlequicksearchbox"))
|
||||||
.isFalse();
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
|||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
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;
|
||||||
@@ -36,6 +37,7 @@ import android.os.UserBatteryConsumer;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.fuelgauge.BatteryEntry.NameAndIcon;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -64,6 +66,7 @@ public class BatteryEntryTest {
|
|||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private Context mMockContext;
|
private Context mMockContext;
|
||||||
|
private Context mContext;
|
||||||
@Mock private Handler mockHandler;
|
@Mock private Handler mockHandler;
|
||||||
@Mock private PackageManager mockPackageManager;
|
@Mock private PackageManager mockPackageManager;
|
||||||
@Mock private UserManager mockUserManager;
|
@Mock private UserManager mockUserManager;
|
||||||
@@ -71,6 +74,7 @@ public class BatteryEntryTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void stubContextToReturnMockPackageManager() {
|
public void stubContextToReturnMockPackageManager() {
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mMockContext.getPackageManager()).thenReturn(mockPackageManager);
|
when(mMockContext.getPackageManager()).thenReturn(mockPackageManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,4 +252,77 @@ public class BatteryEntryTest {
|
|||||||
final String key = entry.getKey();
|
final String key = entry.getKey();
|
||||||
assertThat(key).isEqualTo("U|2");
|
assertThat(key).isEqualTo("U|2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNameAndIconFromUserId_nullUserInfo_returnDefaultNameAndIcon() {
|
||||||
|
final int userId = 1001;
|
||||||
|
doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class);
|
||||||
|
doReturn(null).when(mockUserManager).getUserInfo(userId);
|
||||||
|
|
||||||
|
final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUserId(
|
||||||
|
mContext, userId);
|
||||||
|
assertThat(nameAndIcon.name).isEqualTo(getString(
|
||||||
|
R.string.running_process_item_removed_user_label));
|
||||||
|
assertThat(nameAndIcon.icon).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNameAndIconFromUid_rerturnExpectedName() {
|
||||||
|
final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUid(
|
||||||
|
mContext, /* name */ null, /* uid */ 0);
|
||||||
|
assertThat(nameAndIcon.name).isEqualTo(getString(R.string.process_kernel_label));
|
||||||
|
|
||||||
|
assertNameAndIcon("mediaserver", R.string.process_mediaserver_label);
|
||||||
|
assertNameAndIcon("dex2oat32", R.string.process_dex2oat_label);
|
||||||
|
assertNameAndIcon("dex2oat64", R.string.process_dex2oat_label);
|
||||||
|
assertNameAndIcon("dex2oat", R.string.process_dex2oat_label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNameAndIconFromPowerComponent_rerturnExpectedNameAndIcon() {
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY,
|
||||||
|
R.string.ambient_display_screen_title,
|
||||||
|
R.drawable.ic_settings_aod);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_BLUETOOTH,
|
||||||
|
R.string.power_bluetooth,
|
||||||
|
com.android.internal.R.drawable.ic_settings_bluetooth);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_CAMERA,
|
||||||
|
R.string.power_camera,
|
||||||
|
R.drawable.ic_settings_camera);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
|
||||||
|
R.string.power_cell,
|
||||||
|
R.drawable.ic_cellular_1_bar);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_FLASHLIGHT,
|
||||||
|
R.string.power_flashlight,
|
||||||
|
R.drawable.ic_settings_display);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_PHONE,
|
||||||
|
R.string.power_phone,
|
||||||
|
R.drawable.ic_settings_voice_calls);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_SCREEN,
|
||||||
|
R.string.power_screen,
|
||||||
|
R.drawable.ic_settings_display);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_WIFI,
|
||||||
|
R.string.power_wifi,
|
||||||
|
R.drawable.ic_settings_wireless);
|
||||||
|
assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_IDLE,
|
||||||
|
R.string.power_idle,
|
||||||
|
R.drawable.ic_settings_phone_idle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertNameAndIcon(String name, int stringId) {
|
||||||
|
final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUid(
|
||||||
|
mContext, name, /* uid */ 1000);
|
||||||
|
assertThat(nameAndIcon.name).isEqualTo(getString(stringId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertNameAndIcon(int powerComponentId, int stringId, int iconId) {
|
||||||
|
final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromPowerComponent(
|
||||||
|
mContext, powerComponentId);
|
||||||
|
assertThat(nameAndIcon.name).isEqualTo(getString(stringId));
|
||||||
|
assertThat(nameAndIcon.iconId).isEqualTo(iconId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getString(int stringId) {
|
||||||
|
return mContext.getResources().getString(stringId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user