Snap for 5587110 from fa5aaf9212 to qt-release
Change-Id: Ifcb5da94c13666d945c6ea39bef9db4b79d89bdd
This commit is contained in:
@@ -45,7 +45,8 @@
|
|||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="@dimen/qrcode_preview_size"
|
android:layout_width="@dimen/qrcode_preview_size"
|
||||||
android:layout_height="@dimen/qrcode_preview_size">
|
android:layout_height="@dimen/qrcode_preview_size"
|
||||||
|
android:clipChildren="true">
|
||||||
<TextureView
|
<TextureView
|
||||||
android:id="@+id/preview_view"
|
android:id="@+id/preview_view"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -10543,6 +10543,9 @@
|
|||||||
<!-- Help URI, USB Audio [DO NOT TRANSLATE] -->
|
<!-- Help URI, USB Audio [DO NOT TRANSLATE] -->
|
||||||
<string name="help_url_audio_accessory_not_supported" translatable="false"></string>
|
<string name="help_url_audio_accessory_not_supported" translatable="false"></string>
|
||||||
|
|
||||||
|
<!-- Help URI, USB Contaminant [DO NOT TRANSLATE] -->
|
||||||
|
<string name="help_url_usb_contaminant_detected" translatable="false"></string>
|
||||||
|
|
||||||
<!-- Help URI, restricted apps page [DO NOT TRANSLATE] -->
|
<!-- Help URI, restricted apps page [DO NOT TRANSLATE] -->
|
||||||
<string name="help_uri_restricted_apps" translatable="false"></string>
|
<string name="help_uri_restricted_apps" translatable="false"></string>
|
||||||
|
|
||||||
|
|||||||
@@ -160,8 +160,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
// TODO(b/37313605): Re-enable once this controller supports instant apps
|
// TODO(b/37313605): Re-enable once this controller supports instant apps
|
||||||
return mAppEntry != null && !AppUtils.isInstant(mAppEntry.info)
|
return isInstantApp() || isSystemModule() ? DISABLED_FOR_USER : AVAILABLE;
|
||||||
? AVAILABLE : DISABLED_FOR_USER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -685,6 +684,14 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isInstantApp() {
|
||||||
|
return mAppEntry != null && AppUtils.isInstant(mAppEntry.info);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSystemModule() {
|
||||||
|
return mAppEntry != null && AppUtils.isSystemModule(mContext, mAppEntry.info.packageName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the status of disable/enable for a package
|
* Changes the status of disable/enable for a package
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ import com.android.settingslib.utils.ThreadUtils;
|
|||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -450,16 +452,10 @@ public class BatteryUtils {
|
|||||||
SystemClock.elapsedRealtime());
|
SystemClock.elapsedRealtime());
|
||||||
final BatteryStats stats = statsHelper.getStats();
|
final BatteryStats stats = statsHelper.getStats();
|
||||||
BatteryInfo batteryInfo;
|
BatteryInfo batteryInfo;
|
||||||
Estimate estimate = null;
|
Estimate estimate = getEnhancedEstimate();
|
||||||
// Get enhanced prediction if available
|
|
||||||
if (mPowerUsageFeatureProvider != null &&
|
|
||||||
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
|
|
||||||
estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (estimate != null) {
|
// couldn't get estimate from cache or provider, use fallback
|
||||||
Estimate.storeCachedEstimate(mContext, estimate);
|
if (estimate == null) {
|
||||||
} else {
|
|
||||||
estimate = new Estimate(
|
estimate = new Estimate(
|
||||||
PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)),
|
PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)),
|
||||||
false /* isBasedOnUsage */,
|
false /* isBasedOnUsage */,
|
||||||
@@ -474,6 +470,23 @@ public class BatteryUtils {
|
|||||||
return batteryInfo;
|
return batteryInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
Estimate getEnhancedEstimate() {
|
||||||
|
Estimate estimate = null;
|
||||||
|
// Get enhanced prediction if available
|
||||||
|
if (Duration.between(Estimate.getLastCacheUpdateTime(mContext), Instant.now())
|
||||||
|
.compareTo(Duration.ofSeconds(10)) < 0) {
|
||||||
|
estimate = Estimate.getCachedEstimateIfAvailable(mContext);
|
||||||
|
} else if (mPowerUsageFeatureProvider != null &&
|
||||||
|
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
|
||||||
|
estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext);
|
||||||
|
if (estimate != null) {
|
||||||
|
Estimate.storeCachedEstimate(mContext, estimate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return estimate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the {@link BatterySipper} with the corresponding {@link BatterySipper.DrainType}
|
* Find the {@link BatterySipper} with the corresponding {@link BatterySipper.DrainType}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.util.ArraySet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -58,6 +59,8 @@ import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
|||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.widget.ActionButtonsPreference;
|
import com.android.settingslib.widget.ActionButtonsPreference;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -67,6 +70,10 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
import org.robolectric.annotation.Resetter;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -149,6 +156,11 @@ public class AppButtonsPreferenceControllerTest {
|
|||||||
doAnswer(callable).when(mFragment).startActivityForResult(captor.capture(), anyInt());
|
doAnswer(callable).when(mFragment).startActivityForResult(captor.capture(), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
ShadowAppUtils.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retrieveAppEntry_hasAppEntry_notNull()
|
public void retrieveAppEntry_hasAppEntry_notNull()
|
||||||
throws PackageManager.NameNotFoundException {
|
throws PackageManager.NameNotFoundException {
|
||||||
@@ -212,15 +224,9 @@ public class AppButtonsPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(shadows = ShadowAppUtils.class)
|
||||||
public void isAvailable_nonInstantApp() {
|
public void isAvailable_nonInstantApp() {
|
||||||
mController.mAppEntry = mAppEntry;
|
mController.mAppEntry = mAppEntry;
|
||||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
|
||||||
new InstantAppDataProvider() {
|
|
||||||
@Override
|
|
||||||
public boolean isInstantApp(ApplicationInfo info) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,6 +442,14 @@ public class AppButtonsPreferenceControllerTest {
|
|||||||
// Should not crash in this method
|
// Should not crash in this method
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = ShadowAppUtils.class)
|
||||||
|
public void getAvailabilityStatus_systemModule() {
|
||||||
|
ShadowAppUtils.addHiddenModule(mController.mPackageName);
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||||
|
AppButtonsPreferenceController.DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The test fragment which implements
|
* The test fragment which implements
|
||||||
* {@link ButtonActionDialogFragment.AppButtonsDialogListener}
|
* {@link ButtonActionDialogFragment.AppButtonsDialogListener}
|
||||||
@@ -477,4 +491,29 @@ public class AppButtonsPreferenceControllerTest {
|
|||||||
priority,
|
priority,
|
||||||
false /* isStatic */);
|
false /* isStatic */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implements(AppUtils.class)
|
||||||
|
public static class ShadowAppUtils {
|
||||||
|
|
||||||
|
public static Set<String> sSystemModules = new ArraySet<>();
|
||||||
|
|
||||||
|
@Resetter
|
||||||
|
public static void reset() {
|
||||||
|
sSystemModules.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addHiddenModule(String pkg) {
|
||||||
|
sSystemModules.add(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
protected static boolean isInstant(ApplicationInfo info) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
protected static boolean isSystemModule(Context context, String packageName) {
|
||||||
|
return sSystemModules.contains(packageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ import com.android.settings.fuelgauge.batterytip.AnomalyInfo;
|
|||||||
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||||
|
import com.android.settingslib.fuelgauge.Estimate;
|
||||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -728,4 +729,17 @@ public class BatteryUtilsTest {
|
|||||||
//Should not crash
|
//Should not crash
|
||||||
assertThat(mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG)).isNotNull();
|
assertThat(mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getEnhancedEstimate_doesNotUpdateCache_ifEstimateFresh() {
|
||||||
|
Estimate estimate = new Estimate(1000, true, 1000);
|
||||||
|
Estimate.storeCachedEstimate(mContext, estimate);
|
||||||
|
|
||||||
|
estimate = mBatteryUtils.getEnhancedEstimate();
|
||||||
|
|
||||||
|
// only pass if estimate has not changed
|
||||||
|
assertThat(estimate).isNotNull();
|
||||||
|
assertThat(estimate.isBasedOnUsage()).isTrue();
|
||||||
|
assertThat(estimate.getAverageDischargeTime()).isEqualTo(1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user