summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/android/packageinstaller/InstallAppConfirmation.java2
-rwxr-xr-xsrc/com/android/packageinstaller/InstallAppDone.java5
-rwxr-xr-xsrc/com/android/packageinstaller/InstallAppProgress.java2
-rw-r--r--src/com/android/packageinstaller/PackageInstallerActivity.java3
-rw-r--r--src/com/android/packageinstaller/PackageUtil.java86
-rwxr-xr-xsrc/com/android/packageinstaller/UninstallAppProgress.java4
-rwxr-xr-xsrc/com/android/packageinstaller/UninstallerActivity.java2
7 files changed, 72 insertions, 32 deletions
diff --git a/src/com/android/packageinstaller/InstallAppConfirmation.java b/src/com/android/packageinstaller/InstallAppConfirmation.java
index fe7126b9..5a65e568 100755
--- a/src/com/android/packageinstaller/InstallAppConfirmation.java
+++ b/src/com/android/packageinstaller/InstallAppConfirmation.java
@@ -77,7 +77,7 @@ public class InstallAppConfirmation extends Activity implements View.OnClickList
mContentView = inflater.inflate(R.layout.install_confirm, null);
setContentView(mContentView);
//initialize views
- PackageUtil.initAppSnippet(this, mAppInfo, R.id.app_snippet);
+ PackageUtil.initSnippetForNewApp(this, mAppInfo, R.id.app_snippet, mPkgURI);
if(desc != null) {
((TextView)findViewById(R.id.security_settings_desc)).setText(desc);
}
diff --git a/src/com/android/packageinstaller/InstallAppDone.java b/src/com/android/packageinstaller/InstallAppDone.java
index 141517a7..36bd7e0f 100755
--- a/src/com/android/packageinstaller/InstallAppDone.java
+++ b/src/com/android/packageinstaller/InstallAppDone.java
@@ -23,6 +23,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@@ -42,6 +43,7 @@ public class InstallAppDone extends Activity implements View.OnClickListener {
private final String TAG="InstallAppDone";
private boolean localLOGV = false;
private ApplicationInfo mAppInfo;
+ private Uri mPkgURI;
private Button mDoneButton;
private Button mLaunchButton;
private boolean installFlag;
@@ -52,6 +54,7 @@ public class InstallAppDone extends Activity implements View.OnClickListener {
super.onCreate(icicle);
Intent intent = getIntent();
mAppInfo = intent.getParcelableExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO);
+ mPkgURI = intent.getData();
installFlag = intent.getBooleanExtra(PackageUtil.INTENT_ATTR_INSTALL_STATUS, true);
if(localLOGV) Log.i(TAG, "installFlag="+installFlag);
initView();
@@ -62,7 +65,7 @@ public class InstallAppDone extends Activity implements View.OnClickListener {
String unknown = getString(R.string.unknown);
setContentView(R.layout.install_done);
// Initialize views
- PackageUtil.initAppSnippet(this, mAppInfo, R.id.app_snippet);
+ PackageUtil.initSnippetForInstalledApp(this, mAppInfo, R.id.app_snippet);
TextView centerText = (TextView)findViewById(R.id.center_text);
mDoneButton = (Button)findViewById(R.id.done_button);
mLaunchButton = (Button)findViewById(R.id.launch_button);
diff --git a/src/com/android/packageinstaller/InstallAppProgress.java b/src/com/android/packageinstaller/InstallAppProgress.java
index 5b92d098..28abd3cc 100755
--- a/src/com/android/packageinstaller/InstallAppProgress.java
+++ b/src/com/android/packageinstaller/InstallAppProgress.java
@@ -89,7 +89,7 @@ public class InstallAppProgress extends Activity {
String unknown = getString(R.string.unknown);
setContentView(R.layout.op_progress);
//initialize views
- PackageUtil.initAppSnippet(this, mAppInfo, R.id.app_snippet);
+ PackageUtil.initSnippetForNewApp(this, mAppInfo, R.id.app_snippet, mPackageURI);
TextView installTextView = (TextView)findViewById(R.id.center_text);
installTextView.setText(R.string.installing);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java
index 613432c3..2d0094d8 100644
--- a/src/com/android/packageinstaller/PackageInstallerActivity.java
+++ b/src/com/android/packageinstaller/PackageInstallerActivity.java
@@ -353,7 +353,8 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
//set view
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.install_start);
- PackageUtil.initAppSnippet(this, mPkgInfo.applicationInfo, R.id.app_snippet);
+ PackageUtil.initSnippetForNewApp(this, mPkgInfo.applicationInfo,
+ R.id.app_snippet, mPackageURI);
//check setting
if(!isInstallingUnknownAppsAllowed()) {
//ask user to enable setting first
diff --git a/src/com/android/packageinstaller/PackageUtil.java b/src/com/android/packageinstaller/PackageUtil.java
index b36bcf2b..362c9636 100644
--- a/src/com/android/packageinstaller/PackageUtil.java
+++ b/src/com/android/packageinstaller/PackageUtil.java
@@ -27,9 +27,14 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.ResolveInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.AssetManager;
+import android.content.res.Configuration;
+import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
@@ -73,38 +78,69 @@ public class PackageUtil {
metrics.setToDefaults();
return packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);
}
-
- /*
- * Utility method to get application label from package manager for a given context
- */
- public static CharSequence getApplicationLabel(Context context, ApplicationInfo appInfo) {
- CharSequence appName = appInfo.loadLabel(context.getPackageManager());
- if(appName == null) {
- appName = context.getString(R.string.unknown);
- }
- return appName;
- }
-
+
/*
- * Utility method to getApplicationIcon from package manager for a given context
+ * Utility method to display application snippet of an installed application.
+ * The content view should have been set on context before invoking this method.
+ * appSnippet view should include R.id.app_icon and R.id.app_name
+ * defined on it.
+ *
+ * @param pContext context of package that can load the resources
+ * @param appInfo ApplicationInfo object of package whose resources are to be loaded
+ * @param snippetId view id of app snippet view
*/
- public static Drawable getApplicationIcon(Context context, ApplicationInfo appInfo) {
- return appInfo.loadIcon(context.getPackageManager());
+ public static View initSnippetForInstalledApp(Activity pContext,
+ ApplicationInfo appInfo, int snippetId) {
+ View appSnippet = pContext.findViewById(snippetId);
+ String pkgName = appInfo.packageName;
+ PackageManager pm = pContext.getPackageManager();
+ CharSequence label = appInfo.loadLabel(pm);
+ Drawable icon = appInfo.loadIcon(pm);
+ ((ImageView)appSnippet.findViewById(R.id.app_icon)).setImageDrawable(icon);
+ ((TextView)appSnippet.findViewById(R.id.app_name)).setText(label);
+ return appSnippet;
}
-
+
/*
- * Utility method to display application snippet. make sure to setContentView on context
- * before invoking this method
+ * Utility method to display application snippet of a new package.
+ * The content view should have been set on context before invoking this method.
+ * appSnippet view should include R.id.app_icon and R.id.app_name
+ * defined on it.
+ *
+ * @param pContext context of package that can load the resources
+ * @param appInfo ApplicationInfo object of package whose resources are to be loaded
+ * @param snippetId view id of app snippet view
*/
- public static View initAppSnippet(Activity context, ApplicationInfo appInfo, int snippetId) {
- View appSnippet = context.findViewById(snippetId);
- ((ImageView)appSnippet.findViewById(R.id.app_icon)).setImageDrawable(
- getApplicationIcon(context, appInfo));
- ((TextView)appSnippet.findViewById(R.id.app_name)).setText(
- getApplicationLabel(context, appInfo));
+ public static View initSnippetForNewApp(Activity pContext, ApplicationInfo appInfo,
+ int snippetId, Uri packageURI) {
+ View appSnippet = pContext.findViewById(snippetId);
+ final String archiveFilePath = packageURI.getPath();
+ DisplayMetrics metrics = new DisplayMetrics();
+ metrics.setToDefaults();
+ AssetManager assmgr = new AssetManager();
+ assmgr.addAssetPath(archiveFilePath);
+ Resources res = new Resources(assmgr, metrics, null);
+ CharSequence label = null;
+ // Try to load the label from the package's resources. If an app has not explicitly
+ // specified any label, just use the package name.
+ try {
+ label = res.getText(appInfo.labelRes);
+ } catch (Resources.NotFoundException e) {
+ label = appInfo.packageName;
+ }
+ Drawable icon = null;
+ // Try to load the icon from the package's resources. If an app has not explicitly
+ // specified any resource, just use the default icon for now.
+ try {
+ icon = res.getDrawable(appInfo.icon);
+ } catch (Resources.NotFoundException e) {
+ icon = pContext.getPackageManager().getDefaultActivityIcon();
+ }
+ ((ImageView)appSnippet.findViewById(R.id.app_icon)).setImageDrawable(icon);
+ ((TextView)appSnippet.findViewById(R.id.app_name)).setText(label);
return appSnippet;
}
-
+
public static boolean isPackageAlreadyInstalled(Activity context, String pkgName) {
List<PackageInfo> installedList = context.getPackageManager().getInstalledPackages(
PackageManager.GET_UNINSTALLED_PACKAGES);
diff --git a/src/com/android/packageinstaller/UninstallAppProgress.java b/src/com/android/packageinstaller/UninstallAppProgress.java
index 6b30118b..6be099db 100755
--- a/src/com/android/packageinstaller/UninstallAppProgress.java
+++ b/src/com/android/packageinstaller/UninstallAppProgress.java
@@ -79,8 +79,8 @@ public class UninstallAppProgress extends Activity {
public void initView() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.op_progress);
- //initialize views
- PackageUtil.initAppSnippet(this, mAppInfo, R.id.app_snippet);
+ // Initialize views
+ PackageUtil.initSnippetForInstalledApp(this, mAppInfo, R.id.app_snippet);
TextView installTextView = (TextView)findViewById(R.id.center_text);
installTextView.setText(R.string.uninstalling);
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
diff --git a/src/com/android/packageinstaller/UninstallerActivity.java b/src/com/android/packageinstaller/UninstallerActivity.java
index f22cc28a..00658247 100755
--- a/src/com/android/packageinstaller/UninstallerActivity.java
+++ b/src/com/android/packageinstaller/UninstallerActivity.java
@@ -138,7 +138,7 @@ public class UninstallerActivity extends Activity implements OnClickListener {
requestWindowFeature(Window.FEATURE_NO_TITLE);
//set view
setContentView(R.layout.uninstall_confirm);
- PackageUtil.initAppSnippet(this, mAppInfo, R.id.app_snippet);
+ PackageUtil.initSnippetForInstalledApp(this, mAppInfo, R.id.app_snippet);
//initialize ui elements
mOk = (Button)findViewById(R.id.ok_button);
mCancel = (Button)findViewById(R.id.cancel_button);