码迷,mamicode.com
首页 > 数据库 > 详细

APK:网络adb

时间:2020-05-30 19:47:37      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:图片   rockchip   cli   hapi   targe   this   iss   rap   exce   

 一、网络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

标签:图片   rockchip   cli   hapi   targe   this   iss   rap   exce   

原文地址:https://www.cnblogs.com/crushgirl/p/12994258.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!