APK:网络adb

 一、网络adb

1.1、device\rockchip\common\init.rk30board.rc

# for Internet adb
on property:netadb.status=true
    setprop service.adb.tcp.port 5555
    restart adbd

# for Internet adb
on property:netadb.status=false
    setprop service.adb.tcp.port 0
    restart adbd

1.2、连接

adb connect 192.168.1.1:5555
adb disconnect 192.168.1.1切回usb模式 adb usb

三、仙逆

3.1、AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gatsby.zebra"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <uses-sdk
        android:minSdkVersion="22"
        android:targetSdkVersion="22" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />   
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".ZebraReceiver">
             <intent-filter>
               <action android:name="com.gatsby.action.MCU_WIFI_ADB_Y"/>
               <action android:name="com.gatsby.action.MCU_WIFI_ADB_N"/>
             </intent-filter>
        </receiver>
        
    </application>

</manifest>

 3.2、activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.gatsby.zebra.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:shadowColor="#F9F900"
        android:shadowDx="10.0"
        android:shadowDy="10.0"
        android:shadowRadius="3.0"
        android:text="EthernetStat: "
        android:textColor="#4A4AFF"
        android:textSize="60sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:shadowColor="#F9F900"
        android:shadowDx="10.0"
        android:shadowDy="10.0"
        android:shadowRadius="3.0"
        android:text="EthernetIP: "
        android:textColor="#4A4AFF"
        android:textSize="60sp" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:background="#40BBFA"
        android:text="Start Net ADB"
        android:textSize="40sp" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:background="#BF4507"
        android:text="Stop Net ADB"
        android:textSize="40sp" />

</LinearLayout>

3.3、MainActivity.java

package com.gatsby.zebra;

import android.app.Activity;
import android.content.Intent;

import com.android.xhapimanager.XHApiManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

    private String TAG = "Gatsby";

    XHApiManager apimanager;
    private TextView state, ip;
    private Button btn1, btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        apimanager = new XHApiManager();

        state = (TextView) findViewById(R.id.textView1);
        ip = (TextView) findViewById(R.id.textView2);

        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);

        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);

        state.setText("EthernetStat: " + apimanager.XHEthernetState() + "");
        ip.setText("EthernetIP: " + apimanager.XHEthernetGetIP());

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()) {
        case R.id.btn1:
            Intent intentY = new Intent();
            intentY.setAction("com.gatsby.action.MCU_WIFI_ADB_Y");
            sendBroadcast(intentY);
            break;
        case R.id.btn2:
            Intent intentN = new Intent();
            intentN.setAction("com.gatsby.action.MCU_WIFI_ADB_N");
            sendBroadcast(intentN);
            break;

        }

    }
}

3.4、ZebraReceiver.java

package com.gatsby.zebra;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ZebraReceiver extends BroadcastReceiver {

    private final String MCU_WIFI_ADB_Y = "com.gatsby.action.MCU_WIFI_ADB_Y";
    private final String MCU_WIFI_ADB_N = "com.gatsby.action.MCU_WIFI_ADB_N";

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        if (MCU_WIFI_ADB_Y.equals(intent.getAction())) {
            Log.e("gatsby", "MCU_WIFI_ADB_Y ");
            RootCommand("stop adbd");
            RootCommand("setprop service.adb.tcp.port 5555");
            RootCommand("start adbd");

        } else if (MCU_WIFI_ADB_N.equals(intent.getAction())) {
            Log.e("gatsby", "MCU_WIFI_ADB_N ");
            RootCommand("stop adbd");
            RootCommand("setprop service.adb.tcp.port 0");
            RootCommand("start adbd");
        }
    }

    private void RootCommand(String cmd) {
        Process process = null;
        DataOutputStream os = null;
        DataInputStream is = null;
        try {
            process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(cmd + "\n");
            os.writeBytes("exit\n");
            os.flush();

            int aa = process.waitFor();
            is = new DataInputStream(process.getInputStream());

            byte[] buffer = new byte[is.available()];
            is.read(buffer);

            String out = new String(buffer);
            // Log.d(TAG, out + aa);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                if (is != null) {
                    is.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }
    }
}

APK:网络adb

相关推荐