正在查看: xDrip+ v04633772025.07.16 应用的 AlwaysOnDisplayService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 AlwaysOnDisplayService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.services;
import android.accessibilityservice.AccessibilityService;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.graphics.Rect;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;
import android.widget.FrameLayout;
import android.widget.RemoteViews;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.services.AlwaysOnDisplayService;
import com.eveningoutpost.dexdrip.ui.helpers.UiHelper;
import com.eveningoutpost.dexdrip.utils.math.BlockFinder;
import com.eveningoutpost.dexdrip.xDripWidget;
import java.util.List;
public class AlwaysOnDisplayService extends AccessibilityService {
private View aodView;
private FrameLayout frameLayout;
private volatile long lastScreenOn = 1;
private final WindowManager.LayoutParams layoutParams;
final BroadcastReceiver screenReceiver;
public AlwaysOnDisplayService() {
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
this.layoutParams = layoutParams;
try {
layoutParams.width = UiHelper.convertDpToPixel(180.0f);
layoutParams.height = UiHelper.convertDpToPixel(100.0f);
} catch (Exception unused) {
}
int i = Build.VERSION.SDK_INT;
WindowManager.LayoutParams layoutParams2 = this.layoutParams;
layoutParams2.type = 2032;
layoutParams2.format = -3;
layoutParams2.setTitle("xDrip Always On");
WindowManager.LayoutParams layoutParams3 = this.layoutParams;
layoutParams3.gravity = 49;
layoutParams3.verticalMargin = 0.0f;
if (i >= 28) {
layoutParams3.layoutInDisplayCutoutMode = 2;
}
this.layoutParams.flags = 1296;
this.screenReceiver = new AnonymousClass1();
}
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
UserError.Log.d("AlwaysOnDisplay", "Accessibility event: " + accessibilityEvent.toString());
}
@Override
public void onInterrupt() {
UserError.Log.d("AlwaysOnDisplay", "Interrupt event");
}
@Override
public void onServiceConnected() {
UserError.Log.d("AlwaysOnDisplay", "on Service connected");
registerReceivers();
super.onServiceConnected();
}
@Override
public void onDestroy() {
UserError.Log.d("AlwaysOnDisplay", "on Destroy");
removeLayout();
unregisterReceivers();
super.onDestroy();
}
void registerReceivers() {
try {
IntentFilter intentFilter = new IntentFilter("com.eveingoutpost.dexdrip.action.UPDATE_AOD");
intentFilter.addAction("android.intent.action.TIME_TICK");
intentFilter.addAction("android.intent.action.SCREEN_ON");
intentFilter.addAction("android.intent.action.SCREEN_OFF");
registerReceiver(this.screenReceiver, intentFilter);
} catch (Exception e) {
UserError.Log.e("AlwaysOnDisplay", "Unable to register receivers: " + e);
}
}
void unregisterReceivers() {
try {
unregisterReceiver(this.screenReceiver);
} catch (Exception e) {
UserError.Log.e("AlwaysOnDisplay", "Unable to unregister receivers: " + e);
}
}
void addLayout() {
try {
WindowManager windowManager = (WindowManager) getSystemService("window");
if (windowManager == null) {
UserError.Log.wtf("AlwaysOnDisplay", "Cannot get window manager to inject layout");
} else {
windowManager.addView(this.aodView, this.layoutParams);
}
} catch (Exception e) {
UserError.Log.e("AlwaysOnDisplay", "Unable to add layout " + e);
}
}
void injectLayout() {
refreshView();
}
void removeLayout() {
View view = this.aodView;
if (view != null) {
removeLayout(view);
}
}
void removeLayout(View view) {
try {
WindowManager windowManager = (WindowManager) getSystemService("window");
if (windowManager == null) {
UserError.Log.wtf("AlwaysOnDisplay", "Cannot get window manager to remove layout");
} else if (view != null) {
try {
windowManager.removeView(view);
} catch (IllegalArgumentException unused) {
UserError.Log.d("AlwaysOnDisplay", "Cannot remove layout as not attached");
}
}
} catch (Exception e) {
UserError.Log.e("AlwaysOnDisplay", "Unable to remove layout: " + e);
}
}
public synchronized void refreshView() {
if (this.lastScreenOn != 0) {
UserError.Log.d("AlwaysOnDisplay", "Screen got turned on - skipping");
return;
}
RemoteViews displayCurrentInfo = xDripWidget.displayCurrentInfo(this, UiHelper.convertDpToPixel(75.0f), UiHelper.convertDpToPixel(50.0f));
View view = this.aodView;
if (this.frameLayout == null) {
this.frameLayout = new FrameLayout(this);
}
View apply = displayCurrentInfo.apply(this, this.frameLayout);
this.aodView = apply;
apply.setAlpha(0.8f);
this.aodView.setBackgroundColor(0);
removeLayout(view);
addLayout();
rejigLayout();
}
void rejigLayout() {
String str;
String str2;
String str3 = ",";
try {
WindowManager windowManager = (WindowManager) getSystemService("window");
if (windowManager == null) {
UserError.Log.wtf("AlwaysOnDisplay", "Cannot get window manager to rejig layout");
return;
}
if (this.aodView == null) {
UserError.Log.d("AlwaysOnDisplay", "View not ready yet");
return;
}
BlockFinder blockFinder = new BlockFinder();
List<AccessibilityWindowInfo> windows = getWindows();
UserError.Log.d("AlwaysOnDisplay", "Windows list: " + windows.size());
Rect rect = new Rect();
int i = 0;
for (AccessibilityWindowInfo accessibilityWindowInfo : windows) {
accessibilityWindowInfo.getBoundsInScreen(rect);
i = Math.max(i, rect.bottom);
AccessibilityNodeInfo root = accessibilityWindowInfo.getRoot();
accessibilityWindowInfo.getBoundsInScreen(rect);
UserError.Log.d("AlwaysOnDisplay", "Window bounds: " + rect.left + str3 + rect.top + " " + rect.right + str3 + rect.bottom + " MAX: " + i);
if (root != null) {
int childCount = root.getChildCount();
int i2 = 0;
while (i2 < childCount) {
AccessibilityNodeInfo child = root.getChild(i2);
child.getBoundsInScreen(rect);
if (child.getClassName().equals("android.widget.FrameLayout")) {
int childCount2 = child.getChildCount();
int i3 = 0;
while (i3 < childCount2) {
child.getChild(i3).getBoundsInScreen(rect);
int i4 = rect.top;
if (i4 == 0) {
str2 = str3;
if (rect.bottom >= 200) {
i3++;
str3 = str2;
}
} else {
str2 = str3;
}
blockFinder.addBlockWithMerge(i4, rect.bottom);
i3++;
str3 = str2;
}
}
i2++;
str3 = str3;
}
str = str3;
} else {
str = str3;
UserError.Log.e("AlwaysOnDisplay", "Cannot get root view");
}
str3 = str;
}
UserError.Log.d("AlwaysOnDisplay", blockFinder.toString());
if (i == 0) {
DisplayMetrics displayMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
i = displayMetrics.heightPixels;
UserError.Log.d("AlwaysOnDisplay", "Couldn't determine max Y so using screen max of: " + i);
}
WindowManager.LayoutParams layoutParams = this.layoutParams;
layoutParams.y = blockFinder.findRandomAvailablePositionWithFailSafe(layoutParams.height, i);
windowManager.updateViewLayout(this.aodView, this.layoutParams);
} catch (Exception e) {
UserError.Log.e("AlwaysOnDisplay", "Error with rejig display: " + e);
}
}
class AnonymousClass1 extends BroadcastReceiver {
AnonymousClass1() {
}
@Override
public void onReceive(android.content.Context r5, android.content.Intent r6) {
throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.services.AlwaysOnDisplayService.AnonymousClass1.onReceive(android.content.Context, android.content.Intent):void");
}
public void lambda$onReceive$0() {
AlwaysOnDisplayService.this.injectLayout();
}
public void lambda$onReceive$1() {
JoH.runOnUiThread(new Runnable() {
@Override
public final void run() {
AlwaysOnDisplayService.AnonymousClass1.this.lambda$onReceive$0();
}
});
}
}
}