|
|
@ -40,6 +40,7 @@ import android.os.PowerManager;
|
|
|
|
import android.os.RemoteException;
|
|
|
|
import android.os.RemoteException;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.content.FileProvider;
|
|
|
|
import androidx.core.content.FileProvider;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
@ -485,43 +486,24 @@ public class MicroPhotoService extends Service {
|
|
|
|
// private HashMap<Long, Integer> mTimers = new HashMap<Long, Integer>();
|
|
|
|
// private HashMap<Long, Integer> mTimers = new HashMap<Long, Integer>();
|
|
|
|
public boolean registerTimer(long uid, int timeout, long times) {
|
|
|
|
public boolean registerTimer(long uid, int timeout, long times) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Context context = getApplicationContext();
|
|
|
|
// 创建延迟意图
|
|
|
|
// 创建延迟意图
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
alarmIntent.setAction(ACTION_TIMEOUT);
|
|
|
|
alarmIntent.setAction(ACTION_TIMEOUT);
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
|
|
|
|
|
alarmIntent.setIdentifier(Long.toString(uid));
|
|
|
|
|
|
|
|
}
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMER_UID, uid);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMER_UID, uid);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMEOUT, timeout);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMEOUT, timeout);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMES, times);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMES, times);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_ELASPED_TIMES, 0L);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_ELASPED_TIMES, 0L);
|
|
|
|
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
|
|
mTimers.put(Long.valueOf(uid), pendingIntent);
|
|
|
|
mTimers.put(Long.valueOf(uid), pendingIntent);
|
|
|
|
return registerTimer(pendingIntent, uid, timeout);
|
|
|
|
return registerTimer(pendingIntent, uid, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setDefaultDataSubId(int subId) {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("setDefaultDataSubId", int.class);
|
|
|
|
|
|
|
|
method.invoke(subscriptionManager, subId);
|
|
|
|
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
|
|
|
|
Method method1 = telephonyManager.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
|
|
|
|
|
|
|
|
method1.invoke(telephonyManager, true);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getDefaultDataSubId() {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("getDefaultDataSubscriptionId");
|
|
|
|
|
|
|
|
return (int) method.invoke(subscriptionManager);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "wjz debug getDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) {
|
|
|
|
public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) {
|
|
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
@ -534,8 +516,18 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
public boolean unregisterTimer(long uid) {
|
|
|
|
public boolean unregisterTimer(long uid) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Context context = getApplicationContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getService(context, 0, pendingIntent., PendingIntent.FLAG_NO_CREATE);
|
|
|
|
|
|
|
|
if (pendingIntent != null && alarmManager != null) {
|
|
|
|
|
|
|
|
alarmManager.cancel(pendingIntent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
|
PendingIntent pendingIntent = mTimers.get(uidObj);
|
|
|
|
PendingIntent pendingIntent = mTimers.get(uidObj);
|
|
|
|
|
|
|
|
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
@ -1201,4 +1193,27 @@ cellSignalStrengthGsm.getDbm();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setDefaultDataSubId(int subId) {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("setDefaultDataSubId", int.class);
|
|
|
|
|
|
|
|
method.invoke(subscriptionManager, subId);
|
|
|
|
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
|
|
|
|
Method method1 = telephonyManager.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
|
|
|
|
|
|
|
|
method1.invoke(telephonyManager, true);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getDefaultDataSubId() {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("getDefaultDataSubscriptionId");
|
|
|
|
|
|
|
|
return (int) method.invoke(subscriptionManager);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "wjz debug getDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|