Skip to content

Feat/screen render #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: feat/screen-render-to-dev
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ rootProject.allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://mvn.instabug.com/nexus/repository/instabug-internal/"
credentials {
username "instabug"
password System.getenv("INSTABUG_REPOSITORY_PASSWORD")
}
}
}
}


apply plugin: 'com.android.library'

android {
Expand All @@ -44,11 +52,10 @@ android {
}

dependencies {
api 'com.instabug.library:instabug:14.3.0'
api 'com.instabug.library:instabug:15.0.0.6897042-SNAPSHOT'
testImplementation 'junit:junit:4.13.2'
testImplementation "org.mockito:mockito-inline:3.12.1"
testImplementation "io.mockk:mockk:1.13.13"

}

// add upload_symbols task
Expand Down
1 change: 0 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.Log;
import android.view.Display;
import android.view.View;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -73,7 +75,14 @@ public Bitmap call() {
}
};

ApmApi.init(messenger);
Callable<Float> refreshRateProvider = new Callable<Float>() {
@Override
public Float call(){
return getRefreshRate();
}
};

ApmApi.init(messenger, refreshRateProvider);
BugReportingApi.init(messenger);
CrashReportingApi.init(messenger);
FeatureRequestsApi.init(messenger);
Expand All @@ -99,4 +108,20 @@ private static Bitmap takeScreenshot(FlutterRenderer renderer) {
return null;
}
}

private static float getRefreshRate() {
float refreshRate = 60f;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final Display display = activity.getDisplay();
if (display != null) {
refreshRate = display.getRefreshRate();
}
} else {
refreshRate = activity.getWindowManager().getDefaultDisplay().getRefreshRate();
}

return refreshRate;
}

}
45 changes: 42 additions & 3 deletions android/src/main/java/com/instabug/flutter/modules/ApmApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

public class ApmApi implements ApmPigeon.ApmHostApi {
private final String TAG = ApmApi.class.getName();
private final HashMap<String, ExecutionTrace> traces = new HashMap<>();
private final Callable<Float> refreshRate;

public static void init(BinaryMessenger messenger) {
final ApmApi api = new ApmApi();
public ApmApi(Callable<Float> refreshRate) {
this.refreshRate = refreshRate;
}

public static void init(BinaryMessenger messenger, Callable<Float> refreshRateProvider) {

final ApmApi api = new ApmApi(refreshRateProvider);
ApmPigeon.ApmHostApi.setup(messenger, api);
}

Expand Down Expand Up @@ -435,7 +442,6 @@ public void isEndScreenLoadingEnabled(@NonNull ApmPigeon.Result<Boolean> result)
isScreenLoadingEnabled(result);
}


@Override
public void isEnabled(@NonNull ApmPigeon.Result<Boolean> result) {
try {
Expand Down Expand Up @@ -475,4 +481,37 @@ public void setScreenLoadingEnabled(@NonNull Boolean isEnabled) {
e.printStackTrace();
}
}

@Override
public void setScreenRenderEnabled(@NonNull Boolean isEnabled) {
try {
APM.setScreenRenderingEnabled(isEnabled);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void isScreenRenderEnabled(@NonNull ApmPigeon.Result<Boolean> result) {
try {
InternalAPM._isFeatureEnabledCP(APMFeature.SCREEN_RENDERING, "InstabugCaptureScreenRender", new FeatureAvailabilityCallback() {
@Override
public void invoke(boolean isEnabled) {
result.success(isEnabled);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void deviceRefreshRate(@NonNull ApmPigeon.Result<Double> result) {
try {
result.success(refreshRate.call().doubleValue());
} catch (Exception e) {
e.printStackTrace();
}
}

}
42 changes: 36 additions & 6 deletions android/src/test/java/com/instabug/flutter/ApmApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.instabug.apm.APM;
import com.instabug.apm.InternalAPM;
Expand All @@ -24,8 +23,6 @@
import com.instabug.flutter.util.GlobalMocks;
import com.instabug.flutter.util.MockReflected;

import io.flutter.plugin.common.BinaryMessenger;

import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
Expand All @@ -36,18 +33,21 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import static com.instabug.flutter.util.GlobalMocks.reflected;
import static com.instabug.flutter.util.MockResult.makeResult;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import io.flutter.plugin.common.BinaryMessenger;


public class ApmApiTest {

private final BinaryMessenger mMessenger = mock(BinaryMessenger.class);
private final ApmApi api = new ApmApi();
private final Callable<Float> refreshRateProvider = () -> mock(Float.class);
private final ApmApi api = new ApmApi(refreshRateProvider);
private MockedStatic<APM> mAPM;
private MockedStatic<InternalAPM> mInternalApmStatic;
private MockedStatic<ApmPigeon.ApmHostApi> mHostApi;
Expand Down Expand Up @@ -83,7 +83,7 @@ private ExecutionTrace mockTrace(String id) {
public void testInit() {
BinaryMessenger messenger = mock(BinaryMessenger.class);

ApmApi.init(messenger);
ApmApi.init(messenger, refreshRateProvider);

mHostApi.verify(() -> ApmPigeon.ApmHostApi.setup(eq(messenger), any(ApmApi.class)));
}
Expand Down Expand Up @@ -386,4 +386,34 @@ public void testSetScreenLoadingMonitoringEnabled() {

mAPM.verify(() -> APM.setScreenLoadingEnabled(isEnabled));
}

@Test
public void testIsScreenRenderEnabled() {

boolean expected = true;
ApmPigeon.Result<Boolean> result = spy(makeResult((actual) -> assertEquals(expected, actual)));

mInternalApmStatic.when(() -> InternalAPM._isFeatureEnabledCP(any(), any(), any())).thenAnswer(
invocation -> {
FeatureAvailabilityCallback callback = (FeatureAvailabilityCallback) invocation.getArguments()[2];
callback.invoke(expected);
return null;
});


api.isScreenRenderEnabled(result);

mInternalApmStatic.verify(() -> InternalAPM._isFeatureEnabledCP(any(), any(), any()));
mInternalApmStatic.verifyNoMoreInteractions();

verify(result).success(expected);
}

public void testSetScreenRenderEnabled() {
boolean isEnabled = false;

api.setScreenRenderEnabled(isEnabled);

mAPM.verify(() -> APM.setScreenRenderingEnabled(isEnabled));
}
}
3 changes: 2 additions & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ target 'Runner' do

use_frameworks!
use_modular_headers!
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/fix-main-thread-warning/15.0.0/Instabug.podspec'
# pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/fix-main-thread-warning/15.0.0/Instabug.podspec'
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/faeture-screen_rendering-release/15.1.0/Instabug.podspec'

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
Expand Down
16 changes: 8 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PODS:
- Flutter (1.0.0)
- Instabug (15.0.0)
- Instabug (15.1.0)
- instabug_flutter (14.3.0):
- Flutter
- Instabug (= 15.0.0)
- Instabug (= 15.1.0)
- OCMock (3.6)

DEPENDENCIES:
- Flutter (from `Flutter`)
- Instabug (from `https://ios-releases.instabug.com/custom/fix-main-thread-warning/15.0.0/Instabug.podspec`)
- Instabug (from `https://ios-releases.instabug.com/custom/faeture-screen_rendering-release/15.1.0/Instabug.podspec`)
- instabug_flutter (from `.symlinks/plugins/instabug_flutter/ios`)
- OCMock (= 3.6)

Expand All @@ -20,16 +20,16 @@ EXTERNAL SOURCES:
Flutter:
:path: Flutter
Instabug:
:podspec: https://ios-releases.instabug.com/custom/fix-main-thread-warning/15.0.0/Instabug.podspec
:podspec: https://ios-releases.instabug.com/custom/faeture-screen_rendering-release/15.1.0/Instabug.podspec
instabug_flutter:
:path: ".symlinks/plugins/instabug_flutter/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
Instabug: 3b1db5a683e85ec5a02946aa2b3314036f9022be
instabug_flutter: e59da7a0cae82ce00b2773625ee544c275442000
Instabug: a2b8c384cd4af7a01ab43b2ce2957a880f8862d7
instabug_flutter: 6ee721f30066123a769da64b687eded6eb4ff125
OCMock: 5ea90566be239f179ba766fd9fbae5885040b992

PODFILE CHECKSUM: c16418947581b888c337ed7ff120a59b4b5f3f3f
PODFILE CHECKSUM: e6e180d6b55e3a12f55f266c3f4d8654480877ef

COCOAPODS: 1.16.2
COCOAPODS: 1.15.2
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
Expand Down Expand Up @@ -63,11 +64,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
42 changes: 18 additions & 24 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:instabug_flutter/instabug_flutter.dart';
import 'package:instabug_flutter_example/src/components/apm_switch.dart';
import 'package:instabug_http_client/instabug_http_client.dart';
import 'package:instabug_flutter/src/utils/screen_loading/screen_loading_manager.dart';
import 'package:instabug_flutter_example/src/app_routes.dart';
import 'package:instabug_flutter_example/src/utils/show_messages.dart';
import 'package:instabug_flutter_example/src/widget/nested_view.dart';
import 'package:instabug_http_client/instabug_http_client.dart';

import 'src/native/instabug_flutter_example_method_channel.dart';
import 'src/widget/instabug_button.dart';
import 'src/widget/instabug_clipboard_input.dart';
import 'src/widget/instabug_text_field.dart';
import 'package:instabug_flutter/src/utils/screen_loading/screen_loading_manager.dart';

import 'src/widget/section_title.dart';

part 'src/screens/crashes_page.dart';

part 'src/screens/complex_page.dart';

part 'src/screens/apm_page.dart';

part 'src/screens/screen_capture_premature_extension_page.dart';

part 'src/screens/screen_loading_page.dart';

part 'src/screens/my_home_page.dart';

part 'src/components/animated_box.dart';
part 'src/components/fatal_crashes_content.dart';

part 'src/components/non_fatal_crashes_content.dart';

part 'src/components/flows_content.dart';
part 'src/components/network_content.dart';

part 'src/components/non_fatal_crashes_content.dart';
part 'src/components/page.dart';

part 'src/components/screen_render.dart';
part 'src/components/traces_content.dart';

part 'src/components/flows_content.dart';
part 'src/components/ui_traces_content.dart';
part 'src/screens/apm_page.dart';
part 'src/screens/complex_page.dart';
part 'src/screens/crashes_page.dart';
part 'src/screens/my_home_page.dart';
part 'src/screens/screen_capture_premature_extension_page.dart';
part 'src/screens/screen_loading_page.dart';
part 'src/screens/screen_render_page.dart';
part 'src/components/apm_switch.dart';
part 'src/components/screen_render_switch.dart';

void main() {
runZonedGuarded(
Expand Down
Loading