Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedAlaaInstabug committed Nov 3, 2024
1 parent 96e128a commit 38971ab
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 544 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.instabug.flutter.modules.RepliesApi;
import com.instabug.flutter.modules.SessionReplayApi;
import com.instabug.flutter.modules.SurveysApi;
import com.instabug.library.internal.crossplatform.InternalCore;

import java.util.concurrent.Callable;

Expand All @@ -35,6 +36,7 @@ public class InstabugFlutterPlugin implements FlutterPlugin, ActivityAware {
@SuppressLint("StaticFieldLeak")
private static Activity activity;


/**
* Embedding v1
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.instabug.flutter.generated.InstabugPigeon;
import com.instabug.flutter.util.ArgsRegistry;
import com.instabug.flutter.util.Reflection;
import com.instabug.flutter.util.ThreadManager;
import com.instabug.flutter.util.privateViews.ScreenshotCaptor;
import com.instabug.library.Feature;
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
Expand All @@ -21,13 +24,17 @@
import com.instabug.library.Platform;
import com.instabug.library.ReproConfigurations;
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
import com.instabug.library.internal.crossplatform.InternalCore;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.model.NetworkLog;
import com.instabug.library.screenshot.instacapture.ScreenshotRequest;
import com.instabug.library.ui.onboarding.WelcomeMessage;

import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.loader.FlutterLoader;
import io.flutter.plugin.common.BinaryMessenger;

import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;

Expand Down Expand Up @@ -92,7 +99,9 @@ public Boolean isEnabled() {

@NotNull
@Override
public Boolean isBuilt() { return Instabug.isBuilt(); }
public Boolean isBuilt() {
return Instabug.isBuilt();
}

@Override
public void init(@NonNull String token, @NonNull List<String> invocationEvents, @NonNull String debugLogsLevel) {
Expand Down Expand Up @@ -441,4 +450,24 @@ public void networkLog(@NonNull Map<String, Object> data) {
public void willRedirectToStore() {
Instabug.willRedirectToStore();
}

public static void setScreenshotCaptor(ScreenshotCaptor screenshotCaptor,InternalCore internalCore) {
internalCore._setScreenshotCaptor(new com.instabug.library.screenshot.ScreenshotCaptor() {
@Override
public void capture(@NonNull ScreenshotRequest screenshotRequest) {
screenshotCaptor.capture(new ScreenshotCaptor.CapturingCallback() {
@Override
public void onCapturingFailure(Throwable throwable) {
screenshotRequest.getListener().onCapturingFailure(throwable);
}

@Override
public void onCapturingSuccess(Bitmap bitmap) {
screenshotRequest.getListener().onCapturingSuccess(bitmap);
}
});
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.instabug.flutter.util.privateViews;

import android.graphics.Bitmap;

public interface ScreenshotCaptor {
public void capture(CapturingCallback listener);

public interface CapturingCallback {
public void onCapturingFailure(Throwable throwable);

public void onCapturingSuccess(Bitmap bitmap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import com.instabug.library.ReproConfigurations;
import com.instabug.library.ReproMode;
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
import com.instabug.library.internal.crossplatform.InternalCore;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.model.NetworkLog;
import com.instabug.library.screenshot.ScreenshotCaptor;
import com.instabug.library.ui.onboarding.WelcomeMessage;

import org.json.JSONObject;
Expand All @@ -59,6 +61,7 @@
import java.util.concurrent.Callable;

import io.flutter.plugin.common.BinaryMessenger;

import org.mockito.verification.VerificationMode;

public class InstabugApiTest {
Expand Down Expand Up @@ -349,11 +352,11 @@ public void testClearAllExperiments() {

@Test
public void testAddFeatureFlags() {
Map<String,String > featureFlags = new HashMap<>();
featureFlags.put("key1","variant1");
Map<String, String> featureFlags = new HashMap<>();
featureFlags.put("key1", "variant1");
api.addFeatureFlags(featureFlags);
List<IBGFeatureFlag> flags=new ArrayList<IBGFeatureFlag>();
flags.add(new IBGFeatureFlag("key1","variant1"));
List<IBGFeatureFlag> flags = new ArrayList<IBGFeatureFlag>();
flags.add(new IBGFeatureFlag("key1", "variant1"));
mInstabug.verify(() -> Instabug.addFeatureFlags(flags));
}

Expand Down Expand Up @@ -598,4 +601,12 @@ public void testWillRedirectToStore() {
api.willRedirectToStore();
mInstabug.verify(Instabug::willRedirectToStore);
}

@Test
public void testSetScreenshotCaptor() {
InternalCore internalCore = spy(InternalCore.INSTANCE);

InstabugApi.setScreenshotCaptor(any(), internalCore);
verify(internalCore)._setScreenshotCaptor(any(ScreenshotCaptor.class));
}
}
8 changes: 5 additions & 3 deletions packages/instabug_flutter/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ PODS:

DEPENDENCIES:
- Flutter (from `Flutter`)
- Instabug (from `https://ios-releases.instabug.com/custom/feature-flutter-private-views-base/13.4.2/Instabug.podspec`)
- instabug_flutter (from `.symlinks/plugins/instabug_flutter/ios`)
- OCMock (= 3.6)

SPEC REPOS:
trunk:
- Instabug
- OCMock

EXTERNAL SOURCES:
Flutter:
:path: Flutter
Instabug:
:podspec: https://ios-releases.instabug.com/custom/feature-flutter-private-views-base/13.4.2/Instabug.podspec
instabug_flutter:
:path: ".symlinks/plugins/instabug_flutter/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
Instabug: 7a71890217b97b1e32dbca96661845396b66da2f
Instabug: 7aacd5099c11ce96bc49dda40eba0963c06acccc
instabug_flutter: a2df87e3d4d9e410785e0b1ffef4bc64d1f4b787
OCMock: 5ea90566be239f179ba766fd9fbae5885040b992

PODFILE CHECKSUM: 8f7552fd115ace1988c3db54a69e4a123c448f84
PODFILE CHECKSUM: 02e3295e1482e04d2cbd38390c8ea91a5c0c2ff1

COCOAPODS: 1.14.3
8 changes: 6 additions & 2 deletions packages/instabug_private_views/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.1
# Changelog

* TODO: Describe initial release.
## [UnReleased](https://github.com/Instabug/)

### Added

- Add support for masking private views during screen capturing ([#527](https://github.com/Instabug/Instabug-Flutter/pull/527)).
2 changes: 1 addition & 1 deletion packages/instabug_private_views/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void main() {
invocationEvents: [InvocationEvent.floatingButton],
);
ReproSteps.enablePrivateViews();
ReproSteps.enableMaskingPrivateViews();
runApp(MyApp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void onDetachedFromActivity() {

private void register(BinaryMessenger messenger, FlutterRenderer renderer) {
privateViewManager = new PrivateViewManager(new InstabugPrivateViewPigeon.InstabugPrivateViewFlutterApi(messenger), new PixelCopyCaptureManager(), new BoundryCaptureManager(renderer));
InstabugPrivateView instabugPrivateView=new InstabugPrivateView(messenger,privateViewManager, InternalCore.INSTANCE);
InstabugPrivateView.init(messenger,privateViewManager);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,38 @@

import androidx.annotation.NonNull;

import com.instabug.flutter.generated.InstabugLogPigeon;
import com.instabug.flutter.modules.InstabugApi;
import com.instabug.flutter.modules.InstabugLogApi;
import com.instabug.flutter.util.privateViews.ScreenshotCaptor;
import com.instabug.instabug_private_views.generated.InstabugPrivateViewPigeon;
import com.instabug.library.internal.crossplatform.InternalCore;
import com.instabug.library.screenshot.ScreenshotCaptor;
import com.instabug.library.screenshot.instacapture.ScreenshotRequest;

import io.flutter.plugin.common.BinaryMessenger;

public class InstabugPrivateView implements InstabugPrivateViewPigeon.InstabugPrivateViewHostApi {
PrivateViewManager privateViewManager;
private final InternalCore internalCore;

public InstabugPrivateView(BinaryMessenger messenger, PrivateViewManager privateViewManager, InternalCore internalCore) {
public static void init(BinaryMessenger messenger, PrivateViewManager privateViewManager) {
final InstabugPrivateView api = new InstabugPrivateView(messenger,privateViewManager);
InstabugPrivateViewPigeon.InstabugPrivateViewHostApi.setup(messenger, api);
}

public InstabugPrivateView(BinaryMessenger messenger, PrivateViewManager privateViewManager) {
this.privateViewManager = privateViewManager;
this.internalCore = internalCore;
InstabugPrivateViewPigeon.InstabugPrivateViewHostApi.setup(messenger, this);

}

@Override
public void init() {
internalCore._setScreenshotCaptor(new ScreenshotCaptor() {
InstabugApi.setScreenshotCaptor(new ScreenshotCaptor() {
@Override
public void capture(@NonNull ScreenshotRequest screenshotRequest) {
privateViewManager.mask(screenshotRequest.getListener());
public void capture(CapturingCallback listener) {
privateViewManager.mask(listener);

}
});
},InternalCore.INSTANCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
import androidx.annotation.VisibleForTesting;

import com.instabug.flutter.util.ThreadManager;
import com.instabug.flutter.util.privateViews.ScreenshotCaptor;
import com.instabug.instabug_private_views.generated.InstabugPrivateViewPigeon;
import com.instabug.instabug_private_views.model.ScreenshotResult;
import com.instabug.instabug_private_views.modules.capturing.CaptureManager;
import com.instabug.instabug_private_views.modules.capturing.ScreenshotResultCallback;
import com.instabug.library.screenshot.ScreenshotCaptor;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;

public class PrivateViewManager {
public class PrivateViewManager {
private static final String THREAD_NAME = "IBG-Flutter-Screenshot";
public static final String EXCEPTION_MESSAGE = "IBG-Flutter-Screenshot: error capturing screenshot";

Expand Down
Empty file modified packages/instabug_private_views/example/android/gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
BE133A632CD831A500FEADB5 /* PrivateViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BE133A622CD831A500FEADB5 /* PrivateViewHostApiTests.m */; };
BE9F8D392CD5C068003ADA97 /* PrivateViewApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BE9F8D382CD5C068003ADA97 /* PrivateViewApiTests.m */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -64,6 +65,7 @@
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
99B4BB79D25D93036AAF6480 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
A1871ACDFF6D3EA7210660EF /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
BE133A622CD831A500FEADB5 /* PrivateViewHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PrivateViewHostApiTests.m; sourceTree = "<group>"; };
BE9F8D382CD5C068003ADA97 /* PrivateViewApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PrivateViewApiTests.m; sourceTree = "<group>"; };
BE9F8D3A2CD5C06A003ADA97 /* RunnerTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RunnerTests-Bridging-Header.h"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -93,6 +95,7 @@
children = (
BE9F8D382CD5C068003ADA97 /* PrivateViewApiTests.m */,
BE9F8D3A2CD5C06A003ADA97 /* RunnerTests-Bridging-Header.h */,
BE133A622CD831A500FEADB5 /* PrivateViewHostApiTests.m */,
);
path = RunnerTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -390,6 +393,7 @@
buildActionMask = 2147483647;
files = (
BE9F8D392CD5C068003ADA97 /* PrivateViewApiTests.m in Sources */,
BE133A632CD831A500FEADB5 /* PrivateViewHostApiTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "PrivateViewApi.h"
#import "instabug_flutter/InstabugApi.h"
#import "PrivateViewHostApi.h"

@interface PrivateViewHostApiTests : XCTestCase

@property (nonatomic, strong) PrivateViewHostApi *api;
@property (nonatomic, strong) id privateViewApiMock;

@end

@implementation PrivateViewHostApiTests

- (void)setUp {
[super setUp];

// Set up a mock for PrivateViewApi
self.privateViewApiMock = OCMClassMock([PrivateViewApi class]);

// Initialize the PrivateViewHostApi instance
self.api = [[PrivateViewHostApi alloc] init];
self.api.privateViewApi = self.privateViewApiMock;
}

- (void)tearDown {
self.api = nil;
self.privateViewApiMock = nil;
[super tearDown];
}

- (void)testInitWithError_setsScreenshotMaskingHandler {
// Define an expectation for the screenshot masking handler
UIImage *mockScreenshot = [[UIImage alloc] init];
UIImage *mockMaskedImage = [[UIImage alloc] init];
FlutterError *error = nil;



OCMStub([self.privateViewApiMock mask:mockScreenshot completion:([OCMArg invokeBlockWithArgs:mockMaskedImage, nil])]);


// Call initWithError and set up the screenshot masking handler
[self.api initWithError:&error];

// Invoke the screenshot masking handler
void (^completionHandler)(UIImage * _Nullable) = ^(UIImage * _Nullable maskedImage) {
XCTAssertEqual(maskedImage, mockMaskedImage, @"The masked image should be returned by the completion handler.");
};
[InstabugApi setScreenshotMaskingHandler:^(UIImage * _Nonnull screenshot, void (^ _Nonnull completion)(UIImage * _Nullable)) {
completionHandler(screenshot);
}];
}

@end
Loading

0 comments on commit 38971ab

Please sign in to comment.