| .. | .. |
|---|
| 1 | +package com.jwipc.nodka_reboot_under; |
|---|
| 2 | + |
|---|
| 3 | +import android.app.ProgressDialog; |
|---|
| 4 | +import android.bluetooth.BluetoothAdapter; |
|---|
| 5 | +import android.content.BroadcastReceiver; |
|---|
| 6 | +import android.content.Context; |
|---|
| 7 | +import android.content.Intent; |
|---|
| 8 | +import android.content.SharedPreferences; |
|---|
| 9 | +import android.content.SharedPreferences.Editor; |
|---|
| 10 | +import android.net.EthernetManager; |
|---|
| 11 | +import android.net.wifi.WifiManager; |
|---|
| 12 | +import android.os.Handler; |
|---|
| 13 | +import android.os.Looper; |
|---|
| 14 | +import android.text.TextUtils; |
|---|
| 15 | +import android.util.Log; |
|---|
| 16 | +import android.view.WindowManager; |
|---|
| 17 | + |
|---|
| 18 | +import com.jwipc.nodka_reboot_under.utils.Utils; |
|---|
| 19 | + |
|---|
| 20 | +public class BroadcastReceiver_Sys extends BroadcastReceiver { |
|---|
| 21 | + public static final String TAG = "BroadcastReceiver_Sys"; |
|---|
| 22 | + private Utils mUtils = null; |
|---|
| 23 | + private SharedPreferences sharedPreferences; |
|---|
| 24 | + private Editor editor; |
|---|
| 25 | + |
|---|
| 26 | + private static int MAIN_RESOLUTION_COUNT = 1; |
|---|
| 27 | + |
|---|
| 28 | + @Override |
|---|
| 29 | + public void onReceive(Context context, Intent intent) { |
|---|
| 30 | + mUtils = new Utils(context); |
|---|
| 31 | + sharedPreferences = context.getSharedPreferences(mUtils.shapre, context.MODE_PRIVATE); |
|---|
| 32 | + editor = sharedPreferences.edit(); |
|---|
| 33 | + String action = intent.getAction(); |
|---|
| 34 | + if (action.equals("com.nodka.action.HDMI_RESOLUTION")) { |
|---|
| 35 | + /** |
|---|
| 36 | + * 设置主屏幕分辨率 |
|---|
| 37 | + * action com.nodka.action.HDMI_RESOLUTION |
|---|
| 38 | + * stringExtra params HDMI屏幕参数 |
|---|
| 39 | + * |
|---|
| 40 | + * 设置1080p60 |
|---|
| 41 | + * adb shell am broadcast -a com.nodka.action.HDMI_RESOLUTION --es params 1920x1080@60-1920-2008-2052-2200-1080-1084-1089-1125-5 |
|---|
| 42 | + * 设置720P60 |
|---|
| 43 | + * adb shell am broadcast -a com.nodka.action.HDMI_RESOLUTION --es params 1280x720@60.00-1390-1430-1650-725-730-750-5 |
|---|
| 44 | + * 设置480P60 |
|---|
| 45 | + * adb shell am broadcast -a com.nodka.action.HDMI_RESOLUTION --es params 720x480@59.94-736-798-858-489-495-525-a |
|---|
| 46 | + * |
|---|
| 47 | + * 设置4k60 |
|---|
| 48 | + * setprop persist.vendor.resolution.HDMI-A-0 3840x2160@60-3840-4016-4104-4400-2160-2168-2178-2250-5 |
|---|
| 49 | + * setprop vendor.display.timeline 1 |
|---|
| 50 | + * |
|---|
| 51 | + * 设置1080p60 |
|---|
| 52 | + * setprop persist.vendor.resolution.HDMI-A-0 1920x1080@60-1920-2008-2052-2200-1080-1084-1089-1125-5 |
|---|
| 53 | + * setprop vendor.display.timeline 2 |
|---|
| 54 | + * |
|---|
| 55 | + * 设置720P60 |
|---|
| 56 | + * setprop persist.vendor.resolution.HDMI-A-0 1280x720@60.00-1390-1430-1650-725-730-750-5 |
|---|
| 57 | + * setprop vendor.display.timeline 3 |
|---|
| 58 | + * |
|---|
| 59 | + * 设置480P60 |
|---|
| 60 | + * setprop persist.vendor.resolution.HDMI-A-0 720x480@59.94-736-798-858-489-495-525-a |
|---|
| 61 | + * setprop vendor.display.timeline 4 |
|---|
| 62 | + */ |
|---|
| 63 | + String params = intent.getStringExtra("params"); |
|---|
| 64 | + if (!TextUtils.isEmpty(params)) { |
|---|
| 65 | + String params1 = "setprop persist.vendor.resolution.HDMI-A-0 " + params; |
|---|
| 66 | + String params2 = "setprop vendor.display.timeline " + MAIN_RESOLUTION_COUNT++; |
|---|
| 67 | + String result1 = mUtils.getRootCmdSilent(params1); |
|---|
| 68 | + String result2 = mUtils.getRootCmdSilent(params2); |
|---|
| 69 | + Log.i(TAG, "onReceive: HDMI_RESOLUTION, params1 = " + params1 + |
|---|
| 70 | + ", params2 = " + params2 + ", result1 = " + result1 + ", result2 = " + result2); |
|---|
| 71 | + ProgressDialog progressDialog = new ProgressDialog(context); |
|---|
| 72 | + progressDialog.setCanceledOnTouchOutside(false); |
|---|
| 73 | + progressDialog.setCancelable(false); |
|---|
| 74 | + progressDialog.setMessage("设置HDMI分辨率"); |
|---|
| 75 | + progressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
|---|
| 76 | + progressDialog.show(); |
|---|
| 77 | + new Handler(Looper.getMainLooper()).postDelayed(() -> progressDialog.dismiss(), 1000); |
|---|
| 78 | + } |
|---|
| 79 | + } else if (action.equals("com.nodka.action.APP_ALIVE")) { |
|---|
| 80 | + /** |
|---|
| 81 | + * 设置保活应用(系统重启生效) |
|---|
| 82 | + * action com.nodka.action.APP_ALIVE |
|---|
| 83 | + * stringExtra componentName 应用包名/类名 |
|---|
| 84 | + * |
|---|
| 85 | + * adb shell am broadcast -a com.nodka.action.APP_ALIVE --es componentName com.nodka.screen/.MainActivity |
|---|
| 86 | + * |
|---|
| 87 | + * setprop persist.keep.alive.name |
|---|
| 88 | + */ |
|---|
| 89 | + String componentName = intent.getStringExtra("componentName"); |
|---|
| 90 | + String params; |
|---|
| 91 | + if (!TextUtils.isEmpty(componentName)) { |
|---|
| 92 | + params = "setprop persist.keep.alive.name " + componentName; |
|---|
| 93 | + } else { |
|---|
| 94 | + params = "setprop persist.keep.alive.name \"\""; |
|---|
| 95 | + } |
|---|
| 96 | + String result = mUtils.getRootCmdSilent(params); |
|---|
| 97 | + Log.i(TAG, "onReceive: APP_ALIVE, params = " + params + ", result = " + result); |
|---|
| 98 | + } else if (action.equals("com.nodka.action.SCREEN_CAP")) { |
|---|
| 99 | + /** |
|---|
| 100 | + * 屏幕截图 |
|---|
| 101 | + * action com.nodka.action.SCREEN_CAP |
|---|
| 102 | + * stringExtra path 截图保存路径以及图片名称 |
|---|
| 103 | + * |
|---|
| 104 | + * adb shell am broadcast -a com.nodka.action.SCREEN_CAP --es path sdcard/screenshot.png |
|---|
| 105 | + * |
|---|
| 106 | + * screencap -p /sdcard/screenshot.png |
|---|
| 107 | + */ |
|---|
| 108 | + String path = intent.getStringExtra("path"); |
|---|
| 109 | + if (!TextUtils.isEmpty(path)) { |
|---|
| 110 | + String params = "screencap -p " + path; |
|---|
| 111 | + new Handler(Looper.getMainLooper()).post(() -> { |
|---|
| 112 | + String result = mUtils.getRootCmdSilent(params); |
|---|
| 113 | + Log.i(TAG, "onReceive: SCREEN_CAP, params = " + params + ", result = " + result); |
|---|
| 114 | + }); |
|---|
| 115 | + |
|---|
| 116 | + } |
|---|
| 117 | + } else if (action.equals("com.nodka.action.PKG_INSTALL")) { |
|---|
| 118 | + /** |
|---|
| 119 | + * 静默安装 |
|---|
| 120 | + * action com.nodka.action.PKG_INSTALL |
|---|
| 121 | + * stringExtra path APK路径 |
|---|
| 122 | + * |
|---|
| 123 | + * adb shell am broadcast -a com.nodka.action.PKG_INSTALL --es path sdcard/DeviceID.apk |
|---|
| 124 | + * |
|---|
| 125 | + * pm install -r |
|---|
| 126 | + */ |
|---|
| 127 | + String path = intent.getStringExtra("path"); |
|---|
| 128 | + if (!TextUtils.isEmpty(path)) { |
|---|
| 129 | + String params = "pm install -r " + path; |
|---|
| 130 | + String result = mUtils.getRootCmdSilent(params); |
|---|
| 131 | + Log.i(TAG, "onReceive: PKG_INSTALL, params = " + params + ", result = " + result); |
|---|
| 132 | + } |
|---|
| 133 | + } else if (action.equals("com.nodka.action.PKG_UNINSTALL")) { |
|---|
| 134 | + /** |
|---|
| 135 | + * 静默卸载 |
|---|
| 136 | + * action com.nodka.action.PKG_UNINSTALL |
|---|
| 137 | + * stringExtra pkgName 应用包名 |
|---|
| 138 | + * |
|---|
| 139 | + * adb shell am broadcast -a com.nodka.action.PKG_UNINSTALL --es pkgName com.evozi.deviceid |
|---|
| 140 | + * |
|---|
| 141 | + * pm uninstall |
|---|
| 142 | + */ |
|---|
| 143 | + String pkgName = intent.getStringExtra("pkgName"); |
|---|
| 144 | + if (!TextUtils.isEmpty(pkgName)) { |
|---|
| 145 | + String params = "pm uninstall " + pkgName; |
|---|
| 146 | + String result = mUtils.getRootCmdSilent(params); |
|---|
| 147 | + Log.i(TAG, "onReceive: PKG_UNINSTALL, params = " + params + ", result = " + result); |
|---|
| 148 | + } |
|---|
| 149 | + } else if (action.equals("com.nodka.action.BLUETOOTH")) { |
|---|
| 150 | + /** |
|---|
| 151 | + * 打开关闭蓝牙 |
|---|
| 152 | + * action com.nodka.action.BLUETOOTH |
|---|
| 153 | + * intExtra power 0-关闭 1-开启 |
|---|
| 154 | + * |
|---|
| 155 | + * adb shell am broadcast -a com.nodka.action.BLUETOOTH --ei power 1 |
|---|
| 156 | + */ |
|---|
| 157 | + int power = intent.getIntExtra("power", -1); |
|---|
| 158 | + if (power != -1) { |
|---|
| 159 | + BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); |
|---|
| 160 | + if (power == 1) { |
|---|
| 161 | + if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) { |
|---|
| 162 | + bluetoothAdapter.enable(); // 开启蓝牙 |
|---|
| 163 | + } |
|---|
| 164 | + } else if (power == 0) { |
|---|
| 165 | + if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { |
|---|
| 166 | + bluetoothAdapter.disable(); // 关闭蓝牙 |
|---|
| 167 | + } |
|---|
| 168 | + } |
|---|
| 169 | + Log.i(TAG, "onReceive: BLUETOOTH, power = " + power); |
|---|
| 170 | + } |
|---|
| 171 | + } else if (action.equals("com.nodka.action.WIFI")) { |
|---|
| 172 | + /** |
|---|
| 173 | + * 打开关闭WIFI |
|---|
| 174 | + * action com.nodka.action.WIFI |
|---|
| 175 | + * intExtra power 0-关闭 1-开启 |
|---|
| 176 | + * |
|---|
| 177 | + * adb shell am broadcast -a com.nodka.action.WIFI --ei power 1 |
|---|
| 178 | + */ |
|---|
| 179 | + int power = intent.getIntExtra("power", -1); |
|---|
| 180 | + if (power != -1) { |
|---|
| 181 | + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); |
|---|
| 182 | + if (power == 1) { |
|---|
| 183 | + if (wifiManager != null && !wifiManager.isWifiEnabled()) { |
|---|
| 184 | + wifiManager.setWifiEnabled(true); // 开启 Wi-Fi |
|---|
| 185 | + } |
|---|
| 186 | + } else if (power == 0) { |
|---|
| 187 | + if (wifiManager != null && wifiManager.isWifiEnabled()) { |
|---|
| 188 | + wifiManager.setWifiEnabled(false); // 关闭 Wi-Fi |
|---|
| 189 | + } |
|---|
| 190 | + } |
|---|
| 191 | + Log.i(TAG, "onReceive: WIFI, power = " + power); |
|---|
| 192 | + } |
|---|
| 193 | + } else if (action.equals("com.nodka.action.ETHERNET")) { |
|---|
| 194 | + /** |
|---|
| 195 | + * 打开关闭ETHERNET |
|---|
| 196 | + * action com.nodka.action.ETHERNET |
|---|
| 197 | + * stringExtra ethX eth0 eth1 此参数不指定则控制所有 |
|---|
| 198 | + * intExtra power 0-关闭 1-开启 |
|---|
| 199 | + * |
|---|
| 200 | + * adb shell am broadcast -a com.nodka.action.ETHERNET --ei power 0 |
|---|
| 201 | + * adb shell am broadcast -a com.nodka.action.ETHERNET --es ethX eth0 --ei power 0 |
|---|
| 202 | + * adb shell am broadcast -a com.nodka.action.ETHERNET --es ethX eth1 --ei power 0 |
|---|
| 203 | + */ |
|---|
| 204 | + String ethX = intent.getStringExtra("ethX"); |
|---|
| 205 | + int power = intent.getIntExtra("power", -1); |
|---|
| 206 | + if (power != -1) { |
|---|
| 207 | + EthernetManager mEthManager = (EthernetManager) context.getSystemService("ethernet"); |
|---|
| 208 | + if (power == 1) { |
|---|
| 209 | + if (!TextUtils.isEmpty(ethX)) { |
|---|
| 210 | + mEthManager.setEthernetEnabled(ethX, true); |
|---|
| 211 | + } else { |
|---|
| 212 | + mEthManager.setEthernetEnabled("eth0", true); |
|---|
| 213 | + mEthManager.setEthernetEnabled("eth1", true); |
|---|
| 214 | + } |
|---|
| 215 | + } else if (power == 0) { |
|---|
| 216 | + if (!TextUtils.isEmpty(ethX)) { |
|---|
| 217 | + mEthManager.setEthernetEnabled(ethX, false); |
|---|
| 218 | + } else { |
|---|
| 219 | + mEthManager.setEthernetEnabled("eth0", false); |
|---|
| 220 | + mEthManager.setEthernetEnabled("eth1", false); |
|---|
| 221 | + } |
|---|
| 222 | + } |
|---|
| 223 | + Log.i(TAG, "onReceive: ETHERNET, ethX = " + ethX + ", power = " + power); |
|---|
| 224 | + } |
|---|
| 225 | + } else if (action.equals("com.nodka.action.POWER")) { |
|---|
| 226 | + /** |
|---|
| 227 | + * 系统重启/关机 |
|---|
| 228 | + * action com.nodka.action.POWER |
|---|
| 229 | + * intExtra powerType 1-重启 2-关机 |
|---|
| 230 | + * |
|---|
| 231 | + * adb shell am broadcast -a com.nodka.action.POWER --ei powerType 1 |
|---|
| 232 | + */ |
|---|
| 233 | + int powerType = intent.getIntExtra("powerType", -1); |
|---|
| 234 | + if (powerType != -1) { |
|---|
| 235 | + String params = ""; |
|---|
| 236 | + if (powerType == 1) { |
|---|
| 237 | + params = "reboot"; |
|---|
| 238 | + mUtils.getRootCmdSilent(params); |
|---|
| 239 | + } else if (powerType == 2) { |
|---|
| 240 | + params = "reboot -p"; |
|---|
| 241 | + mUtils.getRootCmdSilent(params); |
|---|
| 242 | + } |
|---|
| 243 | + Log.i(TAG, "onReceive: POWER, params = " + params); |
|---|
| 244 | + } |
|---|
| 245 | + } |
|---|
| 246 | + } |
|---|
| 247 | +} |
|---|