|
Android VNC Server
利用shell开启VNC服务的测试版本==
一、直接开启VNC Server
1)下载地址
android-vnc-server:http://code.google.com/p/android-vnc-server/downloads/list
android-vnc:http://code.google.com/p/android-vnc/downloads/list
2)参考网址
1、电脑控制手机的另一选择——android vnc server
http://bbs.gfan.com/android-116468-1-1.html
2、Android vnc server 安装
http://www.51testing.com/?uid-49689-action-viewspace-itemid-211955
3)操作简述
前提:机子需要是破解的,否则su不可执行。
adb push "F:/androidvncserver" /data/(放进去)
adb shell chmod 755 /data/androidvncserver(加可执行权限)
adb shell /data/androidvncserver(执行androidvncserver)
adb forward tcp:5900 tcp:5901(端口重定向,我没弄==)
3.1)Q1:adb push
有些机子破解后adb shell仍是$符,需要su后才是#。不能直接push进入/data/目录。
因而可以先adb push "F:/androidvncserver" /sdcard/,之后adb shell->su->mv /sdcard/androidvncserver /data/
/data/目录可以再建一层,为/data/local。因为如果你要用程序把androidvncserver写入的话,需要给该目录加写权限,这样涉及到的东西少些。
3.2)Q2:chmod
755指rwxr-xr-x,是为了增加其可执行权限。和之前一样,默认是$符需要su才#的破解机子,也只能一步步来:adb shell->su->cd data->chmod a+x androidvncserver->./fbvncserver &
(su:变更用户身份,不指定时为root;a+x:所有用户执行权限;&:后台运行)
3.3)Q3:关闭服务
ps命令查看pid:ps|grep androidvnc*(这个程序里执行不过==)、ps -l androidvncserver
kill <pid>,杀死进程,即可关闭服务。
3.4)Q4:VNC Viewer连接不到==
1、确认android端开了VNC Server的进程
2、PC端看下能不能ping通android的ip
二、程序执行
1)程序截图

2)活动类(VNCServerActivity.java)- /**
- * @brief 利用shell开启VNC服务的测试版本
- * @detail
- * Question
- *
- * Q1:操作设计不合理,见谅-_-!(应该一直su,不要su后执行个命令就exit)
- * 另外,有些破解手机,默认是$而非#。现在这种操作方式就不适用了==
- * Q2:androidvncserver这个,Google HTC开不起来==
- * 纯shell操作,看到提示“cannot get ABS_X info, Invalid argument”
- * Q3:fbvncserver这个,我的那个Viewer接收到的画面怎么花绿的且有挤压==
- *
- * Solution
- *
- * S1:先还是利用shell来开VNC服务,找下有其他的没且重新改下流程。
- * S2:难道要下VNCServer源码么?要改东西?要加JNI接口?头疼T^T。
- *
- * @author Join
- * @date 2012-3-20
- */
- public class VNCServerActivity extends Activity {
- private static final String TAG = "VNCServerActivity" ;
- private static final boolean LOGD = true ;
- // assets目录下的VNCServer文件名
- private static final String VNC_SERVER_FILENAME = "fbvncserver" ;
- private GlobalUtil globalUtil; // 工具类
- private Button startBtn, stopBtn; // 按钮
- private TextView statusView, connectView; // 标签
- [color=#009933]/* dialog identifiers */
- private static final int DLG_BASE = 0 ;
- private static final int DLG_ROOT_FAILED = DLG_BASE + 1 ;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super .onCreate(savedInstanceState);
- setContentView(R.layout.main);
- startBtn = (Button) findViewById(R.id.startBtn);
- stopBtn = (Button) findViewById(R.id.stopBtn);
- statusView = (TextView) findViewById(R.id.statusView);
- connectView = (TextView) findViewById(R.id.connectView);
- // 直接获IP地址了拼接个端口了,本应该从stdout获的==
- connectView.setText(getLocalIpAddress() + ":5901" );
- globalUtil = GlobalUtil.getInstance(); // 获取工具类
- if (initApp()) { // 初始化应用权限
- /* 判断服务是否开启了,以改变界面 */
- changeViews(globalUtil.getPids(VNC_SERVER_FILENAME).size() >= 1 );
- }
- }
- /** 改变界面状态 */
- private void changeViews( boolean isServerOn) {
- startBtn.setEnabled(!isServerOn);
- stopBtn.setEnabled(isServerOn);
- statusView.setText(isServerOn ? R.string.status_run
- : R.string.status_stop);
- }
- /** startBtn点击事件 */
- public void startBtn(View v) {
- // 运行VNCServer文件(&:后台)
- boolean result = globalUtil.rootCommand( "/data/" + VNC_SERVER_FILENAME
- + " &" );
- if (LOGD)
- Log.d(TAG, "/data/" + VNC_SERVER_FILENAME + " &:
[/color]" + result); - changeViews(result); // 改变界面状态
- connectView.setText(getLocalIpAddress() + ":5901" ); // 重设下IP显示
- }
- /** stopBtn点击事件 */
- public void stopBtn(View v) {
- ArrayList<String> pidArray = globalUtil.getPids(VNC_SERVER_FILENAME);
- boolean result;
- for (String pid : pidArray) {
- result = globalUtil.rootCommand( "kill " + pid);
- if (LOGD)
- Log.d(TAG, "kill " + pid + ":" + result);
- }
- changeViews( false );
- }
- /** 初始化应用权限 */
- private boolean initApp() {
- boolean result = globalUtil.rootCommand( "chmod 777 "
- + getPackageCodePath());
- if (result) {
- copyVNCServer(); // 检查vncserver文件
- } else {
- showDialog(DLG_ROOT_FAILED); // 提示退出应用
- }
- return result;
- }
- /** 检查VNCServer文件,不存在时复制进去 */
- private void copyVNCServer() {
- String filePath = "/data/" + VNC_SERVER_FILENAME;
- File file = new File(filePath);
- /* 文件不存在时,从assets复制进去 */
- if (!file.exists()) {
- try {
- /* /data/目录增加所有用户的写权限 */
- boolean result = globalUtil.rootCommand( "chmod a+w /data" );
- if (LOGD)
- Log.d(TAG, "==/data/目录增加写权限:" + result + "==" );
- if (result) {
- /* 将VNCServer文件复制入/data/ */
- InputStream is = getAssets().open(VNC_SERVER_FILENAME);
- FileOutputStream fos = new FileOutputStream(file);
- byte [] buffer = new byte [ 2048 ];
- int count = 0 ;
- while ((count = is.read(buffer)) > 0 ) {
- fos.write(buffer, 0 , count);
- }
- fos.close();
- is.close();
- if (LOGD)
- Log.d(TAG, "==" + VNC_SERVER_FILENAME + "文件写入/data/!==" );
- /* 给VNCServer文件增加所有用户的执行权限 */
- result = globalUtil.rootCommand( "chmod a+x " + filePath);
- if (LOGD)
- Log.d(TAG, "==" + filePath + "增加执行权限:" + result + "==" );
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- if (LOGD)
- Log.d(TAG, "==" + VNC_SERVER_FILENAME + "文件已存在/data/目录下!==" );
- }
- }
- @Override
- protected Dialog onCreateDialog( int id) {
- switch (id) {
- case DLG_ROOT_FAILED:
- return new AlertDialog.Builder( this )
- .setTitle(R.string.root_title)
- .setMessage(R.string.root_failed)
- .setCancelable( false )
- .setPositiveButton(R.string.dlg_ok,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog,
- int which) {
- finish();
- }
- }).create();
- }
- return super .onCreateDialog(id);
- }
- /** 获取IP地址 */
- public String getLocalIpAddress() {
- try {
- for (Enumeration<NetworkInterface> en = NetworkInterface
- .getNetworkInterfaces(); en.hasMoreElements();) {
- NetworkInterface intf = en.nextElement();
- for (Enumeration<InetAddress> enumIpAddr = intf
- .getInetAddresses(); enumIpAddr.hasMoreElements();) {
- InetAddress inetAddress = enumIpAddr.nextElement();
- if (!inetAddress.isLoopbackAddress()) {
- return inetAddress.getHostAddress().toString();
- }
- }
- }
- } catch (SocketException e) {
- e.printStackTrace();
- }
- return null ;
- }
- }
|
3)工具类(GlobalUtil.java)
三、其他参考
1、linux权限详解
http://blog.csdn.net/fan_zhen_hua/article/details/2050009
2、Linux命令大全(修改版).zip
http://vaero.blog.51cto.com/4350852/796090,附件资料。
3、Android执行shell命令
http://vaero.blog.51cto.com/4350852/778139,附件资料。
4、Google Code的wiki&issues
http://code.google.com/p/android-vnc-server/wiki/README
四、后记
实现的不好,好多问题啊 T^T 。(还待完善,请多担待!)
ps : fastdroid-vnc 这个项目好像也不错 ^^
http://code.google.com/p/fastdroid-vnc/wiki/fastdroidvnc
1 )开启 fastdroid-vnc

2 )关闭 fastdroid-vnc

附件:http://down.51cto.com/data/2360106
----------------------------
原文链接:https://blog.51cto.com/vaero/812967
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 flybird 在 2020-04-08 09:01:54 重新编辑]
|
|