Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[WIP] Delete deprecated v1 code #4457

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,6 @@ public class AndroidAlarmManagerPlugin implements FlutterPlugin, MethodCallHandl
private Object initializationLock = new Object();
private MethodChannel alarmManagerPluginChannel;

/**
* Registers this plugin with an associated Flutter execution context, represented by the given
* {@link io.flutter.plugin.common.PluginRegistry.Registrar}.
*
* <p>Once this method is executed, an instance of {@code AndroidAlarmManagerPlugin} will be
* connected to, and running against, the associated Flutter execution context.
*/
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
if (instance == null) {
instance = new AndroidAlarmManagerPlugin();
}
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.dart.DartExecutor.DartCallback;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.JSONMethodCodec;
import io.flutter.plugin.common.MethodCall;
Expand Down Expand Up @@ -149,12 +148,6 @@ public void startBackgroundIsolate(Context context, long callbackHandle) {
DartCallback dartCallback = new DartCallback(assets, appBundlePath, flutterCallback);

executor.executeDartCallback(dartCallback);

// The pluginRegistrantCallback should only be set in the V1 embedding as
// plugin registration is done via reflection in the V2 embedding.
if (pluginRegistrantCallback != null) {
pluginRegistrantCallback.registerWith(new ShimPluginRegistry(backgroundFlutterEngine));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ public AndroidIntentPlugin() {
impl = new MethodCallHandlerImpl(sender);
}

/**
* Registers a plugin implementation that uses the stable {@code io.flutter.plugin.common}
* package.
*
* <p>Calling this automatically initializes the plugin. However plugins initialized this way
* won't react to changes in activity or context, unlike {@link AndroidIntentPlugin}.
*/
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
IntentSender sender = new IntentSender(registrar.activity(), registrar.context());
MethodCallHandlerImpl impl = new MethodCallHandlerImpl(sender);
impl.startListening(registrar.messenger());
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
sender.setApplicationContext(binding.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ public class BatteryPlugin implements MethodCallHandler, StreamHandler, FlutterP
private MethodChannel methodChannel;
private EventChannel eventChannel;

/** Plugin registration. */
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
final BatteryPlugin instance = new BatteryPlugin();
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ public class DeviceInfoPlugin implements FlutterPlugin {
static final String TAG = "DeviceInfoPlugin";
MethodChannel channel;

/** Plugin registration. */
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
DeviceInfoPlugin plugin = new DeviceInfoPlugin();
plugin.setupMethodChannel(registrar.messenger(), registrar.context());
}

@Override
public void onAttachedToEngine(FlutterPlugin.FlutterPluginBinding binding) {
setupMethodChannel(binding.getBinaryMessenger(), binding.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
channel.setMethodCallHandler(new EspressoPlugin());
}

// This static function is optional and equivalent to onAttachedToEngine. It supports the old
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
// plugin registration via this function while apps migrate to use the new Android APIs
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
//
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "espresso");
channel.setMethodCallHandler(new EspressoPlugin());
}

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
* <p><strong>DO NOT USE THIS CLASS.</strong>
*/
public class FlutterAndroidLifecyclePlugin implements FlutterPlugin {
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
// no-op
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
// no-op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,6 @@ public void onActivityStopped(Activity activity) {
private Lifecycle lifecycle;
private LifeCycleObserver observer;

@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
if (registrar.activity() == null) {
// If a background flutter view tries to register the plugin, there will be no activity from the registrar,
// we stop the registering process immediately because the ImagePicker requires an activity.
return;
}
Activity activity = registrar.activity();
Application application = null;
if (registrar.context() != null) {
application = (Application) (registrar.context().getApplicationContext());
}
ImagePickerPlugin plugin = new ImagePickerPlugin();
plugin.setup(registrar.messenger(), application, activity, registrar, null);
}

/**
* Default constructor for the plugin.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ public void onMethodCall_PickingVideo_WhenSourceIsCamera_InvokesTakeImageWithCam
verify(mockImagePickerDelegate).setCameraDevice(eq(CameraDevice.FRONT));
}

@Test
public void onResiter_WhenAcitivityIsNull_ShouldNotCrash() {
when(mockRegistrar.activity()).thenReturn(null);
ImagePickerPlugin.registerWith((mockRegistrar));
assertTrue(
"No exception thrown when ImagePickerPlugin.registerWith ran with activity = null", true);
}

@Test
public void onConstructor_WhenContextTypeIsActivity_ShouldNotCrash() {
new ImagePickerPlugin(mockImagePickerDelegate, mockActivity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ static final class MethodNames {
private MethodChannel methodChannel;
private MethodCallHandlerImpl methodCallHandler;

/** Plugin registration. */
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
InAppPurchasePlugin plugin = new InAppPurchasePlugin();
registrar.activity().getIntent().putExtra(PROXY_PACKAGE_KEY, PROXY_VALUE);
((Application) registrar.context().getApplicationContext())
.registerActivityLifecycleCallbacks(plugin.methodCallHandler);
}

@Override
public void onAttachedToEngine(FlutterPlugin.FlutterPluginBinding binding) {
setupMethodChannel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,6 @@ public void setUp() {
when(flutterPluginBinding.getApplicationContext()).thenReturn(context);
}

@Test
public void registerWith_doNotCrashWhenRegisterContextIsActivity_V1Embedding() {
when(mockRegistrar.context()).thenReturn(activity);
when(activity.getApplicationContext()).thenReturn(mockApplication);
InAppPurchasePlugin.registerWith(mockRegistrar);
}

// The PROXY_PACKAGE_KEY value of this test (io.flutter.plugins.inapppurchase) should never be changed.
// In case there's a strong reason to change it, please inform the current code owner of the plugin.
@Test
public void registerWith_proxyIsSet_V1Embedding() {
when(mockRegistrar.context()).thenReturn(activity);
when(activity.getApplicationContext()).thenReturn(mockApplication);
InAppPurchasePlugin.registerWith(mockRegistrar);
// The `PROXY_PACKAGE_KEY` value is hard coded in the plugin code as "io.flutter.plugins.inapppurchase".
// We cannot use `BuildConfig.LIBRARY_PACKAGE_NAME` directly in the plugin code because whether to read BuildConfig.APPLICATION_ID or LIBRARY_PACKAGE_NAME
// depends on the "APP's" Android Gradle plugin version. Newer versions of AGP use LIBRARY_PACKAGE_NAME, whereas older ones use BuildConfig.APPLICATION_ID.
Mockito.verify(mockIntent).putExtra(PROXY_PACKAGE_KEY, "io.flutter.plugins.inapppurchase");
assertEquals("io.flutter.plugins.inapppurchase", BuildConfig.LIBRARY_PACKAGE_NAME);
}

// The PROXY_PACKAGE_KEY value of this test (io.flutter.plugins.inapppurchase) should never be changed.
// In case there's a strong reason to change it, please inform the current code owner of the plugin.
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,6 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
}
};

/**
* Registers a plugin with the v1 embedding api {@code io.flutter.plugin.common}.
*
* <p>Calling this will register the plugin with the passed registrar. However, plugins
* initialized this way won't react to changes in activity or context.
*
* @param registrar attaches this plugin's {@link
* io.flutter.plugin.common.MethodChannel.MethodCallHandler} to the registrar's {@link
* io.flutter.plugin.common.BinaryMessenger}.
*/
@SuppressWarnings("deprecation")
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
final LocalAuthPlugin plugin = new LocalAuthPlugin();
plugin.activity = registrar.activity();
channel.setMethodCallHandler(plugin);
registrar.addActivityResultListener(plugin.resultListener);
}

/**
* Default constructor for LocalAuthPlugin.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public class PackageInfoPlugin implements MethodCallHandler, FlutterPlugin {
private Context applicationContext;
private MethodChannel methodChannel;

/** Plugin registration. */
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
final PackageInfoPlugin instance = new PackageInfoPlugin();
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ private void setup(BinaryMessenger messenger, Context context) {
channel.setMethodCallHandler(this);
}

@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
PathProviderPlugin instance = new PathProviderPlugin();
instance.setup(registrar.messenger(), registrar.context());
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
setup(binding.getBinaryMessenger(), binding.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ public class QuickActionsPlugin implements FlutterPlugin, ActivityAware, NewInte
private MethodChannel channel;
private MethodCallHandlerImpl handler;

/**
* Plugin registration.
*
* <p>Must be called when the application is created.
*/
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
final QuickActionsPlugin plugin = new QuickActionsPlugin();
plugin.setupChannel(registrar.messenger(), registrar.context(), registrar.activity());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
setupChannel(binding.getBinaryMessenger(), binding.getApplicationContext(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ public class SensorsPlugin implements FlutterPlugin {
private EventChannel userAccelChannel;
private EventChannel gyroscopeChannel;

/** Plugin registration. */
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
SensorsPlugin plugin = new SensorsPlugin();
plugin.setupEventChannels(registrar.context(), registrar.messenger());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
final Context context = binding.getApplicationContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public class SharePlugin implements FlutterPlugin, ActivityAware {
private Share share;
private MethodChannel methodChannel;

@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
SharePlugin plugin = new SharePlugin();
plugin.setUpChannel(registrar.context(), registrar.activity(), registrar.messenger());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
setUpChannel(binding.getApplicationContext(), null, binding.getBinaryMessenger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ public class SharedPreferencesPlugin implements FlutterPlugin {
private MethodChannel channel;
private MethodCallHandlerImpl handler;

@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
final SharedPreferencesPlugin plugin = new SharedPreferencesPlugin();
plugin.setupChannel(registrar.messenger(), registrar.context());
}

@Override
public void onAttachedToEngine(FlutterPlugin.FlutterPluginBinding binding) {
setupChannel(binding.getBinaryMessenger(), binding.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ public final class UrlLauncherPlugin implements FlutterPlugin, ActivityAware {
@Nullable private MethodCallHandlerImpl methodCallHandler;
@Nullable private UrlLauncher urlLauncher;

/**
* Registers a plugin implementation that uses the stable {@code io.flutter.plugin.common}
* package.
*
* <p>Calling this automatically initializes the plugin. However plugins initialized this way
* won't react to changes in activity or context, unlike {@link UrlLauncherPlugin}.
*/
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
MethodCallHandlerImpl handler =
new MethodCallHandlerImpl(new UrlLauncher(registrar.context(), registrar.activity()));
handler.startListening(registrar.messenger());
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
urlLauncher = new UrlLauncher(binding.getApplicationContext(), /*activity=*/ null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ private VideoPlayerPlugin(io.flutter.plugin.common.PluginRegistry.Registrar regi
flutterState.startListening(this, registrar.messenger());
}

/** Registers this with the stable v1 embedding. Will not respond to lifecycle events. */
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
final VideoPlayerPlugin plugin = new VideoPlayerPlugin(registrar);
registrar.addViewDestroyListener(
view -> {
plugin.onDestroy();
return false; // We are not interested in assuming ownership of the NativeView.
});
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {

Expand Down
Loading