package com.jwipc.nodka_reboot_under;
|
|
import android.app.ProgressDialog;
|
import android.bluetooth.BluetoothAdapter;
|
import android.content.BroadcastReceiver;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.content.SharedPreferences.Editor;
|
import android.net.EthernetManager;
|
import android.net.wifi.WifiManager;
|
import android.os.Handler;
|
import android.os.Looper;
|
import android.text.TextUtils;
|
import android.util.Log;
|
import android.view.WindowManager;
|
|
import com.jwipc.nodka_reboot_under.utils.Utils;
|
|
public class BroadcastReceiver_Sys extends BroadcastReceiver {
|
public static final String TAG = "BroadcastReceiver_Sys";
|
private Utils mUtils = null;
|
private SharedPreferences sharedPreferences;
|
private Editor editor;
|
|
private static int MAIN_RESOLUTION_COUNT = 1;
|
|
@Override
|
public void onReceive(Context context, Intent intent) {
|
mUtils = new Utils(context);
|
sharedPreferences = context.getSharedPreferences(mUtils.shapre, context.MODE_PRIVATE);
|
editor = sharedPreferences.edit();
|
String action = intent.getAction();
|
if (action.equals("com.nodka.action.HDMI_RESOLUTION")) {
|
/**
|
* 设置主屏幕分辨率
|
* action com.nodka.action.HDMI_RESOLUTION
|
* stringExtra params HDMI屏幕参数
|
*
|
* 设置1080p60
|
* adb shell am broadcast -a com.nodka.action.HDMI_RESOLUTION --es params 1920x1080@60-1920-2008-2052-2200-1080-1084-1089-1125-5
|
* 设置720P60
|
* adb shell am broadcast -a com.nodka.action.HDMI_RESOLUTION --es params 1280x720@60.00-1390-1430-1650-725-730-750-5
|
* 设置480P60
|
* adb shell am broadcast -a com.nodka.action.HDMI_RESOLUTION --es params 720x480@59.94-736-798-858-489-495-525-a
|
*
|
* 设置4k60
|
* setprop persist.vendor.resolution.HDMI-A-0 3840x2160@60-3840-4016-4104-4400-2160-2168-2178-2250-5
|
* setprop vendor.display.timeline 1
|
*
|
* 设置1080p60
|
* setprop persist.vendor.resolution.HDMI-A-0 1920x1080@60-1920-2008-2052-2200-1080-1084-1089-1125-5
|
* setprop vendor.display.timeline 2
|
*
|
* 设置720P60
|
* setprop persist.vendor.resolution.HDMI-A-0 1280x720@60.00-1390-1430-1650-725-730-750-5
|
* setprop vendor.display.timeline 3
|
*
|
* 设置480P60
|
* setprop persist.vendor.resolution.HDMI-A-0 720x480@59.94-736-798-858-489-495-525-a
|
* setprop vendor.display.timeline 4
|
*/
|
String params = intent.getStringExtra("params");
|
if (!TextUtils.isEmpty(params)) {
|
String params1 = "setprop persist.vendor.resolution.HDMI-A-0 " + params;
|
String params2 = "setprop vendor.display.timeline " + MAIN_RESOLUTION_COUNT++;
|
String result1 = mUtils.getRootCmdSilent(params1);
|
String result2 = mUtils.getRootCmdSilent(params2);
|
Log.i(TAG, "onReceive: HDMI_RESOLUTION, params1 = " + params1 +
|
", params2 = " + params2 + ", result1 = " + result1 + ", result2 = " + result2);
|
ProgressDialog progressDialog = new ProgressDialog(context);
|
progressDialog.setCanceledOnTouchOutside(false);
|
progressDialog.setCancelable(false);
|
progressDialog.setMessage("设置HDMI分辨率");
|
progressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
progressDialog.show();
|
new Handler(Looper.getMainLooper()).postDelayed(() -> progressDialog.dismiss(), 1000);
|
}
|
} else if (action.equals("com.nodka.action.APP_ALIVE")) {
|
/**
|
* 设置保活应用(系统重启生效)
|
* action com.nodka.action.APP_ALIVE
|
* stringExtra componentName 应用包名/类名
|
*
|
* adb shell am broadcast -a com.nodka.action.APP_ALIVE --es componentName com.nodka.screen/.MainActivity
|
*
|
* setprop persist.keep.alive.name
|
*/
|
String componentName = intent.getStringExtra("componentName");
|
String params;
|
if (!TextUtils.isEmpty(componentName)) {
|
params = "setprop persist.keep.alive.name " + componentName;
|
} else {
|
params = "setprop persist.keep.alive.name \"\"";
|
}
|
String result = mUtils.getRootCmdSilent(params);
|
Log.i(TAG, "onReceive: APP_ALIVE, params = " + params + ", result = " + result);
|
} else if (action.equals("com.nodka.action.SCREEN_CAP")) {
|
/**
|
* 屏幕截图
|
* action com.nodka.action.SCREEN_CAP
|
* stringExtra path 截图保存路径以及图片名称
|
*
|
* adb shell am broadcast -a com.nodka.action.SCREEN_CAP --es path sdcard/screenshot.png
|
*
|
* screencap -p /sdcard/screenshot.png
|
*/
|
String path = intent.getStringExtra("path");
|
if (!TextUtils.isEmpty(path)) {
|
String params = "screencap -p " + path;
|
new Handler(Looper.getMainLooper()).post(() -> {
|
String result = mUtils.getRootCmdSilent(params);
|
Log.i(TAG, "onReceive: SCREEN_CAP, params = " + params + ", result = " + result);
|
});
|
|
}
|
} else if (action.equals("com.nodka.action.PKG_INSTALL")) {
|
/**
|
* 静默安装
|
* action com.nodka.action.PKG_INSTALL
|
* stringExtra path APK路径
|
*
|
* adb shell am broadcast -a com.nodka.action.PKG_INSTALL --es path sdcard/DeviceID.apk
|
*
|
* pm install -r
|
*/
|
String path = intent.getStringExtra("path");
|
if (!TextUtils.isEmpty(path)) {
|
String params = "pm install -r " + path;
|
String result = mUtils.getRootCmdSilent(params);
|
Log.i(TAG, "onReceive: PKG_INSTALL, params = " + params + ", result = " + result);
|
}
|
} else if (action.equals("com.nodka.action.PKG_UNINSTALL")) {
|
/**
|
* 静默卸载
|
* action com.nodka.action.PKG_UNINSTALL
|
* stringExtra pkgName 应用包名
|
*
|
* adb shell am broadcast -a com.nodka.action.PKG_UNINSTALL --es pkgName com.evozi.deviceid
|
*
|
* pm uninstall
|
*/
|
String pkgName = intent.getStringExtra("pkgName");
|
if (!TextUtils.isEmpty(pkgName)) {
|
String params = "pm uninstall " + pkgName;
|
String result = mUtils.getRootCmdSilent(params);
|
Log.i(TAG, "onReceive: PKG_UNINSTALL, params = " + params + ", result = " + result);
|
}
|
} else if (action.equals("com.nodka.action.BLUETOOTH")) {
|
/**
|
* 打开关闭蓝牙
|
* action com.nodka.action.BLUETOOTH
|
* intExtra power 0-关闭 1-开启
|
*
|
* adb shell am broadcast -a com.nodka.action.BLUETOOTH --ei power 1
|
*/
|
int power = intent.getIntExtra("power", -1);
|
if (power != -1) {
|
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
if (power == 1) {
|
if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) {
|
bluetoothAdapter.enable(); // 开启蓝牙
|
}
|
} else if (power == 0) {
|
if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
|
bluetoothAdapter.disable(); // 关闭蓝牙
|
}
|
}
|
Log.i(TAG, "onReceive: BLUETOOTH, power = " + power);
|
}
|
} else if (action.equals("com.nodka.action.WIFI")) {
|
/**
|
* 打开关闭WIFI
|
* action com.nodka.action.WIFI
|
* intExtra power 0-关闭 1-开启
|
*
|
* adb shell am broadcast -a com.nodka.action.WIFI --ei power 1
|
*/
|
int power = intent.getIntExtra("power", -1);
|
if (power != -1) {
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
if (power == 1) {
|
if (wifiManager != null && !wifiManager.isWifiEnabled()) {
|
wifiManager.setWifiEnabled(true); // 开启 Wi-Fi
|
}
|
} else if (power == 0) {
|
if (wifiManager != null && wifiManager.isWifiEnabled()) {
|
wifiManager.setWifiEnabled(false); // 关闭 Wi-Fi
|
}
|
}
|
Log.i(TAG, "onReceive: WIFI, power = " + power);
|
}
|
} else if (action.equals("com.nodka.action.ETHERNET")) {
|
/**
|
* 打开关闭ETHERNET
|
* action com.nodka.action.ETHERNET
|
* stringExtra ethX eth0 eth1 此参数不指定则控制所有
|
* intExtra power 0-关闭 1-开启
|
*
|
* adb shell am broadcast -a com.nodka.action.ETHERNET --ei power 0
|
* adb shell am broadcast -a com.nodka.action.ETHERNET --es ethX eth0 --ei power 0
|
* adb shell am broadcast -a com.nodka.action.ETHERNET --es ethX eth1 --ei power 0
|
*/
|
String ethX = intent.getStringExtra("ethX");
|
int power = intent.getIntExtra("power", -1);
|
if (power != -1) {
|
EthernetManager mEthManager = (EthernetManager) context.getSystemService("ethernet");
|
if (power == 1) {
|
if (!TextUtils.isEmpty(ethX)) {
|
mEthManager.setEthernetEnabled(ethX, true);
|
} else {
|
mEthManager.setEthernetEnabled("eth0", true);
|
mEthManager.setEthernetEnabled("eth1", true);
|
}
|
} else if (power == 0) {
|
if (!TextUtils.isEmpty(ethX)) {
|
mEthManager.setEthernetEnabled(ethX, false);
|
} else {
|
mEthManager.setEthernetEnabled("eth0", false);
|
mEthManager.setEthernetEnabled("eth1", false);
|
}
|
}
|
Log.i(TAG, "onReceive: ETHERNET, ethX = " + ethX + ", power = " + power);
|
}
|
} else if (action.equals("com.nodka.action.POWER")) {
|
/**
|
* 系统重启/关机
|
* action com.nodka.action.POWER
|
* intExtra powerType 1-重启 2-关机
|
*
|
* adb shell am broadcast -a com.nodka.action.POWER --ei powerType 1
|
*/
|
int powerType = intent.getIntExtra("powerType", -1);
|
if (powerType != -1) {
|
String params = "";
|
if (powerType == 1) {
|
params = "reboot";
|
mUtils.getRootCmdSilent(params);
|
} else if (powerType == 2) {
|
params = "reboot -p";
|
mUtils.getRootCmdSilent(params);
|
}
|
Log.i(TAG, "onReceive: POWER, params = " + params);
|
}
|
}
|
}
|
}
|