OSDN Git Service

Track native processes.
authorAmith Yamasani <yamasani@google.com>
Fri, 19 Jun 2009 16:27:35 +0000 (09:27 -0700)
committerAmith Yamasani <yamasani@google.com>
Thu, 25 Jun 2009 07:40:50 +0000 (00:40 -0700)
Add gauge to detail screen and make it look like the item from summary screen.
Some string changes.

res/layout/power_usage_details.xml
res/layout/preference_powergauge.xml
res/values/strings.xml
res/xml/power_usage_summary.xml
src/com/android/settings/fuelgauge/PercentageBar.java [new file with mode: 0644]
src/com/android/settings/fuelgauge/PowerGaugePreference.java
src/com/android/settings/fuelgauge/PowerUsageDetail.java
src/com/android/settings/fuelgauge/PowerUsageSummary.java

index 8aa625f..ea7cfb3 100644 (file)
         android:id="@+id/all_details"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
-        android:paddingRight="6dip"
         android:paddingTop="5dip"
         android:paddingBottom="5dip"
         android:orientation="vertical">
 
-        <!-- Details header - icon, label and percentage -->
-        <RelativeLayout
+        <LinearLayout
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_gravity="center_vertical">
+            android:minHeight="?android:attr/listPreferredItemHeight"
+            android:orientation="horizontal"
+            android:gravity="center_vertical"
+            android:paddingLeft="12dip"
+            android:paddingRight="?android:attr/scrollbarSize">
+
+            <ImageView
+                android:id="@+id/icon"
+                android:layout_width="48dip"
+                android:layout_height="wrap_content"
+                android:layout_marginRight="6dip"
+                android:layout_gravity="center" />
 
-            <LinearLayout
-                android:orientation="vertical"
-                android:layout_alignParentLeft="true"
-                android:layout_width="fill_parent"
+            <RelativeLayout
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:paddingTop="6dip"
-                android:paddingBottom="6dip"
-                android:paddingRight="6dip"
-                android:paddingLeft="6dip" >
-                <!-- application name -->
+                android:layout_marginRight="8dip"
+                android:layout_marginTop="2dip"
+                android:layout_marginBottom="6dip"
+                android:layout_weight="1">
+
                 <TextView android:id="@+id/name"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:textAppearance="?android:attr/textAppearanceMedium"
-                    android:textStyle="bold"
                     android:singleLine="true"
+                    android:layout_marginTop="2dip"
+                    android:layout_alignParentLeft="true"
+                    android:layout_alignParentTop="true"
+                    android:layout_toLeftOf="@+id/battery_percentage"
                     android:ellipsize="marquee"
-                    android:layout_marginBottom="2dip" />
-                <!-- application version -->
+                    android:textAppearance="?android:attr/textAppearanceMedium"/>
                 <TextView android:id="@+id/battery_percentage"
-                    android:layout_marginTop="-4dip"
-                    android:layout_gravity="center_vertical"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:textAppearance="?android:attr/textAppearanceSmall" />
-            </LinearLayout>
-
-            <!-- application icon -->
-            <ImageView android:id="@+id/icon"
-                android:layout_width="@android:dimen/app_icon_size"
-                android:layout_height="@android:dimen/app_icon_size"
-                android:layout_alignParentRight="true"
-                android:paddingTop="6dip"
-                android:paddingBottom="6dip"
-                android:paddingRight="6dip"
-                android:scaleType="fitCenter" />
-        </RelativeLayout>
-
+                    android:singleLine="true"
+                    android:layout_alignParentRight="true"
+                    android:layout_alignBottom="@+id/name"
+                    android:layout_gravity="bottom"
+                    android:textAppearance="?android:attr/textAppearanceSmall"
+                    android:textStyle="bold"/>
+                <ImageView
+                    android:id="@+id/gauge"
+                    android:background="#80404040"
+                    android:layout_height="wrap_content"
+                    android:layout_width="fill_parent"
+                    android:layout_marginTop="5dip"
+                    android:layout_below="@id/battery_percentage"
+                    android:layout_gravity="center_vertical" />
+                <TextView android:id="@+id/summary"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_alignLeft="@id/gauge"
+                    android:layout_below="@id/gauge"
+                    android:textAppearance="?android:attr/textAppearanceSmall"
+                    />
+            </RelativeLayout>
+        </LinearLayout>
 
         <TextView
             style="?android:attr/listSeparatorTextViewStyle"
index b47f6c0..7aafec1 100644 (file)
@@ -61,7 +61,7 @@
 
         <ImageView
             android:id="@+id/appGauge"
-            android:background="#2e2e2e"
+            android:background="#80404040"
             android:layout_height="wrap_content"
             android:layout_width="fill_parent"
             android:layout_marginTop="5dip"
index 2dd2f84..63b343d 100644 (file)
@@ -1647,7 +1647,13 @@ found in the list of installed applications.</string>
     <!-- Battery usage since user reset the stats -->
     <string name="battery_since_reset">Battery use since reset</string>
     <!-- Battery usage duration -->
-    <string name="battery_stats_duration">Use duration - <xliff:g id="time">%1$s</xliff:g></string>
+    <string name="battery_stats_duration"><xliff:g id="time">%1$s</xliff:g> since unplugged</string>
+    <!-- CPU awake time title -->
+    <string name="awake">Device awake time</string>
+    <!-- Wifi on time -->
+    <string name="wifi_on_time">WiFi on time</string>
+    <!-- Bluetooth on time -->
+    <string name="bluetooth_on_time">WiFi on time</string>
     <!-- Application name and battery usage percentage -->
     <string name="usage_name_percent"><xliff:g id="name">%1$s</xliff:g>" - "
             <xliff:g id="percent">%2$s</xliff:g>"%%"</string>
@@ -1705,6 +1711,9 @@ found in the list of installed applications.</string>
     <!-- Label for bluetooth settings -->
     <string name="battery_action_bluetooth">Bluetooth settings</string>
 
+    <!-- Description for voice call detail -->
+    <string name="battery_desc_voice">Battery used by voice calls</string>
+
     <!-- Description for standby detail -->
     <string name="battery_desc_standby">Battery used when phone is idle</string>
 
@@ -1747,7 +1756,12 @@ found in the list of installed applications.</string>
     <string name="menu_stats_total">Usage totals</string>
     <!-- Menu label for refreshing with latest usage numbers -->
     <string name="menu_stats_refresh">Refresh</string>
-    
+
+    <!-- Label for kernel threads -->
+    <string name="process_kernel_label">Android OS</string>
+    <!-- Label for mediaserver process -->
+    <string name="process_mediaserver_label">Mediaserver</string>
+
     <!-- Text-To-Speech (TTS) settings --><skip />
     <!-- Title of setting on main settings screen.  This item will take the user to the screen to tweak settings related to the text-to-speech functionality -->
     <string name="tts_settings">Speech synthesis</string>
index 450e438..b49b140 100644 (file)
@@ -15,7 +15,6 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-        android:title="@string/battery_since_unplugged">
-    <PreferenceCategory
-        android:key="app_list"/>
+        android:title="@string/battery_since_unplugged"
+        android:key="app_list">
 </PreferenceScreen>
diff --git a/src/com/android/settings/fuelgauge/PercentageBar.java b/src/com/android/settings/fuelgauge/PercentageBar.java
new file mode 100644 (file)
index 0000000..1c4478b
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.fuelgauge;
+
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.Drawable;
+
+/**
+ * A drawable for drawing a bar with a background.
+ */
+class PercentageBar extends Drawable {
+
+    Drawable bar;
+    double percent;
+    int lastWidth = -1;
+
+    @Override
+    public void draw(Canvas canvas) {
+        if (lastWidth == -1) {
+            lastWidth = getBarWidth();
+            bar.setBounds(0, 0, lastWidth, bar.getIntrinsicHeight());
+        }
+        bar.draw(canvas);
+    }
+
+    @Override
+    public int getOpacity() {
+        return PixelFormat.TRANSLUCENT;
+    }
+
+    @Override
+    public void setAlpha(int alpha) {
+        // Ignore
+    }
+
+    @Override
+    public void setColorFilter(ColorFilter cf) {
+        // Ignore
+    }
+
+    private int getBarWidth() {
+        int width = (int) ((this.getBounds().width() * percent) / 100);
+        int intrinsicWidth = bar.getIntrinsicWidth();
+        return Math.max(width, intrinsicWidth);
+    }
+
+    @Override
+    public int getIntrinsicHeight() {
+        return bar.getIntrinsicHeight();
+    }
+}
index 5778b39..68f294c 100644 (file)
@@ -37,7 +37,7 @@ import com.android.settings.fuelgauge.PowerUsageSummary.BatterySipper;
 public class PowerGaugePreference extends Preference {
 
     private Drawable mIcon;
-    private GaugeDrawable mGauge;
+    private PercentageBar mGauge;
     private double mValue;
     private BatterySipper mInfo;
     private double mPercent;
@@ -46,7 +46,7 @@ public class PowerGaugePreference extends Preference {
         super(context);
         setLayoutResource(R.layout.preference_powergauge);
         mIcon = icon;
-        mGauge = new GaugeDrawable();
+        mGauge = new PercentageBar();
         mGauge.bar = context.getResources().getDrawable(R.drawable.app_gauge);
         mInfo = info;
     }
@@ -90,44 +90,4 @@ public class PowerGaugePreference extends Preference {
         percentView.setText((int) (Math.ceil(mPercent)) + "%");
     }
 
-    static class GaugeDrawable extends Drawable {
-        Drawable bar;
-        double percent;
-        int lastWidth = -1;
-
-        @Override
-        public void draw(Canvas canvas) {
-            if (lastWidth == -1) {
-                lastWidth = getBarWidth();
-                bar.setBounds(0, 0, lastWidth, bar.getIntrinsicHeight());
-            }
-            bar.draw(canvas);
-        }
-
-        @Override
-        public int getOpacity() {
-            return PixelFormat.TRANSLUCENT;
-        }
-
-        @Override
-        public void setAlpha(int alpha) {
-            // Ignore
-        }
-
-        @Override
-        public void setColorFilter(ColorFilter cf) {
-            // Ignore
-        }
-
-        private int getBarWidth() {
-            int width = (int) ((this.getBounds().width() * percent) / 100);
-            int intrinsicWidth = bar.getIntrinsicWidth();
-            return Math.max(width, intrinsicWidth);
-        }
-
-        @Override
-        public int getIntrinsicHeight() {
-            return bar.getIntrinsicHeight();
-        }
-    }
 }
index e36a8bc..e78e041 100644 (file)
@@ -27,10 +27,12 @@ import android.content.pm.PackageManager.NameNotFoundException;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.provider.Settings;
+import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import com.android.settings.InstalledAppDetails;
@@ -48,6 +50,17 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
         APP
     }
 
+    // Note: Must match the sequence of the DrainType
+    private static int[] sDrainTypeDesciptions = new int[] {
+        R.string.battery_desc_standby,
+        R.string.battery_desc_radio,
+        R.string.battery_desc_voice,
+        R.string.battery_desc_wifi,
+        R.string.battery_desc_bluetooth,
+        R.string.battery_desc_display,
+        R.string.battery_desc_apps
+    };
+    
     public static final int ACTION_DISPLAY_SETTINGS = 1;
     public static final int ACTION_WIFI_SETTINGS = 2;
     public static final int ACTION_BLUETOOTH_SETTINGS = 3;
@@ -59,16 +72,18 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
 
     public static final String EXTRA_TITLE = "title";
     public static final String EXTRA_PERCENT = "percent";
+    public static final String EXTRA_GAUGE = "gauge";
     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";
+    public static final String EXTRA_DETAIL_TYPES = "types"; // Array of usage types (cpu, gps, etc)
+    public static final String EXTRA_DETAIL_VALUES = "values"; // Array of doubles
+    public static final String EXTRA_DRAIN_TYPE = "drainType"; // DrainType
+    public static final String EXTRA_ICON_PACKAGE = "iconPackage"; // String
+    public static final String EXTRA_ICON_ID = "iconId"; // Int
 
     private static final boolean DEBUG = true;
     private String mTitle;
-    private double mPercentage;
     private int mUsageSince;
     private int[] mTypes;
     private int mUid;
@@ -79,6 +94,8 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
     private DrainType mDrainType;
     private int mAction1;
     private int mAction2;
+    private PercentageBar mGauge;
+    private Drawable mAppIcon;
 
     private static final String TAG = "PowerUsageDetail";
     private Button mButton1;
@@ -106,20 +123,51 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
     private void createDetails() {
         final Intent intent = getIntent();
         mTitle = intent.getStringExtra(EXTRA_TITLE);
-        mPercentage = intent.getDoubleExtra(EXTRA_PERCENT, -1);
+        final int percentage = intent.getIntExtra(EXTRA_PERCENT, 1);
+        final int gaugeValue = intent.getIntExtra(EXTRA_GAUGE, 1);
         mUsageSince = intent.getIntExtra(EXTRA_USAGE_SINCE, USAGE_SINCE_UNPLUGGED);
         mUid = intent.getIntExtra(EXTRA_UID, 0);
         mDrainType = (DrainType) intent.getSerializableExtra(EXTRA_DRAIN_TYPE);
+        String iconPackage = intent.getStringExtra(EXTRA_ICON_PACKAGE);
+        int iconId = intent.getIntExtra(EXTRA_ICON_ID, 0);
+        if (!TextUtils.isEmpty(iconPackage)) {
+            try {
+                final PackageManager pm = getPackageManager();
+                ApplicationInfo ai = pm.getPackageInfo(iconPackage, 0).applicationInfo;
+                if (ai != null) {
+                    mAppIcon = ai.loadIcon(pm);
+                }
+            } catch (NameNotFoundException nnfe) {
+                // Use default icon
+            }
+        } else if (iconId != 0) {
+            mAppIcon = getResources().getDrawable(iconId);
+        }
+        if (mAppIcon == null) {
+            mAppIcon = getPackageManager().getDefaultActivityIcon();
+        }
 
+        // Set the description
+        String summary = getDescriptionForDrainType();
+        ((TextView)findViewById(R.id.summary)).setText(summary);
+        
         mTypes = intent.getIntArrayExtra(EXTRA_DETAIL_TYPES);
         mValues = intent.getDoubleArrayExtra(EXTRA_DETAIL_VALUES);
 
         mTitleView = (TextView) findViewById(R.id.name);
         mTitleView.setText(mTitle);
-        // TODO: I18N
         ((TextView)findViewById(R.id.battery_percentage))
-            .setText(String.format("%3.2f%% of battery usage since last unplugged", mPercentage));
+            .setText(String.format("%d%%", percentage));
+
+        ImageView gaugeImage = (ImageView) findViewById(R.id.gauge);
+        mGauge = new PercentageBar();
+        mGauge.percent = gaugeValue;
+        mGauge.bar = getResources().getDrawable(R.drawable.app_gauge);
+        gaugeImage.setImageDrawable(mGauge);
 
+        ImageView iconImage = (ImageView) findViewById(R.id.icon);
+        iconImage.setImageDrawable(mAppIcon);
+        
         mDetailsParent = (ViewGroup) findViewById(R.id.details);
         LayoutInflater inflater = getLayoutInflater();
         if (mTypes != null && mValues != null) {
@@ -181,7 +229,7 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
         mAction1 = 0;
         mAction2 = 0;
         PackageManager pm = getPackageManager();
-        String[] packages = pm.getPackagesForUid(mUid);
+        String[] packages = pm.getPackagesForUid(uid);
         PackageInfo pi = null;
         try {
             pi = packages != null ? pm.getPackageInfo(packages[0], 0) : null;
@@ -189,12 +237,14 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
         ApplicationInfo ai = pi != null? pi.applicationInfo : null;
         boolean isSystem = ai != null? (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0 : false;
 
-        if (uid == 0 || !isSystem) { 
+        if (uid < 1000 || !isSystem) { 
             switch (mDrainType) {
                 case APP:
                     //label1 = getString(R.string.battery_action_stop);
-                    label2 = getString(R.string.battery_action_app_details);
-                    mAction2 = ACTION_APP_DETAILS;
+                    if (packages != null) {
+                        label2 = getString(R.string.battery_action_app_details);
+                        mAction2 = ACTION_APP_DETAILS;
+                    }
                     break;
                 case SCREEN:
                     label2 = getString(R.string.battery_action_display);
@@ -246,7 +296,7 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
     }
 
     private void fillPackagesSection(int uid) {
-        if (uid == 0) {
+        if (uid < 1) {
             removePackagesSection();
             return;
         }
@@ -283,4 +333,8 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
             }
         }
     }
+    
+    private String getDescriptionForDrainType() {
+        return getResources().getString(sDrainTypeDesciptions[mDrainType.ordinal()]);
+    }
 }
index b8919ee..d36dce7 100644 (file)
@@ -85,14 +85,19 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
 
     private PowerProfile mPowerProfile;
 
-    private HashMap<String,String> mNameCache = new HashMap<String,String>();
-    private HashMap<String,Drawable> mIconCache = new HashMap<String,Drawable>();
+    private HashMap<String,UidToDetail> mUidCache = new HashMap<String,UidToDetail>();
 
     /** Queue for fetching name and icon for an application */
     private ArrayList<BatterySipper> mRequestQueue = new ArrayList<BatterySipper>();
     private Thread mRequestThread;
     private boolean mAbort;
     
+    static class UidToDetail {
+        String name;
+        String packageName;
+        Drawable icon;
+    }
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -126,7 +131,12 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
         BatterySipper sipper = pgp.getInfo();
         Intent intent = new Intent(this, PowerUsageDetail.class);
         intent.putExtra(PowerUsageDetail.EXTRA_TITLE, sipper.name);
-        intent.putExtra(PowerUsageDetail.EXTRA_PERCENT, sipper.getSortValue() * 100 / mTotalPower);
+        intent.putExtra(PowerUsageDetail.EXTRA_PERCENT, (int)
+                Math.ceil(sipper.getSortValue() * 100 / mTotalPower));
+        intent.putExtra(PowerUsageDetail.EXTRA_GAUGE, (int)
+                Math.ceil(sipper.getSortValue() * 100 / mMaxPower));
+        intent.putExtra(PowerUsageDetail.EXTRA_ICON_PACKAGE, sipper.defaultPackageName);
+        intent.putExtra(PowerUsageDetail.EXTRA_ICON_ID, sipper.iconId);
         if (sipper.uidObj != null) {
             intent.putExtra(PowerUsageDetail.EXTRA_UID, sipper.uidObj.getUid());
         }
@@ -266,7 +276,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
     private void updateStatsPeriod(long duration) {
         String durationString = Utils.formatElapsedTime(this, duration / 1000);
         String label = getString(R.string.battery_stats_duration, durationString);
-        mAppListGroup.setTitle(label);
+        setTitle(label);
     }
 
     private void processAppUsage() {
@@ -475,8 +485,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
         addWiFiUsage(uSecNow);
         addBluetoothUsage(uSecNow);
         addIdleUsage(uSecNow); // Not including cellular idle power
-        //addRadioUsage(uSecNow); // Cannot include this because airplane mode is not tracked yet
-                                  // and we don't know if the radio is currently running on 2/3G.
+        addRadioUsage(uSecNow);
     }
 
     private void addEntry(String label, DrainType drainType, long time, int iconId, double power) {
@@ -484,6 +493,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
         mTotalPower += power;
         BatterySipper bs = new BatterySipper(label, drainType, iconId, null, new double[] {power});
         bs.usageTime = time;
+        bs.iconId = iconId;
         mUsageList.add(bs);
     }
 
@@ -503,6 +513,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
     class BatterySipper implements Comparable<BatterySipper> {
         String name;
         Drawable icon;
+        int iconId; // For passing to the detail screen.
         Uid uidObj;
         double value;
         double[] values;
@@ -512,6 +523,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
         long gpsTime;
         long cpuFgTime;
         double percent;
+        String defaultPackageName;
 
         BatterySipper(String label, DrainType drainType, int iconId, Uid uid, double[] values) {
             this.values = values;
@@ -548,20 +560,28 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
         void getQuickNameIconForUid(Uid uidObj) {
             final int uid = uidObj.getUid();
             final String uidString = Integer.toString(uid);
-            if (mNameCache.containsKey(uidString)) {
-                name = mNameCache.get(uidString);
-                icon = mIconCache.get(uidString);
+            if (mUidCache.containsKey(uidString)) {
+                UidToDetail utd = mUidCache.get(uidString);
+                defaultPackageName = utd.packageName;
+                name = utd.name;
+                icon = utd.icon;
                 return;
             }
             PackageManager pm = getPackageManager();
             final Drawable defaultActivityIcon = pm.getDefaultActivityIcon();
             String[] packages = pm.getPackagesForUid(uid);
+            icon = pm.getDefaultActivityIcon();
             if (packages == null) {
-                name = Integer.toString(uid);
+                //name = Integer.toString(uid);
+                if (uid == 0) {
+                    name = getResources().getString(R.string.process_kernel_label);
+                } else if (name.equals("mediaserver")) {
+                    name = getResources().getString(R.string.process_mediaserver_label);
+                }
+                return;
             } else {
                 //name = packages[0];
             }
-            icon = pm.getDefaultActivityIcon();
             synchronized (mRequestQueue) {
                 mRequestQueue.add(this);
             }
@@ -596,6 +616,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
                         packageLabels[i] = label.toString();
                     }
                     if (ai.icon != 0) {
+                        defaultPackageName = packages[i];
                         icon = ai.loadIcon(pm);
                         break;
                     }
@@ -617,6 +638,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
                             if (nm != null) {
                                 name = nm.toString();
                                 if (pi.applicationInfo.icon != 0) {
+                                    defaultPackageName = pkgName;
                                     icon = pi.applicationInfo.loadIcon(pm);
                                 }
                                 break;
@@ -627,8 +649,11 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
                 }
             }
             final String uidString = Integer.toString(uidObj.getUid());
-            mNameCache.put(uidString, name);
-            mIconCache.put(uidString, icon);
+            UidToDetail utd = new UidToDetail();
+            utd.name = name;
+            utd.icon = icon;
+            utd.packageName = defaultPackageName;
+            mUidCache.put(uidString, utd);
             mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_NAME_ICON, this));
         }
     }