version:1.3

fix:
add:管理员所有应用开关
This commit is contained in:
2022-01-14 15:47:13 +08:00
parent d9b05e54cc
commit f0307e9027
14 changed files with 346 additions and 128 deletions

View File

@@ -0,0 +1,104 @@
package com.uiui.sn.service;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPortStatus;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
public class ControlPanelService extends Service {
private static final String TAG = ControlPanelService.class.getSimpleName();
public ControlPanelService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
registerUsbConnectionReceiver();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
}
private void registerUsbConnectionReceiver() {
if (mUsbConnectionReceiver == null) {
mUsbConnectionReceiver = new UsbConnectionReceiver();
}
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_STATE);
filter.addAction(UsbManager.ACTION_USB_PORT_CHANGED);
registerReceiver(mUsbConnectionReceiver, filter);
}
UsbConnectionReceiver mUsbConnectionReceiver;
private boolean mConnected;
private long mFunctions;
// private int mDataRole;
// private int mPowerRole;
public class UsbConnectionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "onReceive: " + intent.getAction());
Bundle bundle = intent.getExtras();
if (UsbManager.ACTION_USB_STATE.equals(intent.getAction())) {
mConnected = intent.getExtras().getBoolean(UsbManager.USB_CONNECTED)
|| intent.getExtras().getBoolean(UsbManager.USB_HOST_CONNECTED);
long functions = UsbManager.FUNCTION_NONE;
if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_MTP)
&& intent.getExtras().getBoolean(UsbManager.USB_DATA_UNLOCKED, false)) {
functions |= UsbManager.FUNCTION_MTP;
}
if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_PTP)
&& intent.getExtras().getBoolean(UsbManager.USB_DATA_UNLOCKED, false)) {
functions |= UsbManager.FUNCTION_PTP;
}
if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_MIDI)) {
functions |= UsbManager.FUNCTION_MIDI;
}
if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_RNDIS)) {
functions |= UsbManager.FUNCTION_RNDIS;
}
if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_ACCESSORY)) {
functions |= UsbManager.FUNCTION_ACCESSORY;
}
mFunctions = functions;
// mDataRole = mUsbBackend.getDataRole();
// mPowerRole = mUsbBackend.getPowerRole();
} else if (UsbManager.ACTION_USB_PORT_CHANGED.equals(intent.getAction())) {
UsbPortStatus portStatus = intent.getExtras()
.getParcelable(UsbManager.EXTRA_PORT_STATUS);
if (portStatus != null) {
// mDataRole = portStatus.getCurrentDataRole();
// mPowerRole = portStatus.getCurrentPowerRole();
}
}
// if (mUsbConnectionListener != null) {
// mUsbConnectionListener.onUsbConnectionChanged(mConnected, mFunctions, mPowerRole,
// mDataRole);
// }
}
}
}

View File

@@ -35,6 +35,7 @@ public class DownloadService extends Service {
startService(new Intent(this, GuardService.class));
startService(new Intent(this, MainService.class));
startService(new Intent(this, ManagerService.class));
startService(new Intent(this, ControlPanelService.class));
Aria.download(this).register();
//恢复所有未完成的下载任务
Aria.download(this).resumeAllTask();

View File

@@ -345,6 +345,7 @@ public class ManagerService extends Service implements NetworkUtils.OnNetworkSta
setFloatingWindow();
}
// String packages = ForegroundAppUtil.getForegroundPackageName(context);
// if (!packages.equals("com.estrongs.android.pop")) {
// ApkUtils.openApp(context, "com.estrongs.android.pop");