Skip to content

Commit

Permalink
feat: 以转调到静态方法方式重新实现Dialog支持
Browse files Browse the repository at this point in the history
  • Loading branch information
shifujun committed May 22, 2020
1 parent 42e7369 commit 4e03eba
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 435 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.tencent.shadow.core.runtime;

import android.app.Activity;
import android.app.Dialog;

import com.tencent.shadow.core.runtime.container.PluginContainerActivity;

public class ShadowDialogSupport {

public static void dialogSetOwnerActivity(Dialog dialog, ShadowActivity activity) {
Activity hostActivity = (Activity) activity.hostActivityDelegator.getHostActivity();
dialog.setOwnerActivity(hostActivity);
}

public static ShadowActivity dialogGetOwnerActivity(Dialog dialog) {
PluginContainerActivity ownerActivity = (PluginContainerActivity) dialog.getOwnerActivity();
if (ownerActivity != null) {
return (ShadowActivity) PluginActivity.get(ownerActivity);
} else {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TransformManager(ctClassInputMap: Map<CtClass, InputClass>,
ServiceTransform(),
InstrumentationTransform(),
FragmentSupportTransform(),
DialogTransform(),
DialogSupportTransform(),
WebViewTransform(),
ContentProviderTransform(),
PackageManagerTransform(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Tencent is pleased to support the open source community by making Tencent Shadow available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.tencent.shadow.core.transform.specific

import com.tencent.shadow.core.transform_kit.CodeConverterExtension
import com.tencent.shadow.core.transform_kit.SpecificTransform
import com.tencent.shadow.core.transform_kit.TransformStep
import javassist.CtClass
import javassist.bytecode.Descriptor

class DialogSupportTransform : SpecificTransform() {
companion object {
const val ShadowActivityClassname = "com.tencent.shadow.core.runtime.ShadowActivity"
const val AndroidDialogClassname = "android.app.Dialog"
const val DialogSupportTransformClassname = "com.tencent.shadow.core.runtime.ShadowDialogSupport"
}

override fun setup(allInputClass: Set<CtClass>) {
val androidDialog = mClassPool[AndroidDialogClassname]
val shadowDialogSupport = mClassPool[DialogSupportTransformClassname]
val shadowActivity = mClassPool[ShadowActivityClassname]

val setOwnerActivityMethod = androidDialog.getDeclaredMethod("setOwnerActivity")
val getOwnerActivityMethod = androidDialog.getDeclaredMethod("getOwnerActivity")

//appClass中的Activity都已经被改名为ShadowActivity了.所以要把方法签名也先改一下.
val shadowActivitySig = "Lcom/tencent/shadow/core/runtime/ShadowActivity;"
setOwnerActivityMethod.methodInfo.descriptor = "($shadowActivitySig)V"
getOwnerActivityMethod.methodInfo.descriptor = "()$shadowActivitySig"

val dialogSetOwnerActivityMethod = shadowDialogSupport.getMethod("dialogSetOwnerActivity",
Descriptor.ofMethod(CtClass.voidType,
arrayOf(androidDialog, shadowActivity)))
val dialogGetOwnerActivityMethod = shadowDialogSupport.getMethod("dialogGetOwnerActivity",
Descriptor.ofMethod(shadowActivity,
arrayOf(androidDialog)))

newStep(object : TransformStep {
override fun filter(allInputClass: Set<CtClass>) = allInputClass

override fun transform(ctClass: CtClass) {
ctClass.defrost()
val codeConverter = CodeConverterExtension()
codeConverter.redirectMethodCallToStaticMethodCall(setOwnerActivityMethod, dialogSetOwnerActivityMethod)
codeConverter.redirectMethodCallToStaticMethodCall(getOwnerActivityMethod, dialogGetOwnerActivityMethod)
try {
ctClass.instrument(codeConverter)
} catch (e: Exception) {
System.err.println("处理" + ctClass.name + "时出错:" + e)
throw e
}
}
})

}

}

This file was deleted.

17 changes: 0 additions & 17 deletions projects/sdk/core/transform/src/test/java/android/app/Dialog.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4e03eba

Please sign in to comment.