Search in sources :

Example 26 with AppInfo

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

the class UnrestrictAppAction method handlePositiveAction.

/**
 * Handle the action when user clicks positive button
 */
@Override
public void handlePositiveAction(int metricsKey) {
    final AppInfo appInfo = mUnRestrictAppTip.getUnrestrictAppInfo();
    // Clear force app standby, then app can run in the background
    mBatteryUtils.setForceAppStandby(appInfo.uid, appInfo.packageName, AppOpsManager.MODE_ALLOWED);
    mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_TIP_UNRESTRICT_APP, metricsKey, appInfo.packageName, 0);
}
Also used : AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Example 27 with AppInfo

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

the class RestrictedAppDetails method refreshUi.

@VisibleForTesting
void refreshUi() {
    mRestrictedAppListGroup.removeAll();
    final Context context = getPrefContext();
    final SparseLongArray timestampArray = mBatteryDatabaseManager.queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
    final long now = System.currentTimeMillis();
    for (int i = 0, size = mAppInfos.size(); i < size; i++) {
        final CheckBoxPreference checkBoxPreference = new AppCheckBoxPreference(context);
        final AppInfo appInfo = mAppInfos.get(i);
        try {
            final ApplicationInfo applicationInfo = mPackageManager.getApplicationInfoAsUser(appInfo.packageName, 0, /* flags */
            UserHandle.getUserId(appInfo.uid));
            checkBoxPreference.setChecked(mBatteryUtils.isForceAppStandbyEnabled(appInfo.uid, appInfo.packageName));
            checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
            checkBoxPreference.setIcon(Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, appInfo.packageName, UserHandle.getUserId(appInfo.uid)));
            checkBoxPreference.setKey(getKeyFromAppInfo(appInfo));
            checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
                final BatteryTipDialogFragment fragment = createDialogFragment(appInfo, (Boolean) value);
                fragment.setTargetFragment(this, 0);
                fragment.show(getFragmentManager(), TAG);
                mMetricsFeatureProvider.action(getContext(), SettingsEnums.ACTION_APP_RESTRICTED_LIST_UNCHECKED, appInfo.packageName);
                return false;
            });
            final long timestamp = timestampArray.get(appInfo.uid, TIME_NULL);
            if (timestamp != TIME_NULL) {
                checkBoxPreference.setSummary(getString(R.string.restricted_app_time_summary, StringUtil.formatRelativeTime(context, now - timestamp, false)));
            }
            final CharSequence test = checkBoxPreference.getSummaryOn();
            mRestrictedAppListGroup.addPreference(checkBoxPreference);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Can't find package: " + appInfo.packageName);
        }
    }
}
Also used : Context(android.content.Context) BatteryTipDialogFragment(com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment) PackageManager(android.content.pm.PackageManager) CheckBoxPreference(androidx.preference.CheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) ApplicationInfo(android.content.pm.ApplicationInfo) SparseLongArray(android.util.SparseLongArray) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 28 with AppInfo

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

the class HighUsageTip method log.

@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
    metricsFeatureProvider.action(context, SettingsEnums.ACTION_HIGH_USAGE_TIP, mState);
    for (int i = 0, size = mHighUsageAppList.size(); i < size; i++) {
        final AppInfo appInfo = mHighUsageAppList.get(i);
        metricsFeatureProvider.action(context, SettingsEnums.ACTION_HIGH_USAGE_TIP_LIST, appInfo.packageName);
    }
}
Also used : AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Example 29 with AppInfo

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

the class HighUsageTip method toString.

@Override
public String toString() {
    final StringBuilder stringBuilder = new StringBuilder(super.toString());
    stringBuilder.append(" {");
    for (int i = 0, size = mHighUsageAppList.size(); i < size; i++) {
        final AppInfo appInfo = mHighUsageAppList.get(i);
        stringBuilder.append(" " + appInfo.toString() + " ");
    }
    stringBuilder.append('}');
    return stringBuilder.toString();
}
Also used : AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Example 30 with AppInfo

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

the class RestrictAppTip method toString.

@Override
public String toString() {
    final StringBuilder stringBuilder = new StringBuilder(super.toString());
    stringBuilder.append(" {");
    for (int i = 0, size = mRestrictAppList.size(); i < size; i++) {
        final AppInfo appInfo = mRestrictAppList.get(i);
        stringBuilder.append(" " + appInfo.toString() + " ");
    }
    stringBuilder.append('}');
    return stringBuilder.toString();
}
Also used : AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Aggregations

AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)31 Test (org.junit.Test)11 Parcel (android.os.Parcel)4 VisibleForTesting (androidx.annotation.VisibleForTesting)4 CheckBoxPreference (androidx.preference.CheckBoxPreference)4 BatteryTipDialogFragment (com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment)4 RestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip)4 UnrestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip)4 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)4 Before (org.junit.Before)4 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)3 HighUsageTip (com.android.settings.fuelgauge.batterytip.tips.HighUsageTip)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 Intent (android.content.Intent)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageManager (android.content.pm.PackageManager)2 Bundle (android.os.Bundle)2 SparseLongArray (android.util.SparseLongArray)2 Slice (androidx.slice.Slice)1