Snap for 7311204 from 219dabcabf to sc-release
Change-Id: I329172037d9fadfcf4de0bb2a131c67cd83526c4
This commit is contained in:
@@ -42,6 +42,15 @@
|
|||||||
android:key="recent_notifications_category"
|
android:key="recent_notifications_category"
|
||||||
android:title="@string/recent_notifications">
|
android:title="@string/recent_notifications">
|
||||||
<!-- Placeholder for a list of recent apps -->
|
<!-- Placeholder for a list of recent apps -->
|
||||||
|
<com.android.settings.widget.PrimarySwitchPreference
|
||||||
|
android:key="app1"
|
||||||
|
android:order="5"/>
|
||||||
|
<com.android.settings.widget.PrimarySwitchPreference
|
||||||
|
android:key="app2"
|
||||||
|
android:order="6"/>
|
||||||
|
<com.android.settings.widget.PrimarySwitchPreference
|
||||||
|
android:key="app3"
|
||||||
|
android:order="7"/>
|
||||||
|
|
||||||
<!-- See all apps button -->
|
<!-- See all apps button -->
|
||||||
<Preference
|
<Preference
|
||||||
|
|||||||
@@ -20,13 +20,15 @@ import static com.android.settingslib.display.BrightnessUtils.convertLinearToGam
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
import android.hardware.display.BrightnessInfo;
|
||||||
|
import android.hardware.display.DisplayManager;
|
||||||
|
import android.hardware.display.DisplayManager.DisplayListener;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.provider.Settings.System;
|
import android.provider.Settings.System;
|
||||||
import android.service.vr.IVrManager;
|
import android.service.vr.IVrManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -49,42 +51,53 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
|
|||||||
|
|
||||||
private static final String TAG = "BrightnessPrefCtrl";
|
private static final String TAG = "BrightnessPrefCtrl";
|
||||||
private static final String KEY_BRIGHTNESS = "brightness";
|
private static final String KEY_BRIGHTNESS = "brightness";
|
||||||
private static final Uri BRIGHTNESS_URI;
|
|
||||||
private static final Uri BRIGHTNESS_FOR_VR_URI;
|
private static final Uri BRIGHTNESS_FOR_VR_URI;
|
||||||
private static final Uri BRIGHTNESS_ADJ_URI;
|
private static final Uri BRIGHTNESS_ADJ_URI;
|
||||||
|
|
||||||
private final float mMinBrightness;
|
|
||||||
private final float mMaxBrightness;
|
|
||||||
private final float mMinVrBrightness;
|
private final float mMinVrBrightness;
|
||||||
private final float mMaxVrBrightness;
|
private final float mMaxVrBrightness;
|
||||||
private final ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
|
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
|
private final DisplayManager mDisplayManager;
|
||||||
|
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
BRIGHTNESS_URI = System.getUriFor(System.SCREEN_BRIGHTNESS_FLOAT);
|
|
||||||
BRIGHTNESS_FOR_VR_URI = System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR);
|
BRIGHTNESS_FOR_VR_URI = System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR);
|
||||||
BRIGHTNESS_ADJ_URI = System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ);
|
BRIGHTNESS_ADJ_URI = System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContentObserver mBrightnessObserver =
|
private ContentObserver mBrightnessObserver =
|
||||||
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
new ContentObserver(mHandler) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange) {
|
public void onChange(boolean selfChange) {
|
||||||
updatedSummary(mPreference);
|
updatedSummary(mPreference);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final DisplayListener mDisplayListener = new DisplayListener() {
|
||||||
|
@Override
|
||||||
|
public void onDisplayAdded(int displayId) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisplayRemoved(int displayId) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisplayChanged(int displayId) {
|
||||||
|
updatedSummary(mPreference);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
|
public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mDisplayManager = context.getSystemService(DisplayManager.class);
|
||||||
|
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
final PowerManager powerManager = context.getSystemService(PowerManager.class);
|
||||||
mMinBrightness = powerManager.getBrightnessConstraint(
|
|
||||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
|
|
||||||
mMaxBrightness = powerManager.getBrightnessConstraint(
|
|
||||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
|
|
||||||
mMinVrBrightness = powerManager.getBrightnessConstraint(
|
mMinVrBrightness = powerManager.getBrightnessConstraint(
|
||||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR);
|
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR);
|
||||||
mMaxVrBrightness = powerManager.getBrightnessConstraint(
|
mMaxVrBrightness = powerManager.getBrightnessConstraint(
|
||||||
@@ -115,14 +128,16 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mContentResolver.registerContentObserver(BRIGHTNESS_URI, false, mBrightnessObserver);
|
|
||||||
mContentResolver.registerContentObserver(BRIGHTNESS_FOR_VR_URI, false, mBrightnessObserver);
|
mContentResolver.registerContentObserver(BRIGHTNESS_FOR_VR_URI, false, mBrightnessObserver);
|
||||||
mContentResolver.registerContentObserver(BRIGHTNESS_ADJ_URI, false, mBrightnessObserver);
|
mContentResolver.registerContentObserver(BRIGHTNESS_ADJ_URI, false, mBrightnessObserver);
|
||||||
|
mDisplayManager.registerDisplayListener(mDisplayListener, mHandler,
|
||||||
|
DisplayManager.EVENT_FLAG_DISPLAY_BRIGHTNESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mContentResolver.unregisterContentObserver(mBrightnessObserver);
|
mContentResolver.unregisterContentObserver(mBrightnessObserver);
|
||||||
|
mDisplayManager.unregisterDisplayListener(mDisplayListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatedSummary(Preference preference) {
|
private void updatedSummary(Preference preference) {
|
||||||
@@ -132,15 +147,17 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double getCurrentBrightness() {
|
private double getCurrentBrightness() {
|
||||||
final int value;
|
int value = 0;
|
||||||
if (isInVrMode()) {
|
if (isInVrMode()) {
|
||||||
value = convertLinearToGammaFloat(System.getFloat(mContentResolver,
|
value = convertLinearToGammaFloat(System.getFloat(mContentResolver,
|
||||||
System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT, mMaxBrightness),
|
System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT, mMaxVrBrightness),
|
||||||
mMinVrBrightness, mMaxVrBrightness);
|
mMinVrBrightness, mMaxVrBrightness);
|
||||||
} else {
|
} else {
|
||||||
value = convertLinearToGammaFloat(Settings.System.getFloat(mContentResolver,
|
final BrightnessInfo info = mContext.getDisplay().getBrightnessInfo();
|
||||||
System.SCREEN_BRIGHTNESS_FLOAT, mMinBrightness),
|
if (info != null) {
|
||||||
mMinBrightness, mMaxBrightness);
|
value = convertLinearToGammaFloat(info.brightness, info.brightnessMinimum,
|
||||||
|
info.brightnessMaximum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getPercentage(value, GAMMA_SPACE_MIN, GAMMA_SPACE_MAX);
|
return getPercentage(value, GAMMA_SPACE_MIN, GAMMA_SPACE_MAX);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Sets the chart is clickable if there is at least one valid item in it.
|
// Sets the chart is clickable if there is at least one valid item in it.
|
||||||
for (int index = 0; index < mLevels.length; index++) {
|
for (int index = 0; index < mLevels.length - 1; index++) {
|
||||||
if (mLevels[index] != 0) {
|
if (mLevels[index] != 0 && mLevels[index + 1] != 0) {
|
||||||
setClickable(true);
|
setClickable(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -155,6 +155,11 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int trapezoidIndex = getTrapezoidIndex(mTouchUpEvent.getX());
|
final int trapezoidIndex = getTrapezoidIndex(mTouchUpEvent.getX());
|
||||||
|
// Ignores the click event if the level is zero.
|
||||||
|
if (trapezoidIndex == SELECTED_INDEX_INVALID
|
||||||
|
|| (trapezoidIndex >= 0 && mLevels[trapezoidIndex] == 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Selects all if users click the same trapezoid item two times.
|
// Selects all if users click the same trapezoid item two times.
|
||||||
if (trapezoidIndex == mSelectedIndex) {
|
if (trapezoidIndex == mSelectedIndex) {
|
||||||
setSelectedIndex(SELECTED_INDEX_ALL);
|
setSelectedIndex(SELECTED_INDEX_ALL);
|
||||||
|
|||||||
@@ -70,8 +70,12 @@ public final class ConvertUtils {
|
|||||||
public static final int CONSUMER_TYPE_SYSTEM_BATTERY = 3;
|
public static final int CONSUMER_TYPE_SYSTEM_BATTERY = 3;
|
||||||
|
|
||||||
private static String sZoneId;
|
private static String sZoneId;
|
||||||
private static SimpleDateFormat sSimpleDateFormat;
|
private static String sZoneIdForHour;
|
||||||
private static SimpleDateFormat sSimpleDateFormatForHour;
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static SimpleDateFormat sSimpleDateFormat;
|
||||||
|
@VisibleForTesting
|
||||||
|
static SimpleDateFormat sSimpleDateFormatForHour;
|
||||||
|
|
||||||
private ConvertUtils() {}
|
private ConvertUtils() {}
|
||||||
|
|
||||||
@@ -140,25 +144,19 @@ public final class ConvertUtils {
|
|||||||
sZoneId = currentZoneId;
|
sZoneId = currentZoneId;
|
||||||
sSimpleDateFormat =
|
sSimpleDateFormat =
|
||||||
new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", Locale.ENGLISH);
|
new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", Locale.ENGLISH);
|
||||||
sSimpleDateFormatForHour = null;
|
|
||||||
}
|
}
|
||||||
return sSimpleDateFormat.format(new Date(timestamp));
|
return sSimpleDateFormat.format(new Date(timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Converts UTC timestamp to local time hour data. */
|
/** Converts UTC timestamp to local time hour data. */
|
||||||
public static int utcToLocalTimeHour(long timestamp) {
|
public static String utcToLocalTimeHour(long timestamp) {
|
||||||
final String currentZoneId = TimeZone.getDefault().getID();
|
final String currentZoneId = TimeZone.getDefault().getID();
|
||||||
if (!currentZoneId.equals(sZoneId) || sSimpleDateFormatForHour == null) {
|
if (!currentZoneId.equals(sZoneIdForHour) || sSimpleDateFormatForHour == null) {
|
||||||
sZoneId = currentZoneId;
|
sZoneIdForHour = currentZoneId;
|
||||||
sSimpleDateFormat = null;
|
sSimpleDateFormatForHour = new SimpleDateFormat("h aa", Locale.ENGLISH);
|
||||||
sSimpleDateFormatForHour = new SimpleDateFormat("HH", Locale.ENGLISH);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(
|
|
||||||
sSimpleDateFormatForHour.format(new Date(timestamp)));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return Integer.MIN_VALUE;
|
|
||||||
}
|
}
|
||||||
|
return sSimpleDateFormatForHour.format(new Date(timestamp))
|
||||||
|
.toLowerCase(Locale.getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets indexed battery usage data for each corresponding time slot. */
|
/** Gets indexed battery usage data for each corresponding time slot. */
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import com.android.settings.widget.PrimarySwitchPreference;
|
|||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.utils.StringUtil;
|
import com.android.settingslib.utils.StringUtil;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
import com.android.settingslib.widget.TwoTargetPreference;
|
import com.android.settingslib.widget.TwoTargetPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -70,9 +71,9 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String KEY_SEE_ALL = "all_notifications";
|
static final String KEY_SEE_ALL = "all_notifications";
|
||||||
|
static final String KEY_PLACEHOLDER = "app";
|
||||||
private static final int SHOW_RECENT_APP_COUNT = 3;
|
private static final int SHOW_RECENT_APP_COUNT = 3;
|
||||||
private static final int DAYS = 3;
|
private static final int DAYS = 3;
|
||||||
private static final Set<String> SKIP_SYSTEM_PACKAGES = new ArraySet<>();
|
|
||||||
|
|
||||||
private final Fragment mHost;
|
private final Fragment mHost;
|
||||||
private final PackageManager mPm;
|
private final PackageManager mPm;
|
||||||
@@ -148,13 +149,17 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void refreshUi(Context prefContext) {
|
void refreshUi(Context prefContext) {
|
||||||
reloadData();
|
ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
final List<NotifyingApp> recentApps = getDisplayableRecentAppList();
|
reloadData();
|
||||||
if (recentApps != null && !recentApps.isEmpty()) {
|
final List<NotifyingApp> recentApps = getDisplayableRecentAppList();
|
||||||
displayRecentApps(prefContext, recentApps);
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
} else {
|
if (recentApps != null && !recentApps.isEmpty()) {
|
||||||
displayOnlyAllAppsLink();
|
displayRecentApps(prefContext, recentApps);
|
||||||
}
|
} else {
|
||||||
|
displayOnlyAllAppsLink();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -198,8 +203,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
private static String getKey(int userId, String pkg) {
|
||||||
static String getKey(int userId, String pkg) {
|
|
||||||
return userId + "|" + pkg;
|
return userId + "|" + pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,19 +225,9 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
mSeeAllPref.setSummary(null);
|
mSeeAllPref.setSummary(null);
|
||||||
mSeeAllPref.setIcon(R.drawable.ic_chevron_right_24dp);
|
mSeeAllPref.setIcon(R.drawable.ic_chevron_right_24dp);
|
||||||
|
|
||||||
// Rebind prefs/avoid adding new prefs if possible. Adding/removing prefs causes jank.
|
int keyIndex = 1;
|
||||||
// Build a cached preference pool
|
|
||||||
final Map<String, PrimarySwitchPreference> appPreferences = new ArrayMap<>();
|
|
||||||
int prefCount = mCategory.getPreferenceCount();
|
|
||||||
for (int i = 0; i < prefCount; i++) {
|
|
||||||
final Preference pref = mCategory.getPreference(i);
|
|
||||||
final String key = pref.getKey();
|
|
||||||
if (!TextUtils.equals(key, KEY_SEE_ALL)) {
|
|
||||||
appPreferences.put(key, (PrimarySwitchPreference) pref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final int recentAppsCount = recentApps.size();
|
final int recentAppsCount = recentApps.size();
|
||||||
for (int i = 0; i < recentAppsCount; i++) {
|
for (int i = 0; i < recentAppsCount; i++, keyIndex++) {
|
||||||
final NotifyingApp app = recentApps.get(i);
|
final NotifyingApp app = recentApps.get(i);
|
||||||
// Bind recent apps to existing prefs if possible, or create a new pref.
|
// Bind recent apps to existing prefs if possible, or create a new pref.
|
||||||
final String pkgName = app.getPackage();
|
final String pkgName = app.getPackage();
|
||||||
@@ -243,20 +237,12 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean rebindPref = true;
|
PrimarySwitchPreference pref = mCategory.findPreference(KEY_PLACEHOLDER + keyIndex);
|
||||||
PrimarySwitchPreference pref = appPreferences.remove(getKey(app.getUserId(),
|
|
||||||
pkgName));
|
|
||||||
if (pref == null) {
|
|
||||||
pref = new PrimarySwitchPreference(prefContext);
|
|
||||||
rebindPref = false;
|
|
||||||
}
|
|
||||||
pref.setKey(getKey(app.getUserId(), pkgName));
|
|
||||||
pref.setTitle(appEntry.label);
|
pref.setTitle(appEntry.label);
|
||||||
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
|
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
|
||||||
pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL);
|
pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL);
|
||||||
pref.setSummary(StringUtil.formatRelativeTime(mContext,
|
pref.setSummary(StringUtil.formatRelativeTime(mContext,
|
||||||
System.currentTimeMillis() - app.getLastNotified(), true));
|
System.currentTimeMillis() - app.getLastNotified(), true));
|
||||||
pref.setOrder(i);
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
|
args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
|
||||||
args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid);
|
args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid);
|
||||||
@@ -280,13 +266,10 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
pref.setChecked(
|
pref.setChecked(
|
||||||
!mNotificationBackend.getNotificationsBanned(pkgName, appEntry.info.uid));
|
!mNotificationBackend.getNotificationsBanned(pkgName, appEntry.info.uid));
|
||||||
|
|
||||||
if (!rebindPref) {
|
|
||||||
mCategory.addPreference(pref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Remove unused prefs from pref cache pool
|
// If there are less than SHOW_RECENT_APP_COUNT recent apps, remove placeholders
|
||||||
for (Preference unusedPrefs : appPreferences.values()) {
|
for (int i = keyIndex; i <= SHOW_RECENT_APP_COUNT; i++) {
|
||||||
mCategory.removePreference(unusedPrefs);
|
mCategory.removePreferenceRecursively(KEY_PLACEHOLDER + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,15 +22,16 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.reset;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
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.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.hardware.display.BrightnessInfo;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings.System;
|
import android.provider.Settings.System;
|
||||||
|
import android.view.Display;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -52,6 +53,8 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PowerManager mPowerManager;
|
private PowerManager mPowerManager;
|
||||||
@Mock
|
@Mock
|
||||||
|
private Display mDisplay;
|
||||||
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
@@ -65,7 +68,7 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mContentResolver = mContext.getContentResolver();
|
mContentResolver = mContext.getContentResolver();
|
||||||
when(mPowerManager.getBrightnessConstraint(
|
when(mPowerManager.getBrightnessConstraint(
|
||||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM)).thenReturn(0.0f);
|
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM)).thenReturn(0.0f);
|
||||||
@@ -78,6 +81,7 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
ShadowApplication.getInstance().setSystemService(POWER_SERVICE,
|
ShadowApplication.getInstance().setSystemService(POWER_SERVICE,
|
||||||
mPowerManager);
|
mPowerManager);
|
||||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||||
|
when(mContext.getDisplay()).thenReturn(mDisplay);
|
||||||
mController = spy(new BrightnessLevelPreferenceController(mContext, null));
|
mController = spy(new BrightnessLevelPreferenceController(mContext, null));
|
||||||
doReturn(false).when(mController).isInVrMode();
|
doReturn(false).when(mController).isInVrMode();
|
||||||
}
|
}
|
||||||
@@ -101,8 +105,6 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
|
|
||||||
controller.onStart();
|
controller.onStart();
|
||||||
|
|
||||||
assertThat(shadowContentResolver.getContentObservers(
|
|
||||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FLOAT))).isNotEmpty();
|
|
||||||
assertThat(shadowContentResolver.getContentObservers(
|
assertThat(shadowContentResolver.getContentObservers(
|
||||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty();
|
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty();
|
||||||
assertThat(shadowContentResolver.getContentObservers(
|
assertThat(shadowContentResolver.getContentObservers(
|
||||||
@@ -119,8 +121,6 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
controller.onStart();
|
controller.onStart();
|
||||||
controller.onStop();
|
controller.onStop();
|
||||||
|
|
||||||
assertThat(shadowContentResolver.getContentObservers(
|
|
||||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FLOAT))).isEmpty();
|
|
||||||
assertThat(shadowContentResolver.getContentObservers(
|
assertThat(shadowContentResolver.getContentObservers(
|
||||||
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT))).isEmpty();
|
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT))).isEmpty();
|
||||||
assertThat(shadowContentResolver.getContentObservers(
|
assertThat(shadowContentResolver.getContentObservers(
|
||||||
@@ -143,7 +143,8 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||||
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||||
|
|
||||||
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FLOAT, 0.1f);
|
when(mDisplay.getBrightnessInfo()).thenReturn(
|
||||||
|
new BrightnessInfo(0.1f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF));
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -156,7 +157,8 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||||
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||||
|
|
||||||
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FLOAT, 0.5f);
|
when(mDisplay.getBrightnessInfo()).thenReturn(
|
||||||
|
new BrightnessInfo(0.5f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF));
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -175,32 +177,5 @@ public class BrightnessLevelPreferenceControllerTest {
|
|||||||
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT, -20f);
|
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT, -20f);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
verify(mPreference).setSummary("0%");
|
verify(mPreference).setSummary("0%");
|
||||||
|
|
||||||
// Auto mode
|
|
||||||
doReturn(false).when(mController).isInVrMode();
|
|
||||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
|
||||||
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
|
||||||
|
|
||||||
reset(mPreference);
|
|
||||||
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FLOAT, 1.15f);
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
verify(mPreference).setSummary("100%");
|
|
||||||
|
|
||||||
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FLOAT, -10f);
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
verify(mPreference).setSummary("0%");
|
|
||||||
|
|
||||||
// Manual mode
|
|
||||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
|
||||||
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
|
||||||
|
|
||||||
reset(mPreference);
|
|
||||||
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FLOAT, 1.15f);
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
verify(mPreference).setSummary("100%");
|
|
||||||
|
|
||||||
System.putFloat(mContentResolver, System.SCREEN_BRIGHTNESS_FLOAT, -10f);
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
verify(mPreference).setSummary("0%");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,10 +39,12 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
@@ -254,6 +256,32 @@ public final class ConvertUtilsTest {
|
|||||||
assertBatteryDiffEntry(entryList.get(0), 68, 40L, 50L);
|
assertBatteryDiffEntry(entryList.get(0), 68, 40L, 50L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUtcToLocalTime_returnExpectedResult() {
|
||||||
|
final long timestamp = 1619196786769L;
|
||||||
|
ConvertUtils.sSimpleDateFormat = null;
|
||||||
|
// Invokes the method first to create the SimpleDateFormat.
|
||||||
|
ConvertUtils.utcToLocalTime(/*timestamp=*/ 0);
|
||||||
|
ConvertUtils.sSimpleDateFormat
|
||||||
|
.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
|
||||||
|
assertThat(ConvertUtils.utcToLocalTime(timestamp))
|
||||||
|
.isEqualTo("Apr 23,2021 16:53:06");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUtcToLocalTmeHour_returnExpectedResult() {
|
||||||
|
final long timestamp = 1619196786769L;
|
||||||
|
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||||
|
// Invokes the method first to create the SimpleDateFormat.
|
||||||
|
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0);
|
||||||
|
ConvertUtils.sSimpleDateFormatForHour
|
||||||
|
.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
|
||||||
|
assertThat(ConvertUtils.utcToLocalTimeHour(timestamp))
|
||||||
|
.isEqualTo("4 pm");
|
||||||
|
}
|
||||||
|
|
||||||
private static BatteryHistEntry createBatteryHistEntry(
|
private static BatteryHistEntry createBatteryHistEntry(
|
||||||
String packageName, String appLabel, double consumePower,
|
String packageName, String appLabel, double consumePower,
|
||||||
long uid, long foregroundUsageTimeInMs, long backgroundUsageTimeInMs) {
|
long uid, long foregroundUsageTimeInMs, long backgroundUsageTimeInMs) {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import android.service.notification.NotifyingApp;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.widget.PrimarySwitchPreference;
|
||||||
import com.android.settingslib.applications.AppUtils;
|
import com.android.settingslib.applications.AppUtils;
|
||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||||
@@ -80,6 +81,9 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceCategory mCategory;
|
private PreferenceCategory mCategory;
|
||||||
|
private PrimarySwitchPreference mApp1;
|
||||||
|
private PrimarySwitchPreference mApp2;
|
||||||
|
private PrimarySwitchPreference mApp3;
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mSeeAllPref;
|
private Preference mSeeAllPref;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -115,6 +119,15 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
mController = new RecentNotifyingAppsPreferenceController(
|
mController = new RecentNotifyingAppsPreferenceController(
|
||||||
mContext, mBackend, mIUsageStatsManager, mUserManager, mAppState, mHost);
|
mContext, mBackend, mIUsageStatsManager, mUserManager, mAppState, mHost);
|
||||||
when(mScreen.findPreference(anyString())).thenReturn(mCategory);
|
when(mScreen.findPreference(anyString())).thenReturn(mCategory);
|
||||||
|
mApp1 = new PrimarySwitchPreference(mContext);
|
||||||
|
mApp1.setKey("app1");
|
||||||
|
mApp2 = new PrimarySwitchPreference(mContext);
|
||||||
|
mApp2.setKey("app2");
|
||||||
|
mApp3 = new PrimarySwitchPreference(mContext);
|
||||||
|
mApp3.setKey("app3");
|
||||||
|
when(mCategory.findPreference("app1")).thenReturn(mApp1);
|
||||||
|
when(mCategory.findPreference("app2")).thenReturn(mApp2);
|
||||||
|
when(mCategory.findPreference("app3")).thenReturn(mApp3);
|
||||||
|
|
||||||
when(mScreen.findPreference(RecentNotifyingAppsPreferenceController.KEY_SEE_ALL))
|
when(mScreen.findPreference(RecentNotifyingAppsPreferenceController.KEY_SEE_ALL))
|
||||||
.thenReturn(mSeeAllPref);
|
.thenReturn(mSeeAllPref);
|
||||||
@@ -169,12 +182,18 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
app2.mPackage = "pkg.class2";
|
app2.mPackage = "pkg.class2";
|
||||||
app2.mTimeStamp = System.currentTimeMillis() - 1000;
|
app2.mTimeStamp = System.currentTimeMillis() - 1000;
|
||||||
events.add(app2);
|
events.add(app2);
|
||||||
|
ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
|
||||||
|
ApplicationsState.AppEntry app2Entry = mock(ApplicationsState.AppEntry.class);
|
||||||
|
app1Entry.info = mApplicationInfo;
|
||||||
|
app1Entry.label = "app 1";
|
||||||
|
app2Entry.info = mApplicationInfo;
|
||||||
|
app2Entry.label = "app 2";
|
||||||
|
|
||||||
// app1, app2 are valid apps. app3 is invalid.
|
// app1, app2 are valid apps. app3 is invalid.
|
||||||
when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId()))
|
when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId()))
|
||||||
.thenReturn(mAppEntry);
|
.thenReturn(app1Entry);
|
||||||
when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId()))
|
when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId()))
|
||||||
.thenReturn(mAppEntry);
|
.thenReturn(app2Entry);
|
||||||
when(mAppState.getEntry(app2.getPackageName(), UserHandle.myUserId()))
|
when(mAppState.getEntry(app2.getPackageName(), UserHandle.myUserId()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
|
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
|
||||||
@@ -192,7 +211,10 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
|
|
||||||
verify(mCategory).setTitle(R.string.recent_notifications);
|
verify(mCategory).setTitle(R.string.recent_notifications);
|
||||||
// Only add app1 & app2. app3 skipped because it's invalid app.
|
// Only add app1 & app2. app3 skipped because it's invalid app.
|
||||||
verify(mCategory, times(2)).addPreference(any(Preference.class));
|
assertThat(mApp1.getTitle()).isEqualTo(app1Entry.label);
|
||||||
|
assertThat(mApp2.getTitle()).isEqualTo(app2Entry.label);
|
||||||
|
|
||||||
|
verify(mCategory).removePreferenceRecursively(mApp3.getKey());
|
||||||
|
|
||||||
verify(mSeeAllPref).setSummary(null);
|
verify(mSeeAllPref).setSummary(null);
|
||||||
verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp);
|
verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp);
|
||||||
@@ -209,22 +231,24 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
Event app1 = new Event();
|
Event app1 = new Event();
|
||||||
app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
|
app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
|
||||||
app1.mPackage = "com.foo.barinstant";
|
app1.mPackage = "com.foo.barinstant";
|
||||||
app1.mTimeStamp = System.currentTimeMillis() + 200;
|
app1.mTimeStamp = System.currentTimeMillis() - 200;
|
||||||
events.add(app1);
|
events.add(app1);
|
||||||
UsageEvents usageEvents = getUsageEvents(
|
UsageEvents usageEvents = getUsageEvents(
|
||||||
new String[] {"com.foo.bar", "com.foo.barinstant"}, events);
|
new String[] {"com.foo.bar", "com.foo.barinstant"}, events);
|
||||||
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
|
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
|
||||||
.thenReturn(usageEvents);
|
.thenReturn(usageEvents);
|
||||||
|
|
||||||
|
ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
|
||||||
ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
|
ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
|
||||||
ApplicationsState.AppEntry app2Entry = mock(ApplicationsState.AppEntry.class);
|
appEntry.info = mApplicationInfo;
|
||||||
|
appEntry.label = "app 1";
|
||||||
app1Entry.info = mApplicationInfo;
|
app1Entry.info = mApplicationInfo;
|
||||||
app2Entry.info = mApplicationInfo;
|
app1Entry.label = "app 2";
|
||||||
|
|
||||||
when(mAppState.getEntry(
|
when(mAppState.getEntry(
|
||||||
app.getPackageName(), UserHandle.myUserId())).thenReturn(app1Entry);
|
app.getPackageName(), UserHandle.myUserId())).thenReturn(appEntry);
|
||||||
when(mAppState.getEntry(
|
when(mAppState.getEntry(
|
||||||
app1.getPackageName(), UserHandle.myUserId())).thenReturn(app2Entry);
|
app1.getPackageName(), UserHandle.myUserId())).thenReturn(app1Entry);
|
||||||
|
|
||||||
// Only the regular app app1 should have its intent resolve.
|
// Only the regular app app1 should have its intent resolve.
|
||||||
when(mPackageManager.resolveActivity(argThat(intentMatcher(app.getPackageName())),
|
when(mPackageManager.resolveActivity(argThat(intentMatcher(app.getPackageName())),
|
||||||
@@ -233,7 +257,7 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
// Make sure app2 is considered an instant app.
|
// Make sure app2 is considered an instant app.
|
||||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||||
(InstantAppDataProvider) (ApplicationInfo info) -> {
|
(InstantAppDataProvider) (ApplicationInfo info) -> {
|
||||||
if (info == app2Entry.info) {
|
if (info == app1Entry.info) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -242,15 +266,10 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
|
assertThat(mApp1.getTitle()).isEqualTo(appEntry.label);
|
||||||
verify(mCategory, times(2)).addPreference(prefCaptor.capture());
|
assertThat(mApp2.getTitle()).isEqualTo(app1Entry.label);
|
||||||
List<Preference> prefs = prefCaptor.getAllValues();
|
|
||||||
assertThat(prefs.get(1).getKey()).isEqualTo(
|
verify(mCategory).removePreferenceRecursively(mApp3.getKey());
|
||||||
RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(),
|
|
||||||
app.getPackageName()));
|
|
||||||
assertThat(prefs.get(0).getKey()).isEqualTo(
|
|
||||||
RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(),
|
|
||||||
app1.getPackageName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -274,7 +293,7 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
verify(mCategory).addPreference(argThat(summaryMatches("Just now")));
|
assertThat(mApp1.getSummary()).isEqualTo("Just now");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user