Refactoring

pull/207/head
M66B 3 years ago
parent 481ca4d2d0
commit ff3f9df450

@ -86,7 +86,7 @@ public class ActivityAnswer extends ActivityBase {
String html = answer.getHtml(null); String html = answer.getHtml(null);
String text = HtmlHelper.getText(context, html); String text = HtmlHelper.getText(context, html);
ClipboardManager cbm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(ActivityAnswer.this, ClipboardManager.class);
cbm.setPrimaryClip(ClipData.newHtmlText(getString(R.string.app_name), text, html)); cbm.setPrimaryClip(ClipData.newHtmlText(getString(R.string.app_name), text, html));
ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show(); ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show();

@ -354,8 +354,7 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
ServiceSynchronize.eval(context, "outbox/drafts"); ServiceSynchronize.eval(context, "outbox/drafts");
NotificationManager nm = NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("send:" + id, NotificationHelper.NOTIFICATION_TAGGED);
return message.id; return message.id;

@ -609,7 +609,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
Log.i("Collecting data"); Log.i("Collecting data");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
// Accounts // Accounts
JSONArray jaccounts = new JSONArray(); JSONArray jaccounts = new JSONArray();
@ -898,7 +898,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
JSONObject jimport = new JSONObject(json); JSONObject jimport = new JSONObject(json);
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
try { try {
db.beginTransaction(); db.beginTransaction();

@ -343,7 +343,7 @@ public class ActivitySignature extends ActivityBase {
final int start = etText.getSelectionStart(); final int start = etText.getSelectionStart();
final int end = etText.getSelectionEnd(); final int end = etText.getSelectionEnd();
ClipboardManager cbm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(this, ClipboardManager.class);
if (cbm != null && cbm.hasPrimaryClip()) { if (cbm != null && cbm.hasPrimaryClip()) {
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(this).toString(); String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(this).toString();
uri = Uri.parse(link); uri = Uri.parse(link);

@ -380,7 +380,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
if (account.notify && if (account.notify &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = EntityAccount.getNotificationChannelId(account.id); String channelId = EntityAccount.getNotificationChannelId(account.id);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
NotificationChannel channel = nm.getNotificationChannel(channelId); NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel != null) if (channel != null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, order++, R.string.title_edit_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, order++, R.string.title_edit_channel);

@ -602,7 +602,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) { if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) {
if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = EntityFolder.getNotificationChannelId(folder.id); String channelId = EntityFolder.getNotificationChannelId(folder.id);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
NotificationChannel channel = nm.getNotificationChannel(channelId); NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel == null) if (channel == null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, order++, R.string.title_create_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, order++, R.string.title_create_channel);

@ -3061,8 +3061,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onCopy() { private void onCopy() {
ClipboardManager clipboard = ClipboardManager clipboard = Helper.getSystemService(context, ClipboardManager.class);
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) if (clipboard == null)
return; return;
@ -4457,8 +4456,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onCopy() { private void onCopy() {
ClipboardManager clipboard = ClipboardManager clipboard = Helper.getSystemService(context, ClipboardManager.class);
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) if (clipboard == null)
return; return;
@ -4556,7 +4554,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
private void onNotifyContact(final TupleMessageEx message) { private void onNotifyContact(final TupleMessageEx message) {
final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
final String channelId = message.getNotificationChannelId(); final String channelId = message.getNotificationChannelId();
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibNotifyContact); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibNotifyContact);
@ -4617,7 +4615,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onActionDeleteChannel() { private void onActionDeleteChannel() {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
nm.deleteNotificationChannel(channelId); nm.deleteNotificationChannel(channelId);
} }
}); });
@ -4795,8 +4793,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (TextUtils.isEmpty(message.notes)) if (TextUtils.isEmpty(message.notes))
return; return;
ClipboardManager clipboard = ClipboardManager clipboard = Helper.getSystemService(context, ClipboardManager.class);
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) if (clipboard == null)
return; return;
@ -6339,8 +6336,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onCopyHeaders(TupleMessageEx message) { private void onCopyHeaders(TupleMessageEx message) {
ClipboardManager clipboard = ClipboardManager clipboard = Helper.getSystemService(context, ClipboardManager.class);
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) if (clipboard == null)
return; return;
@ -8232,7 +8228,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String html = HtmlHelper.toHtml((Spanned) tvText.getText(), context); String html = HtmlHelper.toHtml((Spanned) tvText.getText(), context);
String text = HtmlHelper.getText(context, html); String text = HtmlHelper.getText(context, html);
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(context, ClipboardManager.class);
cbm.setPrimaryClip(ClipData.newHtmlText(getString(R.string.app_name), text, html)); cbm.setPrimaryClip(ClipData.newHtmlText(getString(R.string.app_name), text, html));
ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show(); ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show();
} }

@ -55,7 +55,7 @@ public class AlarmManagerCompatEx {
return true; return true;
try { try {
// https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission // https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = Helper.getSystemService(context, AlarmManager.class);
return am.canScheduleExactAlarms(); return am.canScheduleExactAlarms();
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);

@ -175,7 +175,7 @@ public class ConnectionHelper {
static NetworkInfo getNetworkInfo(Context context, Network network) { static NetworkInfo getNetworkInfo(Context context, Network network) {
try { try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
return (cm == null ? null : cm.getNetworkInfo(network)); return (cm == null ? null : cm.getNetworkInfo(network));
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -197,7 +197,7 @@ public class ConnectionHelper {
state.suitable = (isMetered != null && (metered || !isMetered)); state.suitable = (isMetered != null && (metered || !isMetered));
state.active = getActiveNetwork(context); state.active = getActiveNetwork(context);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
if (state.connected && !roaming) { if (state.connected && !roaming) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
@ -215,7 +215,7 @@ public class ConnectionHelper {
if (state.roaming != null && state.roaming && rlah) if (state.roaming != null && state.roaming && rlah)
try { try {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = Helper.getSystemService(context, TelephonyManager.class);
if (tm != null) { if (tm != null) {
String sim = tm.getSimCountryIso(); String sim = tm.getSimCountryIso();
String network = tm.getNetworkCountryIso(); String network = tm.getNetworkCountryIso();
@ -242,7 +242,7 @@ public class ConnectionHelper {
boolean require_validated = prefs.getBoolean("require_validated", false); boolean require_validated = prefs.getBoolean("require_validated", false);
boolean vpn_only = prefs.getBoolean("vpn_only", false); boolean vpn_only = prefs.getBoolean("vpn_only", false);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
if (cm == null) { if (cm == null) {
Log.i("isMetered: no connectivity manager"); Log.i("isMetered: no connectivity manager");
return null; return null;
@ -381,7 +381,7 @@ public class ConnectionHelper {
} }
static Network getActiveNetwork(Context context) { static Network getActiveNetwork(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
if (cm == null) if (cm == null)
return null; return null;
@ -456,8 +456,7 @@ public class ConnectionHelper {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
return false; return false;
ConnectivityManager cm = ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) if (cm == null)
return false; return false;
@ -473,8 +472,7 @@ public class ConnectionHelper {
return null; return null;
try { try {
ConnectivityManager cm = ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) if (cm == null)
return null; return null;
@ -496,7 +494,7 @@ public class ConnectionHelper {
} }
static boolean vpnActive(Context context) { static boolean vpnActive(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
if (cm == null) if (cm == null)
return false; return false;

@ -873,7 +873,7 @@ public class ContactInfo {
private static boolean isRecoverable(Throwable ex, Context context) { private static boolean isRecoverable(Throwable ex, Context context) {
if (ex instanceof SocketTimeoutException) { if (ex instanceof SocketTimeoutException) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
return (ni == null || !ni.isConnected()); return (ni == null || !ni.isConnected());
} }

@ -189,8 +189,7 @@ class Core {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int chunk_size = prefs.getInt("chunk_size", DEFAULT_CHUNK_SIZE); int chunk_size = prefs.getInt("chunk_size", DEFAULT_CHUNK_SIZE);
NotificationManager nm = NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int retry = 0; int retry = 0;
boolean group = true; boolean group = true;
@ -2072,7 +2071,7 @@ class Core {
PendingIntent piExists = PendingIntentCompat.getForegroundService( PendingIntent piExists = PendingIntentCompat.getForegroundService(
context, ServiceSynchronize.PI_EXISTS, intent, PendingIntent.FLAG_UPDATE_CURRENT); context, ServiceSynchronize.PI_EXISTS, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = Helper.getSystemService(context, AlarmManager.class);
AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, piExists); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, piExists);
return; return;
} }
@ -4810,7 +4809,7 @@ class Core {
if (messages == null) if (messages == null)
messages = new ArrayList<>(); messages = new ArrayList<>();
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
if (nm == null) if (nm == null)
return; return;
@ -5034,7 +5033,7 @@ class Core {
if (notify_screen_on && flash) { if (notify_screen_on && flash) {
Log.i("Notify screen on"); Log.i("Notify screen on");
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager pm = Helper.getSystemService(context, PowerManager.class);
PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.WakeLock wakeLock = pm.newWakeLock(
PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
BuildConfig.APPLICATION_ID + ":notification"); BuildConfig.APPLICATION_ID + ":notification");
@ -5057,7 +5056,7 @@ class Core {
// = 0: unified // = 0: unified
// > 0: account // > 0: account
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
if (messages == null || messages.size() == 0 || nm == null) if (messages == null || messages.size() == 0 || nm == null)
return notifications; return notifications;
@ -6029,7 +6028,7 @@ class Core {
// Get existing notifications // Get existing notifications
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
try { try {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
for (StatusBarNotification sbn : nm.getActiveNotifications()) { for (StatusBarNotification sbn : nm.getActiveNotifications()) {
String tag = sbn.getTag(); String tag = sbn.getTag();
if (tag != null && tag.startsWith("unseen.")) { if (tag != null && tag.startsWith("unseen.")) {

@ -447,7 +447,7 @@ public abstract class DB extends RoomDatabase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int sqlite_cache = prefs.getInt("sqlite_cache", DEFAULT_CACHE_SIZE); int sqlite_cache = prefs.getInt("sqlite_cache", DEFAULT_CACHE_SIZE);
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager am = Helper.getSystemService(context, ActivityManager.class);
int class_mb = am.getMemoryClass(); int class_mb = am.getMemoryClass();
int cache_size = sqlite_cache * class_mb * 1024 / 100; int cache_size = sqlite_cache * class_mb * 1024 / 100;

@ -157,7 +157,7 @@ public class DnsHelper {
} }
if (ex == null) { if (ex == null) {
//ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); //ConnectivityManager cm = getSystemService(context, ConnectivityManager.class);
//Network active = (cm == null ? null : cm.getActiveNetwork()); //Network active = (cm == null ? null : cm.getActiveNetwork());
//LinkProperties props = (active == null ? null : cm.getLinkProperties(active)); //LinkProperties props = (active == null ? null : cm.getLinkProperties(active));
//Log.i("DNS private=" + (props == null ? null : props.isPrivateDnsActive())); //Log.i("DNS private=" + (props == null ? null : props.isPrivateDnsActive()));
@ -215,7 +215,7 @@ public class DnsHelper {
} }
private static String getDnsServer(Context context) { private static String getDnsServer(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
if (cm == null) if (cm == null)
return DEFAULT_DNS; return DEFAULT_DNS;

@ -360,7 +360,7 @@ public class EditTextCompose extends FixedEditText {
} }
Context context = getContext(); Context context = getContext();
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(context, ClipboardManager.class);
if (start != end && cbm != null) { if (start != end && cbm != null) {
CharSequence selected = getEditableText().subSequence(start, end); CharSequence selected = getEditableText().subSequence(start, end);
if (selected instanceof Spanned) { if (selected instanceof Spanned) {
@ -373,7 +373,7 @@ public class EditTextCompose extends FixedEditText {
} else if (id == android.R.id.paste) { } else if (id == android.R.id.paste) {
final Context context = getContext(); final Context context = getContext();
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(context, ClipboardManager.class);
if (cbm == null || !cbm.hasPrimaryClip()) if (cbm == null || !cbm.hasPrimaryClip())
return false; return false;

@ -123,7 +123,7 @@ public class EditTextPlain extends FixedEditText {
try { try {
if (id == android.R.id.paste) { if (id == android.R.id.paste) {
Context context = getContext(); Context context = getContext();
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(context, ClipboardManager.class);
if (cbm != null && cbm.hasPrimaryClip()) { if (cbm != null && cbm.hasPrimaryClip()) {
ClipData data = cbm.getPrimaryClip(); ClipData data = cbm.getPrimaryClip();
ClipData.Item item = (data == null ? null : data.getItemAt(0)); ClipData.Item item = (data == null ? null : data.getItemAt(0));

@ -388,7 +388,7 @@ public class EmailService implements AutoCloseable {
if (bind_socket && if (bind_socket &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
try { try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
Network active = cm.getActiveNetwork(); Network active = cm.getActiveNetwork();
if (active != null) { if (active != null) {
EntityLog.log(context, EntityLog.Type.Network, "Binding to" + EntityLog.log(context, EntityLog.Type.Network, "Binding to" +

@ -211,7 +211,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
void createNotificationChannel(Context context) { void createNotificationChannel(Context context) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
NotificationChannelGroup group = new NotificationChannelGroup("group." + id, name); NotificationChannelGroup group = new NotificationChannelGroup("group." + id, name);
nm.createNotificationChannelGroup(group); nm.createNotificationChannelGroup(group);
@ -228,7 +228,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
void deleteNotificationChannel(Context context) { void deleteNotificationChannel(Context context) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
nm.deleteNotificationChannel(getNotificationChannelId(id)); nm.deleteNotificationChannel(getNotificationChannelId(id));
} }

@ -557,7 +557,7 @@ public class EntityMessage implements Serializable {
PendingIntent pi = PendingIntentCompat.getForegroundService( PendingIntent pi = PendingIntentCompat.getForegroundService(
context, ServiceSynchronize.PI_UNSNOOZE, snoozed, PendingIntent.FLAG_UPDATE_CURRENT); context, ServiceSynchronize.PI_UNSNOOZE, snoozed, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = Helper.getSystemService(context, AlarmManager.class);
if (wakeup == null || wakeup == Long.MAX_VALUE) { if (wakeup == null || wakeup == Long.MAX_VALUE) {
Log.i("Cancel snooze id=" + id); Log.i("Cancel snooze id=" + id);
am.cancel(pi); am.cancel(pi);

@ -384,7 +384,7 @@ public class FixedTextView extends AppCompatTextView {
try { try {
if (id == android.R.id.copy) { if (id == android.R.id.copy) {
Context context = getContext(); Context context = getContext();
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(context, ClipboardManager.class);
int start = getSelectionStart(); int start = getSelectionStart();
int end = getSelectionEnd(); int end = getSelectionEnd();

@ -1313,7 +1313,7 @@ public class FragmentAccount extends FragmentBase {
ServiceSynchronize.eval(context, "save account"); ServiceSynchronize.eval(context, "save account");
if (!synchronize) { if (!synchronize) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
nm.cancel("receive:" + account.id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("receive:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
nm.cancel("alert:" + account.id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("alert:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
} }

@ -571,7 +571,7 @@ public class FragmentAnswer extends FragmentBase {
if (action == R.id.menu_link) { if (action == R.id.menu_link) {
Uri uri = null; Uri uri = null;
ClipboardManager cbm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(getContext(), ClipboardManager.class);
if (cbm != null && cbm.hasPrimaryClip()) { if (cbm != null && cbm.hasPrimaryClip()) {
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString(); String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString();
uri = Uri.parse(link); uri = Uri.parse(link);

@ -798,8 +798,7 @@ public class FragmentCompose extends FragmentBase {
if (identity == null || TextUtils.isEmpty(identity.signature)) if (identity == null || TextUtils.isEmpty(identity.signature))
return; return;
ClipboardManager clipboard = ClipboardManager clipboard = Helper.getSystemService(v.getContext(), ClipboardManager.class);
(ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) if (clipboard == null)
return; return;
@ -1345,8 +1344,7 @@ public class FragmentCompose extends FragmentBase {
if (context == null) if (context == null)
return; return;
ClipboardManager clipboard = ClipboardManager clipboard = Helper.getSystemService(context, ClipboardManager.class);
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) if (clipboard == null)
return; return;
@ -1477,7 +1475,7 @@ public class FragmentCompose extends FragmentBase {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
cm.registerNetworkCallback(builder.build(), networkCallback); cm.registerNetworkCallback(builder.build(), networkCallback);
@ -1493,7 +1491,7 @@ public class FragmentCompose extends FragmentBase {
onAction(R.id.action_save, extras, "pause"); onAction(R.id.action_save, extras, "pause");
} }
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
cm.unregisterNetworkCallback(networkCallback); cm.unregisterNetworkCallback(networkCallback);
super.onPause(); super.onPause();
@ -2347,7 +2345,7 @@ public class FragmentCompose extends FragmentBase {
if (uri == null) if (uri == null)
try { try {
ClipboardManager cbm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(getContext(), ClipboardManager.class);
if (cbm != null && cbm.hasPrimaryClip()) { if (cbm != null && cbm.hasPrimaryClip()) {
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString(); String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString();
uri = Uri.parse(link); uri = Uri.parse(link);
@ -6295,7 +6293,7 @@ public class FragmentCompose extends FragmentBase {
if (addresses == null) if (addresses == null)
return; return;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo()); NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo());
if (ani != null && ani.isConnected()) if (ani != null && ani.isConnected())
DnsHelper.checkMx(context, addresses); DnsHelper.checkMx(context, addresses);

@ -72,7 +72,7 @@ public class FragmentDialogFolder extends FragmentDialogBase {
final Context context = getContext(); final Context context = getContext();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = Helper.getSystemService(context, InputMethodManager.class);
List<String> selected_folders = new ArrayList<>(); List<String> selected_folders = new ArrayList<>();
String json = prefs.getString("selected_folders", "[]"); String json = prefs.getString("selected_folders", "[]");

@ -264,7 +264,7 @@ public class FragmentDialogForwardRaw extends FragmentDialogBase {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
cm.registerNetworkCallback(builder.build(), networkCallback); cm.registerNetworkCallback(builder.build(), networkCallback);
@ -274,7 +274,7 @@ public class FragmentDialogForwardRaw extends FragmentDialogBase {
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
cm.unregisterNetworkCallback(networkCallback); cm.unregisterNetworkCallback(networkCallback);
} }

@ -251,8 +251,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
ibCopy.setOnClickListener(new View.OnClickListener() { ibCopy.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
ClipboardManager clipboard = ClipboardManager clipboard = Helper.getSystemService(context, ClipboardManager.class);
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) if (clipboard == null)
return; return;

@ -1163,8 +1163,7 @@ public class FragmentFolders extends FragmentBase {
throw new IllegalArgumentException(context.getString(R.string.title_no_stream)); throw new IllegalArgumentException(context.getString(R.string.title_no_stream));
} }
NotificationManager nm = NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = NotificationCompat.Builder builder =
new NotificationCompat.Builder(context, "progress") new NotificationCompat.Builder(context, "progress")
.setSmallIcon(R.drawable.baseline_get_app_white_24) .setSmallIcon(R.drawable.baseline_get_app_white_24)

@ -407,7 +407,7 @@ public class FragmentGmail extends FragmentBase {
if (TextUtils.isEmpty(password)) if (TextUtils.isEmpty(password))
throw new IllegalArgumentException(context.getString(R.string.title_no_password)); throw new IllegalArgumentException(context.getString(R.string.title_no_password));
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo()); NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo());
if (ani == null || !ani.isConnected()) if (ani == null || !ani.isConnected())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet)); throw new IllegalArgumentException(context.getString(R.string.title_no_internet));

@ -4368,7 +4368,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
iff.addAction(ACTION_KEYWORDS); iff.addAction(ACTION_KEYWORDS);
lbm.registerReceiver(receiver, iff); lbm.registerReceiver(receiver, iff);
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
cm.registerNetworkCallback(builder.build(), networkCallback); cm.registerNetworkCallback(builder.build(), networkCallback);
@ -4432,7 +4432,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.unregisterOnSharedPreferenceChangeListener(this); prefs.unregisterOnSharedPreferenceChangeListener(this);
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
cm.unregisterNetworkCallback(networkCallback); cm.unregisterNetworkCallback(networkCallback);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
@ -8452,8 +8452,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
ServiceSynchronize.eval(context, "delete"); ServiceSynchronize.eval(context, "delete");
NotificationManager nm = NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("send:" + id, NotificationHelper.NOTIFICATION_TAGGED);
return null; return null;
@ -9106,7 +9105,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return; return;
} }
PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE); PrintManager printManager = Helper.getSystemService(context, PrintManager.class);
String jobName = getString(R.string.app_name); String jobName = getString(R.string.app_name);
if (!TextUtils.isEmpty(data[0])) if (!TextUtils.isEmpty(data[0]))
jobName += " - " + data[0]; jobName += " - " + data[0];

@ -748,7 +748,7 @@ public class FragmentOAuth extends FragmentBase {
} else } else
throw new IllegalArgumentException("Unknown provider=" + id); throw new IllegalArgumentException("Unknown provider=" + id);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo()); NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo());
if (ani == null || !ani.isConnected()) if (ani == null || !ani.isConnected())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet)); throw new IllegalArgumentException(context.getString(R.string.title_no_internet));

@ -325,7 +325,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
if (cm == null) if (cm == null)
return; return;
@ -338,7 +338,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
@Override @Override
public void onPause() { public void onPause() {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
if (cm == null) if (cm == null)
return; return;
@ -439,7 +439,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
if ((debug || BuildConfig.DEBUG) && if ((debug || BuildConfig.DEBUG) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
try { try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
Network active = (cm == null ? null : cm.getActiveNetwork()); Network active = (cm == null ? null : cm.getActiveNetwork());
if (active != null) { if (active != null) {
NetworkInfo ni = cm.getNetworkInfo(active); NetworkInfo ni = cm.getNetworkInfo(active);

@ -592,7 +592,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
super.onResume(); super.onResume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(getContext(), NotificationManager.class);
NotificationChannel notification = nm.getNotificationChannel("notification"); NotificationChannel notification = nm.getNotificationChannel("notification");
if (notification != null) { if (notification != null) {

@ -467,7 +467,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
prefs.edit().putString("wipe_mnemonic", mnemonic).apply(); prefs.edit().putString("wipe_mnemonic", mnemonic).apply();
tvMnemonic.setText(mnemonic); tvMnemonic.setText(mnemonic);
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cbm = Helper.getSystemService(context, ClipboardManager.class);
if (cbm == null) if (cbm == null)
return; return;

@ -629,8 +629,7 @@ public class FragmentPop extends FragmentBase {
ServiceSynchronize.eval(context, "POP3"); ServiceSynchronize.eval(context, "POP3");
if (!synchronize) { if (!synchronize) {
NotificationManager nm = NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("receive:" + account.id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("receive:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
nm.cancel("alert:" + account.id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("alert:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
} }

@ -320,7 +320,7 @@ public class FragmentQuickSetup extends FragmentBase {
int at = email.indexOf('@'); int at = email.indexOf('@');
String username = email.substring(0, at); String username = email.substring(0, at);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo()); NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo());
if (ani == null || !ani.isConnected()) if (ani == null || !ani.isConnected())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet)); throw new IllegalArgumentException(context.getString(R.string.title_no_internet));

@ -743,7 +743,7 @@ public class FragmentSetup extends FragmentBase {
updateManual(); updateManual();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
cm.registerDefaultNetworkCallback(networkCallback); cm.registerDefaultNetworkCallback(networkCallback);
} }
@ -770,8 +770,7 @@ public class FragmentSetup extends FragmentBase {
tvDoze12.setVisibility(!canScheduleExact && !isIgnoring ? View.VISIBLE : View.GONE); tvDoze12.setVisibility(!canScheduleExact && !isIgnoring ? View.VISIBLE : View.GONE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ActivityManager am = ActivityManager am = Helper.getSystemService(getContext(), ActivityManager.class);
(ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
grpBackgroundRestricted.setVisibility(am.isBackgroundRestricted() grpBackgroundRestricted.setVisibility(am.isBackgroundRestricted()
? View.VISIBLE : View.GONE); ? View.VISIBLE : View.GONE);
} }
@ -788,7 +787,7 @@ public class FragmentSetup extends FragmentBase {
super.onPause(); super.onPause();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
cm.unregisterNetworkCallback(networkCallback); cm.unregisterNetworkCallback(networkCallback);
} }
} }

@ -27,6 +27,7 @@ import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.app.UiModeManager; import android.app.UiModeManager;
import android.app.usage.UsageStatsManager; import android.app.usage.UsageStatsManager;
@ -456,7 +457,7 @@ public class Helper {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return null; return null;
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager pm = Helper.getSystemService(context, PowerManager.class);
if (pm == null) if (pm == null)
return null; return null;
@ -465,7 +466,7 @@ public class Helper {
static Integer getBatteryLevel(Context context) { static Integer getBatteryLevel(Context context) {
try { try {
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE); BatteryManager bm = Helper.getSystemService(context, BatteryManager.class);
if (bm == null) if (bm == null)
return null; return null;
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
@ -479,7 +480,7 @@ public class Helper {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return false; return false;
try { try {
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE); BatteryManager bm = Helper.getSystemService(context, BatteryManager.class);
if (bm == null) if (bm == null)
return false; return false;
return bm.isCharging(); return bm.isCharging();
@ -520,7 +521,7 @@ public class Helper {
int enabled = Settings.System.getInt(resolver, Settings.Secure.LOCK_PATTERN_ENABLED, 0); int enabled = Settings.System.getInt(resolver, Settings.Secure.LOCK_PATTERN_ENABLED, 0);
return (enabled != 0); return (enabled != 0);
} else { } else {
KeyguardManager kgm = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); KeyguardManager kgm = Helper.getSystemService(context, KeyguardManager.class);
return (kgm != null && kgm.isDeviceSecure()); return (kgm != null && kgm.isDeviceSecure());
} }
} catch (Throwable ex) { } catch (Throwable ex) {
@ -591,8 +592,7 @@ public class Helper {
static boolean isAccessibilityEnabled(Context context) { static boolean isAccessibilityEnabled(Context context) {
try { try {
AccessibilityManager am = AccessibilityManager am = Helper.getSystemService(context, AccessibilityManager.class);
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
return (am != null && am.isEnabled()); return (am != null && am.isEnabled());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -619,6 +619,10 @@ public class Helper {
} }
} }
static <T extends Object> T getSystemService(Context context, Class<T> type) {
return ContextCompat.getSystemService(context.getApplicationContext(), type);
}
// View // View
static int getActionBarHeight(Context context) { static int getActionBarHeight(Context context) {
@ -1123,8 +1127,7 @@ public class Helper {
static String getUiModeType(Context context) { static String getUiModeType(Context context) {
try { try {
UiModeManager uimm = UiModeManager uimm = Helper.getSystemService(context, UiModeManager.class);
(UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
int uiModeType = uimm.getCurrentModeType(); int uiModeType = uimm.getCurrentModeType();
switch (uiModeType) { switch (uiModeType) {
case Configuration.UI_MODE_TYPE_UNDEFINED: case Configuration.UI_MODE_TYPE_UNDEFINED:

@ -406,7 +406,7 @@ public class HtmlHelper {
} }
private static int getMaxFormatTextSize(Context context) { private static int getMaxFormatTextSize(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager am = Helper.getSystemService(context, ActivityManager.class);
int mc = am.getMemoryClass(); int mc = am.getMemoryClass();
if (mc >= 256) if (mc >= 256)
return MAX_FORMAT_TEXT_SIZE; return MAX_FORMAT_TEXT_SIZE;

@ -482,7 +482,7 @@ class ImageHelper {
// H+ HSPA+ ~14.4 Mbps-23.0 Mbps // H+ HSPA+ ~14.4 Mbps-23.0 Mbps
// 4G LTE ~50 Mbps // 4G LTE ~50 Mbps
// 4G LTE-A ~500 Mbps // 4G LTE-A ~500 Mbps
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
Network active = (cm == null ? null : cm.getActiveNetwork()); Network active = (cm == null ? null : cm.getActiveNetwork());
NetworkCapabilities caps = (active == null ? null : cm.getNetworkCapabilities(active)); NetworkCapabilities caps = (active == null ? null : cm.getNetworkCapabilities(active));
if (caps != null) { if (caps != null) {

@ -423,7 +423,7 @@ public class Log {
config.setDiscardClasses(ignore); config.setDiscardClasses(ignore);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager am = Helper.getSystemService(context, ActivityManager.class);
String no_internet = context.getString(R.string.title_no_internet); String no_internet = context.getString(R.string.title_no_internet);
@ -678,7 +678,7 @@ public class Log {
static void logMemory(Context context, String message) { static void logMemory(Context context, String message) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager activityManager = Helper.getSystemService(context, ActivityManager.class);
activityManager.getMemoryInfo(mi); activityManager.getMemoryInfo(mi);
int mb = Math.round(mi.availMem / 0x100000L); int mb = Math.round(mi.availMem / 0x100000L);
int perc = Math.round(mi.availMem / (float) mi.totalMem * 100.0f); int perc = Math.round(mi.availMem / (float) mi.totalMem * 100.0f);
@ -1859,7 +1859,7 @@ public class Log {
sb.append(String.format("Processors: %d\r\n", Runtime.getRuntime().availableProcessors())); sb.append(String.format("Processors: %d\r\n", Runtime.getRuntime().availableProcessors()));
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager am = Helper.getSystemService(context, ActivityManager.class);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi); am.getMemoryInfo(mi);
sb.append(String.format("Memory class: %d/%d MB Total: %s\r\n", sb.append(String.format("Memory class: %d/%d MB Total: %s\r\n",
@ -1906,7 +1906,7 @@ public class Log {
sb.append("\r\n"); sb.append("\r\n");
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); WindowManager wm = Helper.getSystemService(context, WindowManager.class);
Display display = wm.getDefaultDisplay(); Display display = wm.getDefaultDisplay();
Point dim = new Point(); Point dim = new Point();
display.getSize(dim); display.getSize(dim);
@ -1964,7 +1964,7 @@ public class Log {
ignoring == null ? null : Boolean.toString(!ignoring), ignoring == null ? null : Boolean.toString(!ignoring),
Boolean.FALSE.equals(ignoring) ? "!!!" : "")); Boolean.FALSE.equals(ignoring) ? "!!!" : ""));
PowerManager power = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager power = Helper.getSystemService(context, PowerManager.class);
boolean psaving = power.isPowerSaveMode(); boolean psaving = power.isPowerSaveMode();
sb.append(String.format("Battery saving: %s %s\r\n", psaving, psaving ? "!!!" : "")); sb.append(String.format("Battery saving: %s %s\r\n", psaving, psaving ? "!!!" : ""));
@ -1973,7 +1973,7 @@ public class Log {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// https://developer.android.com/reference/android/app/usage/UsageStatsManager // https://developer.android.com/reference/android/app/usage/UsageStatsManager
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE); UsageStatsManager usm = Helper.getSystemService(context, UsageStatsManager.class);
int bucket = usm.getAppStandbyBucket(); int bucket = usm.getAppStandbyBucket();
boolean inactive = usm.isAppInactive(BuildConfig.APPLICATION_ID); boolean inactive = usm.isAppInactive(BuildConfig.APPLICATION_ID);
sb.append(String.format("Standby bucket: %d-%b-%s %s\r\n", sb.append(String.format("Standby bucket: %d-%b-%s %s\r\n",
@ -2282,7 +2282,7 @@ public class Log {
long size = 0; long size = 0;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
NetworkInfo ani = cm.getActiveNetworkInfo(); NetworkInfo ani = cm.getActiveNetworkInfo();
if (ani != null) if (ani != null)
@ -2512,7 +2512,7 @@ public class Log {
long size = 0; long size = 0;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
String name; String name;
@ -2639,7 +2639,7 @@ public class Log {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
try { try {
// https://developer.android.com/reference/android/app/ApplicationExitInfo // https://developer.android.com/reference/android/app/ApplicationExitInfo
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager am = Helper.getSystemService(context, ActivityManager.class);
List<ApplicationExitInfo> infos = am.getHistoricalProcessExitReasons( List<ApplicationExitInfo> infos = am.getHistoricalProcessExitReasons(
context.getPackageName(), 0, 20); context.getPackageName(), 0, 20);
for (ApplicationExitInfo info : infos) for (ApplicationExitInfo info : infos)
@ -2657,7 +2657,7 @@ public class Log {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
try { try {
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE); UsageStatsManager usm = Helper.getSystemService(context, UsageStatsManager.class);
UsageEvents events = usm.queryEventsForSelf(now - 12 * 3600L, now); UsageEvents events = usm.queryEventsForSelf(now - 12 * 3600L, now);
UsageEvents.Event event = new UsageEvents.Event(); UsageEvents.Event event = new UsageEvents.Event();
while (events != null && events.hasNextEvent()) { while (events != null && events.hasNextEvent()) {

@ -81,8 +81,7 @@ public class MediaPlayerHelper {
} }
static boolean isInCall(Context context) { static boolean isInCall(Context context) {
AudioManager am = AudioManager am = Helper.getSystemService(context, AudioManager.class);
(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (am == null) if (am == null)
return false; return false;

@ -61,7 +61,7 @@ class NotificationHelper {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
static void createNotificationChannels(Context context) { static void createNotificationChannels(Context context) {
// https://issuetracker.google.com/issues/65108694 // https://issuetracker.google.com/issues/65108694
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
// Sync // Sync
NotificationChannel service = new NotificationChannel( NotificationChannel service = new NotificationChannel(
@ -151,7 +151,7 @@ class NotificationHelper {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
static void clear(Context context) { static void clear(Context context) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
for (NotificationChannel channel : nm.getNotificationChannels()) { for (NotificationChannel channel : nm.getNotificationChannels()) {
String id = channel.getId(); String id = channel.getId();
if (!PERSISTENT_IDS.contains(id)) { if (!PERSISTENT_IDS.contains(id)) {

@ -94,7 +94,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
owner = new TwoStateOwner(this, "send"); owner = new TwoStateOwner(this, "send");
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager pm = Helper.getSystemService(this, PowerManager.class);
wlOutbox = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":send"); wlOutbox = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":send");
// Observe unsent count // Observe unsent count
@ -107,8 +107,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
EntityLog.log(ServiceSend.this, "Unsent=" + (unsent == null ? null : unsent.count)); EntityLog.log(ServiceSend.this, "Unsent=" + (unsent == null ? null : unsent.count));
try { try {
NotificationManager nm = NotificationManager nm = Helper.getSystemService(ServiceSend.this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SEND, nm.notify(NotificationHelper.NOTIFICATION_SEND,
getNotificationService(false).build()); getNotificationService(false).build());
} catch (Throwable ex) { } catch (Throwable ex) {
@ -157,7 +156,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
if (lastSuitable) if (lastSuitable)
owner.start(); owner.start();
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(this, ConnectivityManager.class);
NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
cm.registerNetworkCallback(builder.build(), networkCallback); cm.registerNetworkCallback(builder.build(), networkCallback);
@ -178,7 +177,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
unregisterReceiver(connectionChangedReceiver); unregisterReceiver(connectionChangedReceiver);
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(this, ConnectivityManager.class);
cm.unregisterNetworkCallback(networkCallback); cm.unregisterNetworkCallback(networkCallback);
getMainHandler().removeCallbacks(_checkConnectivity); getMainHandler().removeCallbacks(_checkConnectivity);
@ -188,8 +187,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
stopForeground(true); stopForeground(true);
NotificationManager nm = NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(NotificationHelper.NOTIFICATION_SEND); nm.cancel(NotificationHelper.NOTIFICATION_SEND);
super.onDestroy(); super.onDestroy();
@ -331,8 +329,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
EntityLog.log(ServiceSend.this, "Service send suitable=" + suitable); EntityLog.log(ServiceSend.this, "Service send suitable=" + suitable);
try { try {
NotificationManager nm = NotificationManager nm = Helper.getSystemService(ServiceSend.this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SEND, nm.notify(NotificationHelper.NOTIFICATION_SEND,
getNotificationService(false).build()); getNotificationService(false).build());
} catch (Throwable ex) { } catch (Throwable ex) {
@ -432,7 +429,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
try { try {
int tries_left = (unrecoverable ? 0 : RETRY_MAX - op.tries); int tries_left = (unrecoverable ? 0 : RETRY_MAX - op.tries);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
nm.notify("send:" + message.id, nm.notify("send:" + message.id,
NotificationHelper.NOTIFICATION_TAGGED, NotificationHelper.NOTIFICATION_TAGGED,
getNotificationError( getNotificationError(
@ -467,7 +464,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
} }
private void onSync(EntityFolder outbox) { private void onSync(EntityFolder outbox) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
try { try {
@ -519,8 +516,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
db.message().setMessageLastAttempt(message.id, message.last_attempt); db.message().setMessageLastAttempt(message.id, message.last_attempt);
} }
NotificationManager nm = NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(true).build()); nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(true).build());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@ -895,7 +891,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
context, PI_SEND, intent, PendingIntent.FLAG_UPDATE_CURRENT); context, PI_SEND, intent, PendingIntent.FLAG_UPDATE_CURRENT);
long trigger = System.currentTimeMillis() + delay; long trigger = System.currentTimeMillis() + delay;
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = Helper.getSystemService(context, AlarmManager.class);
am.cancel(pi); am.cancel(pi);
AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, trigger, pi); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, trigger, pi);
} }

@ -182,7 +182,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
getNotificationService(null, null).build()); getNotificationService(null, null).build());
// Listen for network changes // Listen for network changes
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(this, ConnectivityManager.class);
NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
// Removed because of Android VPN service // Removed because of Android VPN service
@ -240,7 +240,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private int lastQuitId = -1; private int lastQuitId = -1;
private List<Long> initialized = new ArrayList<>(); private List<Long> initialized = new ArrayList<>();
private List<TupleAccountNetworkState> accountStates = new ArrayList<>(); private List<TupleAccountNetworkState> accountStates = new ArrayList<>();
private PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); private PowerManager pm = Helper.getSystemService(ServiceSynchronize.this, PowerManager.class);
private PowerManager.WakeLock wl = pm.newWakeLock( private PowerManager.WakeLock wl = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":service"); PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":service");
private ExecutorService queue = Helper.getBackgroundExecutor(1, "service"); private ExecutorService queue = Helper.getBackgroundExecutor(1, "service");
@ -399,8 +399,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (!isBackgroundService(ServiceSynchronize.this)) if (!isBackgroundService(ServiceSynchronize.this))
try { try {
NotificationManager nm = NotificationManager nm = Helper.getSystemService(ServiceSynchronize.this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SYNCHRONIZE, nm.notify(NotificationHelper.NOTIFICATION_SYNCHRONIZE,
getNotificationService(lastAccounts, lastOperations).build()); getNotificationService(lastAccounts, lastOperations).build());
} catch (Throwable ex) { } catch (Throwable ex) {
@ -567,7 +566,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
db.account().deleteAccount(accountNetworkState.accountState.id); db.account().deleteAccount(accountNetworkState.accountState.id);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(ServiceSynchronize.this, NotificationManager.class);
nm.deleteNotificationChannel(EntityAccount.getNotificationChannelId(accountNetworkState.accountState.id)); nm.deleteNotificationChannel(EntityAccount.getNotificationChannelId(accountNetworkState.accountState.id));
} }
} catch (Throwable ex) { } catch (Throwable ex) {
@ -882,7 +881,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
unregisterReceiver(connectionChangedReceiver); unregisterReceiver(connectionChangedReceiver);
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(this, ConnectivityManager.class);
cm.unregisterNetworkCallback(networkCallback); cm.unregisterNetworkCallback(networkCallback);
liveAccountNetworkState.postDestroy(); liveAccountNetworkState.postDestroy();
@ -916,8 +915,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
*/ */
} }
NotificationManager nm = NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(NotificationHelper.NOTIFICATION_SYNCHRONIZE); nm.cancel(NotificationHelper.NOTIFICATION_SYNCHRONIZE);
super.onDestroy(); super.onDestroy();
@ -1361,7 +1359,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private void monitorAccount( private void monitorAccount(
final EntityAccount account, final Core.State state, final EntityAccount account, final Core.State state,
final boolean sync, final boolean force) throws NoSuchProviderException { final boolean sync, final boolean force) throws NoSuchProviderException {
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); final PowerManager pm = Helper.getSystemService(this, PowerManager.class);
final PowerManager.WakeLock wlAccount = pm.newWakeLock( final PowerManager.WakeLock wlAccount = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id); PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id);
final PowerManager.WakeLock wlFolder = pm.newWakeLock( final PowerManager.WakeLock wlFolder = pm.newWakeLock(
@ -1447,7 +1445,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (!ConnectionHelper.isMaxConnections(message)) if (!ConnectionHelper.isMaxConnections(message))
try { try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(ServiceSynchronize.this, NotificationManager.class);
nm.notify("alert:" + account.id, nm.notify("alert:" + account.id,
NotificationHelper.NOTIFICATION_TAGGED, NotificationHelper.NOTIFICATION_TAGGED,
getNotificationAlert(account, message).build()); getNotificationAlert(account, message).build());
@ -1488,7 +1486,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try { try {
state.setBackoff(2 * CONNECT_BACKOFF_ALARM_MAX * 60); state.setBackoff(2 * CONNECT_BACKOFF_ALARM_MAX * 60);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
nm.notify("receive:" + account.id, nm.notify("receive:" + account.id,
NotificationHelper.NOTIFICATION_TAGGED, NotificationHelper.NOTIFICATION_TAGGED,
Core.getNotificationError(this, "error", account, 0, ex) Core.getNotificationError(this, "error", account, 0, ex)
@ -2237,8 +2235,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
db.account().setAccountConnected(account.id, account.last_connected); db.account().setAccountConnected(account.id, account.last_connected);
db.account().setAccountWarning(account.id, capIdle ? null : getString(R.string.title_no_idle)); db.account().setAccountWarning(account.id, capIdle ? null : getString(R.string.title_no_idle));
NotificationManager nm = NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("receive:" + account.id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("receive:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
nm.cancel("alert:" + account.id, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel("alert:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
@ -2248,7 +2245,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
PendingIntent pi = PendingIntentCompat.getForegroundService( PendingIntent pi = PendingIntentCompat.getForegroundService(
this, PI_KEEPALIVE, intent, PendingIntent.FLAG_UPDATE_CURRENT); this, PI_KEEPALIVE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); AlarmManager am = Helper.getSystemService(this, AlarmManager.class);
try { try {
long duration = account.poll_interval * 60 * 1000L; long duration = account.poll_interval * 60 * 1000L;
long trigger = System.currentTimeMillis() + duration; long trigger = System.currentTimeMillis() + duration;
@ -2301,7 +2298,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
Helper.getDateTimeInstance(this, DateFormat.SHORT, DateFormat.SHORT) Helper.getDateTimeInstance(this, DateFormat.SHORT, DateFormat.SHORT)
.format(account.last_connected)), ex); .format(account.last_connected)), ex);
try { try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
nm.notify("receive:" + account.id, nm.notify("receive:" + account.id,
NotificationHelper.NOTIFICATION_TAGGED, NotificationHelper.NOTIFICATION_TAGGED,
Core.getNotificationError(this, "warning", account, 0, warning) Core.getNotificationError(this, "warning", account, 0, warning)
@ -2477,7 +2474,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
PendingIntent pi = PendingIntentCompat.getForegroundService( PendingIntent pi = PendingIntentCompat.getForegroundService(
this, PI_BACKOFF, intent, PendingIntent.FLAG_UPDATE_CURRENT); this, PI_BACKOFF, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); AlarmManager am = Helper.getSystemService(this, AlarmManager.class);
try { try {
long trigger = System.currentTimeMillis() + backoff * 1000L; long trigger = System.currentTimeMillis() + backoff * 1000L;
EntityLog.log(this, EntityLog.Type.Account, account, EntityLog.log(this, EntityLog.Type.Account, account,
@ -2653,7 +2650,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
@Override @Override
@RequiresApi(api = Build.VERSION_CODES.M) @RequiresApi(api = Build.VERSION_CODES.M)
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager pm = Helper.getSystemService(context, PowerManager.class);
EntityLog.log(context, "Doze mode=" + pm.isDeviceIdleMode() + EntityLog.log(context, "Doze mode=" + pm.isDeviceIdleMode() +
" ignoring=" + pm.isIgnoringBatteryOptimizations(context.getPackageName())); " ignoring=" + pm.isIgnoringBatteryOptimizations(context.getPackageName()));
} }
@ -2666,7 +2663,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
Log.i("Received intent=" + intent + Log.i("Received intent=" + intent +
" " + TextUtils.join(" ", Log.getExtras(intent.getExtras()))); " " + TextUtils.join(" ", Log.getExtras(intent.getExtras())));
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
Integer status = (cm == null ? null : cm.getRestrictBackgroundStatus()); Integer status = (cm == null ? null : cm.getRestrictBackgroundStatus());
EntityLog.log(context, "Data saver=" + status); EntityLog.log(context, "Data saver=" + status);
@ -2737,8 +2734,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (!isBackgroundService(ServiceSynchronize.this)) if (!isBackgroundService(ServiceSynchronize.this))
try { try {
NotificationManager nm = NotificationManager nm = Helper.getSystemService(ServiceSynchronize.this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SYNCHRONIZE, nm.notify(NotificationHelper.NOTIFICATION_SYNCHRONIZE,
getNotificationService(lastAccounts, lastOperations).build()); getNotificationService(lastAccounts, lastOperations).build());
} catch (Throwable ex) { } catch (Throwable ex) {

@ -214,8 +214,7 @@ public class ServiceUI extends IntentService {
// https://issuetracker.google.com/issues/159152393 // https://issuetracker.google.com/issues/159152393
String tag = "unseen." + group + ":" + id; String tag = "unseen." + group + ":" + id;
NotificationManager nm = NotificationManager nm = Helper.getSystemService(this, NotificationManager.class);
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(tag, NotificationHelper.NOTIFICATION_TAGGED); nm.cancel(tag, NotificationHelper.NOTIFICATION_TAGGED);
} }

@ -75,7 +75,7 @@ class Shortcuts {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("shortcuts", true); boolean enabled = prefs.getBoolean("shortcuts", true);
ShortcutManager sm = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE); ShortcutManager sm = Helper.getSystemService(context, ShortcutManager.class);
int app = sm.getMaxShortcutCountPerActivity(); int app = sm.getMaxShortcutCountPerActivity();
int manifest = sm.getManifestShortcuts().size(); int manifest = sm.getManifestShortcuts().size();
int count = Math.min(app - manifest, MAX_SHORTCUTS); int count = Math.min(app - manifest, MAX_SHORTCUTS);

@ -85,7 +85,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
private ExecutorService getExecutor(Context context) { private ExecutorService getExecutor(Context context) {
if (wl == null) { if (wl == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager pm = Helper.getSystemService(context, PowerManager.class);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":task"); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":task");
} }

@ -147,8 +147,7 @@ public class TextHelper {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
return null; return null;
TextClassificationManager tcm = TextClassificationManager tcm = Helper.getSystemService(context, TextClassificationManager.class);
(TextClassificationManager) context.getSystemService(Context.TEXT_CLASSIFICATION_SERVICE);
if (tcm == null) if (tcm == null)
return null; return null;

@ -88,7 +88,7 @@ public class TupleFolderEx extends EntityFolder implements Serializable {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
void createNotificationChannel(Context context) { void createNotificationChannel(Context context) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
NotificationChannelGroup group = new NotificationChannelGroup("group." + accountId, accountName); NotificationChannelGroup group = new NotificationChannelGroup("group." + accountId, accountName);
nm.createNotificationChannelGroup(group); nm.createNotificationChannelGroup(group);
@ -105,7 +105,7 @@ public class TupleFolderEx extends EntityFolder implements Serializable {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
void deleteNotificationChannel(Context context) { void deleteNotificationChannel(Context context) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
nm.deleteNotificationChannel(getNotificationChannelId(id)); nm.deleteNotificationChannel(getNotificationChannelId(id));
} }

@ -164,7 +164,7 @@ public class WorkerCleanup extends Worker {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.i("Checking notification channels"); Log.i("Checking notification channels");
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
for (NotificationChannel channel : nm.getNotificationChannels()) { for (NotificationChannel channel : nm.getNotificationChannels()) {
String cid = channel.getId(); String cid = channel.getId();
Log.i("Notification channel id=" + cid + " name=" + channel.getName()); Log.i("Notification channel id=" + cid + " name=" + channel.getName());

Loading…
Cancel
Save