Skip to content

Commit

Permalink
wifidirect + proxyserver
Browse files Browse the repository at this point in the history
  • Loading branch information
U-MAGNA\peterq.admin authored and U-MAGNA\peterq.admin committed Jun 18, 2019
1 parent 73e1175 commit aab9043
Show file tree
Hide file tree
Showing 40 changed files with 1,400 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.wifidirect.wifidirectproxy;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.wifidirect.wifidirectproxy", appContext.getPackageName());
}
}
35 changes: 35 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wifidirect.wifidirectproxy">

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<service
android:name=".WifiDirectService"
android:enabled="true"
android:exported="true">
</service>

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
111 changes: 111 additions & 0 deletions app/src/main/java/com/wifidirect/wifidirectproxy/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.wifidirect.wifidirectproxy;

import android.os.*;
import android.view.*;
import android.content.*;
import android.widget.*;
import android.app.*;

public class MainActivity extends Activity {

boolean running;
java.util.Timer timer;
BroadcastReceiver receiver;
IntentFilter intentFilter;
String status;

@Override
protected void onCreate(Bundle savedInstanceState) {
android.util.Log.d("WDPS", "MainActivity.onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WifiNotification.initOnce(getApplicationContext());

Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Button button = (Button)findViewById(R.id.button);
if (!running) {
startWifi();
running = true;
button.setText("STOP");
} else {
stopWifi();
running = false;
button.setText("START");
status = "Ready";
}
}
});
status = "Ready";
if (timer == null) {
timer = new java.util.Timer();
timer.schedule(new Updater(), 1000, 1000);
}
Context context = getApplicationContext();
intentFilter = new IntentFilter();
intentFilter.addAction(WifiDirectService.ACTION_SEND_STATUS);
receiver = new MainBroadcastReceiver();
registerReceiver(receiver, intentFilter);
WifiDirectService.getStatus(context);
}

public void onResume() {
super.onResume();
}

public void onPause() {
super.onPause();
}

@Override
public void onDestroy() {
android.util.Log.d("WDPS", "MainActivity.onDestroy()");
super.onDestroy();
if (timer != null) {
timer.cancel();
timer = null;
}
unregisterReceiver(receiver);
}

private void startWifi() {
Context ctx = getApplicationContext();
WifiDirectService.start(ctx);
}

private void stopWifi() {
Context ctx = getApplicationContext();
WifiDirectService.stop(getApplicationContext());
}

public class Updater extends java.util.TimerTask {
public void run() {
runOnUiThread(new Runnable() {public void run() {
TextView tv = (TextView)findViewById(R.id.status);
tv.setText(status);
WifiDirectService.getStatus(getApplicationContext());
}});
}
}

public class MainBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
android.util.Log.d("WDPS", "MainActivity.onReceive() action=" + action);

switch (action) {
case WifiDirectService.ACTION_SEND_STATUS:
status = intent.getStringExtra("status");
if (!running) {
running = true;
Button button = (Button)findViewById(R.id.button);
button.setText("STOP");
}
break;
}
}
}
}
Loading

0 comments on commit aab9043

Please sign in to comment.