Autojs

Introduction to Auto.JS

  Auto. JS is a JavaScript automation tool on Android platform. Its essence is that it can execute simple JavaScript scripts written by itself, especially an android app that can perform some operations on other apps when “barrier free mode” is turned on, which is convenient for automatic operation.

Project realization

  Through the code, the control logic of Android motherboard IO is simplified to the greatest extent, and the developer shows Android motherboard intent according to the product test requirements Setaction broadcast app and shell script app are used to communicate with the peripherals of the Android motherboard, which are used for the function debugging of the production line and reduce the test difficulty of the production line.

Concrete Step

  Before using, we need to import the Android class and register the broadcast.

 1importClass(android.content.IntentFilter);
 2
 3let intent = new Intent();
 4let filter = new IntentFilter();
 5filter.addAction(Intent.ACTION_BATTERY_CHANGED);
 6filter.addAction("android.intent.action.Dustin");
 7filter.addAction("com.fise.system.reboot");
 8filter.addAction("echo 1 > /sys/class/fise_gpio5/level");
 9filter.addAction("echo 0 > /sys/class/fise_gpio5/level");
10filter.addAction("echo 1 > /sys/class/fise_gpio6/level");
11filter.addAction("echo 0 > /sys/class/fise_gpio6/level");
12filter.addAction("echo 1 > /sys/class/fise_gpio7/level");
13filter.addAction("echo 0 > /sys/class/fise_gpio7/level");
14filter.addAction(Intent.ACTION_SCREEN_ON);

  Take Android broadcasting as an example:

1var action = "echo 0 > /sys/class/fise_gpio6/level";
2            app.sendBroadcast({
3                action: action,
4                extras: {
5                    author: "Dustin",
6                },
7            });

  Take Android shell as an example:

1var result = shell("echo 0 > /sys/class/fise_gpio5/level", false);
2            toast(result);

  UI human-computer interaction:

 1ui.layout(
 2    <vertical>
 3        <card padding="10" w="*" h="auto" margin="5 5 5 5" cardCornerRadius="20dp" cardBackgroundColor="#72ffffff" cardElevation="1dp" alpha="0.8" cardCornerRadius="30dp">
 4            <horizontal margin="20 10 20 5" gravity="center" >
 5                <button id="open" text="打开广播" layout_weight="1" style="Widget.AppCompat.Button.Colored" />;
 6                <button id="cq" text="重启" layout_weight="1" style="Widget.AppCompat.Button.Colored" />;
 7                <button id="close" text="关闭广播" layout_weight="1" style="Widget.AppCompat.Button.Colored" />;
 8            </horizontal>
 9        </card>
10        <card padding="10" w="*" h="auto" margin="5 5 5 5" cardCornerRadius="20dp" cardBackgroundColor="#72ffffff" cardElevation="1dp" alpha="0.8" cardCornerRadius="30dp">
11            <horizontal margin="20 10 20 5" gravity="center" >
12                <text text="选择电平:" textColor="black" w="auto" />
13                <spinner id="选择电平7" textStyle="bold" entries="高电平|低电平" spinnerMode="dialog" />
14                <button id="设置GPIO7" text="设置GPIO7" layout_weight="1" style="Widget.AppCompat.Button.Colored" />;
15            </horizontal>
16        </card>
17        <card padding="10" w="*" h="auto" margin="5 5 5 5" cardCornerRadius="20dp" cardBackgroundColor="#72ffffff" cardElevation="1dp" alpha="0.8" cardCornerRadius="30dp">
18            <horizontal margin="20 10 20 5" gravity="center" >
19                <text text="选择电平:" textColor="black" w="auto" />
20                <spinner id="选择电平8" textStyle="bold" entries="高电平|低电平" spinnerMode="dialog" />
21                <button id="设置GPIO8" text="设置GPIO8" layout_weight="1" style="Widget.AppCompat.Button.Colored" />;
22            </horizontal>
23        </card>
24        <card padding="10" w="*" h="auto" margin="5 5 5 5" cardCornerRadius="20dp" cardBackgroundColor="#72ffffff" cardElevation="1dp" alpha="0.8" cardCornerRadius="30dp">
25            <horizontal margin="20 10 20 5" gravity="center" >
26                <text text="选择电平:" textColor="black" w="auto" />
27                <spinner id="选择电平9" textStyle="bold" entries="高电平|低电平" spinnerMode="dialog" />
28                <button id="设置GPIO9" text="设置GPIO9" layout_weight="1" style="Widget.AppCompat.Button.Colored" />;
29            </horizontal>
30        </card>
31    </vertical>
32);

  UI click event:

 1ui.设置GPIO9.on("click", () => {
 2    var i = ui.选择电平9.getSelectedItemPosition();
 3    switch (i) {
 4        case 0:
 5            toast("您选择的高电平!");
 6            var action = "echo 1 > /sys/class/fise_gpio7/level";
 7            app.sendBroadcast({
 8                action: action,
 9                extras: {
10                    author: "yashu",
11                },
12            });
13            var result = shell("echo 1 > /sys/class/fise_gpio7/level", false);
14            toast(result);
15            break;
16        case 1:
17            var action = "echo 0 > /sys/class/fise_gpio7/level";
18            app.sendBroadcast({
19                action: action,
20                extras: {
21                    author: "yashu",
22                },
23            });
24            var result = shell("echo 0 > /sys/class/fise_gpio7/level", false);
25            toast(result);
26            toast("您选择的低电平!");
27            break;
28    }
29});

  The complete source code of this article has been uploaded to gitee,Click to view.

Copyright