More details in the summary and details screens.
Show packages included, time that a subsystem was on for. Load label and icon in the background and cache the values. Switch between totals and since-unplugged. Other UI improvements.
This commit is contained in:
@@ -17,26 +17,54 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.InstalledAppDetails;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class PowerUsageDetail extends Activity {
|
||||
public class PowerUsageDetail extends Activity implements Button.OnClickListener {
|
||||
|
||||
enum DrainType {
|
||||
IDLE,
|
||||
CELL,
|
||||
PHONE,
|
||||
WIFI,
|
||||
BLUETOOTH,
|
||||
SCREEN,
|
||||
APP
|
||||
}
|
||||
|
||||
public static final int ACTION_DISPLAY_SETTINGS = 1;
|
||||
public static final int ACTION_WIFI_SETTINGS = 2;
|
||||
public static final int ACTION_BLUETOOTH_SETTINGS = 3;
|
||||
public static final int ACTION_FORCE_STOP = 4;
|
||||
public static final int ACTION_UNINSTALL = 5;
|
||||
|
||||
public static final int USAGE_SINCE_UNPLUGGED = 1;
|
||||
public static final int USAGE_SINCE_RESET = 2;
|
||||
|
||||
public static final String EXTRA_TITLE = "title";
|
||||
public static final String EXTRA_PERCENT = "percent";
|
||||
public static final String EXTRA_UID = "uid";
|
||||
public static final String EXTRA_USAGE_SINCE = "since";
|
||||
public static final String EXTRA_USAGE_DURATION = "duration";
|
||||
public static final String EXTRA_DETAIL_TYPES = "types";
|
||||
public static final String EXTRA_DETAIL_VALUES = "values";
|
||||
public static final String EXTRA_DRAIN_TYPE = "drainType";
|
||||
|
||||
private static final int SECONDS_PER_MINUTE = 60;
|
||||
private static final int SECONDS_PER_HOUR = 60 * 60;
|
||||
@@ -47,12 +75,19 @@ public class PowerUsageDetail extends Activity {
|
||||
private double mPercentage;
|
||||
private int mUsageSince;
|
||||
private int[] mTypes;
|
||||
private int mUid;
|
||||
private double[] mValues;
|
||||
private TextView mTitleView;
|
||||
private ViewGroup mDetailsParent;
|
||||
private long mStartTime;
|
||||
private DrainType mDrainType;
|
||||
private int mAction1;
|
||||
private int mAction2;
|
||||
|
||||
private static final String TAG = "PowerUsageDetail";
|
||||
private Button mButton1;
|
||||
private Button mButton2;
|
||||
private String[] mPackages;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
@@ -77,6 +112,8 @@ public class PowerUsageDetail extends Activity {
|
||||
mTitle = intent.getStringExtra(EXTRA_TITLE);
|
||||
mPercentage = intent.getDoubleExtra(EXTRA_PERCENT, -1);
|
||||
mUsageSince = intent.getIntExtra(EXTRA_USAGE_SINCE, USAGE_SINCE_UNPLUGGED);
|
||||
mUid = intent.getIntExtra(EXTRA_UID, 0);
|
||||
mDrainType = (DrainType) intent.getSerializableExtra(EXTRA_DRAIN_TYPE);
|
||||
|
||||
mTypes = intent.getIntArrayExtra(EXTRA_DETAIL_TYPES);
|
||||
mValues = intent.getDoubleArrayExtra(EXTRA_DETAIL_VALUES);
|
||||
@@ -112,6 +149,147 @@ public class PowerUsageDetail extends Activity {
|
||||
valueView.setText(value);
|
||||
}
|
||||
}
|
||||
|
||||
fillPackagesSection(mUid);
|
||||
fillControlsSection(mUid);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
int action = v == mButton1 ? mAction1 : mAction2;
|
||||
doAction(action);
|
||||
}
|
||||
|
||||
private void doAction(int action) {
|
||||
switch (action) {
|
||||
case ACTION_DISPLAY_SETTINGS:
|
||||
startActivity(new Intent(Settings.ACTION_DISPLAY_SETTINGS));
|
||||
break;
|
||||
case ACTION_WIFI_SETTINGS:
|
||||
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
|
||||
break;
|
||||
case ACTION_BLUETOOTH_SETTINGS:
|
||||
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));
|
||||
break;
|
||||
case ACTION_FORCE_STOP:
|
||||
killProcesses();
|
||||
break;
|
||||
case ACTION_UNINSTALL:
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setClass(this, InstalledAppDetails.class);
|
||||
intent.putExtra("com.android.settings.ApplicationPkgName", mPackages[0]);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void fillControlsSection(int uid) {
|
||||
String label1 = null;
|
||||
String label2 = null;
|
||||
mAction1 = 0;
|
||||
mAction2 = 0;
|
||||
PackageManager pm = getPackageManager();
|
||||
String[] packages = pm.getPackagesForUid(mUid);
|
||||
PackageInfo pi = null;
|
||||
try {
|
||||
pi = packages != null ? pm.getPackageInfo(packages[0], 0) : null;
|
||||
} catch (NameNotFoundException nnfe) { /* Nothing */ }
|
||||
ApplicationInfo ai = pi != null? pi.applicationInfo : null;
|
||||
boolean isSystem = ai != null? (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0 : false;
|
||||
|
||||
if (uid == 0 || !isSystem) {
|
||||
switch (mDrainType) {
|
||||
case APP:
|
||||
label1 = getString(R.string.battery_action_stop);
|
||||
label2 = getString(R.string.battery_action_app_details);
|
||||
mAction1 = ACTION_FORCE_STOP;
|
||||
mAction2 = ACTION_UNINSTALL;
|
||||
break;
|
||||
case SCREEN:
|
||||
//label2 = getString(R.string.battery_action_display);
|
||||
//mAction2 = ACTION_DISPLAY_SETTINGS;
|
||||
break;
|
||||
case WIFI:
|
||||
label2 = getString(R.string.battery_action_wifi);
|
||||
mAction2 = ACTION_WIFI_SETTINGS;
|
||||
break;
|
||||
case BLUETOOTH:
|
||||
//label2 = getString(R.string.battery_action_bluetooth);
|
||||
//mAction2 = ACTION_BLUETOOTH_SETTINGS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mButton1 = (Button) findViewById(R.id.action_button1);
|
||||
mButton2 = (Button) findViewById(R.id.action_button2);
|
||||
mButton1.setOnClickListener(this);
|
||||
mButton2.setOnClickListener(this);
|
||||
if (label1 == null) {
|
||||
mButton1.setVisibility(View.GONE);
|
||||
} else {
|
||||
mButton1.setText(label1);
|
||||
}
|
||||
if (label2 == null) {
|
||||
findViewById(R.id.controls_section).setVisibility(View.GONE);
|
||||
} else {
|
||||
mButton2.setText(label2);
|
||||
}
|
||||
}
|
||||
|
||||
private void removePackagesSection() {
|
||||
View view;
|
||||
if ((view = findViewById(R.id.packages_section_title)) != null) {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
if ((view = findViewById(R.id.packages_section)) != null) {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void killProcesses() {
|
||||
if (mPackages == null) return;
|
||||
ActivityManager am = (ActivityManager)getSystemService(
|
||||
Context.ACTIVITY_SERVICE);
|
||||
for (int i = 0; i < mPackages.length; i++) {
|
||||
am.restartPackage(mPackages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillPackagesSection(int uid) {
|
||||
if (uid == 0) {
|
||||
removePackagesSection();
|
||||
return;
|
||||
}
|
||||
ViewGroup packagesParent = (ViewGroup) findViewById(R.id.packages_section);
|
||||
if (packagesParent == null) return;
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
|
||||
PackageManager pm = getPackageManager();
|
||||
final Drawable defaultActivityIcon = pm.getDefaultActivityIcon();
|
||||
mPackages = pm.getPackagesForUid(uid);
|
||||
if (mPackages == null || mPackages.length < 2) {
|
||||
removePackagesSection();
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert package names to user-facing labels where possible
|
||||
for (int i = 0; i < mPackages.length; i++) {
|
||||
try {
|
||||
ApplicationInfo ai = pm.getApplicationInfo(mPackages[i], 0);
|
||||
CharSequence label = ai.loadLabel(pm);
|
||||
Drawable icon = defaultActivityIcon;
|
||||
if (label != null) {
|
||||
mPackages[i] = label.toString();
|
||||
}
|
||||
if (ai.icon != 0) {
|
||||
icon = ai.loadIcon(pm);
|
||||
}
|
||||
ViewGroup item = (ViewGroup) inflater.inflate(R.layout.power_usage_package_item,
|
||||
null);
|
||||
packagesParent.addView(item);
|
||||
TextView labelView = (TextView) item.findViewById(R.id.label);
|
||||
labelView.setText(mPackages[i]);
|
||||
} catch (NameNotFoundException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String formatTime(double millis) {
|
||||
|
Reference in New Issue
Block a user