ActivityDelegate extends AbstractDelegate<ICompositeActivity, ActivityPlugin> { public void onPause() { if (mPlugins.isEmpty()) { getOriginal().super_onPause(); return; } final ListIterator<ActivityPlugin> iterator = mPlugins.listIterator(mPlugins.size()); final CallVoid0 superCall = new CallVoid0("onPause()") { @Override public void call() { if (iterator.hasPrevious()) { iterator.previous().onPause(this); } else { getOriginal().super_onPause(); } } }; superCall.call(); } ActivityDelegate(final ICompositeActivity icompositeactivity); void addContentView(View view, LayoutParams params); void applyOverrideConfiguration(Configuration overrideConfiguration); void attachBaseContext(Context newBase); boolean bindService(Intent service, ServiceConnection conn, int flags); int checkCallingOrSelfPermission(String permission); int checkCallingOrSelfUriPermission(Uri uri, int modeFlags); int checkCallingPermission(String permission); int checkCallingUriPermission(Uri uri, int modeFlags); int checkPermission(String permission, int pid, int uid); int checkSelfPermission(String permission); int checkUriPermission(Uri uri, int pid, int uid, int modeFlags); int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid,
            int modeFlags); void clearWallpaper(); void closeContextMenu(); void closeOptionsMenu(); Context createConfigurationContext(Configuration overrideConfiguration); Context createContextForSplit(String splitName); Context createDeviceProtectedStorageContext(); Context createDisplayContext(Display display); Context createPackageContext(String packageName, int flags); PendingIntent createPendingResult(int requestCode, @NonNull Intent data, int flags); String[] databaseList(); boolean deleteDatabase(String name); boolean deleteFile(String name); boolean deleteSharedPreferences(String name); boolean dispatchGenericMotionEvent(MotionEvent ev); boolean dispatchKeyEvent(KeyEvent event); boolean dispatchKeyShortcutEvent(KeyEvent event); boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event); boolean dispatchTouchEvent(MotionEvent ev); boolean dispatchTrackballEvent(MotionEvent ev); void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args); void enforceCallingOrSelfPermission(String permission, String message); void enforceCallingOrSelfUriPermission(Uri uri, int modeFlags, String message); void enforceCallingPermission(String permission, String message); void enforceCallingUriPermission(Uri uri, int modeFlags, String message); void enforcePermission(String permission, int pid, int uid, String message); void enforceUriPermission(Uri uri, int pid, int uid, int modeFlags, String message); void enforceUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid,
            int modeFlags, String message); void enterPictureInPictureMode(); boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params); String[] fileList(); T findViewById(int id); void finish(); void finishActivity(int requestCode); void finishActivityFromChild(@NonNull Activity child, int requestCode); void finishAffinity(); void finishAfterTransition(); void finishAndRemoveTask(); void finishFromChild(Activity child); android.app.ActionBar getActionBar(); void setActionBar(@Nullable android.widget.Toolbar toolbar); Context getApplicationContext(); ApplicationInfo getApplicationInfo(); AssetManager getAssets(); Context getBaseContext(); File getCacheDir(); ComponentName getCallingActivity(); String getCallingPackage(); int getChangingConfigurations(); ClassLoader getClassLoader(); File getCodeCacheDir(); ComponentName getComponentName(); ContentResolver getContentResolver(); Scene getContentScene(); TransitionManager getContentTransitionManager(); void setContentTransitionManager(TransitionManager tm); View getCurrentFocus(); File getDataDir(); File getDatabasePath(String name); AppCompatDelegate getDelegate(); File getDir(String name, int mode); Delegate getDrawerToggleDelegate(); File getExternalCacheDir(); File[] getExternalCacheDirs(); File getExternalFilesDir(String type); File[] getExternalFilesDirs(String type); File[] getExternalMediaDirs(); T getExtraData(Class<T> extraDataClass); File getFileStreamPath(String name); File getFilesDir(); android.app.FragmentManager getFragmentManager(); Intent getIntent(); void setIntent(Intent newIntent); Object getLastCompositeCustomNonConfigurationInstance(); Object getLastNonConfigurationInstance(final String key); LayoutInflater getLayoutInflater(); Lifecycle getLifecycle(); android.app.LoaderManager getLoaderManager(); String getLocalClassName(); Executor getMainExecutor(); Looper getMainLooper(); int getMaxNumPictureInPictureActions(); MenuInflater getMenuInflater(); File getNoBackupFilesDir(); File getObbDir(); File[] getObbDirs(); String getPackageCodePath(); PackageManager getPackageManager(); String getPackageName(); String getPackageResourcePath(); Intent getParentActivityIntent(); SharedPreferences getPreferences(int mode); Uri getReferrer(); int getRequestedOrientation(); void setRequestedOrientation(int requestedOrientation); Resources getResources(); SharedPreferences getSharedPreferences(String name, int mode); ActionBar getSupportActionBar(); void setSupportActionBar(@Nullable Toolbar toolbar); FragmentManager getSupportFragmentManager(); LoaderManager getSupportLoaderManager(); Intent getSupportParentActivityIntent(); Object getSystemService(@NonNull String name); String getSystemServiceName(Class<?> serviceClass); int getTaskId(); Theme getTheme(); void setTheme(int resid); ViewModelStore getViewModelStore(); VoiceInteractor getVoiceInteractor(); Drawable getWallpaper(); void setWallpaper(Bitmap bitmap); int getWallpaperDesiredMinimumHeight(); int getWallpaperDesiredMinimumWidth(); Window getWindow(); WindowManager getWindowManager(); void grantUriPermission(String toPackage, Uri uri, int modeFlags); boolean hasWindowFocus(); void invalidateOptionsMenu(); boolean isActivityTransitionRunning(); boolean isChangingConfigurations(); boolean isDestroyed(); boolean isDeviceProtectedStorage(); boolean isFinishing(); boolean isImmersive(); void setImmersive(boolean i); boolean isInMultiWindowMode(); boolean isInPictureInPictureMode(); boolean isLocalVoiceInteractionSupported(); boolean isRestricted(); boolean isTaskRoot(); boolean isVoiceInteraction(); boolean isVoiceInteractionRoot(); boolean moveDatabaseFrom(Context sourceContext, String name); boolean moveSharedPreferencesFrom(Context sourceContext, String name); boolean moveTaskToBack(boolean nonRoot); boolean navigateUpTo(Intent upIntent); boolean navigateUpToFromChild(Activity child, Intent upIntent); void onActionModeFinished(android.view.ActionMode mode); void onActionModeStarted(android.view.ActionMode mode); void onActivityReenter(int resultCode, Intent data); void onActivityResult(int requestCode, int resultCode, @Nullable Intent data); void onApplyThemeResource(Theme theme, int resid, boolean first); void onAttachFragment(Fragment fragment); void onAttachFragment(android.app.Fragment fragment); void onAttachedToWindow(); void onBackPressed(); void onChildTitleChanged(Activity childActivity, CharSequence title); void onConfigurationChanged(Configuration newConfig); void onContentChanged(); boolean onContextItemSelected(MenuItem item); void onContextMenuClosed(Menu menu); void onCreate(@Nullable Bundle savedInstanceState); void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState); void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); CharSequence onCreateDescription(); Dialog onCreateDialog(int id); Dialog onCreateDialog(int id, Bundle args); void onCreateNavigateUpTaskStack(android.app.TaskStackBuilder builder); boolean onCreateOptionsMenu(Menu menu); boolean onCreatePanelMenu(int featureId, Menu menu); View onCreatePanelView(int featureId); void onCreateSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder); boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas); View onCreateView(View parent, String name, Context context, AttributeSet attrs); View onCreateView(String name, Context context, AttributeSet attrs); void onDestroy(); void onDetachedFromWindow(); void onEnterAnimationComplete(); boolean onGenericMotionEvent(MotionEvent event); boolean onKeyDown(int keyCode, KeyEvent event); boolean onKeyLongPress(int keyCode, KeyEvent event); boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event); boolean onKeyShortcut(int keyCode, KeyEvent event); boolean onKeyUp(int keyCode, KeyEvent event); void onLocalVoiceInteractionStarted(); void onLocalVoiceInteractionStopped(); void onLowMemory(); boolean onMenuOpened(int featureId, Menu menu); void onMultiWindowModeChanged(boolean isInMultiWindowMode); void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig); boolean onNavigateUp(); boolean onNavigateUpFromChild(Activity child); void onNewIntent(Intent intent); boolean onOptionsItemSelected(MenuItem item); void onOptionsMenuClosed(Menu menu); void onPanelClosed(int featureId, Menu menu); void onPause(); void onPictureInPictureModeChanged(boolean isInPictureInPictureMode); void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig); void onPostCreate(@Nullable Bundle savedInstanceState); void onPostCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState); void onPostResume(); void onPrepareDialog(int id, Dialog dialog); void onPrepareDialog(int id, Dialog dialog, Bundle args); void onPrepareNavigateUpTaskStack(android.app.TaskStackBuilder builder); boolean onPrepareOptionsMenu(Menu menu); boolean onPrepareOptionsPanel(View view, Menu menu); boolean onPreparePanel(int featureId, View view, Menu menu); void onPrepareSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder); void onProvideAssistContent(AssistContent outContent); void onProvideAssistData(Bundle data); void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId); Uri onProvideReferrer(); void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
            @NonNull int[] grantResults); void onRestart(); void onRestoreInstanceState(Bundle savedInstanceState); void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState); void onResume(); void onResumeFragments(); Object onRetainNonConfigurationInstance(); void onSaveInstanceState(Bundle outState); void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState); boolean onSearchRequested(@Nullable SearchEvent searchEvent); boolean onSearchRequested(); void onStart(); void onStateNotSaved(); void onStop(); void onSupportActionModeFinished(@NonNull ActionMode mode); void onSupportActionModeStarted(@NonNull ActionMode mode); void onSupportContentChanged(); boolean onSupportNavigateUp(); void onTitleChanged(CharSequence title, int color); boolean onTouchEvent(MotionEvent event); boolean onTrackballEvent(MotionEvent event); void onTrimMemory(int level); void onUserInteraction(); void onUserLeaveHint(); void onVisibleBehindCanceled(); void onWindowAttributesChanged(WindowManager.LayoutParams params); void onWindowFocusChanged(boolean hasFocus); android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback callback); android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback callback, int type); ActionMode onWindowStartingSupportActionMode(@NonNull Callback callback); void openContextMenu(View view); FileInputStream openFileInput(String name); FileOutputStream openFileOutput(String name, int mode); void openOptionsMenu(); SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory); SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory,
            DatabaseErrorHandler errorHandler); void overridePendingTransition(int enterAnim, int exitAnim); Drawable peekWallpaper(); void postponeEnterTransition(); void putExtraData(ExtraData extraData); void recreate(); void registerComponentCallbacks(ComponentCallbacks callback); void registerForContextMenu(View view); Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter); Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags); Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission,
            Handler scheduler); Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission,
            Handler scheduler, int flags); boolean releaseInstance(); void removeStickyBroadcast(Intent intent); void removeStickyBroadcastAsUser(Intent intent, UserHandle user); void reportFullyDrawn(); DragAndDropPermissions requestDragAndDropPermissions(DragEvent event); boolean requestVisibleBehind(boolean visible); void revokeUriPermission(Uri uri, int modeFlags); void revokeUriPermission(String targetPackage, Uri uri, int modeFlags); void sendBroadcast(Intent intent); void sendBroadcast(Intent intent, String receiverPermission); void sendBroadcastAsUser(Intent intent, UserHandle user); void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission); void sendOrderedBroadcast(Intent intent, String receiverPermission); void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver,
            Handler scheduler, int initialCode, String initialData, Bundle initialExtras); void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission,
            BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
            Bundle initialExtras); void sendStickyBroadcast(Intent intent); void sendStickyBroadcastAsUser(Intent intent, UserHandle user); void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, Handler scheduler,
            int initialCode, String initialData, Bundle initialExtras); void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver,
            Handler scheduler, int initialCode, String initialData, Bundle initialExtras); void setContentView(int layoutResID); void setContentView(View view); void setContentView(View view, LayoutParams params); void setEnterSharedElementCallback(SharedElementCallback callback); void setEnterSharedElementCallback(android.app.SharedElementCallback callback); void setExitSharedElementCallback(SharedElementCallback listener); void setExitSharedElementCallback(android.app.SharedElementCallback callback); void setFinishOnTouchOutside(boolean finish); void setPictureInPictureParams(@NonNull PictureInPictureParams params); void setShowWhenLocked(boolean showWhenLocked); void setSupportProgress(int progress); void setSupportProgressBarIndeterminate(boolean indeterminate); void setSupportProgressBarIndeterminateVisibility(boolean visible); void setSupportProgressBarVisibility(boolean visible); void setTaskDescription(TaskDescription taskDescription); void setTitle(CharSequence title); void setTitle(int titleId); void setTitleColor(int textColor); void setTurnScreenOn(boolean turnScreenOn); void setVisible(boolean visible); void setVrModeEnabled(boolean enabled, @NonNull ComponentName requestedComponent); void setWallpaper(InputStream data); boolean shouldShowRequestPermissionRationale(@NonNull String permission); boolean shouldUpRecreateTask(Intent targetIntent); boolean showAssist(Bundle args); void showLockTaskEscapeMessage(); android.view.ActionMode startActionMode(android.view.ActionMode.Callback callback); android.view.ActionMode startActionMode(android.view.ActionMode.Callback callback, int type); void startActivities(Intent[] intents); void startActivities(Intent[] intents, @Nullable Bundle options); void startActivity(Intent intent); void startActivity(Intent intent, @Nullable Bundle options); void startActivityForResult(Intent intent, int requestCode); void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options); void startActivityFromChild(@NonNull Activity child, Intent intent, int requestCode); void startActivityFromChild(@NonNull Activity child, Intent intent, int requestCode,
            @Nullable Bundle options); void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode); void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode,
            @Nullable Bundle options); void startActivityFromFragment(@NonNull android.app.Fragment fragment, Intent intent, int requestCode); void startActivityFromFragment(@NonNull android.app.Fragment fragment, Intent intent, int requestCode,
            @Nullable Bundle options); boolean startActivityIfNeeded(@NonNull Intent intent, int requestCode); boolean startActivityIfNeeded(@NonNull Intent intent, int requestCode, @Nullable Bundle options); ComponentName startForegroundService(Intent service); boolean startInstrumentation(ComponentName className, String profileFile, Bundle arguments); void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, int flagsMask, int flagsValues,
            int extraFlags); void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, int flagsMask, int flagsValues,
            int extraFlags, Bundle options); void startIntentSenderForResult(IntentSender intent, int requestCode, @Nullable Intent fillInIntent,
            int flagsMask, int flagsValues, int extraFlags); void startIntentSenderForResult(IntentSender intent, int requestCode, @Nullable Intent fillInIntent,
            int flagsMask, int flagsValues, int extraFlags, Bundle options); void startIntentSenderFromChild(Activity child, IntentSender intent, int requestCode, Intent fillInIntent,
            int flagsMask, int flagsValues, int extraFlags); void startIntentSenderFromChild(Activity child, IntentSender intent, int requestCode, Intent fillInIntent,
            int flagsMask, int flagsValues, int extraFlags, @Nullable Bundle options); void startIntentSenderFromFragment(Fragment fragment, IntentSender intent, int requestCode,
            @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options); void startLocalVoiceInteraction(Bundle privateOptions); void startLockTask(); void startManagingCursor(Cursor c); boolean startNextMatchingActivity(@NonNull Intent intent); boolean startNextMatchingActivity(@NonNull Intent intent, @Nullable Bundle options); void startPostponedEnterTransition(); void startSearch(@Nullable String initialQuery, boolean selectInitialQuery, @Nullable Bundle appSearchData,
            boolean globalSearch); ComponentName startService(Intent service); ActionMode startSupportActionMode(@NonNull Callback callback); void stopLocalVoiceInteraction(); void stopLockTask(); void stopManagingCursor(Cursor c); boolean stopService(Intent name); boolean superDispatchKeyEvent(KeyEvent event); void supportFinishAfterTransition(); void supportInvalidateOptionsMenu(); void supportNavigateUpTo(@NonNull Intent upIntent); void supportPostponeEnterTransition(); boolean supportRequestWindowFeature(int featureId); boolean supportShouldUpRecreateTask(@NonNull Intent targetIntent); void supportStartPostponedEnterTransition(); void takeKeyEvents(boolean get); void triggerSearch(String query, @Nullable Bundle appSearchData); void unbindService(ServiceConnection conn); void unregisterComponentCallbacks(ComponentCallbacks callback); void unregisterForContextMenu(View view); void unregisterReceiver(BroadcastReceiver receiver);  }
@Test public void testCodeBeforeSuper() throws Exception { final Call beforeBSuper = mock(Call.class); final Call afterBSuper = mock(Call.class); final Call beforeCSuper = mock(Call.class); final Call afterCSuper = mock(Call.class); final ActivityPlugin a = spy(new ActivityPlugin()); final ActivityPlugin b = spy(new ActivityPlugin() { @Override public void onPause() { beforeBSuper.call(); super.onPause(); afterBSuper.call(); } }); final ActivityPlugin c = spy(new ActivityPlugin() { @Override public void onPause() { beforeCSuper.call(); super.onPause(); afterCSuper.call(); } }); final CompositeActivity activity = mock(CompositeActivity.class); final ActivityDelegate delegate = new ActivityDelegate(activity); delegate.addPlugin(a); delegate.addPlugin(b); delegate.addPlugin(c); delegate.onPause(); final InOrder inOrder = inOrder(a, b, c, activity, beforeBSuper, afterBSuper, beforeCSuper, afterCSuper); inOrder.verify(c).onPause(); inOrder.verify(beforeCSuper).call(); inOrder.verify(b).onPause(); inOrder.verify(beforeBSuper).call(); inOrder.verify(a).onPause(); inOrder.verify(activity).super_onPause(); inOrder.verify(afterBSuper).call(); inOrder.verify(afterCSuper).call(); }