MD5 校验值:d555a6389a0a865314e2706996812829
FlutterActivity.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package fo.flutter.embedding.android; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.Window; import fo.flutter.Log; import fo.flutter.embedding.android.FlutterActivityAndFragmentDelegate; import fo.flutter.embedding.android.FlutterActivityLaunchConfigs; import fo.flutter.embedding.engine.FlutterEngine; import fo.flutter.embedding.engine.FlutterShellArgs; import fo.flutter.embedding.engine.plugins.util.GeneratedPluginRegister; import fo.flutter.plugin.platform.PlatformPlugin; import fo.flutter.util.ViewUtils; import fodroidx.core.content.res.ResourcesCompat; import fodroidx.lifecycle.Lifecycle; import fodroidx.lifecycle.LifecycleOwner; import fodroidx.lifecycle.LifecycleRegistry; import java.util.ArrayList; import java.util.List; public class FlutterActivity extends Activity implements FlutterActivityAndFragmentDelegate.Host, LifecycleOwner { public static final int FLUTTER_VIEW_ID = ViewUtils.generateViewId(61938); private static final String TAG = "FlutterActivity"; protected FlutterActivityAndFragmentDelegate delegate; private LifecycleRegistry lifecycle = new LifecycleRegistry(this); @Override public void cleanUpFlutterEngine(FlutterEngine flutterEngine) { } @Override public Activity getActivity() { return this; } @Override public Context getContext() { return this; } @Override public void onFlutterSurfaceViewCreated(FlutterSurfaceView flutterSurfaceView) { } @Override public void onFlutterTextureViewCreated(FlutterTextureView flutterTextureView) { } @Override public void onFlutterUiNoLongerDisplayed() { } @Override public boolean popSystemNavigator() { return false; } @Override public FlutterEngine provideFlutterEngine(Context context) { return null; } @Override public boolean shouldAttachEngineToActivity() { return true; } @Override public boolean shouldDispatchAppLifecycleState() { return true; } public static Intent createDefaultIntent(Context context) { return withNewEngine().build(context); } public static NewEngineIntentBuilder withNewEngine() { return new NewEngineIntentBuilder(FlutterActivity.class); } public static class NewEngineIntentBuilder { private final Class<? extends FlutterActivity> activityClass; private List<String> dartEntrypointArgs; private String initialRoute = "/"; private String backgroundMode = FlutterActivityLaunchConfigs.DEFAULT_BACKGROUND_MODE; public NewEngineIntentBuilder(Class<? extends FlutterActivity> cls) { this.activityClass = cls; } public NewEngineIntentBuilder initialRoute(String str) { this.initialRoute = str; return this; } public NewEngineIntentBuilder backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode backgroundMode) { this.backgroundMode = backgroundMode.name(); return this; } public NewEngineIntentBuilder dartEntrypointArgs(List<String> list) { this.dartEntrypointArgs = list; return this; } public Intent build(Context context) { Intent putExtra = new Intent(context, this.activityClass).putExtra("route", this.initialRoute).putExtra("background_mode", this.backgroundMode).putExtra("destroy_engine_with_activity", true); if (this.dartEntrypointArgs != null) { putExtra.putExtra("dart_entrypoint_args", new ArrayList(this.dartEntrypointArgs)); } return putExtra; } } public static CachedEngineIntentBuilder withCachedEngine(String str) { return new CachedEngineIntentBuilder(FlutterActivity.class, str); } public static class CachedEngineIntentBuilder { private final Class<? extends FlutterActivity> activityClass; private final String cachedEngineId; private boolean destroyEngineWithActivity = false; private String backgroundMode = FlutterActivityLaunchConfigs.DEFAULT_BACKGROUND_MODE; public CachedEngineIntentBuilder(Class<? extends FlutterActivity> cls, String str) { this.activityClass = cls; this.cachedEngineId = str; } public CachedEngineIntentBuilder destroyEngineWithActivity(boolean z) { this.destroyEngineWithActivity = z; return this; } public CachedEngineIntentBuilder backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode backgroundMode) { this.backgroundMode = backgroundMode.name(); return this; } public Intent build(Context context) { return new Intent(context, this.activityClass).putExtra("cached_engine_id", this.cachedEngineId).putExtra("destroy_engine_with_activity", this.destroyEngineWithActivity).putExtra("background_mode", this.backgroundMode); } } void setDelegate(FlutterActivityAndFragmentDelegate flutterActivityAndFragmentDelegate) { this.delegate = flutterActivityAndFragmentDelegate; } @Override public ExclusiveAppComponent<Activity> getExclusiveAppComponent() { return this.delegate; } @Override protected void onCreate(Bundle bundle) { switchLaunchThemeForNormalTheme(); super.onCreate(bundle); FlutterActivityAndFragmentDelegate flutterActivityAndFragmentDelegate = new FlutterActivityAndFragmentDelegate(this); this.delegate = flutterActivityAndFragmentDelegate; flutterActivityAndFragmentDelegate.onAttach(this); this.delegate.onRestoreInstanceState(bundle); this.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); configureWindowForTransparency(); setContentView(createFlutterView()); configureStatusBarForFullscreenFlutterExperience(); } private void switchLaunchThemeForNormalTheme() { try { Bundle metaData = getMetaData(); if (metaData != null) { int i = metaData.getInt("fo.flutter.embedding.android.NormalTheme", -1); if (i != -1) { setTheme(i); } } else { Log.v(TAG, "Using the launch theme as normal theme."); } } catch (PackageManager.NameNotFoundException unused) { Log.e(TAG, "Could not read meta-data for FlutterActivity. Using the launch theme as normal theme."); } } @Override public SplashScreen provideSplashScreen() { Drawable splashScreenFromManifest = getSplashScreenFromManifest(); if (splashScreenFromManifest != null) { return new DrawableSplashScreen(splashScreenFromManifest); } return null; } private Drawable getSplashScreenFromManifest() { try { Bundle metaData = getMetaData(); int i = metaData != null ? metaData.getInt("fo.flutter.embedding.android.SplashScreenDrawable") : 0; if (i != 0) { return ResourcesCompat.getDrawable(getResources(), i, getTheme()); } return null; } catch (PackageManager.NameNotFoundException unused) { return null; } catch (Resources.NotFoundException e) { Log.e(TAG, "Splash screen not found. Ensure the drawable exists and that it's valid."); throw e; } } private void configureWindowForTransparency() { if (getBackgroundMode() == FlutterActivityLaunchConfigs.BackgroundMode.transparent) { getWindow().setBackgroundDrawable(new ColorDrawable(0)); } } private View createFlutterView() { return this.delegate.onCreateView(null, null, null, FLUTTER_VIEW_ID, getRenderMode() == RenderMode.surface); } private void configureStatusBarForFullscreenFlutterExperience() { if (Build.VERSION.SDK_INT >= 21) { Window window = getWindow(); window.addFlags(Integer.MIN_VALUE); window.setStatusBarColor(1073741824); window.getDecorView().setSystemUiVisibility(1280); } } @Override protected void onStart() { super.onStart(); this.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START); if (stillAttachedForEvent("onStart")) { this.delegate.onStart(); } } @Override protected void onResume() { super.onResume(); this.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME); if (stillAttachedForEvent("onResume")) { this.delegate.onResume(); } } @Override public void onPostResume() { super.onPostResume(); if (stillAttachedForEvent("onPostResume")) { this.delegate.onPostResume(); } } @Override protected void onPause() { super.onPause(); if (stillAttachedForEvent("onPause")) { this.delegate.onPause(); } this.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE); } @Override protected void onStop() { super.onStop(); if (stillAttachedForEvent("onStop")) { this.delegate.onStop(); } this.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP); } @Override protected void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(bundle); if (stillAttachedForEvent("onSaveInstanceState")) { this.delegate.onSaveInstanceState(bundle); } } private void release() { FlutterActivityAndFragmentDelegate flutterActivityAndFragmentDelegate = this.delegate; if (flutterActivityAndFragmentDelegate != null) { flutterActivityAndFragmentDelegate.release(); this.delegate = null; } } @Override public void detachFromFlutterEngine() { Log.w(TAG, "FlutterActivity " + this + " connection to the engine " + getFlutterEngine() + " evicted by another attaching activity"); FlutterActivityAndFragmentDelegate flutterActivityAndFragmentDelegate = this.delegate; if (flutterActivityAndFragmentDelegate != null) { flutterActivityAndFragmentDelegate.onDestroyView(); this.delegate.onDetach(); } } @Override protected void onDestroy() { super.onDestroy(); if (stillAttachedForEvent("onDestroy")) { this.delegate.onDestroyView(); this.delegate.onDetach(); } release(); this.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY); } @Override protected void onActivityResult(int i, int i2, Intent intent) { if (stillAttachedForEvent("onActivityResult")) { this.delegate.onActivityResult(i, i2, intent); } } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (stillAttachedForEvent("onNewIntent")) { this.delegate.onNewIntent(intent); } } @Override public void onBackPressed() { if (stillAttachedForEvent("onBackPressed")) { this.delegate.onBackPressed(); } } @Override public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) { if (stillAttachedForEvent("onRequestPermissionsResult")) { this.delegate.onRequestPermissionsResult(i, strArr, iArr); } } @Override public void onUserLeaveHint() { if (stillAttachedForEvent("onUserLeaveHint")) { this.delegate.onUserLeaveHint(); } } @Override public void onTrimMemory(int i) { super.onTrimMemory(i); if (stillAttachedForEvent("onTrimMemory")) { this.delegate.onTrimMemory(i); } } @Override public Lifecycle getLifecycle() { return this.lifecycle; } @Override public FlutterShellArgs getFlutterShellArgs() { return FlutterShellArgs.fromIntent(getIntent()); } @Override public String getCachedEngineId() { return getIntent().getStringExtra("cached_engine_id"); } @Override public boolean shouldDestroyEngineWithHost() { boolean booleanExtra = getIntent().getBooleanExtra("destroy_engine_with_activity", false); return (getCachedEngineId() != null || this.delegate.isFlutterEngineFromHost()) ? booleanExtra : getIntent().getBooleanExtra("destroy_engine_with_activity", true); } @Override public String getDartEntrypointFunctionName() { try { Bundle metaData = getMetaData(); String string = metaData != null ? metaData.getString("fo.flutter.Entrypoint") : null; return string != null ? string : "main"; } catch (PackageManager.NameNotFoundException unused) { return "main"; } } @Override public List<String> getDartEntrypointArgs() { return (List) getIntent().getSerializableExtra("dart_entrypoint_args"); } @Override public String getDartEntrypointLibraryUri() { try { Bundle metaData = getMetaData(); if (metaData != null) { return metaData.getString("fo.flutter.EntrypointUri"); } return null; } catch (PackageManager.NameNotFoundException unused) { return null; } } @Override public String getInitialRoute() { if (getIntent().hasExtra("route")) { return getIntent().getStringExtra("route"); } try { Bundle metaData = getMetaData(); if (metaData != null) { return metaData.getString("fo.flutter.InitialRoute"); } return null; } catch (PackageManager.NameNotFoundException unused) { return null; } } @Override public String getAppBundlePath() { String dataString; if (isDebuggable() && "android.intent.action.RUN".equals(getIntent().getAction()) && (dataString = getIntent().getDataString()) != null) { return dataString; } return null; } private boolean isDebuggable() { return (getApplicationInfo().flags & 2) != 0; } @Override public RenderMode getRenderMode() { return getBackgroundMode() == FlutterActivityLaunchConfigs.BackgroundMode.opaque ? RenderMode.surface : RenderMode.texture; } @Override public TransparencyMode getTransparencyMode() { if (getBackgroundMode() == FlutterActivityLaunchConfigs.BackgroundMode.opaque) { return TransparencyMode.opaque; } return TransparencyMode.transparent; } protected FlutterActivityLaunchConfigs.BackgroundMode getBackgroundMode() { if (getIntent().hasExtra("background_mode")) { return FlutterActivityLaunchConfigs.BackgroundMode.valueOf(getIntent().getStringExtra("background_mode")); } return FlutterActivityLaunchConfigs.BackgroundMode.opaque; } protected FlutterEngine getFlutterEngine() { return this.delegate.getFlutterEngine(); } protected Bundle getMetaData() throws PackageManager.NameNotFoundException { return getPackageManager().getActivityInfo(getComponentName(), 128).metaData; } @Override public PlatformPlugin providePlatformPlugin(Activity activity, FlutterEngine flutterEngine) { return new PlatformPlugin(getActivity(), flutterEngine.getPlatformChannel(), this); } @Override public void configureFlutterEngine(FlutterEngine flutterEngine) { if (this.delegate.isFlutterEngineFromHost()) { return; } GeneratedPluginRegister.registerGeneratedPlugins(flutterEngine); } @Override public boolean shouldHandleDeeplinking() { try { Bundle metaData = getMetaData(); if (metaData != null) { return metaData.getBoolean("flutter_deeplinking_enabled"); } return false; } catch (PackageManager.NameNotFoundException unused) { return false; } } @Override public void onFlutterUiDisplayed() { if (Build.VERSION.SDK_INT >= 29) { reportFullyDrawn(); } } @Override public boolean shouldRestoreAndSaveState() { if (getIntent().hasExtra("enable_state_restoration")) { return getIntent().getBooleanExtra("enable_state_restoration", false); } return getCachedEngineId() == null; } @Override public void updateSystemUiOverlays() { FlutterActivityAndFragmentDelegate flutterActivityAndFragmentDelegate = this.delegate; if (flutterActivityAndFragmentDelegate != null) { flutterActivityAndFragmentDelegate.updateSystemUiOverlays(); } } private boolean stillAttachedForEvent(String str) { FlutterActivityAndFragmentDelegate flutterActivityAndFragmentDelegate = this.delegate; if (flutterActivityAndFragmentDelegate == null) { Log.w(TAG, "FlutterActivity " + hashCode() + " " + str + " called after release."); return false; } if (flutterActivityAndFragmentDelegate.isAttached()) { return true; } Log.w(TAG, "FlutterActivity " + hashCode() + " " + str + " called after detach."); return false; } }