From 44d2f001d7a6131d1d2f56e8c2c54c6a39ff5c7c Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Wed, 26 Oct 2022 15:31:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A3=80=E6=9F=A5=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=85=B7=E6=9C=89root=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../niushuai/project/devcontrol/base/App.java | 17 +++++++++-------- .../devcontrol/base/ui/BaseActivity.java | 4 ++-- .../util/{GlobalVariables.java => Global.java} | 5 ++++- .../ui/nav/device/NavDeviceFragment.java | 8 ++++---- .../ui/powerswitch/PowerSwitchActivity.java | 4 ++-- .../ui/powerswitch/PowerSwitchSetActivity.java | 4 ++-- .../PowerSwitchSetParamActivity.java | 4 ++-- .../project/devcontrol/vo/DeviceInfo.java | 4 ++-- 8 files changed, 27 insertions(+), 23 deletions(-) rename app/src/main/java/cc/niushuai/project/devcontrol/base/util/{GlobalVariables.java => Global.java} (96%) diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java index 07f53cd..baab38c 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/App.java @@ -8,20 +8,17 @@ import android.os.Build; import android.os.Environment; import android.provider.Settings; -import androidx.core.app.ActivityCompat; - import java.io.File; import java.util.ArrayList; -import java.util.Date; import java.util.List; import cc.niushuai.project.devcontrol.BuildConfig; -import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Global; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.db.DB; -import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.text.StrPool; +import cn.hutool.core.util.RuntimeUtil; import cn.hutool.core.util.StrUtil; public class App { @@ -35,7 +32,7 @@ public class App { // 初始化数据库 initDb(activity); // 重建设备信息缓存 - GlobalVariables.initDeviceInfoMap(); + Global.initDeviceInfoMap(); // 初始化日志相关内容 initLog(activity); } @@ -49,7 +46,11 @@ public class App { */ private static void checkRoot(Activity activity) { - + String which_su = RuntimeUtil.execForStr("which su"); + if (StrUtil.isNotEmpty(which_su)) { + Global.HAS_ROOT = true; + } + System.out.println("当前设备具有root权限"); } /** @@ -120,7 +121,7 @@ public class App { } // 内存存储日志根目录 - GlobalVariables.LOG_ROOT_PATH = rootPath; + Global.LOG_ROOT_PATH = rootPath; } private static String getRootPath() { diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java index b62a9c6..5b8dd3c 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java @@ -10,7 +10,7 @@ import java.util.Map; import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.util.ActivityUtil; -import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Global; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.base.util.UiUtil; import cc.niushuai.project.devcontrol.ui.common.IconSelectDialogFragment; @@ -180,6 +180,6 @@ public abstract class BaseActivity extends AppCompatActivity { * @date: 2022/10/24 17:09 */ public void rebuildDeviceInfoMapCache() { - GlobalVariables.initDeviceInfoMap(); + Global.initDeviceInfoMap(); } } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Global.java similarity index 96% rename from app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java rename to app/src/main/java/cc/niushuai/project/devcontrol/base/util/Global.java index a5d85f7..806be3f 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Global.java @@ -12,13 +12,16 @@ import cc.niushuai.project.devcontrol.vo.DeviceInfo; import cn.hutool.core.text.StrPool; import cn.hutool.core.util.StrUtil; -public class GlobalVariables { +public class Global { /** * 全部设备列表map * id为key elem为value */ public static final Map DEVICE_INFO_MAP = new HashMap<>(16); + + public static boolean HAS_ROOT = false; + public static String LOG_ROOT_PATH = StrUtil.join(StrPool.SLASH, Keys.LOG_ROOT_FILE_PATH, BuildConfig.APPLICATION_ID, Keys.LOG_LOG_FOLDER); /** diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java index fa0bf14..2879a8a 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.stream.Collectors; import cc.niushuai.project.devcontrol.R; -import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Global; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding; import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding; @@ -74,7 +74,7 @@ public class NavDeviceFragment extends Fragment { private void setDevices() { - deviceInfoList = GlobalVariables.DEVICE_INFO_MAP.values() + deviceInfoList = Global.DEVICE_INFO_MAP.values() .stream() .sorted((before, after) -> { if (null == before.getOrder() || null == after.getOrder()) { @@ -142,7 +142,7 @@ public class NavDeviceFragment extends Fragment { private void onItemClick(AdapterView parent, View view, int position, long id) { TextView textId = view.findViewById(R.id.device_item_cardView_id); - Intent intent = new Intent(getActivity(), GlobalVariables.getDeviceOperateActivity(textId.getText().toString())); + Intent intent = new Intent(getActivity(), Global.getDeviceOperateActivity(textId.getText().toString())); intent.putExtra(Keys.ID, textId.getText()); startActivity(intent); } @@ -165,7 +165,7 @@ public class NavDeviceFragment extends Fragment { public void onResume() { super.onResume(); // 重新初始化值 - GlobalVariables.initDeviceInfoMap(); + Global.initDeviceInfoMap(); this.setDevices(); } } \ No newline at end of file diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java index e208fea..afebe7b 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java @@ -11,7 +11,7 @@ import java.util.HashMap; import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.ui.BaseActivity; -import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Global; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding; @@ -41,7 +41,7 @@ public class PowerSwitchActivity extends BaseActivity { @Override protected void init() { - this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId()); + this.device = Global.getDeviceInfo(getIntentDeviceId()); // 标题名称 super.setTitle(this.device.getDeviceName(), this.device.getRemark()); // 开关底部的名称 diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java index da34af1..8805b14 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java @@ -8,7 +8,7 @@ import java.util.HashMap; import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.ui.BaseActivity; import cc.niushuai.project.devcontrol.base.util.ActivityUtil; -import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Global; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.base.util.ToastUtil; import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetBinding; @@ -30,7 +30,7 @@ public class PowerSwitchSetActivity extends BaseActivity { @Override protected void init() { - this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId()); + this.device = Global.getDeviceInfo(getIntentDeviceId()); super.setTitle(getString(R.string.set), null); } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetParamActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetParamActivity.java index d68799c..94d3863 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetParamActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetParamActivity.java @@ -8,7 +8,7 @@ import androidx.annotation.Nullable; import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.ui.BaseActivity; import cc.niushuai.project.devcontrol.base.util.CommonUiUtil; -import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Global; import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetParamBinding; import cc.niushuai.project.devcontrol.db.DB; import cc.niushuai.project.devcontrol.vo.DeviceInfo; @@ -30,7 +30,7 @@ public class PowerSwitchSetParamActivity extends BaseActivity { @Override protected void init() { - device = GlobalVariables.getDeviceInfo(getIntentDeviceId()); + device = Global.getDeviceInfo(getIntentDeviceId()); this.setTitle(null, getString(R.string.power_switch_set_paramSet), null, R.drawable.ic_confrim_32); diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/vo/DeviceInfo.java b/app/src/main/java/cc/niushuai/project/devcontrol/vo/DeviceInfo.java index 87b7645..2bb692b 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/vo/DeviceInfo.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/vo/DeviceInfo.java @@ -7,7 +7,7 @@ import cc.niushuai.project.devcontrol.base.entity.BaseVO; import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum; import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.util.DateFormatUtil; -import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Global; import cc.niushuai.project.devcontrol.base.util.IdWorker; import cc.niushuai.project.devcontrol.db.entity.Device; @@ -95,7 +95,7 @@ public class DeviceInfo extends BaseVO { device.setCommandClose("-c light -t 0"); list.add(device); - GlobalVariables.DEVICE_INFO_MAP.put(device.getId(), device); + Global.DEVICE_INFO_MAP.put(device.getId(), device); } return list;