Enable flipper android to use different ports based on prop

Summary:
Part 1 of enabling flipper to run on custom ports: android SDK.
Still to go: iOS SDK and desktop

This should allow you to run mobile apps that use flipper on different ports than the default (8089,8088).

`adb shell`
`su`
`setprop flipper.ports 1111,2222`

From what I can tell, this only works on rooted devices.

Reviewed By: passy

Differential Revision: D13753238

fbshipit-source-id: c5f370c9d8c7382e8c17fb81d4010c642ef7c114
This commit is contained in:
John Knox
2019-01-24 03:08:42 -08:00
committed by Facebook Github Bot
parent c68e74c6a0
commit 324a7ae873
9 changed files with 171 additions and 92 deletions

View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.facebook.flipper.android;
import static org.junit.Assert.assertEquals;
import com.facebook.testing.robolectric.v3.WithTestDefaultsRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(WithTestDefaultsRunner.class)
public class FlipperPropsTest {
@Test
public void shouldParseExpectedInput() throws Exception {
int value1 = FlipperProps.extractIntFromPropValue("1111,2222", 0, 1234);
assertEquals(value1, 1111);
int value2 = FlipperProps.extractIntFromPropValue("1111,2222", 1, 1234);
assertEquals(value2, 2222);
}
@Test
public void shouldFallbackForTruncatedInput() throws Exception {
int value = FlipperProps.extractIntFromPropValue("1111", 1, 1234);
assertEquals(value, 1234);
}
@Test
public void shouldFallbackForMistypedInput() throws Exception {
int value = FlipperProps.extractIntFromPropValue("111ds1", 0, 1234);
assertEquals(value, 1234);
}
@Test
public void shouldFallbackForEmptyInput() throws Exception {
int value = FlipperProps.extractIntFromPropValue("", 0, 1234);
assertEquals(value, 1234);
}
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.flipper.plugins.console;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.MatcherAssert.assertThat;
import com.facebook.flipper.core.FlipperObject;
import com.facebook.flipper.testing.FlipperConnectionMock;
import com.facebook.flipper.testing.FlipperResponderMock;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class ConsoleFlipperPluginTest {
FlipperConnectionMock connection;
FlipperResponderMock responder;
@Before
public void setup() throws Exception {
JavascriptEnvironment jsEnvironment = new JavascriptEnvironment();
final ConsoleFlipperPlugin plugin = new ConsoleFlipperPlugin(jsEnvironment);
connection = new FlipperConnectionMock();
responder = new FlipperResponderMock();
plugin.onConnect(connection);
}
@Test
public void simpleExpressionShouldEvaluateCorrectly() throws Exception {
receiveScript("2 + 2");
assertThat(
responder.successes,
hasItem(new FlipperObject.Builder().put("value", 4).put("type", "json").build()));
}
private void receiveScript(String a) throws Exception {
FlipperObject getValue = new FlipperObject.Builder().put("command", a).build();
connection.receivers.get("executeCommand").onReceive(getValue, responder);
}
}