Commit 10384643 by LAPTOP-146U5DF5\28422

no message

parent 5545c985
......@@ -166,13 +166,15 @@ public class DoCommandService extends Service {
isUploadAdsData = true;
}
public void uploadErrorApkData() {
public void uploadErrorApkData(String type) {
Log.d(TAG, "start upload empty ads data...");
ExecutorService es = Executors.newSingleThreadExecutor();
JSONObject jo = new JSONObject();
try {
jo.put("app_id", mCurPkgName);
jo.put("apk_error", 1);
// jo.put("app_id", mCurPkgName);
jo.put("apk_error", "包名:"+mCurPkgName+" 客户端:"+MainActivity.m_Android_ID+" error_type:"+type);
// jo.put("user", );
// jo.put("error_type",type);
} catch (JSONException e) {
e.printStackTrace();
}
......
......@@ -39,7 +39,7 @@ public class LocalService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("myTest", "onStartCommand: 本地服务启动");
// Log.d("myTest", "onStartCommand: 本地服务启动");
startService(new Intent(LocalService.this,RemoteService.class));
bindService(new Intent(this,RemoteService.class),connection, Context.BIND_IMPORTANT);
return START_STICKY;
......
......@@ -12,16 +12,31 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.lang.ref.WeakReference;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static com.fear1ess.reyunaditool.ExecuteCmdUtils.executeCmd;
public class MainActivity extends AppCompatActivity {
public static String m_Android_ID="";
public static Button m_startBtn=null;
public static Button m_stopBtn=null;
public static String m_myPackageName="";
public static Context m_context=null;
//保持屏幕常量的表示
public static boolean m_isShow=false;
//
// public static Handler m_handler=new MainActivityHandler();
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
......@@ -36,9 +51,18 @@ public class MainActivity extends AppCompatActivity {
AdiToolApp app = (AdiToolApp) getApplication();
Button startBtn = findViewById(R.id.start_btn);
m_startBtn=startBtn;
Button stopBtn = findViewById(R.id.stop_btn);
m_stopBtn=stopBtn;
stopBtn.setEnabled(false);
TextView textView=findViewById(R.id.user_ID);
m_Android_ID= Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);
String user="当前APP的Android ID: "+m_Android_ID;
textView.setText(user);
m_myPackageName=getPackageName();
m_context=getApplicationContext();
requestPermissions(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.READ_EXTERNAL_STORAGE"},100);
......@@ -70,6 +94,7 @@ public class MainActivity extends AppCompatActivity {
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
......@@ -81,17 +106,43 @@ public class MainActivity extends AppCompatActivity {
});
}
}.start();
m_isShow=false;
new Thread(new Runnable() {
@Override
public void run() {
while (true){
try {
// Log.d("myTest","保持屏幕常量状态中");
Thread.sleep(60*1000);
executeCmd("ls");
} catch (InterruptedException e) {
e.printStackTrace();
}
if(m_isShow){
break;
}
}
}
}).start();
}
public static class MainActivityHandler extends Handler{
public static final int NETWORK_ERROR = 0;
public static final int StartMySlef = 11;
private WeakReference<Activity> mActivityWeakRef = null;
public MainActivityHandler(Activity activity){
mActivityWeakRef = new WeakReference<>(activity);
}
// public MainActivityHandler() {
//
// }
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what){
......@@ -100,9 +151,39 @@ public class MainActivity extends AppCompatActivity {
Toast t = Toast.makeText(mActivityWeakRef.get(),errText,Toast.LENGTH_SHORT);
t.show();
break;
case StartMySlef:
startMySelf();
break;
default:
break;
}
}
}
@Override
protected void onStop() {
super.onStop();
try{
if(m_isShow){
startMySelf();
}
// Toast.makeText(MainActivity.m_context,"开始卸载APP",Toast.LENGTH_LONG).show();
}catch (Exception e){
}
}
public static void startMySelf(){
try{
int result= ExecuteCmdUtils.startApp(MainActivity.m_context, MainActivity.m_myPackageName);
if(result ==-1){
MyLog.error("启动Activity结果失败");
}else {
MyLog.error("启动Activity结果成功");
}
}catch (Exception e){
MyLog.error(e.toString());
}
}
}
\ No newline at end of file
package com.fear1ess.reyunaditool;
import android.util.Log;
public class MyLog {
private static final String TAG = "MyTest";
public static boolean is_Open=false;
public static void d(Object object){
if(is_Open){
synchronized (object){
Log.d(TAG, ""+object);
}
}
}
public static void error(Object object){
synchronized (object){
Log.d(TAG, "异常:"+object);
}
}
}
......@@ -6,6 +6,7 @@ import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
......@@ -13,6 +14,7 @@ import com.fear1ess.reyunaditool.AdiToolApp;
import com.fear1ess.reyunaditool.AppInfo;
import com.fear1ess.reyunaditool.DoCommandService;
import com.fear1ess.reyunaditool.ExecuteCmdUtils;
import com.fear1ess.reyunaditool.MainActivity;
import com.fear1ess.reyunaditool.NetWorkUtils;
import com.fear1ess.reyunaditool.cmd.OperateCmd;
import com.fear1ess.reyunaditool.state.AppState;
......@@ -26,6 +28,9 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
//import static com.fear1ess.reyunaditool.MainActivity.m_handler;
import static com.fear1ess.reyunaditool.MainActivity.startMySelf;
public class InstallAndStartAppThread extends Thread {
public static String TAG = "reyunaditool_log";
......@@ -71,19 +76,24 @@ public class InstallAndStartAppThread extends Thread {
@Override
public void run() {
while(needRunning){
try {
startMySelf();
mService.isUploadAdsData = false;
installAndStartNewApp();
sleep(60*1000);
if(mService.isUploadAdsData == false){
mService.uploadErrorApkData();
mService.uploadErrorApkData("上传广告数据失败");
}
removeApp();
} catch (InterruptedException e) {
e.printStackTrace();
}
mNeedWait = true;
startMySelf();
}
/*
......@@ -115,6 +125,10 @@ public class InstallAndStartAppThread extends Thread {
AppInfo appInfo = null;
try {
while(true){
//启动APP本身
// Message message=new Message();
// message.what=1;
// m_handler.sendMessage(message);
Thread.sleep(2000);
appInfo = mDownloadThread.mAppInfoQueue.take();
......@@ -133,7 +147,7 @@ public class InstallAndStartAppThread extends Thread {
if(res == 0){
Log.d(TAG, "install app " + mPkgName + "success!");
} else {
mService.uploadErrorApkData();
mService.uploadErrorApkData("install failed");
Log.e(TAG, "install app " + mPkgName + " failed!");
if(ExecuteCmdUtils.deletePkg(mDownloadPath) != 0){
Log.e(TAG, "delete pkg " + mDownloadPath + " failed!");
......@@ -159,7 +173,7 @@ public class InstallAndStartAppThread extends Thread {
if(ExecuteCmdUtils.startApp(appContext,mPkgName) != 0){
Log.e(TAG, "start app " + mPkgName + " failed!");
mService.uploadErrorApkData();
mService.uploadErrorApkData("启动APP失败");
msg = PushMsgUtils.createPushMsg(mPkgName, null, null,
AppState.APP_INSTALL_FAILED);
mService.sendMsgToClient(msg);
......@@ -171,6 +185,8 @@ public class InstallAndStartAppThread extends Thread {
}
continue;
}
//启动APP成功
MainActivity.m_isShow=true;
//send checking msg
msg = PushMsgUtils.createPushMsg(mPkgName, null, null,
......
......@@ -21,5 +21,10 @@
android:text="Stop"
android:id="@+id/stop_btn">
</Button>
<TextView
android:id="@+id/user_ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment