OSDN Git Service

Manage apps "on SD card" now shows all apps that can go on SD card.
authorDianne Hackborn <hackbod@google.com>
Tue, 5 Oct 2010 01:32:59 +0000 (18:32 -0700)
committerDianne Hackborn <hackbod@google.com>
Tue, 5 Oct 2010 05:35:26 +0000 (22:35 -0700)
Change-Id: Icc413891b2b884bb1af340b4c09ab3935c8e51ca

res/layout/manage_applications_item.xml
src/com/android/settings/applications/ApplicationsState.java
src/com/android/settings/applications/InstalledAppDetails.java
src/com/android/settings/applications/ManageApplications.java

index c4b0937..78d9a02 100755 (executable)
@@ -37,7 +37,8 @@
 
     <LinearLayout
         android:orientation="vertical"
-        android:layout_width="match_parent"
+        android:layout_width="0px"
+        android:layout_weight="1"
         android:layout_height="wrap_content" >
         <TextView android:id="@+id/app_name"
             android:layout_width="wrap_content"
                 android:text="@string/disabled" />
         </LinearLayout>
     </LinearLayout>
+    
+    <CheckBox android:id="@+id/app_on_sdcard"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="5dip"
+        android:layout_gravity="center_vertical"
+        android:visibility="gone"
+        android:clickable="false"
+        android:focusable="false" />
 </LinearLayout>
-
index 8924b29..9515624 100644 (file)
@@ -49,6 +49,7 @@ public class ApplicationsState {
     }
 
     public static interface AppFilter {
+        public void init();
         public boolean filterApp(ApplicationInfo info);
     }
 
@@ -119,6 +120,9 @@ public class ApplicationsState {
     };
 
     public static final AppFilter THIRD_PARTY_FILTER = new AppFilter() {
+        public void init() {
+        }
+        
         @Override
         public boolean filterApp(ApplicationInfo info) {
             if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
@@ -131,12 +135,16 @@ public class ApplicationsState {
     };
 
     public static final AppFilter ON_SD_CARD_FILTER = new AppFilter() {
+        final CanBeOnSdCardChecker mCanBeOnSdCardChecker
+                = new CanBeOnSdCardChecker();
+        
+        public void init() {
+            mCanBeOnSdCardChecker.init();
+        }
+        
         @Override
         public boolean filterApp(ApplicationInfo info) {
-            if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
-                return true;
-            }
-            return false;
+            return mCanBeOnSdCardChecker.check(info);
         }
     };
 
@@ -367,6 +375,10 @@ public class ApplicationsState {
 
         Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
 
+        if (filter != null) {
+            filter.init();
+        }
+        
         List<ApplicationInfo> apps;
         synchronized (mEntriesMap) {
             apps = new ArrayList<ApplicationInfo>(mApplications);
index f684c1d..912cc3e 100644 (file)
@@ -77,6 +77,7 @@ public class InstalledAppDetails extends Activity
     private ApplicationsState mState;
     private ApplicationsState.AppEntry mAppEntry;
     private PackageInfo mPackageInfo;
+    private CanBeOnSdCardChecker mCanBeOnSdCardChecker;
     private Button mUninstallButton;
     private boolean mMoveInProgress = false;
     private boolean mUpdatedSysApp = false;
@@ -229,30 +230,8 @@ public class InstalledAppDetails extends Activity
             moveDisable = false;
         } else {
             mMoveAppButton.setText(R.string.move_app_to_sdcard);
-            if ((mAppEntry.info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0 &&
-                    (mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) == 0 &&
-                    mPackageInfo != null) {
-                if (mPackageInfo.installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL ||
-                        mPackageInfo.installLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
-                    moveDisable = false;
-                } else if (mPackageInfo.installLocation
-                        == PackageInfo.INSTALL_LOCATION_UNSPECIFIED) {
-                    IPackageManager ipm  = IPackageManager.Stub.asInterface(
-                            ServiceManager.getService("package"));
-                    int loc;
-                    try {
-                        loc = ipm.getInstallLocation();
-                    } catch (RemoteException e) {
-                        Log.e(TAG, "Is Pakage Manager running?");
-                        return;
-                    }
-                    if (loc == PackageHelper.APP_INSTALL_EXTERNAL) {
-                        // For apps with no preference and the default value set
-                        // to install on sdcard.
-                        moveDisable = false;
-                    }
-                }
-            }
+            mCanBeOnSdCardChecker.init();
+            moveDisable = !mCanBeOnSdCardChecker.check(mAppEntry.info);
         }
         if (moveDisable) {
             mMoveAppButton.setEnabled(false);
@@ -316,6 +295,8 @@ public class InstalledAppDetails extends Activity
         mState = ApplicationsState.getInstance(getApplication());
         mPm = getPackageManager();
         
+        mCanBeOnSdCardChecker = new CanBeOnSdCardChecker();
+        
         setContentView(R.layout.installed_app_details);
         
         mComputingStr = getText(R.string.computing_size);
index 9c6ae7a..40f4ddd 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.settings.applications;
 
+import com.android.internal.content.PackageHelper;
 import com.android.settings.R;
 import com.android.settings.applications.ApplicationsState.AppEntry;
 
@@ -24,8 +25,12 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.ServiceManager;
 import android.provider.Settings;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -38,6 +43,7 @@ import android.view.animation.AnimationUtils;
 import android.widget.AbsListView;
 import android.widget.AdapterView;
 import android.widget.BaseAdapter;
+import android.widget.CheckBox;
 import android.widget.Filter;
 import android.widget.Filterable;
 import android.widget.ImageView;
@@ -50,6 +56,48 @@ import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
 
+final class CanBeOnSdCardChecker {
+    final IPackageManager mPm;
+    int mInstallLocation;
+    
+    CanBeOnSdCardChecker() {
+        mPm = IPackageManager.Stub.asInterface(
+                ServiceManager.getService("package"));
+    }
+    
+    void init() {
+        try {
+            mInstallLocation = mPm.getInstallLocation();
+        } catch (RemoteException e) {
+            Log.e("CanBeOnSdCardChecker", "Is Package Manager running?");
+            return;
+        }
+    }
+    
+    boolean check(ApplicationInfo info) {
+        boolean canBe = false;
+        if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
+            canBe = true;
+        } else {
+            if ((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0 &&
+                    (info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
+                if (info.installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL ||
+                        info.installLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
+                    canBe = true;
+                } else if (info.installLocation
+                        == PackageInfo.INSTALL_LOCATION_UNSPECIFIED) {
+                    if (mInstallLocation == PackageHelper.APP_INSTALL_EXTERNAL) {
+                        // For apps with no preference and the default value set
+                        // to install on sdcard.
+                        canBe = true;
+                    }
+                }
+            }
+        }
+        return canBe;
+    }
+}
+
 /**
  * Activity to pick an application that will be used to display installation information and
  * options to uninstall/delete user data for system applications. This activity
@@ -125,6 +173,7 @@ public class ManageApplications extends TabActivity implements
         ImageView appIcon;
         TextView appSize;
         TextView disabled;
+        CheckBox checkBox;
         
         void updateSizeText(ManageApplications ma) {
             if (DEBUG) Log.i(TAG, "updateSizeText of " + entry.label + " " + entry
@@ -364,6 +413,7 @@ public class ManageApplications extends TabActivity implements
                 holder.appIcon = (ImageView) convertView.findViewById(R.id.app_icon);
                 holder.appSize = (TextView) convertView.findViewById(R.id.app_size);
                 holder.disabled = (TextView) convertView.findViewById(R.id.app_disabled);
+                holder.checkBox = (CheckBox) convertView.findViewById(R.id.app_on_sdcard);
                 convertView.setTag(holder);
             } else {
                 // Get the ViewHolder back to get fast access to the TextView
@@ -391,6 +441,13 @@ public class ManageApplications extends TabActivity implements
                 } else {
                     holder.disabled.setVisibility(View.GONE);
                 }
+                if (mLastFilterMode == FILTER_APPS_SDCARD) {
+                    holder.checkBox.setVisibility(View.VISIBLE);
+                    holder.checkBox.setChecked((entry.info.flags
+                            & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
+                } else {
+                    holder.checkBox.setVisibility(View.GONE);
+                }
             }
             mActive.remove(convertView);
             mActive.add(convertView);