/**
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses/>.
* Use this application at your own risk.
*
* Copyright (c) 2009 by Harald Mueller and Sofia Lemons.
*/
package android.tether;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.tether.data.ClientData;
import android.tether.system.BluetoothService;
import android.tether.system.Configuration;
import android.tether.system.CoreTask;
import android.tether.system.WebserviceTask;
import android.util.Log;
import android.widget.Toast;
public class TetherApplication extends Application {
public static final String MSG_TAG = "TETHER -> TetherApplication";
public final String DEFAULT_PASSPHRASE = "abcdefghijklm";
public final String DEFAULT_LANNETWORK = "192.168.2.0/24";
public final String DEFAULT_ENCSETUP = "wpa_supplicant";
// Devices-Information
public String deviceType = Configuration.DEVICE_GENERIC;
public String interfaceDriver = Configuration.DRIVER_WEXT;
// StartUp-Check perfomed
public boolean startupCheckPerformed = false;
// Client-Connect-Thread
private Thread clientConnectThread = null;
private static final int CLIENT_CONNECT_ACDISABLED = 0;
private static final int CLIENT_CONNECT_AUTHORIZED = 1;
private static final int CLIENT_CONNECT_NOTAUTHORIZED = 2;
// Data counters
private Thread trafficCounterThread = null;
// WifiManager
private WifiManager wifiManager;
//public String tetherNetworkDevice = null;
// PowerManagement
private PowerManager powerManager = null;
private PowerManager.WakeLock wakeLock = null;
// Bluetooth
BluetoothService bluetoothService = null;
// DNS-Server-Update Thread
private Thread dnsUpdateThread = null;
// Preferences
public SharedPreferences settings = null;
public SharedPreferences.Editor preferenceEditor = null;
// Notification
public NotificationManager notificationManager;
private Notification notification;
private int clientNotificationCount = 0;
// Intents
private PendingIntent mainIntent;
private PendingIntent accessControlIntent;
// Original States
private static boolean origWifiState = false;
private static boolean origBluetoothState = false;
// Client
ArrayList<ClientData> clientDataAddList = new ArrayList<ClientData>();
ArrayList<String> clientMacRemoveList = new ArrayList<String>();
// Access-control
boolean accessControlSupported = true;
// Whitelist
public CoreTask.Whitelist whitelist = null;
// Supplicant
public CoreTask.WpaSupplicant wpasupplicant = null;
// TiWlan.conf
public CoreTask.TiWlanConf tiwlan = null;
// tether.conf
public CoreTask.TetherConfig tethercfg = null;
// dnsmasq.conf
public CoreTask.DnsmasqConfig dnsmasqcfg = null;
// hostapd
public CoreTask.HostapdConfig hostapdcfg = null;
// blue-up.sh
public CoreTask.BluetoothConfig btcfg = null;
// CoreTask
public CoreTask coretask = null;
// WebserviceTask
public WebserviceTask webserviceTask = null;
// Update Url
private static final String APPLICATION_PROPERTIES_URL = "http://android-wifi-tether.googlecode.com/svn/download/update/all/stable/application.properties";
private static final String APPLICATION_DOWNLOAD_URL = "http://android-wifi-tether.googlecode.com/files/";
@Override
public void onCreate() {
Log.d(MSG_TAG, "Calling onCreate()");
//create CoreTask
this.coretask = new CoreTask();
this.coretask.setPath(this.getApplicationContext().getFilesDir().getParent());
Log.d(MSG_TAG, "Current directory is "+this.getApplicationContext().getFilesDir().getParent());
//create WebserviceTask
this.webserviceTask = new WebserviceTask();
// Check Homedir, or create it
this.checkDirs();
// Set device-information
this.deviceType = Configuration.getDeviceType();
this.interfaceDriver = Configuration.getWifiInterfaceDriver(this.deviceType);
// Preferences
this.settings = PreferenceManager.getDefaultSharedPreferences(this);
// preferenceEditor
this.preferenceEditor = settings.edit();
// init wifiManager
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
// Whitelist
this.whitelist = this.coretask.new Whitelist();
// Supplicant config
this.wpasupplicant = this.coretask.new WpaSupplicant();
// tiwlan.conf
this.tiwlan = this.coretask.new TiWlanConf();
// tether.cfg
this.tethercfg = this.coretask.new TetherConfig();
this.tethercfg.read();
// dnsmasq.conf
this.dnsmasqcfg = this.coretask.new DnsmasqConfig();
// hostapd
this.hostapdcfg = this.coretask.new HostapdConfig();
// blue-up.sh
this.btcfg = this.coretask.new BluetoothConfig();
// Powermanagement
powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "TETHER_WAKE_LOCK");
// Bluetooth-Service
this.bluetoothService = BluetoothService.getInstance();
this.bluetoothService.setApplication(this);
// init notificationManager
this.notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
this.notification = new Notification(R.drawable.start_notification, "Wireless Tether", System.currentTimeMillis());
this.mainIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
this.accessControlIntent = PendingIntent.getActivity(this, 1, new Intent(this, AccessControlActivity.class), 0);
}
@Override
public void onTerminate() {
Log.d(MSG_TAG, "Calling onTerminate()");
// Stopping Tether
this.stopTether();
// Remove all notifications
this.notificationManager.cancelAll();
}
// ClientDataList Add
public synchronized void addClientData(ClientData clientData) {
this.clientDataAddList.add(clientData);
}
public synchronized void removeClientMac(String mac) {
this.clientMacRemoveList.add(mac);
}
public synchronized ArrayList<ClientData> getClientDataAddList() {
ArrayList<ClientData> tmp = this.clientDataAddList;
this.clientDataAddList = new ArrayList<ClientData>();
return tmp;
}
public synchronized ArrayList<String> getClientMacRemoveList() {
ArrayList<String> tmp = this.clientMacRemoveList;
this.clientMacRemoveList = new ArrayList<String>();
return tmp;
}
public synchronized void resetClientMacLists() {
this.clientDataAddList = new ArrayList<ClientData>();
this.clientMacRemoveList = new ArrayList<String>();
}
public boolean setBluetoothState(bo
评论6
最新资源