Skip to content

Commit

Permalink
DynamiteModule: Added <init> method
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 committed Dec 5, 2024
1 parent 10a5259 commit ec636fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@

package com.google.android.gms.dynamite.descriptors.com.google.android.gms.ads.dynamite;

import android.content.Context;
import android.content.ContextWrapper;
import android.util.Log;
import android.webkit.WebSettings;
import androidx.annotation.Keep;

@Keep
public class ModuleDescriptor {
public static final String MODULE_ID = "com.google.android.gms.ads.dynamite";
public static final int MODULE_VERSION = 230500001;

public static void init(ContextWrapper context) {
Context baseContext = context.getBaseContext();
WebSettings.getDefaultUserAgent(baseContext);
Log.d("ModuleDescriptor", "init: context: " + baseContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ public static DynamiteContext create(String moduleId, Context originalContext) {
DynamiteModuleInfo moduleInfo = new DynamiteModuleInfo(moduleId);
Context gmsContext = originalContext.createPackageContext(Constants.GMS_PACKAGE_NAME, 0);
Context originalAppContext = originalContext.getApplicationContext();
DynamiteContext dynamiteContext;
if (originalAppContext == null || originalAppContext == originalContext) {
return new DynamiteContext(moduleInfo, originalContext, gmsContext, null);
dynamiteContext = new DynamiteContext(moduleInfo, originalContext, gmsContext, null);
} else {
return new DynamiteContext(moduleInfo, originalContext, gmsContext, new DynamiteContext(moduleInfo, originalAppContext, gmsContext, null));
dynamiteContext = new DynamiteContext(moduleInfo, originalContext, gmsContext, new DynamiteContext(moduleInfo, originalAppContext, gmsContext, null));
}
moduleInfo.init(dynamiteContext);
return dynamiteContext;
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import static android.content.Context.CONTEXT_IGNORE_SECURITY;
import static android.content.Context.CONTEXT_INCLUDE_CODE;
import android.content.ContextWrapper;

public class DynamiteModuleInfo {
private Class<?> descriptor;
Expand Down Expand Up @@ -51,4 +52,12 @@ public Collection<String> getMergedClasses() {
return Collections.emptySet();
}
}

public void init(ContextWrapper dynamiteContext) {
try {
descriptor.getMethod("init", ContextWrapper.class).invoke(null, dynamiteContext);
} catch (Exception e) {
// Ignore
}
}
}

0 comments on commit ec636fd

Please sign in to comment.