diff options
author | Svetoslav <svetoslavganov@google.com> | 2013-10-28 15:22:14 -0700 |
---|---|---|
committer | Svetoslav <svetoslavganov@google.com> | 2013-10-28 16:26:47 -0700 |
commit | baeabb65e1e818c6679036774933f40e8540b293 (patch) | |
tree | dfebc657da1d88614053f4a07afd4f03e01d9ca1 | |
parent | 714ba34556572d36b1f9f8d9b860c4da24da6361 (diff) | |
download | frameworks_base-baeabb65e1e818c6679036774933f40e8540b293.zip frameworks_base-baeabb65e1e818c6679036774933f40e8540b293.tar.gz frameworks_base-baeabb65e1e818c6679036774933f40e8540b293.tar.bz2 |
Not show share targets that cannot be launched.
This changes filters out share targets that we cannot start
because the target does not properly implement the SEND protocol
and has either share target activity hidden or requires a
permission to launch it. Also the code that launches the share
target activity catches the runtime exception and shows an error
message. Note that being able to launch an activity in a moment
of time is not a guarantee that one can do that latter. Hence,
being able to launch an activity while building the share UI
does not guarantee that one can launch it when selecting the
share target.
bug:11402139
Change-Id: Id35732510755b2eeb9eccacc046d289c2f2ee856
-rw-r--r-- | core/java/android/widget/ActivityChooserModel.java | 10 | ||||
-rw-r--r-- | core/java/android/widget/ActivityChooserView.java | 29 | ||||
-rw-r--r-- | core/res/res/values/strings.xml | 3 | ||||
-rw-r--r-- | core/res/res/values/symbols.xml | 1 |
4 files changed, 34 insertions, 9 deletions
diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java index 736566e..00a92ca 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; } 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; } diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 490eab8..62f26c6 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3901,6 +3901,9 @@ <!-- Description of the shwoing of a popup window with activities to choose from. [CHAR LIMIT=NONE] --> <string name="activitychooserview_choose_application">Choose an app</string> + <!-- Error message if the share target app cannto be launched. [CHAR LIMIT=NONE] --> + <string name="activitychooserview_choose_application_error">Couldn\'t launch <xliff:g id="application_name" example="Acme">%s</xliff:g></string> + <!-- ShareActionProvider - accessibility support --> <!-- Description of the choose target button in a ShareActionProvider (share UI). [CHAR LIMIT=NONE] --> <string name="shareactionprovider_share_with">Share with</string> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index a5573c9..22a9402 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -392,6 +392,7 @@ <java-symbol type="string" name="accessibility_enabled" /> <java-symbol type="string" name="activity_chooser_view_see_all" /> <java-symbol type="string" name="activitychooserview_choose_application" /> + <java-symbol type="string" name="activitychooserview_choose_application_error" /> <java-symbol type="string" name="alternate_eri_file" /> <java-symbol type="string" name="alwaysUse" /> <java-symbol type="string" name="autofill_address_line_1_label_re" /> |