mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 检查是否具有root权限
This commit is contained in:
parent
c8c7e12c8f
commit
44d2f001d7
@ -8,20 +8,17 @@ import android.os.Build;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cc.niushuai.project.devcontrol.BuildConfig;
|
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.base.util.Keys;
|
||||||
import cc.niushuai.project.devcontrol.db.DB;
|
import cc.niushuai.project.devcontrol.db.DB;
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.text.StrPool;
|
import cn.hutool.core.text.StrPool;
|
||||||
|
import cn.hutool.core.util.RuntimeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
@ -35,7 +32,7 @@ public class App {
|
|||||||
// 初始化数据库
|
// 初始化数据库
|
||||||
initDb(activity);
|
initDb(activity);
|
||||||
// 重建设备信息缓存
|
// 重建设备信息缓存
|
||||||
GlobalVariables.initDeviceInfoMap();
|
Global.initDeviceInfoMap();
|
||||||
// 初始化日志相关内容
|
// 初始化日志相关内容
|
||||||
initLog(activity);
|
initLog(activity);
|
||||||
}
|
}
|
||||||
@ -49,7 +46,11 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
private static void checkRoot(Activity activity) {
|
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() {
|
private static String getRootPath() {
|
||||||
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.util.ActivityUtil;
|
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.Keys;
|
||||||
import cc.niushuai.project.devcontrol.base.util.UiUtil;
|
import cc.niushuai.project.devcontrol.base.util.UiUtil;
|
||||||
import cc.niushuai.project.devcontrol.ui.common.IconSelectDialogFragment;
|
import cc.niushuai.project.devcontrol.ui.common.IconSelectDialogFragment;
|
||||||
@ -180,6 +180,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
* @date: 2022/10/24 17:09
|
* @date: 2022/10/24 17:09
|
||||||
*/
|
*/
|
||||||
public void rebuildDeviceInfoMapCache() {
|
public void rebuildDeviceInfoMapCache() {
|
||||||
GlobalVariables.initDeviceInfoMap();
|
Global.initDeviceInfoMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,16 @@ import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
|||||||
import cn.hutool.core.text.StrPool;
|
import cn.hutool.core.text.StrPool;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
public class GlobalVariables {
|
public class Global {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全部设备列表map
|
* 全部设备列表map
|
||||||
* id为key elem为value
|
* id为key elem为value
|
||||||
*/
|
*/
|
||||||
public static final Map<String, DeviceInfo> DEVICE_INFO_MAP = new HashMap<>(16);
|
public static final Map<String, DeviceInfo> 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);
|
public static String LOG_ROOT_PATH = StrUtil.join(StrPool.SLASH, Keys.LOG_ROOT_FILE_PATH, BuildConfig.APPLICATION_ID, Keys.LOG_LOG_FOLDER);
|
||||||
|
|
||||||
/**
|
/**
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import cc.niushuai.project.devcontrol.R;
|
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.base.util.Keys;
|
||||||
import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding;
|
import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding;
|
||||||
import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding;
|
import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding;
|
||||||
@ -74,7 +74,7 @@ public class NavDeviceFragment extends Fragment {
|
|||||||
|
|
||||||
private void setDevices() {
|
private void setDevices() {
|
||||||
|
|
||||||
deviceInfoList = GlobalVariables.DEVICE_INFO_MAP.values()
|
deviceInfoList = Global.DEVICE_INFO_MAP.values()
|
||||||
.stream()
|
.stream()
|
||||||
.sorted((before, after) -> {
|
.sorted((before, after) -> {
|
||||||
if (null == before.getOrder() || null == after.getOrder()) {
|
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) {
|
private void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
TextView textId = view.findViewById(R.id.device_item_cardView_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());
|
intent.putExtra(Keys.ID, textId.getText());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ public class NavDeviceFragment extends Fragment {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
// 重新初始化值
|
// 重新初始化值
|
||||||
GlobalVariables.initDeviceInfoMap();
|
Global.initDeviceInfoMap();
|
||||||
this.setDevices();
|
this.setDevices();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ import java.util.HashMap;
|
|||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.enums.OnOffEnum;
|
import cc.niushuai.project.devcontrol.base.enums.OnOffEnum;
|
||||||
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
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.base.util.Keys;
|
||||||
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding;
|
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public class PowerSwitchActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
|
||||||
this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId());
|
this.device = Global.getDeviceInfo(getIntentDeviceId());
|
||||||
// 标题名称
|
// 标题名称
|
||||||
super.setTitle(this.device.getDeviceName(), this.device.getRemark());
|
super.setTitle(this.device.getDeviceName(), this.device.getRemark());
|
||||||
// 开关底部的名称
|
// 开关底部的名称
|
||||||
|
@ -8,7 +8,7 @@ import java.util.HashMap;
|
|||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
||||||
import cc.niushuai.project.devcontrol.base.util.ActivityUtil;
|
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.Keys;
|
||||||
import cc.niushuai.project.devcontrol.base.util.ToastUtil;
|
import cc.niushuai.project.devcontrol.base.util.ToastUtil;
|
||||||
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetBinding;
|
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetBinding;
|
||||||
@ -30,7 +30,7 @@ public class PowerSwitchSetActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId());
|
this.device = Global.getDeviceInfo(getIntentDeviceId());
|
||||||
super.setTitle(getString(R.string.set), null);
|
super.setTitle(getString(R.string.set), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import androidx.annotation.Nullable;
|
|||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
||||||
import cc.niushuai.project.devcontrol.base.util.CommonUiUtil;
|
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.databinding.ActivityPowerSwitchSetParamBinding;
|
||||||
import cc.niushuai.project.devcontrol.db.DB;
|
import cc.niushuai.project.devcontrol.db.DB;
|
||||||
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
||||||
@ -30,7 +30,7 @@ public class PowerSwitchSetParamActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
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);
|
this.setTitle(null, getString(R.string.power_switch_set_paramSet), null, R.drawable.ic_confrim_32);
|
||||||
|
|
||||||
|
@ -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.DeviceTypeEnum;
|
||||||
import cc.niushuai.project.devcontrol.base.enums.OnOffEnum;
|
import cc.niushuai.project.devcontrol.base.enums.OnOffEnum;
|
||||||
import cc.niushuai.project.devcontrol.base.util.DateFormatUtil;
|
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.base.util.IdWorker;
|
||||||
import cc.niushuai.project.devcontrol.db.entity.Device;
|
import cc.niushuai.project.devcontrol.db.entity.Device;
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public class DeviceInfo extends BaseVO {
|
|||||||
device.setCommandClose("-c light -t 0");
|
device.setCommandClose("-c light -t 0");
|
||||||
list.add(device);
|
list.add(device);
|
||||||
|
|
||||||
GlobalVariables.DEVICE_INFO_MAP.put(device.getId(), device);
|
Global.DEVICE_INFO_MAP.put(device.getId(), device);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user