version:1.3

fix:
update:sos界面拨打所有电话
This commit is contained in:
2022-01-14 15:39:10 +08:00
parent b481df8671
commit be302d67e2
55 changed files with 1096 additions and 212 deletions

View File

@@ -0,0 +1,221 @@
package com.uiui.os.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.provider.Settings;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.uiui.os.R;
import com.uiui.os.bean.BaseResponse;
import com.uiui.os.network.NetInterfaceManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
public class EmergencyActivity extends AppCompatActivity {
@BindView(R.id.tv_countdown)
TextView tv_countdown;
@BindView(R.id.iv_finish)
ImageView iv_finish;
private Disposable subscribe;
private String TAG = EmergencyActivity.class.getSimpleName();
private boolean needDial = false;
private boolean isCalling = false;
private List<String> phoneListSet;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.e(TAG, "onCreate: ");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_emergency);
ButterKnife.bind(this);
Intent intent = getIntent();
// String setting_sos = intent.getStringExtra("setting_sos");
// if (TextUtils.isEmpty(setting_sos)) {
// finish();
// return;
// }
String setting_sos = Settings.System.getString(getContentResolver(), "setting_sos");
if (TextUtils.isEmpty(setting_sos)) return;
phoneListSet = new ArrayList<>(Arrays.asList(setting_sos.split(",")));
Log.e(TAG, "onCreate: " + phoneListSet);
final Long time = 3L;
subscribe = Observable.interval(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aLong -> {
Log.e("TAG", "倒计时:" + aLong);
if (aLong < time && !subscribe.isDisposed()) {
tv_countdown.setText("倒计时(" + (time - aLong - 1) + ")秒");
Log.e(TAG, "accept: " + (time - aLong - 1));
} else {
NetInterfaceManager.getInstance()
.getSOSRecordObservable()
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e("SOSRecord", "onSubscribe: ");
}
@Override
public void onNext(@NonNull BaseResponse baseResponse) {
Log.e("SOSRecord", "onNext: " + baseResponse);
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("SOSRecord", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("SOSRecord", "onComplete: ");
}
});
needDial = true;
Intent intent1 = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:" + phoneListSet.get(0));
intent1.setData(data);
startActivity(intent1);
isCalling = true;
phoneListSet.remove(0);
// finish();
subscribe.dispose();
}
});
iv_finish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
// TelephonyManager telM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// telM.listen(new PhoneStateListener() {
// /**
// * 当有精确通话状态时回调
// * Callback invoked when precise device call state changes
// * @hide 隐藏api, 给系统app使用的
// */
// public void onPreciseCallStateChanged(PreciseCallState callState) {
// //当有精确通话状态时回调
// Log.e(TAG, "onPreciseCallStateChanged: " + callState);
// }
// }, PhoneStateListener.LISTEN_PRECISE_CALL_STATE); //需要权限android.permission.READ_PRECISE_PHONE_STATE
//
// StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE);
//// mStatusBarManager.disable(StatusBarManager.DISABLE_HOME);//隐藏home键
}
@Override
protected void onStart() {
super.onStart();
Log.e(TAG, "onResume: ");
Log.e(TAG, "onResume: " + phoneListSet);
if (needDial) {
if (phoneListSet == null || phoneListSet.size() == 0) return;
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent1 = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:" + phoneListSet.get(0));
intent1.setData(data);
startActivity(intent1);
isCalling = true;
phoneListSet.remove(0);
}
}, 2000);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.e(TAG, "onDestroy: ");
if (subscribe != null) {
subscribe.dispose();
subscribe = null;
}
}
// class MobileCallReceiver extends BroadcastReceiver {
// @Override
// public void onReceive(Context context, Intent intent) {
// if (intent.getAction() == null) {
// return;
// }
//// switch (intent.getAction()) {
//// case CustomAction.PRECISE_CALL_STATE:
//// int callState = intent.getIntExtra("foreground_state", -2);
//// switch (callState) {
//// case PreciseCallState.PRECISE_CALL_STATE_IDLE:
//// Log.d(TAG, "IDLE");
//// break;
//// case PreciseCallState.PRECISE_CALL_STATE_DIALING:
//// Log.d(TAG, "DIALING");
//// break;
//// case PreciseCallState.PRECISE_CALL_STATE_ALERTING:
//// Log.d(TAG, "ALERTING isHandFree=" + isHandFree);
//// break;
//// case PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
//// Log.d(TAG, "ACTIVE");
//// break;
//// case PreciseCallState.PRECISE_CALL_STATE_INCOMING:
//// Log.d(TAG, "INCOMING来电");
//// break;
//// case PreciseCallState.PRECISE_CALL_STATE_DISCONNECTING:
//// Log.d(TAG, "DISCONNECTING");
//// break;
//// case PreciseCallState.PRECISE_CALL_STATE_DISCONNECTED:
//// Log.d(TAG, "DISCONNECTED");
//// break;
//// }
//// break;
//// case TelephonyManager.ACTION_PHONE_STATE_CHANGED:
//// break;
//// }
// }
// }
//
// // 精确的九大通话状态
// public class PreciseCallState {
// public static final int PRECISE_CALL_STATE_IDLE = 0; //通话空闲
// public static final int PRECISE_CALL_STATE_ACTIVE = 1; //正在通话(活动中)
// public static final int PRECISE_CALL_STATE_HOLDING = 2; //通话挂起(例如我和多个人通话,其中一个通话在活动,而其它通话就会进入挂起状态)
// public static final int PRECISE_CALL_STATE_DIALING = 3; //拨号开始
// public static final int PRECISE_CALL_STATE_ALERTING = 4; //正在呼出(提醒对方接电话)
// public static final int PRECISE_CALL_STATE_INCOMING = 5; //对方来电
// public static final int PRECISE_CALL_STATE_WAITING = 6; //第三方来电等待(例如我正在和某人通话,而其他人打入时就会就进入等待状态)
// public static final int PRECISE_CALL_STATE_DISCONNECTED = 7; //挂断完成
// public static final int PRECISE_CALL_STATE_DISCONNECTING = 8; //正在挂断
// }
}

View File

@@ -7,14 +7,12 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.KeyEvent;
@@ -26,7 +24,9 @@ import androidx.viewpager.widget.ViewPager;
import com.alarmclock.uiui.IAlarmAidlInterface;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.uiui.os.BuildConfig;
import com.uiui.os.R;
import com.uiui.os.base.BaseActivity;
import com.uiui.os.bean.AlarmItem;
@@ -35,8 +35,9 @@ import com.uiui.os.fragment.AppListFragment;
import com.uiui.os.fragment.BaseFragmentPagerAdapter;
import com.uiui.os.fragment.CustomFragment;
import com.uiui.os.network.NetInterfaceManager;
import com.uiui.os.service.MainService;
import com.uiui.os.utils.APKUtils;
import com.uiui.os.utils.TimeUtils;
import com.uiui.os.utils.AppUsedTimeUtils;
import com.uiui.os.utils.Utils;
import com.uiui.os.view.ScaleCircleNavigator;
@@ -106,7 +107,7 @@ public class MainActivity extends BaseActivity {
try {
String json = mIAlarmAidlInterface.getAlarm();
Log.e(TAG, "onServiceConnected: " + json);
if (json.equalsIgnoreCase("暂无闹钟")) {
if ("暂无闹钟".equalsIgnoreCase(json) || TextUtils.isEmpty(json)) {
customFragment.setAlarmItem(null);
return;
}
@@ -140,6 +141,7 @@ public class MainActivity extends BaseActivity {
@Override
public void initData() {
registmNewAppReceiver();
registerSOSNumberReceiver();
fragments.add(customFragment);
ArrayList<ApplicationInfo> applicationInfoList = APKUtils.queryFilterAppInfo(this);
int x = 0;
@@ -239,63 +241,108 @@ public class MainActivity extends BaseActivity {
}
}
private NewAppReceiver mNewAppReceiver;
@Override
protected void onStart() {
super.onStart();
AppUsedTimeUtils.getInstance().setAppPackageName(BuildConfig.APPLICATION_ID);
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
getAlarmData();
}
@Override
protected void onResume() {
super.onResume();
String packagename = TimeUtils.getInstance().getAppPackageName();
Log.e("SendcloseApp", "packagename=" + packagename);
TimeUtils.getInstance().setEndTime(System.currentTimeMillis());
if (packagename != null && packagename.length() > 0) {
ApplicationInfo app = APKUtils.getApplicationInfo(this, packagename);
PackageManager pm = getPackageManager();
if (app != null) {
Log.e(TAG, "onResume: " + app.loadLabel(pm).toString());
Log.e(TAG, "onResume: " + app.packageName);
NetInterfaceManager.getInstance().getAppUsageRecordControl()
.sendappUsageRecord(Utils.getSerial(),
app.loadLabel(pm).toString(), app.packageName,
TimeUtils.getInstance().getStartTime() / 1000,
TimeUtils.getInstance().getEndTime() / 1000)
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("onResume", "onSubscribe: ");
}
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("onResume", "onNext: " + baseResponse);
}
@Override
public void onError(Throwable e) {
Log.e("onResume", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("onResume", "onComplete: ");
}
});
TimeUtils.getInstance().setAppPackageName("");
} else {
Log.e("fht", "app = null" + packagename);
}
}
getAlarmData();
SendRunningApp(MainActivity.this);
}
private void SendRunningApp(Context context) {
AppUsedTimeUtils.getInstance().setAppPackageName(BuildConfig.APPLICATION_ID);
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
long time = AppUsedTimeUtils.getInstance().getStartTime();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("app_package", BuildConfig.APPLICATION_ID);
jsonObject.addProperty("version_name", APKUtils.getAPPVersionName(context, BuildConfig.APPLICATION_ID));
jsonObject.addProperty("start_time", time / 1000);
String jsonString = jsonObject.toString();
Log.e(TAG, "SendRunningApp: " + jsonString);
NetInterfaceManager.getInstance()
.getRunningAppObservable(jsonString)
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("SendRunningApp", "onSubscribe: ");
}
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("SendRunningApp", "onSubscribe: " + baseResponse);
}
@Override
public void onError(Throwable e) {
Log.e("SendRunningApp", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("SendRunningApp", "onComplete: ");
}
});
}
@Override
protected void onRestart() {
super.onRestart();
AppUsedTimeUtils.getInstance().setEndTime(System.currentTimeMillis());
String packagename = AppUsedTimeUtils.getInstance().getAppPackageName();
Log.e(TAG, "onRestart packagename == " + packagename);
if (!TextUtils.isEmpty(packagename)) {
Log.e(TAG, "onRestart: " + APKUtils.getAppNameByPackage(MainActivity.this, packagename));
Log.e(TAG, "onRestart: " + packagename);
NetInterfaceManager.getInstance().getAppUsageRecordControl()
.sendappUsageRecord(Utils.getSerial(),
APKUtils.getAppNameByPackage(MainActivity.this, packagename),
packagename,
AppUsedTimeUtils.getInstance().getStartTime() / 1000,
AppUsedTimeUtils.getInstance().getEndTime() / 1000)
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("sendappUsageRecord", "onSubscribe: ");
}
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("sendappUsageRecord", "onNext: " + baseResponse);
}
@Override
public void onError(Throwable e) {
Log.e("sendappUsageRecord", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("sendappUsageRecord", "onComplete: ");
}
});
} else {
Log.e("onRestart", "app = null" + packagename);
}
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onStop() {
super.onStop();
AppUsedTimeUtils.getInstance().setEndTime(System.currentTimeMillis());
}
private void registmNewAppReceiver() {
@@ -309,6 +356,8 @@ public class MainActivity extends BaseActivity {
registerReceiver(mNewAppReceiver, filter);
}
private NewAppReceiver mNewAppReceiver;
class NewAppReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
@@ -320,4 +369,26 @@ public class MainActivity extends BaseActivity {
}
}
}
private SOSNumberReceiver sosNumberReceiver;
private void registerSOSNumberReceiver() {
if (sosNumberReceiver == null) {
sosNumberReceiver = new SOSNumberReceiver();
}
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction("setting_sos");
registerReceiver(sosNumberReceiver, filter);
}
class SOSNumberReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "onReceive: " + intent.getAction());
String setting_sos = intent.getStringExtra("setting_sos");
if (TextUtils.isEmpty(setting_sos)) return;
customFragment.setSosNumber();
}
}
}

View File

@@ -0,0 +1,67 @@
package com.uiui.os.adapter;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
import com.uiui.os.R;
import com.uiui.os.activity.EmergencyActivity;
import com.uiui.os.bean.AlarmItem;
import java.util.List;
public class SOSNnmberAdapter extends RecyclerView.Adapter<SOSNnmberAdapter.ViewHolder> {
private List<String> phoneNumberList;
private Context mContext;
public void setPhoneNumberList(List<String> phoneList) {
this.phoneNumberList = phoneList;
notifyDataSetChanged();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
mContext = parent.getContext();
return new SOSNnmberAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sosnumber, parent, false));
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
String phone = phoneNumberList.get(position);
holder.tv_number.setText(phone);
holder.root.setOnClickListener(v -> {
Intent intent = new Intent(mContext, EmergencyActivity.class);
intent.putExtra("setting_sos", phone);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
});
}
@Override
public int getItemCount() {
return phoneNumberList == null ? 0 : phoneNumberList.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
TextView tv_number;
TextView tv_dial;
ConstraintLayout root;
ViewHolder(@NonNull View itemView) {
super(itemView);
tv_number = itemView.findViewById(R.id.tv_number);
tv_dial = itemView.findViewById(R.id.tv_dial);
root = itemView.findViewById(R.id.root);
}
}
}

View File

@@ -16,7 +16,7 @@ import com.uiui.os.network.NetInterfaceManager;
import com.uiui.os.service.MainService;
import com.uiui.os.utils.AlarmUtils;
import com.uiui.os.utils.AmapManager;
import com.uiui.os.utils.TimeUtils;
import com.uiui.os.utils.AppUsedTimeUtils;
public class BaseApplication extends Application {
@@ -51,7 +51,7 @@ public class BaseApplication extends Application {
Aria.init(this);
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
TimeUtils.init(this);
AppUsedTimeUtils.init(this);
AlarmUtils.init(this);
HeConfig.init("HE2111041506381545", "32b5ec69545e44119583a5e0ed4e87df");
AmapManager.init(this);

View File

@@ -24,7 +24,7 @@ import com.uiui.os.network.NetInterfaceManager;
import com.uiui.os.utils.APKUtils;
import com.uiui.os.utils.BitmapUtils;
import com.uiui.os.utils.IconUtils;
import com.uiui.os.utils.TimeUtils;
import com.uiui.os.utils.AppUsedTimeUtils;
import com.uiui.os.view.MyGridLayout;
import java.util.ArrayList;
@@ -125,6 +125,7 @@ public class AppListFragment extends Fragment {
String val = IconUtils.appIconList.get(i);
int resID = getActivity().getResources().getIdentifier(val, "drawable", "com.uiui.os");
if (resID == 0) {
Log.e(TAG, "getView: not found src : " + applicationInfo.packageName);
iv.setImageDrawable(applicationInfo.loadIcon(pm));
} else {
iv.setImageDrawable(getActivity().getResources().getDrawable(resID));
@@ -154,8 +155,8 @@ public class AppListFragment extends Fragment {
ApplicationInfo applicationInfo = applicationInfos.get(index);
if (applicationInfo != null) {
APKUtils.openPackage(v.getContext(), applicationInfo.packageName);
TimeUtils.getInstance().setAppPackageName(applicationInfo.packageName);
TimeUtils.getInstance().setStartTime(System.currentTimeMillis());
AppUsedTimeUtils.getInstance().setAppPackageName(applicationInfo.packageName);
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
SendRunningApp(getActivity());
}
}
@@ -163,8 +164,8 @@ public class AppListFragment extends Fragment {
}
private void SendRunningApp(Context context) {
String packageName = TimeUtils.getInstance().getAppPackageName();
long time = TimeUtils.getInstance().getStartTime();
String packageName = AppUsedTimeUtils.getInstance().getAppPackageName();
long time = AppUsedTimeUtils.getInstance().getStartTime();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("app_package", packageName);
jsonObject.addProperty("version_name", APKUtils.getAPPVersionName(context, packageName));

View File

@@ -2,6 +2,7 @@ package com.uiui.os.fragment;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -41,10 +42,14 @@ import com.qweather.sdk.view.QWeather;
import com.tencent.mmkv.MMKV;
import com.uiui.os.BuildConfig;
import com.uiui.os.R;
import com.uiui.os.activity.EmergencyActivity;
import com.uiui.os.adapter.AlarmClockAdapter;
import com.uiui.os.adapter.NotificationAdapter;
import com.uiui.os.adapter.SOSNnmberAdapter;
import com.uiui.os.bean.AlarmClockData;
import com.uiui.os.bean.AlarmItem;
import com.uiui.os.bean.BaseResponse;
import com.uiui.os.network.NetInterfaceManager;
import com.uiui.os.utils.AmapManager;
import com.uiui.os.utils.APKUtils;
import com.uiui.os.utils.AppUtil;
@@ -52,10 +57,15 @@ import com.uiui.os.utils.Utils;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
/**
@@ -88,6 +98,15 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
TextView wifi_ssid;
@BindView(R.id.cl_wifi)
ConstraintLayout cl_wifi;
@BindView(R.id.iv_sos)
ImageView iv_sos;
@BindView(R.id.rv_sos)
RecyclerView rv_sos;
@BindView(R.id.cl_sos)
ConstraintLayout cl_soso;
@BindView(R.id.iv_note_nodata)
ImageView iv_note_nodata;
private String TAG = CustomFragment.class.getSimpleName();
private int[] mShaderColors = new int[]{0xFFfa3db5, 0xFFF8867E, 0xFFF79F6B, 0xFFF79F6B, 0xFFF79F6B, 0xFFF8867E, 0xFFfa3db5};
@@ -95,7 +114,10 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
private List<AlarmItem> alarmItemList;
private NotificationAdapter notificationAdapter;
private AlarmClockAdapter alarmClockAdapter;
private SOSNnmberAdapter sosNnmberAdapter;
private MMKV mmkv;
private Context context;
private ContentResolver mCRv;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@@ -227,11 +249,11 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
if (rootView != null) {
iv_charging.setVisibility(View.VISIBLE);
// iv_charging.setVisibility(View.VISIBLE);
}
} else {
if (rootView != null) {
iv_charging.setVisibility(View.GONE);
// iv_charging.setVisibility(View.GONE);
}
}
}
@@ -243,6 +265,8 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootView = inflater.inflate(R.layout.fragment_custom, container, false);
context = rootView.getContext();
mCRv = context.getContentResolver();
ButterKnife.bind(this, rootView);
initView();
initData();
@@ -281,10 +305,42 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
alarmClockAdapter = new AlarmClockAdapter();
rv_clock.setLayoutManager(new LinearLayoutManager(getActivity()));
rv_clock.setAdapter(alarmClockAdapter);
sosNnmberAdapter = new SOSNnmberAdapter();
rv_sos.setLayoutManager(new LinearLayoutManager(getActivity()));
rv_sos.setAdapter(sosNnmberAdapter);
cl_soso.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), EmergencyActivity.class);
// intent.putExtra("setting_sos", phone);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(intent);
}
});
setAlarm();
refreshMemory();
}
@Override
public void onResume() {
super.onResume();
setAlarm();
setSosNumber();
}
public void setSosNumber() {
String setting_sos = Settings.System.getString(mCRv, "setting_sos");
if (TextUtils.isEmpty(setting_sos)) {
// rv_sos.setVisibility(View.GONE);
// iv_sos.setVisibility(View.VISIBLE);
} else {
// rv_sos.setVisibility(View.VISIBLE);
// iv_sos.setVisibility(View.GONE);
List<String> phoneList = new ArrayList<>(Arrays.asList(setting_sos.split(",")));
sosNnmberAdapter.setPhoneNumberList(phoneList);
}
}
private void setAlarm() {
if (rootView == null) return;
if (alarmItemList == null) {
@@ -328,7 +384,13 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
}.getType();
Gson gson = new Gson();
List<AlarmClockData> data = gson.fromJson(jsonString, type);
List<AlarmClockData> showData = data.subList(0, 1);
notificationAdapter.setDataList(data);
recyclerView.setVisibility(View.VISIBLE);
iv_note_nodata.setVisibility(View.GONE);
} else {
recyclerView.setVisibility(View.GONE);
iv_note_nodata.setVisibility(View.VISIBLE);
}
}
@@ -369,7 +431,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
private void killBackgroundApp() {
List<String> pkgList = APKUtils.queryFilterAppList(getActivity());
List<String> pkgList = APKUtils.queryFilterAppList(context);
for (String pkg : pkgList) {
if (pkg.equalsIgnoreCase(BuildConfig.APPLICATION_ID)) continue;
killBackgroundProcesses(pkg);
@@ -380,7 +442,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
ActivityManager activityManager;
try {
activityManager = (ActivityManager)
getActivity().getSystemService(Context.ACTIVITY_SERVICE);
context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses(packageName);
Method forceStopPackage = activityManager.getClass()
.getDeclaredMethod("forceStopPackage", String.class);
@@ -395,8 +457,8 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
}
private void refreshMemory() {
long avail = AppUtil.getAvailMemory(getActivity());
long total = AppUtil.getTotalMemory(getActivity());
long avail = AppUtil.getAvailMemory(context);
long total = AppUtil.getTotalMemory(context);
int x = (int) (((total - avail) / (double) total) * 100);
cpv.setProgressColor(mShaderColors);
cpv.showAnimation(0, x, 1000);

View File

@@ -9,6 +9,7 @@ import com.uiui.os.bean.BaseResponse;
import com.uiui.os.network.api.AlarmClockApi;
import com.uiui.os.network.api.AppUsageRecordApi;
import com.uiui.os.network.api.RunNewApp;
import com.uiui.os.network.api.SOSRecord;
import com.uiui.os.network.api.SendScreenshotApi;
import com.uiui.os.utils.MD5Util;
import com.uiui.os.utils.Utils;
@@ -168,6 +169,13 @@ public class NetInterfaceManager {
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getSOSRecordObservable() {
return mRetrofit.create(SOSRecord.class)
.sendSOSRecord(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public AppUsageRecordApi getAppUsageRecordControl() {
return mRetrofit.create(AppUsageRecordApi.class);
}

View File

@@ -10,4 +10,7 @@ public class URLAddress {
public static final String RUN_NEW_APP = "app/runNewApp";
//上传截图
public static final String SEND_SCREENSHOT = "sn/uploadScreenshot";
//sos记录
public static final String SOS_RECORD = "sosRecord";
}

View File

@@ -0,0 +1,17 @@
package com.uiui.os.network.api;
import com.uiui.os.bean.BaseResponse;
import com.uiui.os.network.URLAddress;
import io.reactivex.rxjava3.core.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface SOSRecord {
@FormUrlEncoded
@POST(URLAddress.SOS_RECORD)
Observable<BaseResponse> sendSOSRecord(
@Field("sn") String sn
);
}

View File

@@ -4,6 +4,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.IBinder;
@@ -17,6 +19,7 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.DownloadTask;
import com.blankj.utilcode.util.ImageUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.uiui.os.BuildConfig;
import com.uiui.os.activity.MainContact;
import com.uiui.os.activity.MainPresenter;
import com.uiui.os.activity.NoticeActivity;
@@ -24,9 +27,10 @@ import com.uiui.os.base.BaseService;
import com.uiui.os.bean.AlarmClockData;
import com.uiui.os.bean.BaseResponse;
import com.uiui.os.network.NetInterfaceManager;
import com.uiui.os.utils.APKUtils;
import com.uiui.os.utils.CmdUtil;
import com.uiui.os.utils.ForegroundAppUtil;
import com.uiui.os.utils.TimeUtils;
import com.uiui.os.utils.AppUsedTimeUtils;
import com.uiui.os.utils.ToastUtil;
import com.uiui.os.utils.Utils;
@@ -36,9 +40,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
@@ -92,6 +94,7 @@ public class MainService extends BaseService implements MainContact.MainView, Ne
mPresenter.getAlarmClock();
registerAlarmReceiver();
registerTimeReceiver();
registerLockScreenReceiver();
}
@Override
@@ -185,7 +188,6 @@ public class MainService extends BaseService implements MainContact.MainView, Ne
private final static long ONE_HOURS_TIME = 60 * 60 * 1000;
private final static long TEN_MINUTES_TIME = 60 * 10 * 1000;
private void isScreenshot() {
//1、检测应用使用情况如果设备长时间运行一个应用超过1小时启动截屏一次。
//2、检测设备在非正常时间使用时使用第三方应用在运行10分钟后启动截屏功能一次
@@ -193,8 +195,8 @@ public class MainService extends BaseService implements MainContact.MainView, Ne
// TODO: 2021/12/20 计算当前app打开时间
String topPackageName = ForegroundAppUtil.getForegroundPackageName(MainService.this);
Log.e(TAG, "isScreenshot: " + topPackageName);
String pkg = TimeUtils.getInstance().getAppPackageName();
if (TextUtils.isEmpty(pkg)) {
String pkg = AppUsedTimeUtils.getInstance().getAppPackageName();
if (TextUtils.isEmpty(pkg)|| BuildConfig.APPLICATION_ID.equals(pkg)) {
return;
}
@@ -204,8 +206,8 @@ public class MainService extends BaseService implements MainContact.MainView, Ne
Log.e(TAG, "isScreenshot: screenOn = " + screenOn);
if (!screenOn) return;
long startTime = TimeUtils.getInstance().getStartTime();
if (TimeUtils.getInstance().isNormalTime()) {//正常时间段
long startTime = AppUsedTimeUtils.getInstance().getStartTime();
if (AppUsedTimeUtils.getInstance().isNormalTime()) {//正常时间段
if (System.currentTimeMillis() - startTime >= ONE_HOURS_TIME) {
Log.e(TAG, "isScreenshot: " + "截图");
doscreenshot(this);
@@ -253,21 +255,21 @@ public class MainService extends BaseService implements MainContact.MainView, Ne
if (!file.exists()) {
throw new FileNotFoundException(filePath);
}
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
if (bitmap.getWidth() < bitmap.getHeight()) {
bitmap = ImageUtils.rotate(bitmap, -90, bitmap.getWidth(), bitmap.getHeight());
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
int x;
byte[] b = new byte[1024 * 100];
while ((x = is.read(b)) != -1) {
fos.write(b, 0, x);
}
fos.close();
// Bitmap bitmap = BitmapFactory.decodeFile(filePath);
// if (bitmap.getWidth() < bitmap.getHeight()) {
// bitmap = ImageUtils.rotate(bitmap, -90, bitmap.getWidth(), bitmap.getHeight());
// }
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
// file.createNewFile();
// FileOutputStream fos = new FileOutputStream(file);
// InputStream is = new ByteArrayInputStream(baos.toByteArray());
// int x;
// byte[] b = new byte[1024 * 100];
// while ((x = is.read(b)) != -1) {
// fos.write(b, 0, x);
// }
// fos.close();
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
return getSendFile(filePath, body);
@@ -298,6 +300,89 @@ public class MainService extends BaseService implements MainContact.MainView, Ne
});
}
private LockScreenReceiver lockScreenReceiver;
private void registerLockScreenReceiver() {
if (lockScreenReceiver == null) {
lockScreenReceiver = new LockScreenReceiver();
}
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(Intent.ACTION_USER_PRESENT);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(lockScreenReceiver, filter);
}
static class LockScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (TextUtils.isEmpty(action)) return;
Log.e(TAG, "onReceive: " + action);
switch (action) {
default:
break;
case Intent.ACTION_USER_PRESENT:
resetStartTime(context);
break;
case Intent.ACTION_SCREEN_ON:
break;
case Intent.ACTION_SCREEN_OFF:
//关闭屏幕上传数据
sendAppUsed(context);
break;
}
}
}
private static void resetStartTime(Context context) {
String topPackageName = ForegroundAppUtil.getForegroundPackageName(context);
Log.e(TAG, "resetStartTime: " + topPackageName);
AppUsedTimeUtils.getInstance().setAppPackageName(topPackageName);
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
}
private static void sendAppUsed(Context context) {
String packagename = AppUsedTimeUtils.getInstance().getAppPackageName();
Log.e(TAG, "onResume packagename == " + packagename);
// AppUsedTimeUtils.getInstance().setEndTime(System.currentTimeMillis());
if (!TextUtils.isEmpty(packagename)) {
NetInterfaceManager.getInstance().getAppUsageRecordControl()
.sendappUsageRecord(Utils.getSerial(),
APKUtils.getAppNameByPackage(context, packagename),
packagename,
AppUsedTimeUtils.getInstance().getStartTime() / 1000,
AppUsedTimeUtils.getInstance().getEndTime() / 1000)
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("sendAppUsed", "onSubscribe: ");
}
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("sendAppUsed", "onNext: " + baseResponse);
}
@Override
public void onError(Throwable e) {
Log.e("sendAppUsed", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("sendAppUsed", "onComplete: ");
}
});
} else {
Log.e("fht", "app = null" + packagename);
}
}
//在这里处理任务执行中的状态,如进度进度条的刷新
@Download.onTaskRunning
protected void running(DownloadTask task) {

View File

@@ -13,14 +13,24 @@ import android.util.Log;
import com.uiui.os.BuildConfig;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
public class APKUtils {
private static String[] excludePackageName = {BuildConfig.APPLICATION_ID};
private static HashSet<String> excludePackageName = new HashSet<String>() {{
this.add(BuildConfig.APPLICATION_ID);
this.add("org.chromium.browser");
this.add("com.sprd.sprdnote");
this.add("com.android.deskclock");
this.add("com.alldocube.store");
}};
private static String TAG = APKUtils.class.getSimpleName();
public static ArrayList<ApplicationInfo> queryFilterAppInfo(Context context) {
@@ -37,6 +47,7 @@ public class APKUtils {
List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);
Set<String> allowPackages = new HashSet();
for (ResolveInfo resolveInfo : resolveinfoList) {
Log.i(TAG, "queryFilterAppInfo: " + resolveInfo.activityInfo.packageName);
allowPackages.add(resolveInfo.activityInfo.packageName);
}
@@ -48,11 +59,28 @@ public class APKUtils {
// if(app.uid > 10000){//通过uid排除系统应用在一些手机上效果不好
// applicationInfos.add(app);
// }
if (allowPackages.contains(app.packageName) && !Arrays.asList(excludePackageName).contains(app.packageName)) {
if (allowPackages.contains(app.packageName) && !excludePackageName.contains(app.packageName)) {
// if (allowPackages.contains(app.packageName)) {
applicationInfos.add(app);
}
}
applicationInfos.sort(new Comparator<ApplicationInfo>() {
@Override
public int compare(ApplicationInfo o1, ApplicationInfo o2) {
return Collator.getInstance(Locale.CHINESE).compare(o1.loadLabel(pm).toString(),o2.loadLabel(pm).toString());
// return o1.loadLabel(pm).toString().compareTo(o2.loadLabel(pm).toString());
}
});
applicationInfos.sort(new Comparator<ApplicationInfo>() {
@Override
public int compare(ApplicationInfo o1, ApplicationInfo o2) {
if ((o1.flags & ApplicationInfo.FLAG_SYSTEM) <= (o2.flags & ApplicationInfo.FLAG_SYSTEM)) {
return 1;
} else {
return -1;
}
}
});
return applicationInfos;
}
@@ -180,4 +208,15 @@ public class APKUtils {
return versionName;
}
public static String getAppNameByPackage(Context context, String pkg) {
PackageManager packageManager = context.getPackageManager();
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(pkg, PackageManager.GET_META_DATA);
String packageName = packageManager.getApplicationLabel(applicationInfo).toString();
return packageName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "";
}
}

View File

@@ -0,0 +1,169 @@
package com.uiui.os.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
public class AppUsedTimeUtils {
private static final String TAG = AppUsedTimeUtils.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
private static AppUsedTimeUtils sInstance;
private Context mContext;
private SimpleDateFormat ruleSDF = new SimpleDateFormat("HH:mm:ss");
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private AppTimeinfo appTimeinfo;
private AppUsedTimeUtils(Context context) {
this.mContext = context;
appTimeinfo = getAppTimeinfo();
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new AppUsedTimeUtils(context);
}
}
public static AppUsedTimeUtils getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init TimeUtils first");
}
return sInstance;
}
private static String normalStartTime = "8:00:00";
private static String unusualStartTime = "22:00:00";
static class AppTimeinfo implements Serializable {
private static final long serialVersionUID = 5373751133823666192L;
AppTimeinfo() {
this.appPackageName = "";
this.endTime = 0;
this.startTime = 0;
}
private String appPackageName;
private long endTime;
private long startTime;
public String getAppPackageName() {
return appPackageName;
}
public void setAppPackageName(String appPackageName) {
this.appPackageName = appPackageName;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(long endTime) {
this.endTime = endTime;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
@NonNull
@Override
public String toString() {
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
}
}
synchronized public void setAppPackageName(String name) {
appTimeinfo.setAppPackageName(name);
setAppTimeinfo();
}
synchronized public String getAppPackageName() {
return appTimeinfo.getAppPackageName();
}
synchronized public void setStartTime(long time) {
appTimeinfo.setStartTime(time);
setAppTimeinfo();
}
synchronized public long getStartTime() {
return appTimeinfo.getStartTime();
}
synchronized public void setEndTime(long time) {
appTimeinfo.setEndTime(time);
setAppTimeinfo();
}
synchronized public long getEndTime() {
return appTimeinfo.getEndTime();
}
synchronized private AppTimeinfo getAppTimeinfo() {
String jsonString = Settings.System.getString(mContext.getContentResolver(), "runningAppInfo");
if (TextUtils.isEmpty(jsonString)) {
return new AppTimeinfo();
}
Log.e(TAG, "getAppTimeinfo: " + jsonString);
Type type = new TypeToken<AppTimeinfo>() {
}.getType();
Gson gson = new Gson();
AppTimeinfo appTimeinfo = gson.fromJson(jsonString, type);
return appTimeinfo;
}
synchronized private void setAppTimeinfo() {
String jsonString = JsonParser.parseString(appTimeinfo.toString()).getAsJsonObject().toString();
Settings.System.putString(mContext.getContentResolver(), "runningAppInfo", jsonString);
}
private static final long DAY_TIME = 1000 * 60 * 60 * 24;
public boolean isNormalTime() {
long nowTime = System.currentTimeMillis();
String nowTimeString = ruleSDF.format(new Date(nowTime)); // 时间戳转换日期
try {
Date startDate = ruleSDF.parse(normalStartTime);
Date endDate = ruleSDF.parse(unusualStartTime);
Date now = ruleSDF.parse(nowTimeString);
Log.e(TAG, "isScreenshot: startDate = " + startDate);
Log.e(TAG, "isScreenshot: endDate = " + endDate);
Log.e(TAG, "isScreenshot: now = " + now);
if (startDate.getTime() <= now.getTime() && now.getTime() <= endDate.getTime()) {
return true;
} else if (endDate.getTime() < now.getTime() && now.getTime() <= startDate.getTime() + DAY_TIME) {
return false;
}
} catch (ParseException e) {
e.printStackTrace();
Log.e(TAG, "isScreenshot: " + e.getMessage());
}
return false;
}
}

View File

@@ -18,6 +18,7 @@ public class IconUtils {
this.add("com.android.dialer");//电话
this.add("com.android.gallery3d");//图库
this.add("com.android.mms.ui");//信息
this.add("com.android.messaging");//信息
this.add("com.android.music");//音乐
this.add("com.android.providers.downloads.ui");//下载
this.add("com.android.quicksearchbox");//搜索
@@ -45,6 +46,7 @@ public class IconUtils {
this.add("com_android_dialer");
this.add("com_android_gallery3d_app");
this.add("com_android_mms_ui");
this.add("com_android_mms_ui");
this.add("com_android_music");
this.add("com_android_providers_downloads_ui");
this.add("com_android_quicksearchbox");

View File

@@ -1,93 +0,0 @@
package com.uiui.os.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeUtils {
@SuppressLint("StaticFieldLeak")
private static TimeUtils sInstance;
private Context mContext;
private SimpleDateFormat ruleSDF = new SimpleDateFormat("HH:mm:ss");
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private String TAG = TimeUtils.class.getSimpleName();
private TimeUtils(Context context) {
this.mContext = context;
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new TimeUtils(context);
}
}
public static TimeUtils getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init TimeUtils first");
}
return sInstance;
}
private static String normalStartTime = "8:00:00";
private static String unusualStartTime = "22:00:00";
private String appPackageName;
private long endTime = 0;
private long startTime = 0;
public void setAppPackageName(String name) {
this.appPackageName = name;
}
public String getAppPackageName() {
return appPackageName;
}
public void setStartTime(long time) {
this.startTime = time;
}
public long getStartTime() {
return startTime;
}
public void setEndTime(long time) {
this.endTime = time;
}
public long getEndTime() {
return endTime;
}
private static final long DAY_TIME = 1000 * 60 * 60 * 24;
public boolean isNormalTime() {
long nowTime = System.currentTimeMillis();
String nowTimeString = ruleSDF.format(new Date(nowTime)); // 时间戳转换日期
try {
Date startDate = ruleSDF.parse(normalStartTime);
Date endDate = ruleSDF.parse(unusualStartTime);
Date now = ruleSDF.parse(nowTimeString);
Log.e(TAG, "isScreenshot: startDate = " + startDate);
Log.e(TAG, "isScreenshot: endDate = " + endDate);
Log.e(TAG, "isScreenshot: now = " + now);
if (startDate.getTime() <= now.getTime() && now.getTime() <= endDate.getTime()) {
return true;
} else if (endDate.getTime() < now.getTime() && now.getTime() <= startDate.getTime() + DAY_TIME) {
return false;
}
} catch (ParseException e) {
e.printStackTrace();
Log.e(TAG, "isScreenshot: " + e.getMessage());
}
return false;
}
}