diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/widget/ActivityChooserModel.java | 30 | ||||
| -rw-r--r-- | core/java/android/widget/ActivityChooserView.java | 29 |
2 files changed, 41 insertions, 18 deletions
diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java index 736566e..61df922 100644 --- a/core/java/android/widget/ActivityChooserModel.java +++ b/core/java/android/widget/ActivityChooserModel.java @@ -16,9 +16,12 @@ package android.widget; +import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.DataSetObservable; import android.os.AsyncTask; @@ -708,7 +711,12 @@ public class ActivityChooserModel extends DataSetObservable { final int resolveInfoCount = resolveInfos.size(); for (int i = 0; i < resolveInfoCount; i++) { ResolveInfo resolveInfo = resolveInfos.get(i); - mActivities.add(new ActivityResolveInfo(resolveInfo)); + ActivityInfo activityInfo = resolveInfo.activityInfo; + if (ActivityManager.checkComponentPermission(activityInfo.permission, + android.os.Process.myUid(), activityInfo.applicationInfo.uid, + activityInfo.exported) == PackageManager.PERMISSION_GRANTED) { + mActivities.add(new ActivityResolveInfo(resolveInfo)); + } } return true; } @@ -930,29 +938,31 @@ public class ActivityChooserModel extends DataSetObservable { private final class DefaultSorter implements ActivitySorter { private static final float WEIGHT_DECAY_COEFFICIENT = 0.95f; - private final Map<String, ActivityResolveInfo> mPackageNameToActivityMap = - new HashMap<String, ActivityResolveInfo>(); + private final Map<ComponentName, ActivityResolveInfo> mPackageNameToActivityMap = + new HashMap<ComponentName, ActivityResolveInfo>(); public void sort(Intent intent, List<ActivityResolveInfo> activities, List<HistoricalRecord> historicalRecords) { - Map<String, ActivityResolveInfo> packageNameToActivityMap = - mPackageNameToActivityMap; - packageNameToActivityMap.clear(); + Map<ComponentName, ActivityResolveInfo> componentNameToActivityMap = + mPackageNameToActivityMap; + componentNameToActivityMap.clear(); final int activityCount = activities.size(); for (int i = 0; i < activityCount; i++) { ActivityResolveInfo activity = activities.get(i); activity.weight = 0.0f; - String packageName = activity.resolveInfo.activityInfo.packageName; - packageNameToActivityMap.put(packageName, activity); + ComponentName componentName = new ComponentName( + activity.resolveInfo.activityInfo.packageName, + activity.resolveInfo.activityInfo.name); + componentNameToActivityMap.put(componentName, activity); } final int lastShareIndex = historicalRecords.size() - 1; float nextRecordWeight = 1; for (int i = lastShareIndex; i >= 0; i--) { HistoricalRecord historicalRecord = historicalRecords.get(i); - String packageName = historicalRecord.activity.getPackageName(); - ActivityResolveInfo activity = packageNameToActivityMap.get(packageName); + ComponentName componentName = historicalRecord.activity; + ActivityResolveInfo activity = componentNameToActivityMap.get(componentName); if (activity != null) { activity.weight += historicalRecord.weight * nextRecordWeight; nextRecordWeight = nextRecordWeight * WEIGHT_DECAY_COEFFICIENT; diff --git a/core/java/android/widget/ActivityChooserView.java b/core/java/android/widget/ActivityChooserView.java index dff1531..8612964 100644 --- a/core/java/android/widget/ActivityChooserView.java +++ b/core/java/android/widget/ActivityChooserView.java @@ -18,6 +18,7 @@ package android.widget; import com.android.internal.R; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -27,6 +28,7 @@ import android.content.res.TypedArray; import android.database.DataSetObserver; import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.util.Log; import android.view.ActionProvider; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -63,6 +65,8 @@ import android.widget.ListPopupWindow.ForwardingListener; */ public class ActivityChooserView extends ViewGroup implements ActivityChooserModelClient { + private static final String LOG_TAG = "ActivityChooserView"; + /** * An adapter for displaying the activities in an {@link AdapterView}. */ @@ -543,9 +547,9 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod } // Activity chooser content. if (mDefaultActivityButton.getVisibility() == VISIBLE) { - mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground); + mActivityChooserContent.setBackground(mActivityChooserContentBackground); } else { - mActivityChooserContent.setBackgroundDrawable(null); + mActivityChooserContent.setBackground(null); } } @@ -577,7 +581,8 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod Intent launchIntent = mAdapter.getDataModel().chooseActivity(position); if (launchIntent != null) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - mContext.startActivity(launchIntent); + ResolveInfo resolveInfo = mAdapter.getDataModel().getActivity(position); + startActivity(launchIntent, resolveInfo); } } } break; @@ -595,7 +600,7 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod Intent launchIntent = mAdapter.getDataModel().chooseActivity(index); if (launchIntent != null) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - mContext.startActivity(launchIntent); + startActivity(launchIntent, defaultActivity); } } else if (view == mExpandActivityOverflowButton) { mIsSelectingDefaultActivity = false; @@ -632,6 +637,18 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod mOnDismissListener.onDismiss(); } } + + private void startActivity(Intent intent, ResolveInfo resolveInfo) { + try { + mContext.startActivity(intent); + } catch (RuntimeException re) { + CharSequence appLabel = resolveInfo.loadLabel(mContext.getPackageManager()); + String message = mContext.getString( + R.string.activitychooserview_choose_application_error, appLabel); + Log.e(LOG_TAG, message); + Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); + } + } } /** @@ -805,10 +822,6 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod return mDataModel.getHistorySize(); } - public int getMaxActivityCount() { - return mMaxActivityCount; - } - public ActivityChooserModel getDataModel() { return mDataModel; } |
