Loading core/java/com/android/internal/app/ChooserActivity.java +3 −168 Original line number Original line Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.content.IntentSender; import android.content.IntentSender; import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; Loading @@ -71,11 +70,9 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Bundle; import android.os.Environment; import android.os.Environment; import android.os.Handler; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Message; import android.os.Parcelable; import android.os.Parcelable; import android.os.PatternMatcher; import android.os.PatternMatcher; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ResultReceiver; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; Loading @@ -86,13 +83,10 @@ import android.provider.Downloads; import android.provider.OpenableColumns; import android.provider.OpenableColumns; import android.provider.Settings; import android.provider.Settings; import android.service.chooser.ChooserTarget; import android.service.chooser.ChooserTarget; import android.service.chooser.IChooserTargetResult; import android.service.chooser.IChooserTargetService; import android.text.TextUtils; import android.text.TextUtils; import android.util.AttributeSet; import android.util.AttributeSet; import android.util.HashedStringCache; import android.util.HashedStringCache; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Size; import android.util.Size; import android.util.Slog; import android.util.Slog; import android.view.LayoutInflater; import android.view.LayoutInflater; Loading Loading @@ -144,10 +138,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Collections; import java.util.Comparator; import java.util.Comparator; import java.util.HashMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.List; import java.util.Map; import java.util.Map; import java.util.Set; /** /** * The Chooser Activity handles intent resolution specifically for sharing intents - * The Chooser Activity handles intent resolution specifically for sharing intents - Loading Loading @@ -205,7 +197,6 @@ public class ChooserActivity extends ResolverActivity implements private boolean mIsAppPredictorComponentAvailable; private boolean mIsAppPredictorComponentAvailable; private Map<ChooserTarget, AppTarget> mDirectShareAppTargetCache; private Map<ChooserTarget, AppTarget> mDirectShareAppTargetCache; private Map<ChooserTarget, ShortcutInfo> mDirectShareShortcutInfoCache; private Map<ChooserTarget, ShortcutInfo> mDirectShareShortcutInfoCache; private Map<ComponentName, ComponentName> mChooserTargetComponentNameCache; public static final int TARGET_TYPE_DEFAULT = 0; public static final int TARGET_TYPE_DEFAULT = 0; public static final int TARGET_TYPE_CHOOSER_TARGET = 1; public static final int TARGET_TYPE_CHOOSER_TARGET = 1; Loading Loading @@ -274,9 +265,6 @@ public class ChooserActivity extends ResolverActivity implements private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment"; private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment"; private final List<ChooserTargetServiceConnection> mServiceConnections = new ArrayList<>(); private final Set<Pair<ComponentName, UserHandle>> mServicesRequested = new HashSet<>(); private static final int MAX_LOG_RANK_POSITION = 12; private static final int MAX_LOG_RANK_POSITION = 12; private static final int MAX_EXTRA_INITIAL_INTENTS = 2; private static final int MAX_EXTRA_INITIAL_INTENTS = 2; Loading Loading @@ -453,16 +441,12 @@ public class ChooserActivity extends ResolverActivity implements private final ChooserHandler mChooserHandler = new ChooserHandler(); private final ChooserHandler mChooserHandler = new ChooserHandler(); private class ChooserHandler extends Handler { private class ChooserHandler extends Handler { private static final int CHOOSER_TARGET_SERVICE_RESULT = 1; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT = 4; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT = 4; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED = 5; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED = 5; private static final int LIST_VIEW_UPDATE_MESSAGE = 6; private static final int LIST_VIEW_UPDATE_MESSAGE = 6; private boolean mReceivedDirectShareTargets = false; private void removeAllMessages() { private void removeAllMessages() { removeMessages(LIST_VIEW_UPDATE_MESSAGE); removeMessages(LIST_VIEW_UPDATE_MESSAGE); removeMessages(CHOOSER_TARGET_SERVICE_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED); } } Loading @@ -474,36 +458,6 @@ public class ChooserActivity extends ResolverActivity implements } } switch (msg.what) { switch (msg.what) { case CHOOSER_TARGET_SERVICE_RESULT: if (DEBUG) Log.d(TAG, "CHOOSER_TARGET_SERVICE_RESULT"); final ServiceResultInfo sri = (ServiceResultInfo) msg.obj; if (!mServiceConnections.contains(sri.connection)) { Log.w(TAG, "ChooserTargetServiceConnection " + sri.connection + sri.originalTarget.getResolveInfo().activityInfo.packageName + " returned after being removed from active connections." + " Have you considered returning results faster?"); break; } if (sri.resultTargets != null) { ChooserListAdapter adapterForUserHandle = mChooserMultiProfilePagerAdapter.getListAdapterForUserHandle( sri.userHandle); if (adapterForUserHandle != null) { adapterForUserHandle.addServiceResults(sri.originalTarget, sri.resultTargets, TARGET_TYPE_CHOOSER_TARGET, /* directShareShortcutInfoCache */ null); if (!sri.resultTargets.isEmpty() && sri.originalTarget != null) { mChooserTargetComponentNameCache.put( sri.resultTargets.get(0).getComponentName(), sri.originalTarget.getResolvedComponentName()); } } } unbindService(sri.connection); sri.connection.destroy(); mServiceConnections.remove(sri.connection); break; case LIST_VIEW_UPDATE_MESSAGE: case LIST_VIEW_UPDATE_MESSAGE: if (DEBUG) { if (DEBUG) { Log.d(TAG, "LIST_VIEW_UPDATE_MESSAGE; "); Log.d(TAG, "LIST_VIEW_UPDATE_MESSAGE; "); Loading Loading @@ -748,7 +702,6 @@ public class ChooserActivity extends ResolverActivity implements target.getAction() target.getAction() ); ); mDirectShareShortcutInfoCache = new HashMap<>(); mDirectShareShortcutInfoCache = new HashMap<>(); mChooserTargetComponentNameCache = new HashMap<>(); setEnterSharedElementCallback(new SharedElementCallback() { setEnterSharedElementCallback(new SharedElementCallback() { @Override @Override Loading Loading @@ -1588,7 +1541,6 @@ public class ChooserActivity extends ResolverActivity implements mRefinementResultReceiver.destroy(); mRefinementResultReceiver.destroy(); mRefinementResultReceiver = null; mRefinementResultReceiver = null; } } unbindRemainingServices(); mChooserHandler.removeAllMessages(); mChooserHandler.removeAllMessages(); if (mPreviewCoord != null) mPreviewCoord.cancelLoads(); if (mPreviewCoord != null) mPreviewCoord.cancelLoads(); Loading Loading @@ -2013,7 +1965,7 @@ public class ChooserActivity extends ResolverActivity implements final Message msg = Message.obtain(); final Message msg = Message.obtain(); msg.what = ChooserHandler.SHORTCUT_MANAGER_SHARE_TARGET_RESULT; msg.what = ChooserHandler.SHORTCUT_MANAGER_SHARE_TARGET_RESULT; msg.obj = new ServiceResultInfo(chooserListAdapter.getDisplayResolveInfo(i), msg.obj = new ServiceResultInfo(chooserListAdapter.getDisplayResolveInfo(i), chooserTargets, null, userHandle); chooserTargets, userHandle); msg.arg1 = shortcutType; msg.arg1 = shortcutType; mChooserHandler.sendMessage(msg); mChooserHandler.sendMessage(msg); } } Loading Loading @@ -2132,20 +2084,6 @@ public class ChooserActivity extends ResolverActivity implements return fullName; return fullName; } } void unbindRemainingServices() { if (DEBUG) { Log.d(TAG, "unbindRemainingServices, " + mServiceConnections.size() + " left"); } for (int i = 0, N = mServiceConnections.size(); i < N; i++) { final ChooserTargetServiceConnection conn = mServiceConnections.get(i); if (DEBUG) Log.d(TAG, "unbinding " + conn); unbindService(conn); conn.destroy(); } mServicesRequested.clear(); mServiceConnections.clear(); } private void logDirectShareTargetReceived(int logCategory) { private void logDirectShareTargetReceived(int logCategory) { final int apiLatency = (int) (System.currentTimeMillis() - mQueriedSharingShortcutsTimeMs); final int apiLatency = (int) (System.currentTimeMillis() - mQueriedSharingShortcutsTimeMs); getMetricsLogger().write(new LogMaker(logCategory).setSubtype(apiLatency)); getMetricsLogger().write(new LogMaker(logCategory).setSubtype(apiLatency)); Loading Loading @@ -2193,8 +2131,7 @@ public class ChooserActivity extends ResolverActivity implements List<AppTargetId> targetIds = new ArrayList<>(); List<AppTargetId> targetIds = new ArrayList<>(); for (ChooserTargetInfo chooserTargetInfo : surfacedTargetInfo) { for (ChooserTargetInfo chooserTargetInfo : surfacedTargetInfo) { ChooserTarget chooserTarget = chooserTargetInfo.getChooserTarget(); ChooserTarget chooserTarget = chooserTargetInfo.getChooserTarget(); ComponentName componentName = mChooserTargetComponentNameCache.getOrDefault( ComponentName componentName = chooserTarget.getComponentName(); chooserTarget.getComponentName(), chooserTarget.getComponentName()); if (mDirectShareShortcutInfoCache.containsKey(chooserTarget)) { if (mDirectShareShortcutInfoCache.containsKey(chooserTarget)) { String shortcutId = mDirectShareShortcutInfoCache.get(chooserTarget).getId(); String shortcutId = mDirectShareShortcutInfoCache.get(chooserTarget).getId(); targetIds.add(new AppTargetId( targetIds.add(new AppTargetId( Loading Loading @@ -2685,7 +2622,6 @@ public class ChooserActivity extends ResolverActivity implements @Override // ResolverListCommunicator @Override // ResolverListCommunicator public void onHandlePackagesChanged(ResolverListAdapter listAdapter) { public void onHandlePackagesChanged(ResolverListAdapter listAdapter) { mServicesRequested.clear(); mChooserMultiProfilePagerAdapter.getActiveListAdapter().notifyDataSetChanged(); mChooserMultiProfilePagerAdapter.getActiveListAdapter().notifyDataSetChanged(); super.onHandlePackagesChanged(listAdapter); super.onHandlePackagesChanged(listAdapter); } } Loading Loading @@ -3793,116 +3729,15 @@ public class ChooserActivity extends ResolverActivity implements } } } } static class ChooserTargetServiceConnection implements ServiceConnection { private DisplayResolveInfo mOriginalTarget; private ComponentName mConnectedComponent; private ChooserActivity mChooserActivity; private final UserHandle mUserHandle; private final Object mLock = new Object(); private final IChooserTargetResult mChooserTargetResult = new IChooserTargetResult.Stub() { @Override public void sendResult(List<ChooserTarget> targets) throws RemoteException { synchronized (mLock) { if (mChooserActivity == null) { Log.e(TAG, "destroyed ChooserTargetServiceConnection received result from " + mConnectedComponent + "; ignoring..."); return; } Context contextAsUser = mChooserActivity.createContextAsUser(mUserHandle, 0 /* flags */); mChooserActivity.filterServiceTargets(contextAsUser, mOriginalTarget.getResolveInfo().activityInfo.packageName, targets); final Message msg = Message.obtain(); msg.what = ChooserHandler.CHOOSER_TARGET_SERVICE_RESULT; msg.obj = new ServiceResultInfo(mOriginalTarget, targets, ChooserTargetServiceConnection.this, mUserHandle); mChooserActivity.mChooserHandler.sendMessage(msg); } } }; public ChooserTargetServiceConnection(ChooserActivity chooserActivity, DisplayResolveInfo dri, UserHandle userHandle) { mChooserActivity = chooserActivity; mOriginalTarget = dri; mUserHandle = userHandle; } @Override public void onServiceConnected(ComponentName name, IBinder service) { if (DEBUG) Log.d(TAG, "onServiceConnected: " + name); synchronized (mLock) { if (mChooserActivity == null) { Log.e(TAG, "destroyed ChooserTargetServiceConnection got onServiceConnected"); return; } final IChooserTargetService icts = IChooserTargetService.Stub.asInterface(service); try { icts.getChooserTargets(mOriginalTarget.getResolvedComponentName(), mOriginalTarget.getResolveInfo().filter, mChooserTargetResult); } catch (RemoteException e) { Log.e(TAG, "Querying ChooserTargetService " + name + " failed.", e); mChooserActivity.unbindService(this); mChooserActivity.mServiceConnections.remove(this); destroy(); } } } @Override public void onServiceDisconnected(ComponentName name) { if (DEBUG) Log.d(TAG, "onServiceDisconnected: " + name); synchronized (mLock) { if (mChooserActivity == null) { Log.e(TAG, "destroyed ChooserTargetServiceConnection got onServiceDisconnected"); return; } mChooserActivity.unbindService(this); mChooserActivity.mServiceConnections.remove(this); if (mChooserActivity.mServiceConnections.isEmpty()) { mChooserActivity.sendVoiceChoicesIfNeeded(); } mConnectedComponent = null; destroy(); } } public void destroy() { synchronized (mLock) { mChooserActivity = null; mOriginalTarget = null; } } @Override public String toString() { return "ChooserTargetServiceConnection{service=" + mConnectedComponent + ", activity=" + (mOriginalTarget != null ? mOriginalTarget.getResolveInfo().activityInfo.toString() : "<connection destroyed>") + "}"; } public ComponentName getComponentName() { return mOriginalTarget.getResolveInfo().activityInfo.getComponentName(); } } static class ServiceResultInfo { static class ServiceResultInfo { public final DisplayResolveInfo originalTarget; public final DisplayResolveInfo originalTarget; public final List<ChooserTarget> resultTargets; public final List<ChooserTarget> resultTargets; public final ChooserTargetServiceConnection connection; public final UserHandle userHandle; public final UserHandle userHandle; public ServiceResultInfo(DisplayResolveInfo ot, List<ChooserTarget> rt, public ServiceResultInfo(DisplayResolveInfo ot, List<ChooserTarget> rt, ChooserTargetServiceConnection c, UserHandle userHandle) { UserHandle userHandle) { originalTarget = ot; originalTarget = ot; resultTargets = rt; resultTargets = rt; connection = c; this.userHandle = userHandle; this.userHandle = userHandle; } } } } Loading Loading
core/java/com/android/internal/app/ChooserActivity.java +3 −168 Original line number Original line Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.content.IntentSender; import android.content.IntentSender; import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; Loading @@ -71,11 +70,9 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Bundle; import android.os.Environment; import android.os.Environment; import android.os.Handler; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Message; import android.os.Parcelable; import android.os.Parcelable; import android.os.PatternMatcher; import android.os.PatternMatcher; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ResultReceiver; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; Loading @@ -86,13 +83,10 @@ import android.provider.Downloads; import android.provider.OpenableColumns; import android.provider.OpenableColumns; import android.provider.Settings; import android.provider.Settings; import android.service.chooser.ChooserTarget; import android.service.chooser.ChooserTarget; import android.service.chooser.IChooserTargetResult; import android.service.chooser.IChooserTargetService; import android.text.TextUtils; import android.text.TextUtils; import android.util.AttributeSet; import android.util.AttributeSet; import android.util.HashedStringCache; import android.util.HashedStringCache; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Size; import android.util.Size; import android.util.Slog; import android.util.Slog; import android.view.LayoutInflater; import android.view.LayoutInflater; Loading Loading @@ -144,10 +138,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Collections; import java.util.Comparator; import java.util.Comparator; import java.util.HashMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.List; import java.util.Map; import java.util.Map; import java.util.Set; /** /** * The Chooser Activity handles intent resolution specifically for sharing intents - * The Chooser Activity handles intent resolution specifically for sharing intents - Loading Loading @@ -205,7 +197,6 @@ public class ChooserActivity extends ResolverActivity implements private boolean mIsAppPredictorComponentAvailable; private boolean mIsAppPredictorComponentAvailable; private Map<ChooserTarget, AppTarget> mDirectShareAppTargetCache; private Map<ChooserTarget, AppTarget> mDirectShareAppTargetCache; private Map<ChooserTarget, ShortcutInfo> mDirectShareShortcutInfoCache; private Map<ChooserTarget, ShortcutInfo> mDirectShareShortcutInfoCache; private Map<ComponentName, ComponentName> mChooserTargetComponentNameCache; public static final int TARGET_TYPE_DEFAULT = 0; public static final int TARGET_TYPE_DEFAULT = 0; public static final int TARGET_TYPE_CHOOSER_TARGET = 1; public static final int TARGET_TYPE_CHOOSER_TARGET = 1; Loading Loading @@ -274,9 +265,6 @@ public class ChooserActivity extends ResolverActivity implements private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment"; private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment"; private final List<ChooserTargetServiceConnection> mServiceConnections = new ArrayList<>(); private final Set<Pair<ComponentName, UserHandle>> mServicesRequested = new HashSet<>(); private static final int MAX_LOG_RANK_POSITION = 12; private static final int MAX_LOG_RANK_POSITION = 12; private static final int MAX_EXTRA_INITIAL_INTENTS = 2; private static final int MAX_EXTRA_INITIAL_INTENTS = 2; Loading Loading @@ -453,16 +441,12 @@ public class ChooserActivity extends ResolverActivity implements private final ChooserHandler mChooserHandler = new ChooserHandler(); private final ChooserHandler mChooserHandler = new ChooserHandler(); private class ChooserHandler extends Handler { private class ChooserHandler extends Handler { private static final int CHOOSER_TARGET_SERVICE_RESULT = 1; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT = 4; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT = 4; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED = 5; private static final int SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED = 5; private static final int LIST_VIEW_UPDATE_MESSAGE = 6; private static final int LIST_VIEW_UPDATE_MESSAGE = 6; private boolean mReceivedDirectShareTargets = false; private void removeAllMessages() { private void removeAllMessages() { removeMessages(LIST_VIEW_UPDATE_MESSAGE); removeMessages(LIST_VIEW_UPDATE_MESSAGE); removeMessages(CHOOSER_TARGET_SERVICE_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED); removeMessages(SHORTCUT_MANAGER_SHARE_TARGET_RESULT_COMPLETED); } } Loading @@ -474,36 +458,6 @@ public class ChooserActivity extends ResolverActivity implements } } switch (msg.what) { switch (msg.what) { case CHOOSER_TARGET_SERVICE_RESULT: if (DEBUG) Log.d(TAG, "CHOOSER_TARGET_SERVICE_RESULT"); final ServiceResultInfo sri = (ServiceResultInfo) msg.obj; if (!mServiceConnections.contains(sri.connection)) { Log.w(TAG, "ChooserTargetServiceConnection " + sri.connection + sri.originalTarget.getResolveInfo().activityInfo.packageName + " returned after being removed from active connections." + " Have you considered returning results faster?"); break; } if (sri.resultTargets != null) { ChooserListAdapter adapterForUserHandle = mChooserMultiProfilePagerAdapter.getListAdapterForUserHandle( sri.userHandle); if (adapterForUserHandle != null) { adapterForUserHandle.addServiceResults(sri.originalTarget, sri.resultTargets, TARGET_TYPE_CHOOSER_TARGET, /* directShareShortcutInfoCache */ null); if (!sri.resultTargets.isEmpty() && sri.originalTarget != null) { mChooserTargetComponentNameCache.put( sri.resultTargets.get(0).getComponentName(), sri.originalTarget.getResolvedComponentName()); } } } unbindService(sri.connection); sri.connection.destroy(); mServiceConnections.remove(sri.connection); break; case LIST_VIEW_UPDATE_MESSAGE: case LIST_VIEW_UPDATE_MESSAGE: if (DEBUG) { if (DEBUG) { Log.d(TAG, "LIST_VIEW_UPDATE_MESSAGE; "); Log.d(TAG, "LIST_VIEW_UPDATE_MESSAGE; "); Loading Loading @@ -748,7 +702,6 @@ public class ChooserActivity extends ResolverActivity implements target.getAction() target.getAction() ); ); mDirectShareShortcutInfoCache = new HashMap<>(); mDirectShareShortcutInfoCache = new HashMap<>(); mChooserTargetComponentNameCache = new HashMap<>(); setEnterSharedElementCallback(new SharedElementCallback() { setEnterSharedElementCallback(new SharedElementCallback() { @Override @Override Loading Loading @@ -1588,7 +1541,6 @@ public class ChooserActivity extends ResolverActivity implements mRefinementResultReceiver.destroy(); mRefinementResultReceiver.destroy(); mRefinementResultReceiver = null; mRefinementResultReceiver = null; } } unbindRemainingServices(); mChooserHandler.removeAllMessages(); mChooserHandler.removeAllMessages(); if (mPreviewCoord != null) mPreviewCoord.cancelLoads(); if (mPreviewCoord != null) mPreviewCoord.cancelLoads(); Loading Loading @@ -2013,7 +1965,7 @@ public class ChooserActivity extends ResolverActivity implements final Message msg = Message.obtain(); final Message msg = Message.obtain(); msg.what = ChooserHandler.SHORTCUT_MANAGER_SHARE_TARGET_RESULT; msg.what = ChooserHandler.SHORTCUT_MANAGER_SHARE_TARGET_RESULT; msg.obj = new ServiceResultInfo(chooserListAdapter.getDisplayResolveInfo(i), msg.obj = new ServiceResultInfo(chooserListAdapter.getDisplayResolveInfo(i), chooserTargets, null, userHandle); chooserTargets, userHandle); msg.arg1 = shortcutType; msg.arg1 = shortcutType; mChooserHandler.sendMessage(msg); mChooserHandler.sendMessage(msg); } } Loading Loading @@ -2132,20 +2084,6 @@ public class ChooserActivity extends ResolverActivity implements return fullName; return fullName; } } void unbindRemainingServices() { if (DEBUG) { Log.d(TAG, "unbindRemainingServices, " + mServiceConnections.size() + " left"); } for (int i = 0, N = mServiceConnections.size(); i < N; i++) { final ChooserTargetServiceConnection conn = mServiceConnections.get(i); if (DEBUG) Log.d(TAG, "unbinding " + conn); unbindService(conn); conn.destroy(); } mServicesRequested.clear(); mServiceConnections.clear(); } private void logDirectShareTargetReceived(int logCategory) { private void logDirectShareTargetReceived(int logCategory) { final int apiLatency = (int) (System.currentTimeMillis() - mQueriedSharingShortcutsTimeMs); final int apiLatency = (int) (System.currentTimeMillis() - mQueriedSharingShortcutsTimeMs); getMetricsLogger().write(new LogMaker(logCategory).setSubtype(apiLatency)); getMetricsLogger().write(new LogMaker(logCategory).setSubtype(apiLatency)); Loading Loading @@ -2193,8 +2131,7 @@ public class ChooserActivity extends ResolverActivity implements List<AppTargetId> targetIds = new ArrayList<>(); List<AppTargetId> targetIds = new ArrayList<>(); for (ChooserTargetInfo chooserTargetInfo : surfacedTargetInfo) { for (ChooserTargetInfo chooserTargetInfo : surfacedTargetInfo) { ChooserTarget chooserTarget = chooserTargetInfo.getChooserTarget(); ChooserTarget chooserTarget = chooserTargetInfo.getChooserTarget(); ComponentName componentName = mChooserTargetComponentNameCache.getOrDefault( ComponentName componentName = chooserTarget.getComponentName(); chooserTarget.getComponentName(), chooserTarget.getComponentName()); if (mDirectShareShortcutInfoCache.containsKey(chooserTarget)) { if (mDirectShareShortcutInfoCache.containsKey(chooserTarget)) { String shortcutId = mDirectShareShortcutInfoCache.get(chooserTarget).getId(); String shortcutId = mDirectShareShortcutInfoCache.get(chooserTarget).getId(); targetIds.add(new AppTargetId( targetIds.add(new AppTargetId( Loading Loading @@ -2685,7 +2622,6 @@ public class ChooserActivity extends ResolverActivity implements @Override // ResolverListCommunicator @Override // ResolverListCommunicator public void onHandlePackagesChanged(ResolverListAdapter listAdapter) { public void onHandlePackagesChanged(ResolverListAdapter listAdapter) { mServicesRequested.clear(); mChooserMultiProfilePagerAdapter.getActiveListAdapter().notifyDataSetChanged(); mChooserMultiProfilePagerAdapter.getActiveListAdapter().notifyDataSetChanged(); super.onHandlePackagesChanged(listAdapter); super.onHandlePackagesChanged(listAdapter); } } Loading Loading @@ -3793,116 +3729,15 @@ public class ChooserActivity extends ResolverActivity implements } } } } static class ChooserTargetServiceConnection implements ServiceConnection { private DisplayResolveInfo mOriginalTarget; private ComponentName mConnectedComponent; private ChooserActivity mChooserActivity; private final UserHandle mUserHandle; private final Object mLock = new Object(); private final IChooserTargetResult mChooserTargetResult = new IChooserTargetResult.Stub() { @Override public void sendResult(List<ChooserTarget> targets) throws RemoteException { synchronized (mLock) { if (mChooserActivity == null) { Log.e(TAG, "destroyed ChooserTargetServiceConnection received result from " + mConnectedComponent + "; ignoring..."); return; } Context contextAsUser = mChooserActivity.createContextAsUser(mUserHandle, 0 /* flags */); mChooserActivity.filterServiceTargets(contextAsUser, mOriginalTarget.getResolveInfo().activityInfo.packageName, targets); final Message msg = Message.obtain(); msg.what = ChooserHandler.CHOOSER_TARGET_SERVICE_RESULT; msg.obj = new ServiceResultInfo(mOriginalTarget, targets, ChooserTargetServiceConnection.this, mUserHandle); mChooserActivity.mChooserHandler.sendMessage(msg); } } }; public ChooserTargetServiceConnection(ChooserActivity chooserActivity, DisplayResolveInfo dri, UserHandle userHandle) { mChooserActivity = chooserActivity; mOriginalTarget = dri; mUserHandle = userHandle; } @Override public void onServiceConnected(ComponentName name, IBinder service) { if (DEBUG) Log.d(TAG, "onServiceConnected: " + name); synchronized (mLock) { if (mChooserActivity == null) { Log.e(TAG, "destroyed ChooserTargetServiceConnection got onServiceConnected"); return; } final IChooserTargetService icts = IChooserTargetService.Stub.asInterface(service); try { icts.getChooserTargets(mOriginalTarget.getResolvedComponentName(), mOriginalTarget.getResolveInfo().filter, mChooserTargetResult); } catch (RemoteException e) { Log.e(TAG, "Querying ChooserTargetService " + name + " failed.", e); mChooserActivity.unbindService(this); mChooserActivity.mServiceConnections.remove(this); destroy(); } } } @Override public void onServiceDisconnected(ComponentName name) { if (DEBUG) Log.d(TAG, "onServiceDisconnected: " + name); synchronized (mLock) { if (mChooserActivity == null) { Log.e(TAG, "destroyed ChooserTargetServiceConnection got onServiceDisconnected"); return; } mChooserActivity.unbindService(this); mChooserActivity.mServiceConnections.remove(this); if (mChooserActivity.mServiceConnections.isEmpty()) { mChooserActivity.sendVoiceChoicesIfNeeded(); } mConnectedComponent = null; destroy(); } } public void destroy() { synchronized (mLock) { mChooserActivity = null; mOriginalTarget = null; } } @Override public String toString() { return "ChooserTargetServiceConnection{service=" + mConnectedComponent + ", activity=" + (mOriginalTarget != null ? mOriginalTarget.getResolveInfo().activityInfo.toString() : "<connection destroyed>") + "}"; } public ComponentName getComponentName() { return mOriginalTarget.getResolveInfo().activityInfo.getComponentName(); } } static class ServiceResultInfo { static class ServiceResultInfo { public final DisplayResolveInfo originalTarget; public final DisplayResolveInfo originalTarget; public final List<ChooserTarget> resultTargets; public final List<ChooserTarget> resultTargets; public final ChooserTargetServiceConnection connection; public final UserHandle userHandle; public final UserHandle userHandle; public ServiceResultInfo(DisplayResolveInfo ot, List<ChooserTarget> rt, public ServiceResultInfo(DisplayResolveInfo ot, List<ChooserTarget> rt, ChooserTargetServiceConnection c, UserHandle userHandle) { UserHandle userHandle) { originalTarget = ot; originalTarget = ot; resultTargets = rt; resultTargets = rt; connection = c; this.userHandle = userHandle; this.userHandle = userHandle; } } } } Loading