Loading core/java/android/service/selectiontoolbar/DefaultSelectionToolbarRenderService.java +0 −12 Original line number Diff line number Diff line Loading @@ -105,18 +105,6 @@ public final class DefaultSelectionToolbarRenderService extends SelectionToolbar } } @Override public void onToolbarShowTimeout(int callingUid) { Slog.w(TAG, "onToolbarShowTimeout for callingUid = " + callingUid); Pair<Long, RemoteSelectionToolbar> toolbarPair = mToolbarCache.get(callingUid); if (toolbarPair != null) { RemoteSelectionToolbar remoteToolbar = toolbarPair.second; remoteToolbar.dismiss(toolbarPair.first); remoteToolbar.onToolbarShowTimeout(); mToolbarCache.remove(callingUid); } } @Override public void onUidDied(int callingUid) { Slog.w(TAG, "onUidDied for callingUid = " + callingUid); Loading core/java/android/service/selectiontoolbar/RemoteSelectionToolbar.java +0 −4 Original line number Diff line number Diff line Loading @@ -316,10 +316,6 @@ public final class RemoteSelectionToolbar { updatePopupSize(); } public void onToolbarShowTimeout() { mCallbackWrapper.onToolbarShowTimeout(); } /** * Show the specified selection toolbar. */ Loading core/java/android/service/selectiontoolbar/SelectionToolbarRenderCallback.java +0 −4 Original line number Diff line number Diff line Loading @@ -37,10 +37,6 @@ public interface SelectionToolbarRenderCallback { * The menu item index on the selection toolbar has been clicked. */ void onMenuItemClicked(int itemIndex); /** * The toolbar doesn't be dismissed after showing on a given timeout. */ void onToolbarShowTimeout(); /** * The error occurred when operating on the selection toolbar. */ Loading core/java/android/service/selectiontoolbar/SelectionToolbarRenderService.java +33 −77 Original line number Diff line number Diff line Loading @@ -28,14 +28,11 @@ import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.util.Log; import android.util.Pair; import android.util.SparseArray; import android.view.selectiontoolbar.ISelectionToolbarCallback; import android.view.selectiontoolbar.ShowInfo; import android.view.selectiontoolbar.WidgetInfo; import java.util.concurrent.TimeUnit; /** * Service for rendering selection toolbar. * Loading @@ -45,10 +42,6 @@ public abstract class SelectionToolbarRenderService extends Service { private static final String TAG = "SelectionToolbarRenderService"; // TODO(b/215497659): read from DeviceConfig // The timeout to clean the cache if the client forgot to call dismiss() private static final long CACHE_CLEAN_AFTER_SHOW_TIMEOUT_IN_MS = TimeUnit.MINUTES.toMillis(10); /** * The {@link Intent} that must be declared as handled by the service. * Loading @@ -62,46 +55,46 @@ public abstract class SelectionToolbarRenderService extends Service { private Handler mHandler; private ISelectionToolbarRenderServiceCallback mServiceCallback; /** * Maps the uid of the calling app who the toolbar is for to the callback for toolbar events * and the runnable that cleans up the toolbar properly. */ private final SparseArray<Pair<RemoteCallbackWrapper, CleanCacheRunnable>> mCache = new SparseArray<>(); /** * Binder to receive calls from system server. */ private final ISelectionToolbarRenderService mInterface = new ISelectionToolbarRenderService.Stub() { /** * Maps the uid of the calling app who the toolbar is for to the callback for * toolbar events. */ private final SparseArray<RemoteCallbackWrapper> mCache = new SparseArray<>(); @Override public void onShow(int callingUid, ShowInfo showInfo, ISelectionToolbarCallback callback) { if (mCache.indexOfKey(callingUid) < 0) { RemoteCallbackWrapper remoteCallbackWrapper; synchronized (mCache) { remoteCallbackWrapper = mCache.get(callingUid); if (remoteCallbackWrapper == null) { try { DeathRecipient deathRecipient = () -> { mHandler.removeCallbacks(mCache.get(callingUid).second); synchronized (mCache) { mCache.remove(callingUid); } onUidDied(callingUid); }; callback.asBinder().linkToDeath(deathRecipient, 0); mCache.put(callingUid, new Pair<>(new RemoteCallbackWrapper(callback, deathRecipient), new CleanCacheRunnable(callingUid))); remoteCallbackWrapper = new RemoteCallbackWrapper(callback, deathRecipient); mCache.put(callingUid, remoteCallbackWrapper); } catch (RemoteException e) { Log.e(TAG, "ISelectionToolbarCallback has already died"); return; } } Pair<RemoteCallbackWrapper, CleanCacheRunnable> toolbarPair = mCache.get( callingUid); CleanCacheRunnable cleanRunnable = toolbarPair.second; mHandler.removeCallbacks(cleanRunnable); } mHandler.sendMessage(obtainMessage(SelectionToolbarRenderService::onShow, SelectionToolbarRenderService.this, callingUid, showInfo, toolbarPair.first)); mHandler.postDelayed(cleanRunnable, CACHE_CLEAN_AFTER_SHOW_TIMEOUT_IN_MS); remoteCallbackWrapper)); } @Override Loading @@ -114,12 +107,12 @@ public abstract class SelectionToolbarRenderService extends Service { public void onDismiss(int callingUid, long widgetToken) { mHandler.sendMessage(obtainMessage(SelectionToolbarRenderService::onDismiss, SelectionToolbarRenderService.this, widgetToken)); Pair<RemoteCallbackWrapper, CleanCacheRunnable> toolbarPair = mCache.get( callingUid); if (toolbarPair != null) { mHandler.removeCallbacks(toolbarPair.second); mCache.remove(callingUid); toolbarPair.first.unlinkToDeath(); synchronized (mCache) { RemoteCallbackWrapper remoteCallbackWrapper = mCache.removeReturnOld(callingUid); if (remoteCallbackWrapper != null) { remoteCallbackWrapper.unlinkToDeath(); } } } Loading Loading @@ -195,18 +188,11 @@ public abstract class SelectionToolbarRenderService extends Service { */ public abstract void onHide(long widgetToken); /** * Called when dismissing the selection toolbar. */ public abstract void onDismiss(long widgetToken); /** * Called when showing the selection toolbar for a specific timeout. This avoids the client * forgot to call dismiss to clean the state. */ public abstract void onToolbarShowTimeout(int callingUid); /** * Called when the client process dies. */ Loading Loading @@ -241,16 +227,6 @@ public abstract class SelectionToolbarRenderService extends Service { } } @Override public void onToolbarShowTimeout() { try { unlinkToDeath(); mRemoteCallback.onToolbarShowTimeout(); } catch (RemoteException e) { // no-op } } @Override public void onWidgetUpdated(WidgetInfo widgetInfo) { try { Loading @@ -272,7 +248,6 @@ public abstract class SelectionToolbarRenderService extends Service { @Override public void onError(int errorCode, int sequenceNumber) { try { unlinkToDeath(); mRemoteCallback.onError(errorCode, sequenceNumber); } catch (RemoteException e) { // no-op Loading @@ -280,25 +255,6 @@ public abstract class SelectionToolbarRenderService extends Service { } } private class CleanCacheRunnable implements Runnable { int mCleanUid; CleanCacheRunnable(int cleanUid) { mCleanUid = cleanUid; } @Override public void run() { Pair<RemoteCallbackWrapper, CleanCacheRunnable> toolbarPair = mCache.get(mCleanUid); if (toolbarPair != null) { Log.w(TAG, "CleanCacheRunnable: remove " + mCleanUid + " from cache."); mCache.remove(mCleanUid); onToolbarShowTimeout(mCleanUid); } } } /** * A listener to notify the service to the transfer touch focus. */ Loading core/java/com/android/internal/widget/floatingtoolbar/RemoteFloatingToolbarPopup.java +10 −1 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.view.MenuItem; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.view.ViewRootImpl; import android.view.WindowManager; import android.view.selectiontoolbar.ISelectionToolbarCallback; import android.view.selectiontoolbar.SelectionToolbarManager; Loading Loading @@ -153,6 +154,14 @@ public final class RemoteFloatingToolbarPopup implements FloatingToolbarPopup { MenuItem.OnMenuItemClickListener menuItemClickListener, Rect contentRect) { Objects.requireNonNull(menuItems); Objects.requireNonNull(menuItemClickListener); ViewRootImpl viewRootImpl = mParent.getViewRootImpl(); if (viewRootImpl == null) { Log.w(FloatingToolbar.FLOATING_TOOLBAR_TAG, "RemoteFloatingToolbarPopup.show(): viewRootImpl is null."); return; } if (isShowing() && Objects.equals(menuItems, mMenuItems) && Objects.equals(contentRect, mContentRect)) { if (DEBUG) { Loading Loading @@ -188,7 +197,7 @@ public final class RemoteFloatingToolbarPopup implements FloatingToolbarPopup { showInfo.contentRect = contentRect; showInfo.suggestedWidth = suggestWidth; showInfo.viewPortOnScreen = mScreenViewPort; showInfo.hostInputToken = mParent.getViewRootImpl().getInputToken(); showInfo.hostInputToken = viewRootImpl.getInputToken(); showInfo.isLightTheme = mIsLightTheme; showInfo.configuration = mContext.getResources().getConfiguration(); if (DEBUG) { Loading Loading
core/java/android/service/selectiontoolbar/DefaultSelectionToolbarRenderService.java +0 −12 Original line number Diff line number Diff line Loading @@ -105,18 +105,6 @@ public final class DefaultSelectionToolbarRenderService extends SelectionToolbar } } @Override public void onToolbarShowTimeout(int callingUid) { Slog.w(TAG, "onToolbarShowTimeout for callingUid = " + callingUid); Pair<Long, RemoteSelectionToolbar> toolbarPair = mToolbarCache.get(callingUid); if (toolbarPair != null) { RemoteSelectionToolbar remoteToolbar = toolbarPair.second; remoteToolbar.dismiss(toolbarPair.first); remoteToolbar.onToolbarShowTimeout(); mToolbarCache.remove(callingUid); } } @Override public void onUidDied(int callingUid) { Slog.w(TAG, "onUidDied for callingUid = " + callingUid); Loading
core/java/android/service/selectiontoolbar/RemoteSelectionToolbar.java +0 −4 Original line number Diff line number Diff line Loading @@ -316,10 +316,6 @@ public final class RemoteSelectionToolbar { updatePopupSize(); } public void onToolbarShowTimeout() { mCallbackWrapper.onToolbarShowTimeout(); } /** * Show the specified selection toolbar. */ Loading
core/java/android/service/selectiontoolbar/SelectionToolbarRenderCallback.java +0 −4 Original line number Diff line number Diff line Loading @@ -37,10 +37,6 @@ public interface SelectionToolbarRenderCallback { * The menu item index on the selection toolbar has been clicked. */ void onMenuItemClicked(int itemIndex); /** * The toolbar doesn't be dismissed after showing on a given timeout. */ void onToolbarShowTimeout(); /** * The error occurred when operating on the selection toolbar. */ Loading
core/java/android/service/selectiontoolbar/SelectionToolbarRenderService.java +33 −77 Original line number Diff line number Diff line Loading @@ -28,14 +28,11 @@ import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.util.Log; import android.util.Pair; import android.util.SparseArray; import android.view.selectiontoolbar.ISelectionToolbarCallback; import android.view.selectiontoolbar.ShowInfo; import android.view.selectiontoolbar.WidgetInfo; import java.util.concurrent.TimeUnit; /** * Service for rendering selection toolbar. * Loading @@ -45,10 +42,6 @@ public abstract class SelectionToolbarRenderService extends Service { private static final String TAG = "SelectionToolbarRenderService"; // TODO(b/215497659): read from DeviceConfig // The timeout to clean the cache if the client forgot to call dismiss() private static final long CACHE_CLEAN_AFTER_SHOW_TIMEOUT_IN_MS = TimeUnit.MINUTES.toMillis(10); /** * The {@link Intent} that must be declared as handled by the service. * Loading @@ -62,46 +55,46 @@ public abstract class SelectionToolbarRenderService extends Service { private Handler mHandler; private ISelectionToolbarRenderServiceCallback mServiceCallback; /** * Maps the uid of the calling app who the toolbar is for to the callback for toolbar events * and the runnable that cleans up the toolbar properly. */ private final SparseArray<Pair<RemoteCallbackWrapper, CleanCacheRunnable>> mCache = new SparseArray<>(); /** * Binder to receive calls from system server. */ private final ISelectionToolbarRenderService mInterface = new ISelectionToolbarRenderService.Stub() { /** * Maps the uid of the calling app who the toolbar is for to the callback for * toolbar events. */ private final SparseArray<RemoteCallbackWrapper> mCache = new SparseArray<>(); @Override public void onShow(int callingUid, ShowInfo showInfo, ISelectionToolbarCallback callback) { if (mCache.indexOfKey(callingUid) < 0) { RemoteCallbackWrapper remoteCallbackWrapper; synchronized (mCache) { remoteCallbackWrapper = mCache.get(callingUid); if (remoteCallbackWrapper == null) { try { DeathRecipient deathRecipient = () -> { mHandler.removeCallbacks(mCache.get(callingUid).second); synchronized (mCache) { mCache.remove(callingUid); } onUidDied(callingUid); }; callback.asBinder().linkToDeath(deathRecipient, 0); mCache.put(callingUid, new Pair<>(new RemoteCallbackWrapper(callback, deathRecipient), new CleanCacheRunnable(callingUid))); remoteCallbackWrapper = new RemoteCallbackWrapper(callback, deathRecipient); mCache.put(callingUid, remoteCallbackWrapper); } catch (RemoteException e) { Log.e(TAG, "ISelectionToolbarCallback has already died"); return; } } Pair<RemoteCallbackWrapper, CleanCacheRunnable> toolbarPair = mCache.get( callingUid); CleanCacheRunnable cleanRunnable = toolbarPair.second; mHandler.removeCallbacks(cleanRunnable); } mHandler.sendMessage(obtainMessage(SelectionToolbarRenderService::onShow, SelectionToolbarRenderService.this, callingUid, showInfo, toolbarPair.first)); mHandler.postDelayed(cleanRunnable, CACHE_CLEAN_AFTER_SHOW_TIMEOUT_IN_MS); remoteCallbackWrapper)); } @Override Loading @@ -114,12 +107,12 @@ public abstract class SelectionToolbarRenderService extends Service { public void onDismiss(int callingUid, long widgetToken) { mHandler.sendMessage(obtainMessage(SelectionToolbarRenderService::onDismiss, SelectionToolbarRenderService.this, widgetToken)); Pair<RemoteCallbackWrapper, CleanCacheRunnable> toolbarPair = mCache.get( callingUid); if (toolbarPair != null) { mHandler.removeCallbacks(toolbarPair.second); mCache.remove(callingUid); toolbarPair.first.unlinkToDeath(); synchronized (mCache) { RemoteCallbackWrapper remoteCallbackWrapper = mCache.removeReturnOld(callingUid); if (remoteCallbackWrapper != null) { remoteCallbackWrapper.unlinkToDeath(); } } } Loading Loading @@ -195,18 +188,11 @@ public abstract class SelectionToolbarRenderService extends Service { */ public abstract void onHide(long widgetToken); /** * Called when dismissing the selection toolbar. */ public abstract void onDismiss(long widgetToken); /** * Called when showing the selection toolbar for a specific timeout. This avoids the client * forgot to call dismiss to clean the state. */ public abstract void onToolbarShowTimeout(int callingUid); /** * Called when the client process dies. */ Loading Loading @@ -241,16 +227,6 @@ public abstract class SelectionToolbarRenderService extends Service { } } @Override public void onToolbarShowTimeout() { try { unlinkToDeath(); mRemoteCallback.onToolbarShowTimeout(); } catch (RemoteException e) { // no-op } } @Override public void onWidgetUpdated(WidgetInfo widgetInfo) { try { Loading @@ -272,7 +248,6 @@ public abstract class SelectionToolbarRenderService extends Service { @Override public void onError(int errorCode, int sequenceNumber) { try { unlinkToDeath(); mRemoteCallback.onError(errorCode, sequenceNumber); } catch (RemoteException e) { // no-op Loading @@ -280,25 +255,6 @@ public abstract class SelectionToolbarRenderService extends Service { } } private class CleanCacheRunnable implements Runnable { int mCleanUid; CleanCacheRunnable(int cleanUid) { mCleanUid = cleanUid; } @Override public void run() { Pair<RemoteCallbackWrapper, CleanCacheRunnable> toolbarPair = mCache.get(mCleanUid); if (toolbarPair != null) { Log.w(TAG, "CleanCacheRunnable: remove " + mCleanUid + " from cache."); mCache.remove(mCleanUid); onToolbarShowTimeout(mCleanUid); } } } /** * A listener to notify the service to the transfer touch focus. */ Loading
core/java/com/android/internal/widget/floatingtoolbar/RemoteFloatingToolbarPopup.java +10 −1 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.view.MenuItem; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.view.ViewRootImpl; import android.view.WindowManager; import android.view.selectiontoolbar.ISelectionToolbarCallback; import android.view.selectiontoolbar.SelectionToolbarManager; Loading Loading @@ -153,6 +154,14 @@ public final class RemoteFloatingToolbarPopup implements FloatingToolbarPopup { MenuItem.OnMenuItemClickListener menuItemClickListener, Rect contentRect) { Objects.requireNonNull(menuItems); Objects.requireNonNull(menuItemClickListener); ViewRootImpl viewRootImpl = mParent.getViewRootImpl(); if (viewRootImpl == null) { Log.w(FloatingToolbar.FLOATING_TOOLBAR_TAG, "RemoteFloatingToolbarPopup.show(): viewRootImpl is null."); return; } if (isShowing() && Objects.equals(menuItems, mMenuItems) && Objects.equals(contentRect, mContentRect)) { if (DEBUG) { Loading Loading @@ -188,7 +197,7 @@ public final class RemoteFloatingToolbarPopup implements FloatingToolbarPopup { showInfo.contentRect = contentRect; showInfo.suggestedWidth = suggestWidth; showInfo.viewPortOnScreen = mScreenViewPort; showInfo.hostInputToken = mParent.getViewRootImpl().getInputToken(); showInfo.hostInputToken = viewRootImpl.getInputToken(); showInfo.isLightTheme = mIsLightTheme; showInfo.configuration = mContext.getResources().getConfiguration(); if (DEBUG) { Loading