Search in sources :

Example 1 with HighUsageTip

use of com.android.settings.fuelgauge.batterytip.tips.HighUsageTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryTipDialogFragmentTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    FakeFeatureFactory.setupForTest();
    ShadowUtils.setApplicationLabel(PACKAGE_NAME, DISPLAY_NAME);
    List<AppInfo> highUsageTips = new ArrayList<>();
    mAppInfo = new AppInfo.Builder().setScreenOnTimeMs(SCREEN_TIME_MS).setPackageName(PACKAGE_NAME).build();
    highUsageTips.add(mAppInfo);
    mHighUsageTip = new HighUsageTip(SCREEN_TIME_MS, highUsageTips);
    final List<AppInfo> restrictApps = new ArrayList<>();
    restrictApps.add(mAppInfo);
    mRestrictedOneAppTip = new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>(restrictApps));
    restrictApps.add(mAppInfo);
    mRestrictTwoAppsTip = new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>(restrictApps));
    mUnrestrictAppTip = new UnrestrictAppTip(BatteryTip.StateType.NEW, mAppInfo);
    mSummaryTip = spy(new SummaryTip(BatteryTip.StateType.NEW, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
}
Also used : HighUsageTip(com.android.settings.fuelgauge.batterytip.tips.HighUsageTip) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) SummaryTip(com.android.settings.fuelgauge.batterytip.tips.SummaryTip) ArrayList(java.util.ArrayList) UnrestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip) Before(org.junit.Before)

Example 2 with HighUsageTip

use of com.android.settings.fuelgauge.batterytip.tips.HighUsageTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class HighUsageDetectorTest method testDetect_containsHighUsageApp_tipVisibleAndSorted.

@Test
public void testDetect_containsHighUsageApp_tipVisibleAndSorted() {
    doReturn(true).when(mDataParser).isDeviceHeavilyUsed();
    final HighUsageTip highUsageTip = (HighUsageTip) mHighUsageDetector.detect();
    assertThat(highUsageTip.isVisible()).isTrue();
    // Contain two appInfo and large one comes first
    final List<AppInfo> appInfos = highUsageTip.getHighUsageAppList();
    assertThat(appInfos).containsExactly(mLowAppInfo, mHighAppInfo);
    assertThat(appInfos.get(0)).isEqualTo(mHighAppInfo);
}
Also used : HighUsageTip(com.android.settings.fuelgauge.batterytip.tips.HighUsageTip) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) Test(org.junit.Test)

Example 3 with HighUsageTip

use of com.android.settings.fuelgauge.batterytip.tips.HighUsageTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryTipDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Bundle bundle = getArguments();
    final Context context = getContext();
    mBatteryTip = bundle.getParcelable(ARG_BATTERY_TIP);
    mMetricsKey = bundle.getInt(ARG_METRICS_KEY);
    switch(mBatteryTip.getType()) {
        case BatteryTip.TipType.SUMMARY:
            return new AlertDialog.Builder(context).setMessage(R.string.battery_tip_dialog_summary_message).setPositiveButton(android.R.string.ok, null).create();
        case BatteryTip.TipType.HIGH_DEVICE_USAGE:
            final HighUsageTip highUsageTip = (HighUsageTip) mBatteryTip;
            final RecyclerView view = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.recycler_view, null);
            view.setLayoutManager(new LinearLayoutManager(context));
            view.setAdapter(new HighUsageAdapter(context, highUsageTip.getHighUsageAppList()));
            return new AlertDialog.Builder(context).setMessage(getString(R.string.battery_tip_dialog_message, highUsageTip.getHighUsageAppList().size())).setView(view).setPositiveButton(android.R.string.ok, null).create();
        case BatteryTip.TipType.APP_RESTRICTION:
            final RestrictAppTip restrictAppTip = (RestrictAppTip) mBatteryTip;
            final List<AppInfo> restrictedAppList = restrictAppTip.getRestrictAppList();
            final int num = restrictedAppList.size();
            final CharSequence appLabel = Utils.getApplicationLabel(context, restrictedAppList.get(0).packageName);
            final AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(context.getResources().getQuantityString(R.plurals.battery_tip_restrict_app_dialog_title, num, num)).setPositiveButton(R.string.battery_tip_restrict_app_dialog_ok, this).setNegativeButton(android.R.string.cancel, null);
            if (num == 1) {
                builder.setMessage(getString(R.string.battery_tip_restrict_app_dialog_message, appLabel));
            } else if (num <= 5) {
                builder.setMessage(getString(R.string.battery_tip_restrict_apps_less_than_5_dialog_message));
                final RecyclerView restrictionView = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.recycler_view, null);
                restrictionView.setLayoutManager(new LinearLayoutManager(context));
                restrictionView.setAdapter(new HighUsageAdapter(context, restrictedAppList));
                builder.setView(restrictionView);
            } else {
                builder.setMessage(context.getString(R.string.battery_tip_restrict_apps_more_than_5_dialog_message, restrictAppTip.getRestrictAppsString(context)));
            }
            return builder.create();
        case BatteryTip.TipType.REMOVE_APP_RESTRICTION:
            final UnrestrictAppTip unrestrictAppTip = (UnrestrictAppTip) mBatteryTip;
            final CharSequence name = Utils.getApplicationLabel(context, unrestrictAppTip.getPackageName());
            return new AlertDialog.Builder(context).setTitle(getString(R.string.battery_tip_unrestrict_app_dialog_title)).setMessage(R.string.battery_tip_unrestrict_app_dialog_message).setPositiveButton(R.string.battery_tip_unrestrict_app_dialog_ok, this).setNegativeButton(R.string.battery_tip_unrestrict_app_dialog_cancel, null).create();
        default:
            throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
    }
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) HighUsageTip(com.android.settings.fuelgauge.batterytip.tips.HighUsageTip) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) RecyclerView(androidx.recyclerview.widget.RecyclerView) UnrestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip)

Example 4 with HighUsageTip

use of com.android.settings.fuelgauge.batterytip.tips.HighUsageTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class HighUsageDetector method detect.

@Override
public BatteryTip detect() {
    final long lastFullChargeTimeMs = mBatteryUtils.calculateLastFullChargeTime(mBatteryStatsHelper, System.currentTimeMillis());
    if (mPolicy.highUsageEnabled && mDischarging) {
        parseBatteryData();
        if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
            final BatteryStats batteryStats = mBatteryStatsHelper.getStats();
            final List<BatterySipper> batterySippers = new ArrayList<>(mBatteryStatsHelper.getUsageList());
            final double totalPower = mBatteryStatsHelper.getTotalPower();
            final int dischargeAmount = batteryStats != null ? batteryStats.getDischargeAmount(BatteryStats.STATS_SINCE_CHARGED) : 0;
            Collections.sort(batterySippers, (sipper1, sipper2) -> Double.compare(sipper2.totalSmearedPowerMah, sipper1.totalSmearedPowerMah));
            for (BatterySipper batterySipper : batterySippers) {
                final double percent = mBatteryUtils.calculateBatteryPercent(batterySipper.totalSmearedPowerMah, totalPower, 0, dischargeAmount);
                if ((percent + 0.5f < 1f) || mBatteryUtils.shouldHideSipper(batterySipper)) {
                    // Don't show it if we should hide or usage percentage is lower than 1%
                    continue;
                }
                mHighUsageAppList.add(new AppInfo.Builder().setUid(batterySipper.getUid()).setPackageName(mBatteryUtils.getPackageName(batterySipper.getUid())).build());
                if (mHighUsageAppList.size() >= mPolicy.highUsageAppCount) {
                    break;
                }
            }
            // When in test mode, add an app if necessary
            if (mPolicy.testHighUsageTip && mHighUsageAppList.isEmpty()) {
                mHighUsageAppList.add(new AppInfo.Builder().setPackageName(SETTINGS_PACKAGE_NAME).setScreenOnTimeMs(TimeUnit.HOURS.toMillis(3)).build());
            }
        }
    }
    return new HighUsageTip(lastFullChargeTimeMs, mHighUsageAppList);
}
Also used : HighUsageTip(com.android.settings.fuelgauge.batterytip.tips.HighUsageTip) BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList) BatteryStats(android.os.BatteryStats)

Example 5 with HighUsageTip

use of com.android.settings.fuelgauge.batterytip.tips.HighUsageTip in project android_packages_apps_Settings by omnirom.

the class HighUsageDetector method detect.

@Override
public BatteryTip detect() {
    final long lastFullChargeTimeMs = mBatteryUtils.calculateLastFullChargeTime(mBatteryUsageStats, System.currentTimeMillis());
    if (mPolicy.highUsageEnabled && mDischarging) {
        parseBatteryData();
        if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
            final double totalPower = mBatteryUsageStats.getConsumedPower();
            final int dischargeAmount = mBatteryUsageStats.getDischargePercentage();
            final List<UidBatteryConsumer> uidBatteryConsumers = mBatteryUsageStats.getUidBatteryConsumers();
            // Sort by descending power
            uidBatteryConsumers.sort((consumer1, consumer2) -> Double.compare(consumer2.getConsumedPower(), consumer1.getConsumedPower()));
            for (UidBatteryConsumer consumer : uidBatteryConsumers) {
                final double percent = mBatteryUtils.calculateBatteryPercent(consumer.getConsumedPower(), totalPower, dischargeAmount);
                if ((percent + 0.5f < 1f) || mBatteryUtils.shouldHideUidBatteryConsumer(consumer)) {
                    // Don't show it if we should hide or usage percentage is lower than 1%
                    continue;
                }
                mHighUsageAppList.add(new AppInfo.Builder().setUid(consumer.getUid()).setPackageName(mBatteryUtils.getPackageName(consumer.getUid())).build());
                if (mHighUsageAppList.size() >= mPolicy.highUsageAppCount) {
                    break;
                }
            }
            // When in test mode, add an app if necessary
            if (mPolicy.testHighUsageTip && mHighUsageAppList.isEmpty()) {
                mHighUsageAppList.add(new AppInfo.Builder().setPackageName(SETTINGS_PACKAGE_NAME).setScreenOnTimeMs(TimeUnit.HOURS.toMillis(3)).build());
            }
        }
    }
    return new HighUsageTip(lastFullChargeTimeMs, mHighUsageAppList);
}
Also used : HighUsageTip(com.android.settings.fuelgauge.batterytip.tips.HighUsageTip) UidBatteryConsumer(android.os.UidBatteryConsumer)

Aggregations

HighUsageTip (com.android.settings.fuelgauge.batterytip.tips.HighUsageTip)9 RestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip)4 UnrestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip)4 ArrayList (java.util.ArrayList)4 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)3 Test (org.junit.Test)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 SummaryTip (com.android.settings.fuelgauge.batterytip.tips.SummaryTip)2 Before (org.junit.Before)2 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 BatteryStats (android.os.BatteryStats)1 UidBatteryConsumer (android.os.UidBatteryConsumer)1 Slice (androidx.slice.Slice)1 BatterySipper (com.android.internal.os.BatterySipper)1