summaryrefslogtreecommitdiff
path: root/src/com/amlogic/pppoe/PppoeOperation.java (plain)
blob: d7be25408e4f757f2aa6a8b5ff52e37e94b3c667
1package com.amlogic.pppoe;
2
3import android.util.Log;
4
5public class PppoeOperation
6{
7 public static final String TAG = "PppoeOperation";
8 public static final int PPP_STATUS_CONNECTED = 0x10;
9 public static final int PPP_STATUS_DISCONNECTED = 0x20;
10 public static final int PPP_STATUS_CONNECTING = 0x40;
11
12 private native boolean _connect(String ifname, String account, String passwd);
13 private native boolean _disconnect();
14 private native boolean _terminate();
15 public native int isNetAdded(String ifname);
16 public native int status(String ifname);
17 private static LooperThread mLooper = null;
18 static {
19 System.loadLibrary("pppoejni");
20 Log.d(TAG, "LooperThread init!");
21 mLooper = new LooperThread();
22 mLooper.start();
23 }
24
25 public PppoeOperation() {
26 Log.d(TAG, "PppoeOperation init!");
27 }
28
29 public boolean connect(String ifname, String account, String passwd) {
30 String func = "connect";
31 Log.d(TAG, func + ", ifname: " + ifname + " account: " + account + " passwd: " + passwd);
32
33 if((ifname == null) || (isNetAdded(ifname) == 0)) {
34 Log.w(TAG, "The " + ifname + " is down or ifname is null, don't do connect!");
35 return false;
36 }
37 RunnableImpl mLast = mLooper.getLast();
38 if((mLast != null) && func.equals(mLast.mName)) {
39 Log.w(TAG, "the last action is connect, don't do again!");
40 return false;
41 }
42 final String Ifname = ifname;
43 final String Account = account;
44 final String Passwd = passwd;
45 RunnableImpl mCur = new RunnableImpl();
46 mCur.mName = func;
47 mCur.mRunnable = new Runnable() {
48 public void run() {
49 _connect(Ifname, Account, Passwd);
50 }
51 };
52 mLooper.post(mCur);
53 return true;
54 }
55
56 public boolean disconnect() {
57 String func = "disconnect";
58
59 Log.d(TAG, func);
60 RunnableImpl mLast = mLooper.getLast();
61 if((mLast != null) && func.equals(mLast.mName)) {
62 Log.w(TAG, "the last action is disconnect, don't do again!");
63 return false;
64 }
65 RunnableImpl mCur = new RunnableImpl();
66 mCur.mName = func;
67 mCur.mRunnable = new Runnable() {
68 public void run() {
69 _disconnect();
70 }
71 };
72 mLooper.post(mCur);
73 return true;
74 }
75
76 public boolean terminate() {
77 String func = "terminate";
78 String connect = "connect";
79
80 Log.d(TAG, func);
81 if((isNetAdded("eth0") == 0) && (isNetAdded("wlan0") == 0) && (isNetAdded("usbnet0") == 0)) {
82 Log.w(TAG, "The eht0/wlan0/usbnet0 is down, don't do terminate!");
83 return false;
84 }
85 RunnableImpl mLast = mLooper.getLast();
86 if(mLast != null) {
87 if(func.equals(mLast.mName)) {
88 Log.w(TAG, "the last action is terminate, don't do again!");
89 return false;
90 }
91 else if(connect.equals(mLast.mName)) {
92 Log.w(TAG, "the last action is connect, don't do terminate!");
93 return false;
94 }
95 }
96 RunnableImpl mCur = new RunnableImpl();
97 mCur.mName = func;
98 mCur.mRunnable = new Runnable() {
99 public void run() {
100 _terminate();
101 }
102 };
103 mLooper.post(mCur);
104 return true;
105 }
106}
107