|
|
|
@ -50,7 +50,6 @@ import androidx.core.app.NotificationCompat;
|
|
|
|
|
import androidx.core.content.FileProvider;
|
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
|
|
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
|
import android.telephony.SignalStrength;
|
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
@ -60,7 +59,6 @@ import android.util.Log;
|
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.dev.api.XyDev;
|
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
|
import com.xypower.common.FileDownloader;
|
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
@ -76,12 +74,10 @@ import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.RandomAccessFile;
|
|
|
|
|
import java.io.Reader;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.net.Inet4Address;
|
|
|
|
|
import java.net.InetAddress;
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
import java.nio.channels.FileLock;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
@ -452,6 +448,27 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
mService = service;
|
|
|
|
|
}
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
try {
|
|
|
|
|
ProcessReceivedAction(context, intent);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void restartSelf(Context context, String reason) {
|
|
|
|
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
|
|
|
int noDelay = 1;
|
|
|
|
|
intent.putExtra("noDelay", noDelay);
|
|
|
|
|
if (!TextUtils.isEmpty(reason)) {
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessReceivedAction(Context context, Intent intent) {
|
|
|
|
|
String action = intent.getAction();
|
|
|
|
|
if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
|
|
|
|
|
long ts = System.currentTimeMillis();
|
|
|
|
@ -526,19 +543,11 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Take Photo CH=" + channel + " PR=" + preset + " Mannually");
|
|
|
|
|
mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, 0, photoOrVideo);
|
|
|
|
|
} else if (TextUtils.equals(ACTION_MSG_BROADCAST, action)) {
|
|
|
|
|
|
|
|
|
|
int what = intent.getIntExtra("what", 0);
|
|
|
|
|
int data = intent.getIntExtra("data", 0);
|
|
|
|
|
|
|
|
|
|
if (what == MSG_WHAT_SENDING_HB) {
|
|
|
|
|
mService.sendHeartbeat(mService.mNativeHandle, mService.getSignalLevel());
|
|
|
|
|
}
|
|
|
|
|
} else if (TextUtils.equals(ACTION_UPDATE_CONFIGS, action)) {
|
|
|
|
|
int restart = intent.getIntExtra("restart", 0);
|
|
|
|
|
Log.i(TAG, "UPD CFG Fired ACTION=" + action + " restart=" + restart);
|
|
|
|
|
if (restart != 0) {
|
|
|
|
|
MicroPhotoService.restartApp(context, context.getPackageName(), "Config Updated");
|
|
|
|
|
restartSelf(context, "Cfg Updated");
|
|
|
|
|
} else if (mService.mNativeHandle != 0) {
|
|
|
|
|
mService.reloadConfigs(mService.mNativeHandle);
|
|
|
|
|
}
|
|
|
|
@ -652,7 +661,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
Log.i(TAG, "After disable GPS");
|
|
|
|
|
mService.mPreviousGpsTimer = null;
|
|
|
|
|
} else if (TextUtils.equals(ACTION_RESTART, action)) {
|
|
|
|
|
|
|
|
|
|
String reason = intent.getStringExtra("reason");
|
|
|
|
|
MicroPhotoService.infoLog("Recv RESTART APP cmd, reason=" + (TextUtils.isEmpty(reason) ? "" : reason));
|
|
|
|
|
try {
|
|
|
|
@ -660,7 +668,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
MicroPhotoService.restartApp(context.getApplicationContext(), MicroPhotoContext.PACKAGE_NAME_MPAPP, "Restart Cmd");
|
|
|
|
|
restartSelf(context, reason);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1483,7 +1491,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
public void run() {
|
|
|
|
|
if (rebootType == 0) {
|
|
|
|
|
Context context = MicroPhotoService.this.getApplicationContext();
|
|
|
|
|
restartApp(context, context.getPackageName(), reason);
|
|
|
|
|
restartSelf(context, reason);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Log.w(TAG, "Recv REBOOT command");
|
|
|
|
@ -1494,52 +1502,15 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
mHander.postDelayed(runnable, timeout > 0 ? timeout : 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void restartApp(Context context, String packageName, String reason) {
|
|
|
|
|
public static void restartSelf(Context context, String reason) {
|
|
|
|
|
|
|
|
|
|
// "com.xypower.mpmaster.ACT_REQ_RST_APP"
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setAction("com.xypower.mpmaster.ACT_REQ_RST_APP");
|
|
|
|
|
intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPMASTER);
|
|
|
|
|
intent.setAction(ACTION_RESTART);
|
|
|
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
|
intent.putExtra("noDelay", 1);
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
intent.putExtra("packageName", context.getPackageName());
|
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (TextUtils.equals(packageName, MicroPhotoContext.PACKAGE_NAME_MPAPP)) {
|
|
|
|
|
MicroPhotoContext.restartMpApp(context, reason, 0);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
} else {
|
|
|
|
|
MicroPhotoContext.restartApp(context, packageName, reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Intent intent = new Intent(context, MainActivity.class);
|
|
|
|
|
int noDelay = 1;
|
|
|
|
|
intent.putExtra("noDelay", noDelay);
|
|
|
|
|
if (!TextUtils.isEmpty(reason)) {
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
|
|
|
int noDelay = 1;
|
|
|
|
|
intent.putExtra("noDelay", noDelay);
|
|
|
|
|
PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
|
|
|
|
AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
mgr.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, restartIntent);
|
|
|
|
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void enableGps(boolean enabled) {
|
|
|
|
|