version:1.3
fix: update:sos界面拨打所有电话
This commit is contained in:
221
app/src/main/java/com/uiui/os/activity/EmergencyActivity.java
Normal file
221
app/src/main/java/com/uiui/os/activity/EmergencyActivity.java
Normal 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; //正在挂断
|
||||
// }
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user