diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b7f0424..970b57b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,8 @@ android:name="android.app.lib_name" android:value="" /> + + \ No newline at end of file diff --git a/app/src/main/java/cn/tongdun/android/activity/ItemListActivity.java b/app/src/main/java/cn/tongdun/android/activity/ItemListActivity.java new file mode 100644 index 0000000..c0fefaa --- /dev/null +++ b/app/src/main/java/cn/tongdun/android/activity/ItemListActivity.java @@ -0,0 +1,201 @@ +package cn.tongdun.android.activity; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; +import android.hardware.Sensor; +import android.hardware.SensorManager; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.trustdevice.android.R; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.OnClick; +import cn.tongdun.android.adapter.AppListRecyclerViewAdapter; +import cn.tongdun.android.base.BaseActivity; +import cn.tongdun.android.beans.AppItemData; + +public class ItemListActivity extends BaseActivity { + + @BindView(R.id.tv_title) + TextView tvTitle; + @BindView(R.id.tv_title_right) + TextView tvTitleRight; + @BindView(R.id.rv_item_list) + RecyclerView rvItemList; + + private int mType; + private boolean mShowSystemApp = false; + private List mItemData = new ArrayList<>(); + private AppListRecyclerViewAdapter mAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected int getContentViewResId() { + return R.layout.activity_app_list; + } + + @Override + protected void initData() { + mType = getIntent().getIntExtra("type", -1); + if (mType == 0) { + loadInstalledAppList(mShowSystemApp); + } else if (mType == 1) { + loadSensorList(); + } + } + + @Override + protected void initView() { + if (mType == 0) { + tvTitle.setText(getResources().getString(R.string.app_list)); + tvTitleRight.setText(getResources().getString(R.string.show_system_apps)); + } else if (mType == 1) { + tvTitle.setText(getResources().getString(R.string.sensor_list)); + tvTitleRight.setVisibility(View.GONE); + } + LinearLayoutManager manager = new LinearLayoutManager(this); + rvItemList.setLayoutManager(manager); + mAdapter = new AppListRecyclerViewAdapter(mItemData); + rvItemList.setAdapter(mAdapter); + rvItemList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); + } + + @OnClick({R.id.tv_title, R.id.tv_title_right}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.tv_title: + this.finish(); + break; + case R.id.tv_title_right: + mShowSystemApp = !mShowSystemApp; + if (mShowSystemApp) { + tvTitleRight.setText(getResources().getString(R.string.hide_system_apps)); + } else { + tvTitleRight.setText(getResources().getString(R.string.show_system_apps)); + } + loadInstalledAppList(mShowSystemApp); + mAdapter.updateData(mItemData); + break; + } + } + + private void loadInstalledAppList(boolean showSystemApp) { + PackageManager packageManager = getPackageManager(); + if (packageManager == null) { + return; + } + List packageInfoList = packageManager.getInstalledPackages(0); + for (PackageInfo info : packageInfoList) { + if (info == null) { + continue; + } + if (!showSystemApp && isSystemApp(info.applicationInfo)) { + continue; + } + String packageName = info.packageName; + String versionName = info.versionName; + Drawable icon = info.applicationInfo.loadIcon(packageManager); + String appName = packageManager.getApplicationLabel(info.applicationInfo).toString(); +// if (mAppItemDataSet.contains(appName)){ +// continue; +// } + mItemData.add(new AppItemData(icon, appName, packageName, versionName)); + } + } + + private boolean isSystemApp(ApplicationInfo info) { + boolean isSysApp = (info.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM; + boolean isSysUpd = (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; + return isSysApp || isSysUpd; + } + + private void loadSensorList() { + + SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); + List sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); + for (Sensor sensor : sensorList) { + Drawable icon = ContextCompat.getDrawable(this, getIconByType(sensor.getType())); + String name = sensor.getName(); + String vendor = sensor.getVendor(); + String version = String.valueOf(sensor.getVersion()); + mItemData.add(new AppItemData(icon, name, vendor, version)); + } + } + + private int getIconByType(int sensorType) { + switch (sensorType) { + case 1: + case 10: + case 35: + return R.drawable.ic_sensor_accelerometer; + case 2: + case 14: + return R.drawable.ic_sensor_magnetic_field; + case 3: + case 11: + case 15: + case 20: + case 27: + return R.drawable.ic_sensor_orientation; + case 4: + case 16: + return R.drawable.ic_sensor_gyroscope; + case 5: + return R.drawable.ic_sensor_light; + case 6: + return R.drawable.ic_sensor_pressure; + case 7: + case 13: + return R.drawable.ic_sensor_temperature; + case 8: + return R.drawable.ic_sensor_proximity; + case 9: + return R.drawable.ic_sensor_gravity; + case 12: + return R.drawable.ic_sensor_humidity; + case 17: + case 30: + return R.drawable.ic_sensor_motion; + case 18: + case 19: + return R.drawable.ic_sensor_step; + case 21: + case 31: + return R.drawable.ic_sensor_heartrate; + case 22: + case 26: + return R.drawable.ic_sensor_tilt; + case 23: + case 24: + case 25: + case 28: + case 29: + case 32: + case 33: + case 34: + return R.drawable.ic_sensor_all; + case 36: + return R.drawable.ic_sensor_hinge; + default: + return R.drawable.ic_sensor_private; + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/cn/tongdun/android/activity/MainActivity.java b/app/src/main/java/cn/tongdun/android/activity/MainActivity.java index d7e7029..bcdf370 100644 --- a/app/src/main/java/cn/tongdun/android/activity/MainActivity.java +++ b/app/src/main/java/cn/tongdun/android/activity/MainActivity.java @@ -1,44 +1,29 @@ package cn.tongdun.android.activity; -import android.text.TextUtils; -import android.util.Pair; +import android.widget.TextView; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager2.widget.ViewPager2; +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; import com.trustdevice.android.R; -import org.json.JSONObject; - import java.util.ArrayList; import java.util.List; import butterknife.BindView; -import cn.tongdun.android.adapter.DeviceModuleItemAdapter; +import cn.tongdun.android.adapter.ViewPagerAdapter; import cn.tongdun.android.base.BaseActivity; -import cn.tongdun.android.beans.DetailsItemBean; -import cn.tongdun.android.beans.DeviceModuleItemBean; -import cn.tongdun.mobrisk.TDRisk; -import cn.tongdun.mobrisk.TDRiskCallback; -import cn.tongdun.mobrisk.providers.InfoProvider; -import cn.tongdun.mobrisk.providers.applist.AppListProvider; -import cn.tongdun.mobrisk.providers.battery.BatteryInfoProvider; -import cn.tongdun.mobrisk.providers.build.BuildInfoProvider; -import cn.tongdun.mobrisk.providers.cpu.CpuInfoProvider; -import cn.tongdun.mobrisk.providers.device_id.DeviceIdProvider; -import cn.tongdun.mobrisk.providers.memory.MemoryInfoProvider; -import cn.tongdun.mobrisk.providers.risk.RiskInfoProvider; -import cn.tongdun.mobrisk.providers.screen.ScreenInfoProvider; -import cn.tongdun.mobrisk.providers.sensor.SensorInfoProvider; -import cn.tongdun.mobrisk.providers.setting.SettingInfoProvider; public class MainActivity extends BaseActivity { - @BindView(R.id.device_info_container) - RecyclerView rvDeviceInfoContainer; - private DeviceModuleItemAdapter mAdapter; - private List mItemData = new ArrayList<>(); + @BindView(R.id.tab_layout) + TabLayout mTabLayout; + @BindView(R.id.viewpager) + ViewPager2 mViewPager; + + private final List mTabList = new ArrayList<>(); + private TabLayoutMediator mTabLayoutMediator; @Override protected int getContentViewResId() { @@ -47,54 +32,27 @@ protected int getContentViewResId() { @Override protected void initData() { - createDeviceInfo(); + mTabList.add("Device id"); + mTabList.add("Device info"); } @Override protected void initView() { - LinearLayoutManager manager = new LinearLayoutManager(this); - manager.setOrientation(GridLayoutManager.VERTICAL); - rvDeviceInfoContainer.setLayoutManager(manager); - mAdapter = new DeviceModuleItemAdapter(mItemData); - rvDeviceInfoContainer.setAdapter(mAdapter); + ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(mTabList.size(), getSupportFragmentManager(), getLifecycle()); + mViewPager.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT); + mViewPager.setAdapter(viewPagerAdapter); + mTabLayoutMediator = new TabLayoutMediator(mTabLayout, mViewPager, (tab, position) -> { + TextView tabView = new TextView(MainActivity.this); + tabView.setText(mTabList.get(position)); + tab.setCustomView(tabView); + }); + // binding + mTabLayoutMediator.attach(); } - private void createDeviceInfo() { - JSONObject deviceInfo = TDRisk.getBlackbox(); - createData(deviceInfo); - } - - private void createData(JSONObject deviceInfo) { - createItemInfo(new DeviceIdProvider(deviceInfo)); - createItemInfo(new RiskInfoProvider(deviceInfo)); - createItemInfo(new BuildInfoProvider(deviceInfo)); - createItemInfo(new ScreenInfoProvider(deviceInfo)); - createItemInfo(new BatteryInfoProvider(deviceInfo)); - createItemInfo(new SettingInfoProvider(deviceInfo)); - createItemInfo(new CpuInfoProvider(deviceInfo)); - createItemInfo(new MemoryInfoProvider(deviceInfo)); - createItemInfo(new SensorInfoProvider(deviceInfo)); - createAppList(new AppListProvider(deviceInfo)); - } - - private void createItemInfo(InfoProvider infoProvider) { - List detailsItemBeanList = new ArrayList<>(); - for (Pair infos : infoProvider.getRawData()) { - detailsItemBeanList.add(new DetailsItemBean(infos.first, infos.second)); - } - mItemData.add(new DeviceModuleItemBean(infoProvider.getProviderName(), detailsItemBeanList)); - } - - private void createAppList(InfoProvider appListProvider) { - for (Pair infos : appListProvider.getRawData()) { - List appListDetailsItemList = new ArrayList<>(); - for (String appInfo : infos.second) { - if (TextUtils.isEmpty(appInfo)) { - continue; - } - appListDetailsItemList.add(new DetailsItemBean(appInfo, "")); - } - mItemData.add(new DeviceModuleItemBean(infos.first, appListDetailsItemList)); - } + @Override + protected void onDestroy() { + mTabLayoutMediator.detach(); + super.onDestroy(); } } \ No newline at end of file diff --git a/app/src/main/java/cn/tongdun/android/adapter/AppListRecyclerViewAdapter.java b/app/src/main/java/cn/tongdun/android/adapter/AppListRecyclerViewAdapter.java new file mode 100644 index 0000000..332dc43 --- /dev/null +++ b/app/src/main/java/cn/tongdun/android/adapter/AppListRecyclerViewAdapter.java @@ -0,0 +1,45 @@ +package cn.tongdun.android.adapter; + +import android.widget.ImageView; +import android.widget.TextView; + +import com.trustdevice.android.R; + +import java.util.List; + +import cn.tongdun.android.beans.AppItemData; + +/** + * @description: app list RecyclerView Adapter + * @author: wuzuchang + * @date: 2023/3/8 + */ +public class AppListRecyclerViewAdapter extends BaseRecyclerViewAdapter { + + public AppListRecyclerViewAdapter(List data) { + super(data); + } + + @Override + public int getLayoutId(int viewType) { + + return R.layout.item_app_list; + } + + @Override + public void convert(BaseViewHolder holder, final AppItemData data, final int position) { + + ImageView iv_icon = holder.getView(R.id.iv_app_icon); + iv_icon.setImageDrawable(data.getIcon()); + TextView tv_app_name = holder.getView(R.id.tv_app_name); + tv_app_name.setText(data.getAppName() + ": " + data.getVersionName()); + TextView tv_application = holder.getView(R.id.tv_application); + tv_application.setText(data.getPackageName()); + } + + + public void updateData(List data) { + this.mData = data; + notifyDataSetChanged(); + } +} diff --git a/app/src/main/java/cn/tongdun/android/adapter/DetailsItemAdapter.java b/app/src/main/java/cn/tongdun/android/adapter/DeviceInfoItemAdapter.java similarity index 56% rename from app/src/main/java/cn/tongdun/android/adapter/DetailsItemAdapter.java rename to app/src/main/java/cn/tongdun/android/adapter/DeviceInfoItemAdapter.java index 0b83b02..2a8ed06 100644 --- a/app/src/main/java/cn/tongdun/android/adapter/DetailsItemAdapter.java +++ b/app/src/main/java/cn/tongdun/android/adapter/DeviceInfoItemAdapter.java @@ -1,22 +1,22 @@ package cn.tongdun.android.adapter; import android.text.TextUtils; +import android.util.Pair; import android.view.View; import android.widget.TextView; import com.trustdevice.android.R; -import cn.tongdun.android.beans.DetailsItemBean; import java.util.List; /** - * @description: Details Item Adapter + * @description: BuildInfo Item Adapter * @author: wuzuchang * @date: 2022/12/6 */ -public class DetailsItemAdapter extends BaseRecyclerViewAdapter { +public class DeviceInfoItemAdapter extends BaseRecyclerViewAdapter> { - public DetailsItemAdapter(List data) { + public DeviceInfoItemAdapter(List> data) { super(data); } @@ -26,14 +26,14 @@ public int getLayoutId(int viewType) { } @Override - public void convert(BaseViewHolder holder, DetailsItemBean data, int position) { + public void convert(BaseViewHolder holder, Pair data, int position) { TextView name = holder.getView(R.id.tv_name); - name.setText(data.getName()); + name.setText(data.first); TextView value = holder.getView(R.id.tv_value); - if (TextUtils.isEmpty(data.getValue())) { + if (TextUtils.isEmpty(data.second)) { value.setVisibility(View.GONE); } else { - value.setText(data.getValue()); + value.setText(data.second); } } } diff --git a/app/src/main/java/cn/tongdun/android/adapter/DeviceModuleItemAdapter.java b/app/src/main/java/cn/tongdun/android/adapter/DeviceModuleItemAdapter.java deleted file mode 100644 index 9215739..0000000 --- a/app/src/main/java/cn/tongdun/android/adapter/DeviceModuleItemAdapter.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.tongdun.android.adapter; - -import android.view.LayoutInflater; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import com.trustdevice.android.R; -import cn.tongdun.android.beans.DeviceModuleItemBean; -import cn.tongdun.android.view.DeviceDetailsItemView; - -import java.util.List; - -/** - * @description: Device Module RecyclerView Adapter - * @author: wuzuchang - * @date: 2022/12/6 - */ -public class DeviceModuleItemAdapter extends RecyclerView.Adapter { - - private List mData; - - public DeviceModuleItemAdapter(List data) { - mData = data; - } - - @NonNull - @Override - public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - DeviceDetailsItemView convertView = (DeviceDetailsItemView) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_device_module, parent, false); - return new ViewHolder(convertView); - } - - @Override - public void onBindViewHolder(@NonNull ViewHolder holder, int position) { - DeviceModuleItemBean deviceModuleItemBean = mData.get(position); - if (position==0){ - holder.deviceDetailsItemView.setExpanded(true); - } - holder.deviceDetailsItemView.setModuleName(deviceModuleItemBean.getModuleName()); - holder.deviceDetailsItemView.setDescribe(deviceModuleItemBean.getDescribe()); - holder.deviceDetailsItemView.setDetailsContainer(deviceModuleItemBean.getDetailsItemBeans()); - } - - @Override - public int getItemCount() { - return mData == null ? 0 : mData.size(); - } - - public static class ViewHolder extends RecyclerView.ViewHolder { - DeviceDetailsItemView deviceDetailsItemView; - - public ViewHolder(@NonNull DeviceDetailsItemView itemView) { - super(itemView); - deviceDetailsItemView = itemView; - } - } -} diff --git a/app/src/main/java/cn/tongdun/android/adapter/ViewPagerAdapter.java b/app/src/main/java/cn/tongdun/android/adapter/ViewPagerAdapter.java new file mode 100644 index 0000000..24a413e --- /dev/null +++ b/app/src/main/java/cn/tongdun/android/adapter/ViewPagerAdapter.java @@ -0,0 +1,41 @@ +package cn.tongdun.android.adapter; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.Lifecycle; +import androidx.viewpager2.adapter.FragmentStateAdapter; + +import cn.tongdun.android.fragments.DeviceIdFragment; +import cn.tongdun.android.fragments.DeviceInfoFragment; + +/** + * @description: ViewPager2 Adapter + * @author: wuzuchang + * @date: 2023/2/28 + */ +public class ViewPagerAdapter extends FragmentStateAdapter { + + private int mItemCount; + + public ViewPagerAdapter(int itemCount, @NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle) { + super(fragmentManager, lifecycle); + mItemCount = itemCount; + } + + @NonNull + @Override + public Fragment createFragment(int position) { + if (position == 0) { + return new DeviceIdFragment(); + } else if (position == 1) { + return new DeviceInfoFragment(); + } + return new DeviceIdFragment(); + } + + @Override + public int getItemCount() { + return mItemCount; + } +} diff --git a/app/src/main/java/cn/tongdun/android/beans/AppItemData.java b/app/src/main/java/cn/tongdun/android/beans/AppItemData.java new file mode 100644 index 0000000..bba7cf0 --- /dev/null +++ b/app/src/main/java/cn/tongdun/android/beans/AppItemData.java @@ -0,0 +1,76 @@ +package cn.tongdun.android.beans; + + +import android.graphics.drawable.Drawable; +import android.os.Build; + +import java.util.Objects; + +/** + * @description: app item + * @author: wuzuchang + * @date: 2023/3/8 + */ +public class AppItemData { + + private Drawable icon; + private String appName; + private String packageName; + private String versionName; + + + public AppItemData(Drawable icon, String appName, String packageName, String versionName) { + this.icon = icon; + this.appName = appName; + this.packageName = packageName; + this.versionName = versionName; + } + + public Drawable getIcon() { + return icon; + } + + public void setIcon(Drawable icon) { + this.icon = icon; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getVersionName() { + return versionName; + } + + public void setVersionName(String versionName) { + this.versionName = versionName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof AppItemData)) return false; + AppItemData that = (AppItemData) o; + return getAppName().equals(that.getAppName()) && getPackageName().equals(that.getPackageName()) && getVersionName().equals(that.getVersionName()); + } + + @Override + public int hashCode() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + return Objects.hash(getAppName(), getPackageName(), getVersionName()); + } + return 0; + } +} diff --git a/app/src/main/java/cn/tongdun/android/fragments/DeviceIdFragment.java b/app/src/main/java/cn/tongdun/android/fragments/DeviceIdFragment.java new file mode 100644 index 0000000..89aaf72 --- /dev/null +++ b/app/src/main/java/cn/tongdun/android/fragments/DeviceIdFragment.java @@ -0,0 +1,92 @@ +package cn.tongdun.android.fragments; + +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.trustdevice.android.R; + +import org.json.JSONException; +import org.json.JSONObject; + +import butterknife.BindView; +import butterknife.ButterKnife; +import cn.tongdun.mobrisk.TDRisk; +import cn.tongdun.mobrisk.providers.device_id.DeviceIdProvider; +import cn.tongdun.mobrisk.providers.risk.RiskInfoProvider; + +/** + * @description:DeviceId Fragment + * @author: wuzuchang + * @date: 2023/2/28 + */ +public class DeviceIdFragment extends Fragment { + + @BindView(R.id.tv_device_id) + TextView mTvDeviceID; + @BindView(R.id.tv_android_id) + TextView mTvAndroidID; + @BindView(R.id.tv_gsf_id) + TextView mTvGSF_ID; + @BindView(R.id.tv_media_drm_id) + TextView mTvMediaDrmID; + @BindView(R.id.tv_vmd_id) + TextView mTvVMD_ID; + @BindView(R.id.tv_risk_labels_title) + TextView mTvRiskLabelsTitle; + @BindView(R.id.tv_risk_labels) + TextView mTvRiskLabels; + private DeviceIdProvider mDeviceIdProvider; + private RiskInfoProvider mRiskInfoProvider; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getDeviceID(); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_device_id, container, false); + ButterKnife.bind(this, rootView); + initView(); + return rootView; + } + + private void getDeviceID() { + JSONObject deviceInfo = TDRisk.getBlackbox(); + try { + Log.d("TrustDevice", "deviceInfo = " + deviceInfo.toString(1)); + } catch (JSONException e) { + e.printStackTrace(); + } + mDeviceIdProvider = new DeviceIdProvider(deviceInfo); + mRiskInfoProvider = new RiskInfoProvider(deviceInfo); + } + + private void initView() { + mTvDeviceID.setText(mDeviceIdProvider.getDeviceId()); + mTvAndroidID.setText(mDeviceIdProvider.getAndroidId()); + mTvGSF_ID.setText(mDeviceIdProvider.getGsfId()); + mTvMediaDrmID.setText(mDeviceIdProvider.getMediaDrmId()); + mTvVMD_ID.setText(mDeviceIdProvider.getVbMetaDigest()); + String riskLabels = mRiskInfoProvider.getRiskLabels(); + if (TextUtils.isEmpty(riskLabels)) { + mTvRiskLabelsTitle.setVisibility(View.GONE); + mTvRiskLabels.setVisibility(View.GONE); + } else { + mTvRiskLabelsTitle.setVisibility(View.VISIBLE); + mTvRiskLabels.setVisibility(View.VISIBLE); + mTvRiskLabels.setText(riskLabels); + } + } +} diff --git a/app/src/main/java/cn/tongdun/android/fragments/DeviceInfoFragment.java b/app/src/main/java/cn/tongdun/android/fragments/DeviceInfoFragment.java new file mode 100644 index 0000000..005f674 --- /dev/null +++ b/app/src/main/java/cn/tongdun/android/fragments/DeviceInfoFragment.java @@ -0,0 +1,225 @@ +package cn.tongdun.android.fragments; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.os.Environment; +import android.util.Pair; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ProgressBar; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.trustdevice.android.R; + +import org.json.JSONObject; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; +import java.util.Locale; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import cn.tongdun.android.activity.ItemListActivity; +import cn.tongdun.android.adapter.DeviceInfoItemAdapter; +import cn.tongdun.mobrisk.TDRisk; +import cn.tongdun.mobrisk.providers.applist.AppListProvider; +import cn.tongdun.mobrisk.providers.battery.BatteryInfoProvider; +import cn.tongdun.mobrisk.providers.build.BuildInfoProvider; +import cn.tongdun.mobrisk.providers.memory.MemoryInfoProvider; +import cn.tongdun.mobrisk.providers.sensor.SensorInfoProvider; +import cn.tongdun.mobrisk.providers.setting.SettingInfoProvider; + +/** + * @description:DeviceId Fragment + * @author: wuzuchang + * @date: 2023/2/28 + */ +@SuppressLint("SetTextI18n") +public class DeviceInfoFragment extends Fragment { + + //BuildInfo + @BindView(R.id.tv_brand) + TextView mTvBrand; + @BindView(R.id.tv_model) + TextView mTvModel; + @BindView(R.id.rv_build_info) + RecyclerView mRcBuildInfo; + private BuildInfoProvider mBuildInfoProvider; + //Setting + @BindView(R.id.rv_setting) + RecyclerView mRcSetting; + private SettingInfoProvider mSettingInfoProvider; + // MemoryIndo + @BindView(R.id.tv_internal_storage_path) + TextView mTvInternalStoragePath; + @BindView(R.id.internal_storage_progress) + ProgressBar mPbInternalStorageProgress; + @BindView(R.id.tv_internal_storage_scale) + TextView mTvInternalStorageScale; + @BindView(R.id.tv_internal_storage_info) + TextView mTvInternalStorageInfo; + @BindView(R.id.tv_ram_path) + TextView mTvRAMPath; + @BindView(R.id.ram_progress) + ProgressBar mPbRAMProgress; + @BindView(R.id.tv_ram_scale) + TextView mTvRAMScale; + @BindView(R.id.tv_ram_info) + TextView mTvRAMInfo; + private MemoryInfoProvider mMemoryInfoProvider; + // Battery + @BindView(R.id.tv_battery_status) + TextView mTvBatterStatus; + @BindView(R.id.tv_battery_health) + TextView mTvBatterHealth; + @BindView(R.id.battery_progress) + ProgressBar mPbBatteryProgress; + @BindView(R.id.tv_battery_power) + TextView mTvBatteryPower; + @BindView(R.id.tv_battery_info) + TextView mTvBatteryInfo; + private BatteryInfoProvider mBatteryInfoProvider; + // Apps + @BindView(R.id.tv_app_total) + TextView mTvAppTotal; + @BindView(R.id.all_apps_layout) + ConstraintLayout mAppLayout; + private AppListProvider mAppListProvider; + //Sensor + @BindView(R.id.tv_sensor_total) + TextView mTvSensorTotal; + @BindView(R.id.all_sensor_layout) + ConstraintLayout mSensorLayout; + private SensorInfoProvider mSensorInfoProvider; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getDeviceInfo(); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_device_info, container, false); + ButterKnife.bind(this, rootView); + initView(); + return rootView; + } + + private void getDeviceInfo() { + JSONObject deviceInfo = TDRisk.getBlackbox(); + mBuildInfoProvider = new BuildInfoProvider(deviceInfo); + mSettingInfoProvider = new SettingInfoProvider(deviceInfo); + mMemoryInfoProvider = new MemoryInfoProvider(deviceInfo); + mBatteryInfoProvider = new BatteryInfoProvider(deviceInfo); + mAppListProvider = new AppListProvider(deviceInfo); + mSensorInfoProvider = new SensorInfoProvider(deviceInfo); + } + + private void initView() { + initBuildInfoView(); + initSettingView(); + initInternalStorageView(); + initRAMView(); + initBatteryView(); + initAppTotalView(); + initSensorTotalView(); + } + + private void initBuildInfoView() { + mTvBrand.setText(mBuildInfoProvider.getBrand()); + mTvModel.setText(mBuildInfoProvider.getModel()); + LinearLayoutManager manager = new LinearLayoutManager(getActivity()); + manager.setOrientation(GridLayoutManager.VERTICAL); + mRcBuildInfo.setLayoutManager(manager); + List> buildData = mBuildInfoProvider.getRawData(); + DeviceInfoItemAdapter deviceInfoItemAdapter = new DeviceInfoItemAdapter(buildData); + mRcBuildInfo.setAdapter(deviceInfoItemAdapter); + } + + private void initSettingView() { + LinearLayoutManager manager = new LinearLayoutManager(getActivity()); + manager.setOrientation(GridLayoutManager.VERTICAL); + mRcSetting.setLayoutManager(manager); + List> buildData = mSettingInfoProvider.getRawData(); + DeviceInfoItemAdapter deviceInfoItemAdapter = new DeviceInfoItemAdapter(buildData); + mRcSetting.setAdapter(deviceInfoItemAdapter); + } + + private void initInternalStorageView() { + mTvInternalStoragePath.setText(Environment.getDataDirectory().getPath()); + double totalStorage = mMemoryInfoProvider.getTotalStorage() / Math.pow(1024, 3); + double availableStorage = mMemoryInfoProvider.getAvailableStorage() / Math.pow(1024, 3); + double useStorage = totalStorage - availableStorage; + String internalStorageInfo = String.format(Locale.US, "%.2fGB", useStorage) + " / " + String.format(Locale.US, "%.2fGB", totalStorage) + ", Free: " + String.format(Locale.US, "%.2fGB", availableStorage); + mTvInternalStorageInfo.setText(internalStorageInfo); + double scale = 100 / totalStorage; + mPbInternalStorageProgress.setProgress((int) (useStorage * scale)); + mTvInternalStorageScale.setText(String.format(Locale.US, "%.2f", useStorage / totalStorage * 100) + "%"); + } + + private void initRAMView() { + mTvRAMPath.setText("The state at the time of collection"); + double totalMemory = mMemoryInfoProvider.getTotalMemory() / Math.pow(1024, 3); + double availableMemory = mMemoryInfoProvider.getAvailableMemory() / Math.pow(1024, 3); + double useMemory = totalMemory - availableMemory; + String internalStorageInfo = String.format(Locale.US, "%.2fGB", useMemory) + " / " + String.format(Locale.US, "%.2fGB", totalMemory) + ", Free: " + String.format(Locale.US, "%.2fGB", availableMemory); + mTvRAMInfo.setText(internalStorageInfo); + double scale = 100 / totalMemory; + mPbRAMProgress.setProgress((int) (useMemory * scale)); + mTvRAMScale.setText(String.format(Locale.US, "%.2f", useMemory / totalMemory * 100) + "%"); + } + + private void initBatteryView() { + mTvBatterStatus.setText("(" + mBatteryInfoProvider.getStatus() + ")"); + mTvBatterHealth.setText("total capacity: " + mBatteryInfoProvider.getTotalCapacity() + "mAh"); + int power = mBatteryInfoProvider.getLevel(); + mPbBatteryProgress.setProgress(power); + mTvBatteryPower.setText(power + "%"); + int temp = mBatteryInfoProvider.getTemp(); + double temperature = BigDecimal.valueOf((float) temp / 10).setScale(2, RoundingMode.HALF_UP).doubleValue(); + mTvBatteryInfo.setText("health: " + mBatteryInfoProvider.getHealth() + ", temperature: " + temperature + "℃"); + } + + private void initAppTotalView() { + int total = mAppListProvider.getUserAppTotal() + mAppListProvider.getSystemAppTotal(); + mTvAppTotal.setText(total + ""); + } + + private void initSensorTotalView() { + int total = mSensorInfoProvider.getSensorTotal(); + mTvSensorTotal.setText(total + ""); + } + + @OnClick({R.id.all_apps_layout, R.id.all_sensor_layout}) + public void onViewClick(View view) { + switch (view.getId()) { + case R.id.all_apps_layout: + jumpToListActivity(0); + break; + case R.id.all_sensor_layout: + jumpToListActivity(1); + break; + } + } + + private void jumpToListActivity(int type) { + Intent sensor = new Intent(getActivity(), ItemListActivity.class); + sensor.putExtra("type", type); + startActivity(sensor); + } + +} diff --git a/app/src/main/java/cn/tongdun/android/view/DeviceDetailsItemView.java b/app/src/main/java/cn/tongdun/android/view/DeviceDetailsItemView.java deleted file mode 100644 index 243abc5..0000000 --- a/app/src/main/java/cn/tongdun/android/view/DeviceDetailsItemView.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.tongdun.android.view; - -import android.content.Context; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.trustdevice.android.R; -import cn.tongdun.android.adapter.DetailsItemAdapter; -import cn.tongdun.android.beans.DetailsItemBean; - -import java.util.List; - -/** - * @description: Device Details Item View - * @author: wuzuchang - * @date: 2022/12/6 - */ -public class DeviceDetailsItemView extends ConstraintLayout { - - private boolean isExpanded = false; - private TextView tvModuleName; - private TextView tvDescribe; - private ImageView ivArrow; - private RecyclerView rvDetailsContainer; - - public DeviceDetailsItemView(@NonNull Context context) { - super(context); - } - - public DeviceDetailsItemView(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - - public DeviceDetailsItemView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - public void setExpanded(boolean expanded) { - isExpanded = expanded; - } - - public void setModuleName(String name) { - tvModuleName = findViewById(R.id.tv_module_name); - tvModuleName.setText(name); - } - - public void setDescribe(String desc) { - tvDescribe = findViewById(R.id.tv_module_des); - if (TextUtils.isEmpty(desc)) { - tvDescribe.setVisibility(GONE); - } else { - tvDescribe.setText(desc); - } - } - - public void setDetailsContainer(List list) { - ivArrow = findViewById(R.id.iv_arrow); - rvDetailsContainer = findViewById(R.id.rv_details_container); - LinearLayoutManager manager = new LinearLayoutManager(this.getContext()); - manager.setOrientation(GridLayoutManager.VERTICAL); - rvDetailsContainer.setLayoutManager(manager); - DetailsItemAdapter adapter = new DetailsItemAdapter(list); - rvDetailsContainer.setAdapter(adapter); - DividerItemDecoration decoration = new DividerItemDecoration(this.getContext(), DividerItemDecoration.VERTICAL); - decoration.setDrawable(getResources().getDrawable(R.drawable.detail_item_divider)); - rvDetailsContainer.addItemDecoration(decoration); - if (isExpanded){ - rvDetailsContainer.setVisibility(VISIBLE); - ivArrow.setImageResource(R.drawable.ic_up_arrow); - } - setOnClickListener(v -> toggleExpanding()); - } - - private void toggleExpanding() { - if (!isExpanded) { - rvDetailsContainer.setVisibility(VISIBLE); - ivArrow.setImageResource(R.drawable.ic_up_arrow); - } else { - rvDetailsContainer.setVisibility(GONE); - ivArrow.setImageResource(R.drawable.ic_down_arrow); - } - isExpanded = !isExpanded; - } -} diff --git a/app/src/main/res/drawable/build_info_background.xml b/app/src/main/res/drawable/build_info_background.xml new file mode 100644 index 0000000..5f31599 --- /dev/null +++ b/app/src/main/res/drawable/build_info_background.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_back.xml b/app/src/main/res/drawable/ic_back.xml new file mode 100644 index 0000000..65bbec6 --- /dev/null +++ b/app/src/main/res/drawable/ic_back.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery.xml b/app/src/main/res/drawable/ic_battery.xml new file mode 100644 index 0000000..2d82891 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_installed_app.xml b/app/src/main/res/drawable/ic_installed_app.xml new file mode 100644 index 0000000..01864f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_installed_app.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_internal_storage.xml b/app/src/main/res/drawable/ic_internal_storage.xml new file mode 100644 index 0000000..4ada733 --- /dev/null +++ b/app/src/main/res/drawable/ic_internal_storage.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_phone.xml b/app/src/main/res/drawable/ic_phone.xml new file mode 100644 index 0000000..cbfca8a --- /dev/null +++ b/app/src/main/res/drawable/ic_phone.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_random_access_memory.xml b/app/src/main/res/drawable/ic_random_access_memory.xml new file mode 100644 index 0000000..a48959c --- /dev/null +++ b/app/src/main/res/drawable/ic_random_access_memory.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_accelerometer.xml b/app/src/main/res/drawable/ic_sensor_accelerometer.xml new file mode 100644 index 0000000..25e6fd0 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_accelerometer.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_all.xml b/app/src/main/res/drawable/ic_sensor_all.xml new file mode 100644 index 0000000..7545148 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_all.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_sensor_gravity.xml b/app/src/main/res/drawable/ic_sensor_gravity.xml new file mode 100644 index 0000000..862f03e --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_gravity.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_gyroscope.xml b/app/src/main/res/drawable/ic_sensor_gyroscope.xml new file mode 100644 index 0000000..0f78255 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_gyroscope.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_heartrate.xml b/app/src/main/res/drawable/ic_sensor_heartrate.xml new file mode 100644 index 0000000..7b0186e --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_heartrate.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_hinge.xml b/app/src/main/res/drawable/ic_sensor_hinge.xml new file mode 100644 index 0000000..69c41ae --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_hinge.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_humidity.xml b/app/src/main/res/drawable/ic_sensor_humidity.xml new file mode 100644 index 0000000..199e83f --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_humidity.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_light.xml b/app/src/main/res/drawable/ic_sensor_light.xml new file mode 100644 index 0000000..956f470 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_light.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_magnetic_field.xml b/app/src/main/res/drawable/ic_sensor_magnetic_field.xml new file mode 100644 index 0000000..95d90a9 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_magnetic_field.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_motion.xml b/app/src/main/res/drawable/ic_sensor_motion.xml new file mode 100644 index 0000000..beea5ed --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_motion.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_next.xml b/app/src/main/res/drawable/ic_sensor_next.xml new file mode 100644 index 0000000..12116ee --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_next.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/ic_sensor_orientation.xml b/app/src/main/res/drawable/ic_sensor_orientation.xml new file mode 100644 index 0000000..cace4a1 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_orientation.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_pressure.xml b/app/src/main/res/drawable/ic_sensor_pressure.xml new file mode 100644 index 0000000..feae9c8 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_pressure.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_private.xml b/app/src/main/res/drawable/ic_sensor_private.xml new file mode 100644 index 0000000..8b36aad --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/ic_sensor_proximity.xml b/app/src/main/res/drawable/ic_sensor_proximity.xml new file mode 100644 index 0000000..7e82b31 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_proximity.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_step.xml b/app/src/main/res/drawable/ic_sensor_step.xml new file mode 100644 index 0000000..e45b3dc --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_step.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/ic_sensor_temperature.xml b/app/src/main/res/drawable/ic_sensor_temperature.xml new file mode 100644 index 0000000..791a5f0 --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_temperature.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_sensor_tilt.xml b/app/src/main/res/drawable/ic_sensor_tilt.xml new file mode 100644 index 0000000..15bed6d --- /dev/null +++ b/app/src/main/res/drawable/ic_sensor_tilt.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/ic_setting.xml b/app/src/main/res/drawable/ic_setting.xml new file mode 100644 index 0000000..be10604 --- /dev/null +++ b/app/src/main/res/drawable/ic_setting.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/item_card_background.xml b/app/src/main/res/drawable/item_card_background.xml index 3082731..0e69eb9 100644 --- a/app/src/main/res/drawable/item_card_background.xml +++ b/app/src/main/res/drawable/item_card_background.xml @@ -3,5 +3,5 @@ android:shape="rectangle"> - + diff --git a/app/src/main/res/layout/activity_app_list.xml b/app/src/main/res/layout/activity_app_list.xml new file mode 100644 index 0000000..89f03a2 --- /dev/null +++ b/app/src/main/res/layout/activity_app_list.xml @@ -0,0 +1,29 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c9cfc53..e116f32 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -14,12 +14,35 @@ android:layout_marginHorizontal="20dp" android:layout_marginTop="20dp" android:text="@string/app_name" - android:textColor="#52B456" + android:textColor="@color/app_theme" android:textSize="20sp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + + + + app:layout_constraintTop_toBottomOf="@+id/viewpager" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_device_id.xml b/app/src/main/res/layout/fragment_device_id.xml new file mode 100644 index 0000000..54eba7a --- /dev/null +++ b/app/src/main/res/layout/fragment_device_id.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_device_info.xml b/app/src/main/res/layout/fragment_device_info.xml new file mode 100644 index 0000000..777aab0 --- /dev/null +++ b/app/src/main/res/layout/fragment_device_info.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/include_battery_info.xml b/app/src/main/res/layout/include_battery_info.xml new file mode 100644 index 0000000..7d21a40 --- /dev/null +++ b/app/src/main/res/layout/include_battery_info.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/include_build_info.xml b/app/src/main/res/layout/include_build_info.xml new file mode 100644 index 0000000..e9d7f53 --- /dev/null +++ b/app/src/main/res/layout/include_build_info.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/include_installed_app_list.xml b/app/src/main/res/layout/include_installed_app_list.xml new file mode 100644 index 0000000..3aedb71 --- /dev/null +++ b/app/src/main/res/layout/include_installed_app_list.xml @@ -0,0 +1,38 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/include_memory_info.xml b/app/src/main/res/layout/include_memory_info.xml new file mode 100644 index 0000000..1e9c325 --- /dev/null +++ b/app/src/main/res/layout/include_memory_info.xml @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/include_sensor_list.xml b/app/src/main/res/layout/include_sensor_list.xml new file mode 100644 index 0000000..7252009 --- /dev/null +++ b/app/src/main/res/layout/include_sensor_list.xml @@ -0,0 +1,38 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/include_setting_info.xml b/app/src/main/res/layout/include_setting_info.xml new file mode 100644 index 0000000..e8dcd1b --- /dev/null +++ b/app/src/main/res/layout/include_setting_info.xml @@ -0,0 +1,42 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/include_title_layout.xml b/app/src/main/res/layout/include_title_layout.xml new file mode 100644 index 0000000..3f0a777 --- /dev/null +++ b/app/src/main/res/layout/include_title_layout.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_app_list.xml b/app/src/main/res/layout/item_app_list.xml new file mode 100644 index 0000000..772cd6e --- /dev/null +++ b/app/src/main/res/layout/item_app_list.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_details.xml b/app/src/main/res/layout/item_details.xml index deaff13..4842df1 100644 --- a/app/src/main/res/layout/item_details.xml +++ b/app/src/main/res/layout/item_details.xml @@ -14,7 +14,7 @@ android:textColor="@color/normal_text" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/tv_value" - app:layout_constraintHorizontal_weight="3" + app:layout_constraintHorizontal_weight="4" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="name" /> @@ -26,7 +26,7 @@ android:layout_marginStart="20dp" app:layout_constraintBottom_toBottomOf="@+id/tv_name" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_weight="7" + app:layout_constraintHorizontal_weight="6" app:layout_constraintStart_toEndOf="@+id/tv_name" app:layout_constraintTop_toTopOf="@+id/tv_name" tools:text="xxxx" /> diff --git a/app/src/main/res/layout/item_device_module.xml b/app/src/main/res/layout/item_device_module.xml deleted file mode 100644 index 43c8332..0000000 --- a/app/src/main/res/layout/item_device_module.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ae2b7d9..608c620 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,9 +7,11 @@ #FF018786 #FF000000 #FFFFFFFF + #52B456 #F5F5F5 @color/white @color/black @color/black #F2F2F2 + #FF6C5C \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9e6f283..32260d2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,19 @@ TrustDevice + Your Device ID + Android ID + Risk Labels + GSF ID + Media DRM ID + VMD ID + Settings + Internal Storage + Random Access Memory + Battery + Apps + Sensors + App list + show system apps + hide system apps + Sensor list \ No newline at end of file diff --git a/resources/demo.gif b/resources/demo.gif index 32e44f5..03dda2d 100644 Binary files a/resources/demo.gif and b/resources/demo.gif differ diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/applist/AppListProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/applist/AppListProvider.java index 99a2d2a..8379e9b 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/applist/AppListProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/applist/AppListProvider.java @@ -22,6 +22,20 @@ public AppListProvider(JSONObject deviceInfo) { mDeviceInfo = deviceInfo.optJSONObject(Constants.KEY_DEVICE_DETAIL); } + public int getUserAppTotal(){ + if (mDeviceInfo == null) { + return 0; + } + return mDeviceInfo.optString(Constants.KEY_APP_LIST).split(",").length; + } + + public int getSystemAppTotal(){ + if (mDeviceInfo == null) { + return 0; + } + return mDeviceInfo.optString(Constants.KEY_SYSTEM_APP_LIST).split(",").length; + } + private String getAppList() { if (mDeviceInfo == null) { return ""; diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/battery/BatteryInfoProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/battery/BatteryInfoProvider.java index d08e80e..4440ddb 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/battery/BatteryInfoProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/battery/BatteryInfoProvider.java @@ -1,13 +1,8 @@ package cn.tongdun.mobrisk.providers.battery; -import android.util.Pair; - import org.json.JSONObject; -import java.util.List; - import cn.tongdun.mobrisk.core.utils.Constants; -import cn.tongdun.mobrisk.providers.InfoProvider; /** * @description: BatteryInfo Provider @@ -15,7 +10,7 @@ * @date: 2022/12/6 */ @Deprecated(since = "pro no such class") -public class BatteryInfoProvider extends InfoProvider { +public class BatteryInfoProvider { private final JSONObject mDeviceInfo; @@ -23,45 +18,35 @@ public BatteryInfoProvider(JSONObject deviceInfo) { mDeviceInfo = deviceInfo.optJSONObject(Constants.KEY_DEVICE_DETAIL); } - @Override - public String getProviderName() { - return "Battery info"; - } - - @Override - public List> getRawData() { - return new BatteryInfoRawData(getHealth(), getStatus(), getLevel(), getTemp(), getTotalCapacity()).loadData(); - } - - private String getHealth() { + public String getHealth() { if (mDeviceInfo == null) { return ""; } return mDeviceInfo.optString(Constants.KEY_BATTERY_HEALTH_STATUS); } - private String getStatus() { + public String getStatus() { if (mDeviceInfo == null) { return ""; } return mDeviceInfo.optString(Constants.KEY_BATTERY_STATUS); } - private String getLevel() { + public int getLevel() { if (mDeviceInfo == null) { - return ""; + return 0; } - return mDeviceInfo.optString(Constants.KEY_BATTERY_LEVEL); + return mDeviceInfo.optInt(Constants.KEY_BATTERY_LEVEL); } - private String getTemp() { + public int getTemp() { if (mDeviceInfo == null) { - return ""; + return 0; } - return mDeviceInfo.optString(Constants.KEY_BATTERY_TEMP); + return mDeviceInfo.optInt(Constants.KEY_BATTERY_TEMP); } - private String getTotalCapacity() { + public String getTotalCapacity() { if (mDeviceInfo == null) { return ""; } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/battery/BatteryInfoRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/battery/BatteryInfoRawData.java deleted file mode 100644 index 96ede59..0000000 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/battery/BatteryInfoRawData.java +++ /dev/null @@ -1,61 +0,0 @@ -package cn.tongdun.mobrisk.providers.battery; - -import android.util.Pair; - -import java.util.ArrayList; -import java.util.List; - -import cn.tongdun.mobrisk.providers.RawData; - -/** - * @description: BatteryInfoRawData - * @author: wuzuchang - * @date: 2022/12/6 - */ -@Deprecated(since = "pro no such class") -public class BatteryInfoRawData extends RawData { - private String health; - private String status; - private String level; - private String temp; - private String totalCapacity; - - public BatteryInfoRawData(String health, String status, String level, String temp, String totalCapacity) { - this.health = health; - this.status = status; - this.level = level; - this.temp = temp; - this.totalCapacity = totalCapacity; - } - - private String getHealth() { - return health; - } - - private String getStatus() { - return status; - } - - private String getLevel() { - return level; - } - - private String getTemp() { - return temp; - } - - private String getTotalCapacity() { - return totalCapacity; - } - - @Override - public List> loadData() { - List> data = new ArrayList<>(); - data.add(new Pair<>("health", getHealth())); - data.add(new Pair<>("status", getStatus())); - data.add(new Pair<>("level", getLevel())); - data.add(new Pair<>("temp", getTemp())); - data.add(new Pair<>("total capacity", getTotalCapacity())); - return data; - } -} diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoProvider.java index 40b17e3..afe5d53 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoProvider.java @@ -7,7 +7,6 @@ import java.util.List; import cn.tongdun.mobrisk.core.utils.Constants; -import cn.tongdun.mobrisk.providers.InfoProvider; /** * @description: BuildInfo Provider @@ -15,21 +14,21 @@ * @date: 2022/12/6 */ @Deprecated(since = "pro no such class") -public class BuildInfoProvider extends InfoProvider { +public class BuildInfoProvider { private final JSONObject mDeviceInfo; public BuildInfoProvider(JSONObject deviceInfo) { mDeviceInfo = deviceInfo.optJSONObject(Constants.KEY_DEVICE_DETAIL); } - private String getModel() { + public String getModel() { if (mDeviceInfo == null) { return ""; } return mDeviceInfo.optString(Constants.KEY_MODEL); } - private String getBrand() { + public String getBrand() { if (mDeviceInfo == null) { return ""; } @@ -50,7 +49,7 @@ private String getAndroidVersion() { return mDeviceInfo.optString(Constants.KEY_ANDROID_VERSION); } - public String getSdkVersion() { + private String getSdkVersion() { if (mDeviceInfo == null) { return ""; } @@ -78,13 +77,36 @@ private String getHost() { return mDeviceInfo.optString(Constants.KEY_HOST); } - @Override - public String getProviderName() { - return "Build info "; + + private String getScreenResolution() { + if (mDeviceInfo == null) { + return ""; + } + return mDeviceInfo.optString(Constants.KEY_SCREEN_RESOLUTION); + } + + private String getScreenInches() { + if (mDeviceInfo == null) { + return ""; + } + return mDeviceInfo.optString(Constants.KEY_SCREEN_INCHES); + } + + private String getScreenBrightness() { + if (mDeviceInfo == null) { + return ""; + } + return mDeviceInfo.optString(Constants.KEY_SCREEN_BRIGHTNESS); + } + + private String getScreenOffTimeout() { + if (mDeviceInfo == null) { + return ""; + } + return mDeviceInfo.optString(Constants.KEY_SCREEN_OFF_TIMEOUT); } - @Override public List> getRawData() { - return new BuildInfoRawData(getModel(), getBrand(), getManufacturer(), getAndroidVersion(), getSdkVersion(), getKernelVersion(), getFingerprint(), getHost()).loadData(); + return new BuildInfoRawData(getModel(), getBrand(), getManufacturer(), getAndroidVersion(), getSdkVersion(), getKernelVersion(), getFingerprint(), getHost(), getScreenResolution(), getScreenInches(), getScreenBrightness(), getScreenOffTimeout()).loadData(); } } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoRawData.java index a53426d..0b4c317 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoRawData.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/build/BuildInfoRawData.java @@ -22,8 +22,12 @@ public class BuildInfoRawData extends RawData { private String kernelVersion; private String fingerprint; private String host; + private String screenResolution; + private String screenInches; + private String screenBrightness; - public BuildInfoRawData(String model,String brand, String manufacturer, String androidVersion, String sdkVersion, String kernelVersion, String fingerprint, String host) { + + public BuildInfoRawData(String model, String brand, String manufacturer, String androidVersion, String sdkVersion, String kernelVersion, String fingerprint, String host, String screenResolution, String screenInches, String screenBrightness, String screenOffTimeout) { this.model = model; this.brand = brand; this.manufacturer = manufacturer; @@ -32,6 +36,9 @@ public BuildInfoRawData(String model,String brand, String manufacturer, String a this.kernelVersion = kernelVersion; this.fingerprint = fingerprint; this.host = host; + this.screenResolution = screenResolution; + this.screenInches = screenInches; + this.screenBrightness = screenBrightness; } private String getModel() { @@ -66,17 +73,32 @@ private String getHost() { return host; } + public String getScreenResolution() { + return screenResolution; + } + + public String getScreenInches() { + return screenInches; + } + + public String getScreenBrightness() { + return screenBrightness; + } + @Override public List> loadData() { List> data = new ArrayList<>(); - data.add(new Pair<>("model", getModel())); data.add(new Pair<>("brand", getBrand())); + data.add(new Pair<>("model", getModel())); data.add(new Pair<>("manufacturer", getManufacturer())); data.add(new Pair<>("android version", getAndroidVersion())); data.add(new Pair<>("sdk version", getSdkVersion())); data.add(new Pair<>("kernel version", getKernelVersion())); data.add(new Pair<>("fingerprint", getFingerprint())); data.add(new Pair<>("host", getHost())); + data.add(new Pair<>("screen resolution", getScreenResolution())); + data.add(new Pair<>("screen inches", getScreenInches())); + data.add(new Pair<>("screen brightness", getScreenBrightness())); return data; } } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/device_id/DeviceIdProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/device_id/DeviceIdProvider.java index e31f977..b47510c 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/device_id/DeviceIdProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/device_id/DeviceIdProvider.java @@ -1,13 +1,8 @@ package cn.tongdun.mobrisk.providers.device_id; -import android.util.Pair; - import org.json.JSONObject; -import java.util.List; - import cn.tongdun.mobrisk.core.utils.Constants; -import cn.tongdun.mobrisk.providers.InfoProvider; /** * @description: DeviceId Provider @@ -15,7 +10,7 @@ * @date: 2022/12/6 */ @Deprecated(since = "pro no such class") -public class DeviceIdProvider extends InfoProvider { +public class DeviceIdProvider { private JSONObject mDeviceInfo; @@ -23,7 +18,7 @@ public DeviceIdProvider(JSONObject deviceInfo) { mDeviceInfo = deviceInfo; } - private String getDeviceId() { + public String getDeviceId() { if (mDeviceInfo == null) { return ""; @@ -31,7 +26,7 @@ private String getDeviceId() { return mDeviceInfo.optString(Constants.KEY_DEVICE_ID); } - private String getAndroidId() { + public String getAndroidId() { if (mDeviceInfo == null) { return ""; } @@ -42,7 +37,7 @@ private String getAndroidId() { return getData(Constants.KEY_ANDROID_ID); } - private String getGsfId() { + public String getGsfId() { if (mDeviceInfo == null) { return ""; } @@ -53,11 +48,11 @@ private String getGsfId() { return getData(Constants.KEY_GSF_ID); } - private String getMediaDrmId() { + public String getMediaDrmId() { return getData(Constants.KEY_MEDIA_DRM_ID); } - private String getVbMetaDigest() { + public String getVbMetaDigest() { return getData(Constants.KEY_VB_META_DIGEST); } @@ -72,14 +67,4 @@ private String getData(String Key) { } return deviceDetail.optString(Key); } - - @Override - public String getProviderName() { - return "Device id"; - } - - @Override - public List> getRawData() { - return new DeviceIdRawData(getDeviceId(), getAndroidId(), getGsfId(), getMediaDrmId(), getVbMetaDigest()).loadData(); - } } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/device_id/DeviceIdRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/device_id/DeviceIdRawData.java deleted file mode 100644 index 4b34cfb..0000000 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/device_id/DeviceIdRawData.java +++ /dev/null @@ -1,66 +0,0 @@ -package cn.tongdun.mobrisk.providers.device_id; - -import android.text.TextUtils; -import android.util.Pair; - -import java.util.ArrayList; -import java.util.List; - -import cn.tongdun.mobrisk.providers.RawData; - -/** - * @description: DeviceIdRawData - * @author: wuzuchang - * @date: 2022/12/6 - */ -@Deprecated(since = "pro no such class") -public class DeviceIdRawData extends RawData { - private String deviceId; - private String androidId; - private String gsfId; - private String mediaDrmId; - private String vbMetaDigest; - - public DeviceIdRawData(String deviceId, String android_id, String gsf_id, String mediaDrm_id, String vb_meta_digest) { - this.deviceId = deviceId; - this.androidId = android_id; - this.gsfId = gsf_id; - this.mediaDrmId = mediaDrm_id; - this.vbMetaDigest = vb_meta_digest; - } - - private String getDeviceId() { - return deviceId; - } - - private String getAndroidId() { - return androidId; - } - - private String getGsfId() { - if (TextUtils.isEmpty(gsfId) || "null".equals(gsfId)) { - return ""; - } - return gsfId; - } - - private String getMediaDrmId() { - return mediaDrmId; - } - - private String getVbMetaDigest() { - return vbMetaDigest; - } - - - @Override - public List> loadData() { - List> data = new ArrayList<>(); - data.add(new Pair<>("device id", getDeviceId())); - data.add(new Pair<>("android id", getAndroidId())); - data.add(new Pair<>("gsf id", getGsfId())); - data.add(new Pair<>("media drm id", getMediaDrmId())); - data.add(new Pair<>("vbmeta digest", getVbMetaDigest())); - return data; - } -} diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/memory/MemoryInfoProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/memory/MemoryInfoProvider.java index 47cf06a..af1456d 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/memory/MemoryInfoProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/memory/MemoryInfoProvider.java @@ -1,13 +1,8 @@ package cn.tongdun.mobrisk.providers.memory; -import android.util.Pair; - import org.json.JSONObject; -import java.util.List; - import cn.tongdun.mobrisk.core.utils.Constants; -import cn.tongdun.mobrisk.providers.InfoProvider; /** * @description: Memory info Provider @@ -15,47 +10,26 @@ * @date: 2022/12/6 */ @Deprecated(since = "pro no such class") -public class MemoryInfoProvider extends InfoProvider { +public class MemoryInfoProvider { private final JSONObject mDeviceInfo; + public MemoryInfoProvider(JSONObject deviceInfo) { mDeviceInfo = deviceInfo.optJSONObject(Constants.KEY_DEVICE_DETAIL); } - private String getTotalMemory() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_TOTAL_MEMORY); - } - - private String getAvailableMemory() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_AVAILABLE_MEMORY); - } - - private String getTotalStorage() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_TOTAL_STORAGE); + public long getTotalMemory() { + return mDeviceInfo.optLong(Constants.KEY_TOTAL_MEMORY); } - private String getAvailableStorage() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_AVAILABLE_STORAGE); + public long getAvailableMemory() { + return mDeviceInfo.optLong(Constants.KEY_AVAILABLE_MEMORY); } - @Override - public String getProviderName() { - return "Memory info"; + public long getTotalStorage() { + return mDeviceInfo.optLong(Constants.KEY_TOTAL_STORAGE); } - @Override - public List> getRawData() { - return new MemoryInfoRawData(getTotalMemory(), getAvailableMemory(),getTotalStorage(),getAvailableStorage()).loadData(); + public long getAvailableStorage() { + return mDeviceInfo.optLong(Constants.KEY_AVAILABLE_STORAGE); } } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/memory/MemoryInfoRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/memory/MemoryInfoRawData.java deleted file mode 100644 index ab71f75..0000000 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/memory/MemoryInfoRawData.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.tongdun.mobrisk.providers.memory; - -import android.util.Pair; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import cn.tongdun.mobrisk.providers.RawData; - -/** - * @description: MemoryInfoRawData - * @author: wuzuchang - * @date: 2022/12/6 - */ -@Deprecated(since = "pro no such class") -public class MemoryInfoRawData extends RawData { - String totalMemory; - String availableMemory; - String totalStorage; - String availableStorage; - - public MemoryInfoRawData(String totalMemory, String availableMemory, String totalStorage, String availableStorage) { - this.totalMemory = totalMemory; - this.availableMemory = availableMemory; - this.totalStorage = totalStorage; - this.availableStorage = availableStorage; - } - - private String getTotalMemory() { - return String.format(Locale.US, "%.2fMB", Long.parseLong(totalMemory) / Math.pow(1024, 2)); - } - - private String getAvailableMemory() { - return String.format(Locale.US, "%.2fMB", Long.parseLong(availableMemory) / Math.pow(1024, 2)); - } - - private String getTotalStorage() { - return String.format(Locale.US, "%.2fGB", Long.parseLong(totalStorage) / Math.pow(1024, 3)); - } - - private String getAvailableStorage() { - return String.format(Locale.US, "%.2fGB", Long.parseLong(availableStorage) / Math.pow(1024, 3)); - } - - @Override - public List> loadData() { - List> data = new ArrayList<>(); - data.add(new Pair<>("total memory", getTotalMemory())); - data.add(new Pair<>("available memory", getAvailableMemory())); - data.add(new Pair<>("total storage", getTotalStorage())); - data.add(new Pair<>("available storage", getAvailableStorage())); - return data; - } -} diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/risk/RiskInfoProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/risk/RiskInfoProvider.java index 88b875f..aa8c420 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/risk/RiskInfoProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/risk/RiskInfoProvider.java @@ -1,9 +1,10 @@ package cn.tongdun.mobrisk.providers.risk; -import android.util.Pair; +import android.text.TextUtils; import org.json.JSONObject; +import java.util.ArrayList; import java.util.List; import cn.tongdun.mobrisk.core.utils.Constants; @@ -15,49 +16,55 @@ * @date: 2022/12/6 */ @Deprecated(since = "pro no such class") -public class RiskInfoProvider extends InfoProvider { +public class RiskInfoProvider { private final JSONObject mDeviceInfo; public RiskInfoProvider(JSONObject deviceInfo) { mDeviceInfo = deviceInfo.optJSONObject(Constants.KEY_DEVICE_RISK_LABEL); } - private String getRoot() { + private boolean getRoot() { if (mDeviceInfo == null) { - return ""; + return false; } - return mDeviceInfo.optString(Constants.KEY_ROOT); + return mDeviceInfo.optBoolean(Constants.KEY_ROOT); } - private String getDebug() { + private boolean getDebug() { if (mDeviceInfo == null) { - return ""; + return false; } - return mDeviceInfo.optString(Constants.KEY_DEBUG); + return mDeviceInfo.optBoolean(Constants.KEY_DEBUG); } - private String getMultiple() { + private boolean getMultiple() { if (mDeviceInfo == null) { - return ""; + return false; } - return mDeviceInfo.optString(Constants.KEY_MULTIPLE); + return mDeviceInfo.optBoolean(Constants.KEY_MULTIPLE); } - private String getXposedStatus() { + private boolean getXposedStatus() { if (mDeviceInfo == null) { - return ""; + return false; } - return mDeviceInfo.optString(Constants.KEY_XPOSED); + return mDeviceInfo.optBoolean(Constants.KEY_XPOSED); } - - @Override - public String getProviderName() { - return "Risk info"; - } - - @Override - public List> getRawData() { - return new RiskInfoRawData(getRoot(), getDebug(), getMultiple(), getXposedStatus()).loadData(); + public String getRiskLabels() { + List riskLabels = new ArrayList<>(); + if (getRoot()) { + riskLabels.add("root"); + } + if (getDebug()) { + riskLabels.add("debug"); + } + if (getMultiple()) { + riskLabels.add("multiple"); + } + if (getXposedStatus()) { + riskLabels.add("Xposed"); + } + return TextUtils.join(",", riskLabels); } } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/risk/RiskInfoRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/risk/RiskInfoRawData.java deleted file mode 100644 index f03473a..0000000 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/risk/RiskInfoRawData.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.tongdun.mobrisk.providers.risk; - -import android.util.Pair; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import cn.tongdun.mobrisk.providers.RawData; - -/** - * @description: RiskInfoRawData - * @author: wuzuchang - * @date: 2022/12/6 - */ -@Deprecated(since = "pro no such class") -public class RiskInfoRawData extends RawData { - private String root; - private String debug; - private String multiple; - private String xposed; - - public RiskInfoRawData(String root, String debug, String multiple, String xposed) { - this.root = root; - this.debug = debug; - this.multiple = multiple; - this.xposed = xposed; - } - - private String getRoot() { - return root; - } - - private String getDebug() { - return debug; - } - - private String getMultiple() { - return multiple; - } - - private String getXposedStatus() { - return xposed; - } - - @Override - public List> loadData() { - List> data = new ArrayList<>(); - data.add(new Pair<>("root", getRoot())); - data.add(new Pair<>("debug", getDebug())); - data.add(new Pair<>("multiple", getMultiple())); - data.add(new Pair<>("xposed", getXposedStatus())); - return data; - } -} diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/screen/ScreenInfoProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/screen/ScreenInfoProvider.java deleted file mode 100644 index f617ffb..0000000 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/screen/ScreenInfoProvider.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.tongdun.mobrisk.providers.screen; - -import android.util.Pair; - -import org.json.JSONObject; - -import java.util.List; - -import cn.tongdun.mobrisk.core.utils.Constants; -import cn.tongdun.mobrisk.providers.InfoProvider; - -/** - * @description: Screen info Provider - * @author: wuzuchang - * @date: 2022/12/6 - */ -@Deprecated(since = "pro no such class") -public class ScreenInfoProvider extends InfoProvider { - private final JSONObject mDeviceInfo; - - public ScreenInfoProvider(JSONObject deviceInfo) { - mDeviceInfo = deviceInfo.optJSONObject(Constants.KEY_DEVICE_DETAIL); - } - - private String getScreenResolution() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_SCREEN_RESOLUTION); - } - - private String getScreenInches() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_SCREEN_INCHES); - } - - private String getScreenBrightness() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_SCREEN_BRIGHTNESS); - } - - private String getScreenOffTimeout() { - if (mDeviceInfo == null) { - return ""; - } - return mDeviceInfo.optString(Constants.KEY_SCREEN_OFF_TIMEOUT); - } - - @Override - public String getProviderName() { - return "Screen info"; - } - - @Override - public List> getRawData() { - return new ScreenInfoRawData(getScreenResolution(), getScreenInches(), getScreenBrightness(), getScreenOffTimeout()).loadData(); - } -} diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/screen/ScreenInfoRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/screen/ScreenInfoRawData.java deleted file mode 100644 index 5482356..0000000 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/screen/ScreenInfoRawData.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.tongdun.mobrisk.providers.screen; - -import android.util.Pair; - -import java.util.ArrayList; -import java.util.List; - -import cn.tongdun.mobrisk.providers.RawData; - -/** - * @description: ScreenInfoRawData - * @author: wuzuchang - * @date: 2022/12/6 - */ -@Deprecated(since = "pro no such class") -public class ScreenInfoRawData extends RawData { - private String screenResolution; - private String screenInches; - private String screenBrightness; - private String screenOffTimeout; - - public ScreenInfoRawData(String screenResolution, String screenInches, String screenBrightness, String screenOffTimeout) { - this.screenResolution = screenResolution; - this.screenInches = screenInches; - this.screenBrightness = screenBrightness; - this.screenOffTimeout = screenOffTimeout; - } - - private String getScreenResolution() { - return screenResolution; - } - - private String getScreenInches() { - return screenInches; - } - - private String getScreenBrightness() { - return screenBrightness; - } - - private String getScreenOffTimeout() { - return screenOffTimeout; - } - - @Override - public List> loadData() { - List> data = new ArrayList<>(); - data.add(new Pair<>("screen resolution", getScreenResolution())); - data.add(new Pair<>("screen inches", getScreenInches())); - data.add(new Pair<>("screen brightness", getScreenBrightness())); - data.add(new Pair<>("screen Off timeout", getScreenOffTimeout())); - return data; - } -} diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/sensor/SensorInfoProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/sensor/SensorInfoProvider.java index 2a773d0..fd3f60a 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/sensor/SensorInfoProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/sensor/SensorInfoProvider.java @@ -15,27 +15,25 @@ * @date: 2022/12/6 */ @Deprecated(since = "pro no such class") -public class SensorInfoProvider extends InfoProvider { +public class SensorInfoProvider{ private final JSONObject mDeviceInfo; public SensorInfoProvider(JSONObject deviceInfo) { mDeviceInfo = deviceInfo.optJSONObject(Constants.KEY_DEVICE_DETAIL); } - private String getSensorInfo() { + public int getSensorTotal() { if (mDeviceInfo == null) { - return ""; + return 0; } - return mDeviceInfo.optString(Constants.KEY_SENSORS_INFO); + return mDeviceInfo.optString(Constants.KEY_SENSORS_INFO).split(",").length; } - @Override - public String getProviderName() { - return "Sensor info"; + public String getSensorInfo() { + if (mDeviceInfo == null) { + return ""; + } + return mDeviceInfo.optString(Constants.KEY_SENSORS_INFO); } - @Override - public List> getRawData() { - return new SensorInfoRawData(getSensorInfo()).loadData(); - } } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/sensor/SensorInfoRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/sensor/SensorInfoRawData.java deleted file mode 100644 index ef3b31f..0000000 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/sensor/SensorInfoRawData.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.tongdun.mobrisk.providers.sensor; - -import android.util.Pair; - -import java.util.ArrayList; -import java.util.List; - -import cn.tongdun.mobrisk.providers.RawData; - -/** - * @description: SensorInfoRawData - * @author: wuzuchang - * @date: 2022/12/6 - */ -@Deprecated(since = "pro no such class") -public class SensorInfoRawData extends RawData { - private String sensorInfo; - - public SensorInfoRawData(String sensorInfo) { - this.sensorInfo = sensorInfo; - } - - private String[] getSensorInfo() { - return sensorInfo.split(","); - } - - @Override - public List> loadData() { - List> data = new ArrayList<>(); - for (String sensorInfo : getSensorInfo()) { - String[] sensor = sensorInfo.split(":"); - if (sensor.length >= 2) { - data.add(new Pair<>(sensor[0], sensor[1])); - } - } - return data; - } -} diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoProvider.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoProvider.java index 49e2055..f0f500d 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoProvider.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoProvider.java @@ -78,6 +78,13 @@ private String getTouchExplorationEnabled() { return mDeviceInfo.optString(Constants.KEY_TOUCH_EXPLORATION_ENABLED); } + private int getScreenOffTimeout() { + if (mDeviceInfo == null) { + return 0; + } + return mDeviceInfo.optInt(Constants.KEY_SCREEN_OFF_TIMEOUT); + } + @Override public String getProviderName() { return "Setting info"; @@ -85,6 +92,6 @@ public String getProviderName() { @Override public List> getRawData() { - return new SettingInfoRawData(getAdbEnable(), getDevelopmentSettingEnabled(), getHttpProxy(), getDataRoaming(), getAllowMockLocation(), getAccessibilityEnabled(), getDefaultInputMethod(), getTouchExplorationEnabled()).loadData(); + return new SettingInfoRawData(getAdbEnable(), getDevelopmentSettingEnabled(), getHttpProxy(), getDataRoaming(), getAllowMockLocation(), getAccessibilityEnabled(), getDefaultInputMethod(), getTouchExplorationEnabled(),getScreenOffTimeout()).loadData(); } } diff --git a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoRawData.java b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoRawData.java index c5e6575..00d957d 100644 --- a/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoRawData.java +++ b/trustdevice/src/main/java/cn/tongdun/mobrisk/providers/setting/SettingInfoRawData.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import cn.tongdun.mobrisk.providers.RawData; @@ -22,8 +23,9 @@ public class SettingInfoRawData extends RawData { private String accessibilityEnabled; private String defaultInputMethod; private String touchExplorationEnabled; + private int screenOffTimeout; - public SettingInfoRawData(String adbEnable, String developmentSettingEnabled, String httpProxy, String dataRoaming, String allowMockLocation, String accessibilityEnabled, String defaultInputMethod, String touchExplorationEnabled) { + public SettingInfoRawData(String adbEnable, String developmentSettingEnabled, String httpProxy, String dataRoaming, String allowMockLocation, String accessibilityEnabled, String defaultInputMethod, String touchExplorationEnabled, int screenOffTimeout) { this.adbEnable = adbEnable; this.developmentSettingEnabled = developmentSettingEnabled; this.httpProxy = httpProxy; @@ -32,6 +34,7 @@ public SettingInfoRawData(String adbEnable, String developmentSettingEnabled, St this.accessibilityEnabled = accessibilityEnabled; this.defaultInputMethod = defaultInputMethod; this.touchExplorationEnabled = touchExplorationEnabled; + this.screenOffTimeout = screenOffTimeout; } private String getAdbEnable() { @@ -70,6 +73,10 @@ private String formatSwitch(String data) { return "1".equals(data) ? "open" : "close"; } + public int getScreenOffTimeout() { + return screenOffTimeout; + } + @Override public List> loadData() { List> data = new ArrayList<>(); @@ -79,6 +86,7 @@ public List> loadData() { data.add(new Pair<>("mock location", getAllowMockLocation())); data.add(new Pair<>("accessibility", getAccessibilityEnabled())); data.add(new Pair<>("touch exploration", getTouchExplorationEnabled())); + data.add(new Pair<>("screen off timeout", String.format(Locale.US, "%dS", getScreenOffTimeout() / 1000))); data.add(new Pair<>("http proxy", getHttpProxy())); data.add(new Pair<>("default inputMethod", getDefaultInputMethod())); return data;