Repository: flutter
Issue: The drawing of the outer frame of the application is strange when in picture-in-picture with FireTab
Labels: e: device-specific,platform-android,a: platform-views,P2,team-android,triaged-android

## Steps to Reproduce

1. Add a `PlatformViewLink` widget to your Fire Tablet(Android) application
2. Create an AndroidView that returns `PlatformViewsService.initExpensiveAndroidView` in `onCreatePlatformView`
3. For example, implement a widget that puts you in Android's picture-in-picture(https://developer.android.com/develop/ui/views/picture-in-picture) mode when you tap a button
4. Run the code, Frames are drawn incorrectly when using picture-in-picture

**Expected results:** <!-- what did you want to see? -->
Renders correctly when in picture-in-picture.

**Actual results:** <!-- what did you see? -->
When running an app using `PlatformViewsService.initExpensiveAndroidView` on a Fire Tablet, the borders of the app are drawn incorrectly when doing a picture-in-picture.

|  | Fire Tablet | Pixel2 XL |
| :---         |     :---:      |          ---: |
| Normal | <img src="https://user-images.githubusercontent.com/25051897/220492367-4e7ef8c5-282c-4ab2-8c9c-0b7672bd3981.png" width = "250">  | <img src="https://user-images.githubusercontent.com/25051897/220492396-3c2fa543-54d3-4859-9141-eaf0516e404a.png" width = "250">  |
| picture-in-picture | <img src="https://user-images.githubusercontent.com/25051897/220492439-99ab8b37-eff0-4ede-a305-434f38f6f9e7.png" width = "250">  | <img src="https://user-images.githubusercontent.com/25051897/220492469-da1b4937-0b4a-472b-9da7-c9e00e027c04.png" width = "250">  |
| picture-in-picture(details)  | <img src="https://user-images.githubusercontent.com/25051897/220492513-3c766caa-f019-441b-9374-ba5963102a0c.png" width = "250">  | <img src="https://user-images.githubusercontent.com/25051897/220492649-f1f7b8ca-5e83-4fe8-bf65-16172e6e18cb.png" width = "250">  |


<details>
<summary>Code sample</summary>

* main.dart

```dart
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    const String viewType = '<platform-view-type>';
    final Map<String, dynamic> creationParams = <String, dynamic>{};

    return MaterialApp(
      title: 'Sample',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('sample'),
          actions: [
            IconButton(
              icon: const Icon(Icons.add),
              onPressed: () async {
                // Tap buton to PIP in Android app
                await Native.doPIPDebug();
              },
            ),
          ],
        ),
        body: PlatformViewLink(
          viewType: viewType,
          surfaceFactory:
              (BuildContext context, PlatformViewController controller) {
            return AndroidViewSurface(
              controller: controller as AndroidViewController,
              gestureRecognizers: const <
                  Factory<OneSequenceGestureRecognizer>>{},
              hitTestBehavior: PlatformViewHitTestBehavior.opaque,
            );
          },
          onCreatePlatformView: (PlatformViewCreationParams params) {
            return PlatformViewsService.initExpensiveAndroidView(
              id: params.id,
              viewType: viewType,
              layoutDirection: TextDirection.ltr,
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
            )
              ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
              ..create();
          },
        ),
      ),
    );
  }
}

class Native {
  static const _channel = MethodChannel('<platform-view-type>');

  static Future<void> doPIPDebug() async {
    _channel.invokeMethod<void>('doPIPDebug');
  }
}

```

* MainActivity.kt

```kotlin
package com.example.flutter_application_platformviewlink

import android.app.Activity
import android.app.PictureInPictureParams
import android.content.Context
import android.os.Build
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {
    private lateinit var mContext: Context
    private lateinit var mPictureInPictureParamsBuilder: PictureInPictureParams.Builder

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        flutterEngine
            .platformViewsController
            .registry
            .registerViewFactory("<platform-view-type>", NativeViewFactory())

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "<platform-view-type>").setMethodCallHandler {
                call, result ->
            when (call.method) {
                "doPIPDebug" -> {
                    mContext = context

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        mPictureInPictureParamsBuilder = PictureInPictureParams.Builder()
                        (mContext as Activity).enterPictureInPictureMode(mPictureInPictureParamsBuilder.build())
                    }

                    result.success(true)
                }
            }
        }
    }
}
```

* NativeViewFactory.kt

```kotlin
package com.example.flutter_application_platformviewlink

import android.content.Context
import android.view.View
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory

class NativeViewFactory : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
    override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
        val creationParams = args as Map<String?, Any?>?
        return NativeView(context, viewId, creationParams)
    }
}
```


* AndroidManifest.xml
```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.flutter_application_platformviewlink">
   <application
        android:label="flutter_application_platformviewlink"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:supportsPictureInPicture="true"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>
```

</details>

<details>
  <summary>Logs</summary>

* flutter run --verbose`
  * [gist](https://gist.github.com/ms11165/4087e9818abe47309863c6145399a08f)

* flutter analyze
```
$ flutter analyze
Analyzing flutter_application_platformviewlink...                       
No issues found! (ran in 1.2s)
```

* flutter doctor
```
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel unknown, 3.7.3, on macOS 13.1 22C65 darwin-arm64 (Rosetta), locale ja-JP)
    ! Flutter version 3.7.3 on channel unknown at /Users/koji.yamada/development/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.75.0)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

! Doctor found issues in 1 category.
```

</details>

<details>
  <summary>Device Info</summary>

* [Amazon Fire Tablet](https://developer.amazon.com/docs/fire-tablets/ft-device-specifications-firehd-models.html?v=firehd10_2019)
* Android 9.0
* API Level 28
* Fire OS Version 7 (7.3.2.6)
* Device model Fire HD 10 (9th generation)

```
$ adb devices -l
List of devices attached
G0011J0604660HXW       device usb:17825792X product:maverick model:KFMAWI device:maverick transport_id:51
```

</details>