I want to disable my camera using xposed. So I am not able to understand which native method should I hook so that my phone camera gets disabled.
I tried this:-
public class main1 implements IXposedHookLoadPackage {
#Override
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable{
if(!lpparam.packageName.equals("android.hardware.camera2"))
return;
findAndHookMethod("android.hardware.camera2.CameraManager", lpparam.classLoader, "openCamera", String.class, CameraDevice.StateCallback.class, Handler.class, new XC_MethodReplacement() {
#Override
protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
XposedBridge.log("CameraBlocked");
return null;
}
});
XposedBridge.log("Loaded app: " + lpparam.packageName);
}
}
But it doesn't work. Please help me out with this.
Related
I am new to websockets and I am trying to write a unit test.
My unit test runs fine but it has following two issue
Idk why but it forces me to expect same object that is being sent as an input(i.e WebSocketRequestData) to the websocket instead of the actual response from the websocket which is WebSocketData
And it returns an empty object as result so it passes NotNull assertion.
Can anyone please clear out this confusion for me!
And also what is the right way to get response from the my websocket in unit test?
here is the code for my websocketTest Class
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ServerWebSocketTest {
#LocalServerPort
private Integer port;
static final String WEBSOCKET_TOPIC = "/user/locationrealtimedata/item" ;
BlockingQueue<WebSocketRequestData> blockingQueue;
WebSocketStompClient stompClient;
#BeforeEach
public void setup() {
blockingQueue = new LinkedBlockingDeque<>();
stompClient = new WebSocketStompClient(new SockJsClient(
asList(new WebSocketTransport(new StandardWebSocketClient()))));
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
}
#Test
public void shouldReceiveAMessageFromTheServer() throws Exception {
StompSession session = stompClient
.connect(getWsPath(), new DefaultStompFrameHandler() {
})
.get(1, TimeUnit.SECONDS);
session.subscribe(WEBSOCKET_TOPIC, new DefaultStompFrameHandler());
WebSocketRequestData webSocketRequestData = new WebSocketRequestData();
webSocketRequestData.setUserId("usr-1");
webSocketRequestData.setAccountId("acc-1");
webSocketRequestData.setGroupId("grp-1");
session.send("/wsconn/start", webSocketRequestData);
WebSocketRequestData responseObj = blockingQueue.poll(15, TimeUnit.SECONDS);
Assertions.assertNotNull(responseObj);
}
class DefaultStompFrameHandler extends StompSessionHandlerAdapter{
#Override
public Type getPayloadType(StompHeaders stompHeaders) {
return WebSocketRequestData.class;
}
#Override
public void handleFrame(StompHeaders stompHeaders, Object o) {
blockingQueue.offer((WebSocketRequestData) o); // instead of **WebSocketData** it forces me to add casting for **WebSocketRequestData**
}
#Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
exception.printStackTrace();
}
}
private String getWsPath() {
return String.format("ws://localhost:%d/location_services/locationrealtimedata", port);
}
}
Thanks in advance
You are not forced to use the same Java class for the input and response type.
The request type is what you use within session.send("/endpoint", payload); in your case that's WebSocketRequestData:
WebSocketRequestData webSocketRequestData = new WebSocketRequestData();
webSocketRequestData.setUserId("usr-1");
webSocketRequestData.setAccountId("acc-1");
webSocketRequestData.setGroupId("grp-1");
session.send("/wsconn/start", webSocketRequestData);
When it comes to consuming messages you specify the actual response type you expect when implementing StompFrameHandler and overriding getPayloadType.
So instead of implementing StompSessionHandlerAdapter, use the StompFrameHandler interface and implement it as the following:
class DefaultStompFrameHandler extends StompSessionHandlerAdapter{
#Override
public Type getPayloadType(StompHeaders stompHeaders) {
return WebSocketData.class; // or any other class your expect
}
#Override
public void handleFrame(StompHeaders stompHeaders, Object o) {
blockingQueue.offer((WebSocketData) o);
}
#Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
exception.printStackTrace();
}
}
Also make sure your BlockingQueue is using the correct type BlockingQueue<WebSocketData> blockingQueue
When using StreamDSL, I can call .print(Printed.toConsole()) to see the output in the console.
Is there sth similar when using the Processor API? I expect a PrintToConsoleProcessor, or?
For sure I can create a dummy processor, but a PrintToConsoleProcessor would be very useful.
Ok could be fairly easy
topology.addProcessor("console", () -> new Processor() {
#Override
public void init(ProcessorContext context) {
}
#Override
public void process(Object key, Object value) {
System.out.println(value.toString());
}
#Override
public void punctuate(long timestamp) {
}
#Override
public void close() {
}
}, "PARENT")
I'm trying to handle exceptions with AOP approach in my Spring/Swing Application and I couldn't make it work.
Main Class:
public class MainFrame extends JFrame {
private JPanel mainPanel;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public MainFrame() {
initializeMainPanel();
}
private void initializeMainPanel() {
exitLabel.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
throw new Exception("test");
}
});
}
}
Aspect Class:
#Aspect
public class AspectTest{
#AfterThrowing(pointcut = "execution(* com.test.MainFrame.*(..))", throwing = "ex")
public void logError(Exception ex) throws Throwable {
// ex.printStackTrace();
}
}
So, I throw an exception within my Mouse Listener and expect to catch it in my AspectTest class' AfterThrowing method but it does not work.
Can someone please help me to understand what I'm missing here?
#AfterThrowing cannot catch exceptions, only notice them and log them or do something similar. If you want to handle exceptions in an aspect you need to use an #Around advice.
I am working on developing a JMeter plugin. I'm trying to create an AbstractVisualizer that is capable of monitoring the current test state. However, implementing the TestStateListener doesn't seem to be working.
I'm testing this by creating a basic listener that has a login to output arbitrary info to JMeter's logging console. When a sample is sent through the Add function, a line is sent to the console. But nothing is ever triggered on the various TestState functions. Is there something more structural I'm missing?
public class TestListener extends AbstractVisualizer
implements TestStateListener
{
private static final Logger log = LoggingManager.getLoggerForClass();
#Override
public void add(SampleResult arg0) {
log.info("add");
}
#Override
public void clearData() {
// TODO Auto-generated method stub
}
#Override
public String getStaticLabel()
{
return "Test Listener";
}
#Override
public String getLabelResource() {
return null;
}
#Override
public void testEnded() {
log.info("Test Ended");
}
#Override
public void testEnded(String arg0) {
log.info("Test Ended");
}
#Override
public void testStarted() {
log.info("Test started");
}
#Override
public void testStarted(String arg0) {
log.info("Test started");
}
}
I'm not sure how to do it in 1 class. I have 2 classes:
The UI:
public class MonitorGui extends AbstractListenerGui
{
// ...
#Override
public TestElement createTestElement()
{
TestElement element = new Monitor();// <-- this is the backend
modifyTestElement(element);
return element;
}
// ...
}
And then the backend goes like this:
public class Monitor extends AbstractListenerElement
implements SampleListener,
Clearable, Serializable,
TestStateListener, Remoteable,
NoThreadClone
{
private static final String TEST_IS_LOCAL = "*local*";
// ...
#Override
public void testStarted()
{
testStarted(TEST_IS_LOCAL);
}
#Override
public void testEnded()
{
testEnded(TEST_IS_LOCAL);
}
#Override
public void testStarted(String host)
{
// ...
}
// ...
}
You may not need to implement SampleListener like I do, but probably other things are quite similar.
I based that implementation on a built-in pair of ResultSaverGui and ResultCollector which are the components that are saving results into the file(s) for Simple Data Writer, Summary Report and so on.
I need to update my GUI based on client input. Calling my controller class method, from the background task works. But it can't update the GUI, because it is not the JavaFX application thread..please help.
I tried many of the related Q & A, but I am still confused.
Should I use Platform. runLater or Task ?
Here's my class where I create an instance of controller class
public class FactoryClass {
public static Controller_Gui1 createGUI() {
FXMLLoader fxLoader = new FXMLLoader();
fxLoader.setLocation(MainApp_Gui1.class.getResource("/com/Gui_1.fxml"));
AnchorPane anchorPane = null;
try {
anchorPane = (AnchorPane) fxLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
Controller_Gui1 controller_Gui1 = (Controller_Gui1) fxLoader
.getController();
Scene scene = new Scene(anchorPane);
//System.out.println(scene);
controller_Gui1.setScene(scene);
return controller_Gui1;
}
}
Controller class
#FXML
Button B1 = new Button();
#FXML
public void handleButton1() {
B1.setDisable(true);
}
Application class
public class MainApp_Gui1 extends Application {
Controller_Gui1 cGui;
#Override
public void start(Stage primaryStage) throws Exception {
initScene(primaryStage);
primaryStage.show();
System.out.println("asdasd");
SceneSetting sceneSetting = new SceneSetting();
//handleEvent();
System.out.println("after");
sceneSetting.setSceneAfter();
System.out.println("after2");
}
// creating scene
private void initScene(Stage primaryStage) throws IOException {
primaryStage.setScene(getScene(primaryStage));
}
public Scene getScene(Stage primaryStage) {
Controller_Gui1 cGui;
cGui = FactoryClass.createGUI();
return cGui.getScene();
}
public void ExcessFromOutside() {
Platform.runLater(new Runnable() {
public void run() {
System.out.println(Platform.isFxApplicationThread());
cGui.handleButton1();
}
});
}
public static void main(String[] args) {
launch(args);
}
}
I want to call ExcessFromOutside() method from another thread.
I got a null pointer exception while trying to update the GUI
Here's my application class
public class MainAppGui1 extends Application {
Controller_Gui1 controller_Gui1;
#Override
public void start(Stage primaryStage) throws Exception {
initScene(primaryStage);
primaryStage.show();
}
// creating scene
public void initScene(Stage primaryStage) throws IOException {
FXMLLoader fxLoader = new FXMLLoader();
fxLoader.setLocation(MainApp_Gui1.class.getResource("/com/Gui_1.fxml"));
AnchorPane anchorPane=new AnchorPane();
anchorPane = (AnchorPane) fxLoader.load();
Controller_Gui1 controller_Gui1 = (Controller_Gui1) fxLoader.getController();
Scene scene = new Scene(anchorPane);
primaryStage.setScene(scene);
}
#FXML
public void ExcessFromOutside()
{
Platform.runLater(new Runnable() {
#Override
public void run() {
System.out.println("called atleast");
controller_Gui1.handleButton1();
}
});
}
public static void main(String[] args) {
launch(args);
}
}
and this is the class from where i tried to update the GUI
public class Hudai {
public static void main(String args[]) throws InterruptedException
{
new Thread()
{
public void run()
{
MainAppGui1.main(null);
}
}.start();
Thread.sleep(5000);
MainAppGui1 m = new MainAppGui1();
m.ExcessFromOutside();
}
}
To disable your button in a different thread you can use Task's updateValue.
Task<Boolean> task = new Task<Boolean>() {
#Override
public Boolean call() {
... // The task that this thread needs to do
updateValue(true);
...
return null;
}
};
button.disableProperty().bind(task.valueProperty());
If you want to use a new thread to call a method, which alters the scene graph, the best chance you have is to use Platform.runLater() in it.
//code inside Thread
...
// code to run on the JavaFX Application thread
Platform.runLater(new Runnable() {
#Override
public void run() {
handleButton1();
}
});
...
You should get a NullPointerException when you run this program.
The problem is, the member of MainApp_Gui1
Controller_Gui1 cGui;
never gets a value.
Remove line "Controller_Gui1 cGui;" from this code:
public Scene getScene(Stage primaryStage) {
// Hudai hudai = new Hudai(primaryStage);
// return hudai.getScene();
Controller_Gui1 cGui;
cGui = FactoryClass.createGUI();
return cGui.getScene();
}