运维APP增加一些实现

serial
BlueMatthew 1 year ago
parent 73fecd3851
commit 4e223d8105

@ -4,7 +4,7 @@
package="com.xypower.mpmaster">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
@ -27,7 +27,7 @@
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.REBOOT"
tools:ignore="ProtectedPermissions" />
@ -61,6 +61,9 @@
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"
tools:ignore="ProtectedPermissions" /> <!-- WiFi AP startTethering -->
<uses-permission
android:name="android.permission.TETHER_PRIVILEGED"
tools:ignore="ProtectedPermissions" />
<application
@ -68,16 +71,21 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/Theme.MpMaster"
tools:targetApi="28">
<service
android:name=".MpMasterService"
android:name=".HotSpotService"
android:enabled="true"
android:process=":hotspot"
android:exported="true"></service>
<service
android:name=".MpMasterService"
android:enabled="true"
android:exported="true" />
<activity
android:name=".MainActivity"

@ -0,0 +1,16 @@
package com.xypower.mpmaster;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class HotSpotService extends Service {
public HotSpotService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}

@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
@ -64,6 +65,16 @@ public class MainActivity extends AppCompatActivity {
}
});
findViewById(R.id.btnTurnAppOn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// SysApi.enableApp(v.getContext(), "abcd1234");
}
});
startMicroPhotoService(getApplicationContext());
}

@ -66,13 +66,14 @@ public class MpMasterService extends Service {
// public static final int NOTIFICATION_ID_FOREGROUND_SERVICE = 0;
public static final String ACTION_MSG_BROADCAST = "ACT_MSG_BROADCAST";
public static final String ACTION_START = "ACT_START";
public static final String ACTION_STOP = "ACT_STOP";
public static final String ACTION_MAIN = "ACT_MAIN";
private static final String ACTION_HEARTBEAT = "ACT_HB";
private static final String ACTION_TAKE_PHOTO = "ACT_TP";
private static final String ACTION_TAKE_PHOTO_MANUALLY = "ACT_TP_M";
private static final String ACTION_TIMEOUT = "ACT_TIMEOUT";
public static final String ACTION_START = "com.xypower.mpmaster.ACT_START";
public static final String ACTION_STOP = "com.xypower.mpmaster.ACT_STOP";
public static final String ACTION_MAIN = "com.xypower.mpmaster.ACT_MAIN";
private static final String ACTION_HEARTBEAT = "com.xypower.mpmaster.ACT_HB";
private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
//private static final String ACTION_TAKE_PHOTO_MANUALLY = "ACT_TP_M";
//private static final String ACTION_TIMEOUT = "ACT_TIMEOUT";
private static final String EXTRA_PARAM_CHANNEL = "Channel";
private static final String EXTRA_PARAM_PRESET = "Preset";
private static final String EXTRA_PARAM_PHOTO_OR_VIDEO = "PhotoOrVideo";
@ -148,9 +149,9 @@ public class MpMasterService extends Service {
{
mAlarmReceiver = new AlarmReceiver(this);
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
intentFilter.addAction(ACTION_TAKE_PHOTO);
intentFilter.addAction(ACTION_TIMEOUT);
intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
// intentFilter.addAction(ACTION_TAKE_PHOTO);
// intentFilter.addAction(ACTION_TIMEOUT);
// intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
intentFilter.addAction(ACTION_MSG_BROADCAST);
registerReceiver(mAlarmReceiver, intentFilter);
}
@ -225,16 +226,6 @@ public class MpMasterService extends Service {
}
}
public static void sendMessage(Context context, int what, int data) {
Intent intent = new Intent(ACTION_MSG_BROADCAST);
intent.putExtra("what", what);
intent.putExtra("data", data);
intent.setPackage(context.getPackageName());
// String typeName = AlarmReceiver.class.getTypeName();
// intent.setComponent( new ComponentName(context.getPackageName(), AlarmReceiver.class.getTypeName()) );
// context.sendBroadcast(intent);
}
private void startMaster() {
String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL;
@ -326,54 +317,7 @@ public class MpMasterService extends Service {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
}
private void registerPhotoTimer(int channel, int preset, long ts, long timeout, List<Long> schedules) {
registerPhotoTimer(this.getApplicationContext(), channel, preset, ts, timeout, schedules);
}
// private HashMap<Long, Integer> mTimers = new HashMap<Long, Integer>();
public boolean registerTimer(long uid, int timeout, long times) {
// 创建延迟意图
Intent alarmIntent = new Intent();
alarmIntent.setAction(ACTION_TIMEOUT);
alarmIntent.putExtra(EXTRA_PARAM_TIMER_UID, uid);
alarmIntent.putExtra(EXTRA_PARAM_TIMEOUT, timeout);
alarmIntent.putExtra(EXTRA_PARAM_TIMES, times);
alarmIntent.putExtra(EXTRA_PARAM_ELASPED_TIMES, 0L);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mTimers.put(Long.valueOf(uid), pendingIntent);
return registerTimer(pendingIntent, uid, timeout);
}
public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + timeout, pendingIntent);
Log.i(TAG, "RegTimer:" + uid + " timeout=" + timeout);
return true;
}
public boolean unregisterTimer(long uid) {
Long uidObj = Long.valueOf(uid);
PendingIntent pendingIntent = mTimers.get(uidObj);
if (pendingIntent != null) {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
mTimers.remove(uidObj);
Log.i(TAG, "UnregTimer:" + uid);
}
return true;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

@ -51,9 +51,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="OTG Off"
app:layout_constraintStart_toEndOf="@+id/btnTurnOtgOn"
app:layout_constraintTop_toTopOf="@+id/btnTurnOtgOn" />
<Button
android:id="@+id/btnTurnAppOn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="APP On"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnTurnOtgOn" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save