Skip to content

compat android 12 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ public static void hookInflaterFactory(LayoutInflater layoutInflater) {

private LayoutInflater.Factory mOutFactory;

private Integer mImageSrc = null;

private int[] mImageStyle = null;

private Integer mViewBackground = null;

private int[] mViewStyle = null;

public String rootDrawableTag;

public String rootBackgroundTag;
Expand Down Expand Up @@ -111,25 +103,12 @@ private void trySetViewBackgroundInfo(Context context, View view, String name, A
}
String drawableName = null;
try {
if (mViewStyle == null) {
Class clz = Class.forName("com.android.internal.R$styleable");
Field field = ReflectUtils.getClassField(clz, "View");
mViewStyle = (int[]) field.get(null);
field = ReflectUtils.getClassField(clz, "View_background");
mViewBackground = (Integer) field.get(null);
}
} catch (Throwable t) {
Log.d(CodeLocator.TAG, "Hook view background error, " + Log.getStackTraceString(t));
}
try {
if (mViewStyle != null && mViewBackground != null) {
final TypedArray a = context.obtainStyledAttributes(attrs, mViewStyle, 0, 0);
final int resourceId = a.getResourceId(mViewBackground, 0);
if (resourceId != 0) {
drawableName = context.getResources().getResourceName(resourceId).replace(context.getPackageName(), "");
if (!drawableName.contains("drawable/")) {
drawableName = null;
}
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CodeLocator, 0, 0);
final int resourceId = a.getResourceId(R.styleable.CodeLocator_android_background, 0);
if (resourceId != 0) {
drawableName = context.getResources().getResourceName(resourceId).replace(context.getPackageName(), "");
if (!drawableName.contains("drawable/")) {
drawableName = null;
}
}
} catch (Throwable t) {
Expand Down Expand Up @@ -160,23 +139,10 @@ private void trySetImageViewScrInfo(Context context, View view, String name, Att
}
String drawableName = null;
try {
if (mImageStyle == null) {
Class clz = Class.forName("com.android.internal.R$styleable");
Field field = ReflectUtils.getClassField(clz, "ImageView");
mImageStyle = (int[]) field.get(null);
field = ReflectUtils.getClassField(clz, "ImageView_src");
mImageSrc = (Integer) field.get(null);
}
} catch (Throwable t) {
Log.d(CodeLocator.TAG, "Hook view background error, " + Log.getStackTraceString(t));
}
try {
if (mImageStyle != null && mImageSrc != null) {
final TypedArray a = context.obtainStyledAttributes(attrs, mImageStyle, 0, 0);
final int resourceId = a.getResourceId(mImageSrc, 0);
if (resourceId != 0) {
drawableName = context.getResources().getResourceName(resourceId).replace(context.getPackageName(), "");
}
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CodeLocator, 0, 0);
final int resourceId = a.getResourceId(R.styleable.CodeLocator_android_src, 0);
if (resourceId != 0) {
drawableName = context.getResources().getResourceName(resourceId).replace(context.getPackageName(), "");
}
} catch (Throwable t) {
Log.d(CodeLocator.TAG, "get view background name error, " + Log.getStackTraceString(t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import android.view.TouchDelegate
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import android.widget.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
Expand All @@ -29,15 +25,10 @@ import com.bytedance.tools.codelocator.CodeLocator
import com.bytedance.tools.codelocator.R
import com.bytedance.tools.codelocator.config.AppInfoProvider
import com.bytedance.tools.codelocator.config.CodeLocatorConfigFetcher
import com.bytedance.tools.codelocator.model.WActivity
import com.bytedance.tools.codelocator.model.WApplication
import com.bytedance.tools.codelocator.model.WFile
import com.bytedance.tools.codelocator.model.WFragment
import com.bytedance.tools.codelocator.model.WView
import com.bytedance.tools.codelocator.model.*
import com.bytedance.tools.codelocator.operate.ViewOperate
import java.io.File
import java.lang.Math.abs
import java.lang.reflect.Field

object ActivityUtils {

Expand Down Expand Up @@ -684,32 +675,40 @@ object ActivityUtils {
val currentWindowToken = activity.window.attributes.token
val mGlobal = ReflectUtils.getClassField(windowManager.javaClass, "mGlobal")
val mWindowManagerGlobal = mGlobal?.get(windowManager) ?: return dialogViews
val mRoots = ReflectUtils.getClassField(mWindowManagerGlobal.javaClass, "mRoots")
val list = mRoots?.get(mWindowManagerGlobal) as? List<Any>

val mViewsField = ReflectUtils.getClassField(mWindowManagerGlobal.javaClass, "mViews")
val mParamsField = ReflectUtils.getClassField(mWindowManagerGlobal.javaClass, "mParams")
val mViews = mViewsField?.get(mWindowManagerGlobal) as? List<Any>
val mParams = mParamsField?.get(mWindowManagerGlobal) as? List<Any>

val activityDecorView = activity.window.decorView
if (list?.isNotEmpty() == true) {
for (element in list) {
val viewRoot = element
val mAttrFiled: Field? = ReflectUtils.getClassField(viewRoot.javaClass, "mWindowAttributes")
val layoutParams: WindowManager.LayoutParams? =
mAttrFiled?.get(viewRoot) as? WindowManager.LayoutParams
if (layoutParams?.token != currentWindowToken && (layoutParams?.type != WindowManager.LayoutParams.FIRST_SUB_WINDOW
&& layoutParams?.type != WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)) {
if (mViews?.isNotEmpty() == true && mParams?.isNotEmpty() == true) {
for (i in mViews.indices) {
val view = mViews[i] as View
if (activityDecorView == view) {
continue
}
val viewFiled: Field? = ReflectUtils.getClassField(viewRoot.javaClass, "mView")
var view: View = viewFiled?.get(viewRoot) as? View ?: continue
if (activityDecorView == view) {
val layoutParams = mParams[i] as? WindowManager.LayoutParams
if (layoutParams?.token != currentWindowToken && (layoutParams?.type != WindowManager.LayoutParams.FIRST_SUB_WINDOW
&& layoutParams?.type != WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)
) {
continue
}
val winFrameRectField = ReflectUtils.getClassField(viewRoot.javaClass, "mWinFrame")
val winFrameRect: Rect? = winFrameRectField?.get(viewRoot) as? Rect

val winFrameRect = Rect()
val loc = IntArray(2)
view.getLocationOnScreen(loc)
winFrameRect.left = loc[0]
winFrameRect.top = loc[1]
winFrameRect.right = loc[0] + view.width
winFrameRect.bottom = loc[1] + view.height

val decorView = convertViewToWView(view, winFrameRect)
dialogViews.add(decorView)
}
}
} catch (e: Exception) {
Log.d(CodeLocator.TAG, "getDialogWindow Fail $e")
Log.d(CodeLocator.TAG, "getDialogWindow Fail", e)
}
return dialogViews
}
Expand Down
5 changes: 5 additions & 0 deletions CodeLocatorApp/CodeLocatorCore/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
<item name="codeLocator_viewholder_id" type="id" />
<item name="codeLocator_viewholder_adapter_tag_id" type="id" />
<item name="codeLocator_view_extra" type="id" />

<declare-styleable name="CodeLocator">
<attr name="android:background" />
<attr name="android:src" />
</declare-styleable>
</resources>
26 changes: 15 additions & 11 deletions CodeLocatorApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.bytedance.tools.codelocator.demo">
xmlns:tools="http://schemas.android.com/tools"
package="com.bytedance.tools.codelocator.demo">

<application
android:name="com.bytedance.tools.codelocator.demo.MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.bytedance.tools.codelocator.demo.MainActivity">
android:name="com.bytedance.tools.codelocator.demo.MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.bytedance.tools.codelocator.demo.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name="com.bytedance.tools.codelocator.demo.TestActivity" />
<activity
android:name="com.bytedance.tools.codelocator.demo.TestActivity"
android:exported="false" />
</application>

</manifest>