Skip to content

Commit

Permalink
new feature: modify param 'splitName' to 'SplitBriefInfo' of SplitAct…
Browse files Browse the repository at this point in the history
…ivityLifecycleCallbacks
  • Loading branch information
kissonchan committed Jan 2, 2020
1 parent 9c1a0ea commit 576033e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 51 deletions.
27 changes: 13 additions & 14 deletions app/src/main/java/com/iqiyi/qigsaw/sample/QigsawApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.iqiyi.android.qigsaw.core.SplitConfiguration;
import com.iqiyi.android.qigsaw.core.Qigsaw;
import com.iqiyi.android.qigsaw.core.splitload.SplitLoad;
import com.iqiyi.android.qigsaw.core.splitreport.SplitBriefInfo;
import com.iqiyi.qigsaw.sample.downloader.SampleDownloader;
import com.iqiyi.qigsaw.sample.reporter.SampleLogger;
import com.iqiyi.qigsaw.sample.reporter.SampleSplitInstallReporter;
Expand Down Expand Up @@ -46,53 +47,51 @@ protected void attachBaseContext(Context base) {
.obtainUserConfirmationDialogClass(SampleObtainUserConfirmationDialog.class)
.build();
Qigsaw.install(this, new SampleDownloader(), configuration);
}

@Override
public void onCreate() {
super.onCreate();
Qigsaw.onApplicationCreated();
Qigsaw.registerSplitActivityLifecycleCallbacks(new SplitActivityLifecycleCallbacks() {

@Override
public void onSplitActivityCreated(@NonNull String splitName, @NonNull Activity activity, @Nullable Bundle savedInstanceState) {
public void onSplitActivityCreated(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity, @Nullable Bundle savedInstanceState) {

}

@Override
public void onSplitActivityStarted(@NonNull String splitName, @NonNull Activity activity) {
public void onSplitActivityStarted(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity) {

}

@Override
public void onSplitActivityResumed(@NonNull String splitName, @NonNull Activity activity) {
public void onSplitActivityResumed(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity) {

}

@Override
public void onSplitActivityPaused(@NonNull String splitName, @NonNull Activity activity) {
public void onSplitActivityPaused(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity) {

}

@Override
public void onSplitActivityStopped(@NonNull String splitName, @NonNull Activity activity) {
public void onSplitActivityStopped(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity) {

}

@Override
public void onSplitActivitySaveInstanceState(@NonNull String splitName, @NonNull Activity activity, @NonNull Bundle outState) {
public void onSplitActivitySaveInstanceState(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity, @NonNull Bundle outState) {

}

@Override
public void onSplitActivityDestroyed(@NonNull String splitName, @NonNull Activity activity) {
public void onSplitActivityDestroyed(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity) {

}

});
}

@Override
public void onCreate() {
super.onCreate();
Qigsaw.onApplicationCreated();
}

@Override
public Resources getResources() {
Qigsaw.onApplicationGetResources(super.getResources());
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx1536m
JAVA_VERSION=1.7
AGP_VERSION=3.4.2
GROUP_ID=com.iqiyi.android.qigsaw
VERSION_NAME=1.2.0
VERSION_NAME=1.2.3-beta01
BINTRAY_REPO=maven
POM_DESCRIPTION=A dynamic modularization library which is based on Android App Bundles.
POM_PACKAGING=pom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

import com.iqiyi.android.qigsaw.core.common.SplitLog;
import com.iqiyi.android.qigsaw.core.extension.AABExtension;
import com.iqiyi.android.qigsaw.core.splitreport.SplitBriefInfo;
import com.iqiyi.android.qigsaw.core.splitrequest.splitinfo.SplitInfo;
import com.iqiyi.android.qigsaw.core.splitrequest.splitinfo.SplitInfoManager;
import com.iqiyi.android.qigsaw.core.splitrequest.splitinfo.SplitInfoManagerService;

public abstract class SplitActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {

Expand All @@ -19,76 +23,96 @@ public abstract class SplitActivityLifecycleCallbacks implements Application.Act

private final LruCache<String, String> splitActivityNameCache = new LruCache<>(20);

private final LruCache<String, SplitBriefInfo> splitBriefInfoCache = new LruCache<>(10);

@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public final void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
String splitName = getSplitNameForActivityName(activity);
if (!SPLIT_NAME_BASE.equals(splitName)) {
onSplitActivityCreated(splitName, activity, savedInstanceState);
SplitLog.i(TAG, "Activity %s of split %s is created.", activity.getClass().getName(), splitName);
SplitBriefInfo briefInfo = getSplitBriefInfoForActivity(activity);
if (briefInfo != null) {
onSplitActivityCreated(briefInfo, activity, savedInstanceState);
SplitLog.i(TAG, "Activity %s of split %s is created.", activity.getClass().getName(), briefInfo.toString());
}
}

@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void onActivityStarted(@NonNull Activity activity) {
String splitName = getSplitNameForActivityName(activity);
if (!SPLIT_NAME_BASE.equals(splitName)) {
onSplitActivityStarted(splitName, activity);
SplitLog.i(TAG, "Activity %s of split %s is started.", activity.getClass().getName(), splitName);
SplitBriefInfo briefInfo = getSplitBriefInfoForActivity(activity);
if (briefInfo != null) {
onSplitActivityStarted(briefInfo, activity);
SplitLog.i(TAG, "Activity %s of split %s is started.", activity.getClass().getName(), briefInfo.toString());
}
}

@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void onActivityResumed(@NonNull Activity activity) {
String splitName = getSplitNameForActivityName(activity);
if (!SPLIT_NAME_BASE.equals(splitName)) {
onSplitActivityResumed(splitName, activity);
SplitLog.i(TAG, "Activity %s of split %s is started.", activity.getClass().getName(), splitName);
SplitBriefInfo briefInfo = getSplitBriefInfoForActivity(activity);
if (briefInfo != null) {
onSplitActivityResumed(briefInfo, activity);
SplitLog.i(TAG, "Activity %s of split %s is resumed.", activity.getClass().getName(), briefInfo.toString());
}
}

@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void onActivityPaused(@NonNull Activity activity) {
String splitName = getSplitNameForActivityName(activity);
if (!SPLIT_NAME_BASE.equals(splitName)) {
onSplitActivityPaused(splitName, activity);
SplitLog.i(TAG, "Activity %s of split %s is paused.", activity.getClass().getName(), splitName);

SplitBriefInfo briefInfo = getSplitBriefInfoForActivity(activity);
if (briefInfo != null) {
onSplitActivityPaused(briefInfo, activity);
SplitLog.i(TAG, "Activity %s of split %s is paused.", activity.getClass().getName(), briefInfo.toString());
}
}

@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void onActivityStopped(@NonNull Activity activity) {
String splitName = getSplitNameForActivityName(activity);
if (!SPLIT_NAME_BASE.equals(splitName)) {
onSplitActivityStopped(splitName, activity);
SplitLog.i(TAG, "Activity %s of split %s is stopped.", activity.getClass().getName(), splitName);

SplitBriefInfo briefInfo = getSplitBriefInfoForActivity(activity);
if (briefInfo != null) {
onSplitActivityStopped(briefInfo, activity);
SplitLog.i(TAG, "Activity %s of split %s is stopped.", activity.getClass().getName(), briefInfo.toString());
}
}

@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
String splitName = getSplitNameForActivityName(activity);
if (!SPLIT_NAME_BASE.equals(splitName)) {
onSplitActivitySaveInstanceState(splitName, activity, outState);
SplitLog.i(TAG, "Activity %s of split %s is saving state.", activity.getClass().getName(), splitName);
SplitBriefInfo briefInfo = getSplitBriefInfoForActivity(activity);
if (briefInfo != null) {
onSplitActivitySaveInstanceState(briefInfo, activity, outState);
SplitLog.i(TAG, "Activity %s of split %s is saving state.", activity.getClass().getName(), briefInfo.toString());
}
}

@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void onActivityDestroyed(@NonNull Activity activity) {
SplitBriefInfo briefInfo = getSplitBriefInfoForActivity(activity);
if (briefInfo != null) {
onSplitActivityDestroyed(briefInfo, activity);
SplitLog.i(TAG, "Activity %s of split %s is destroyed.", activity.getClass().getName(), briefInfo.toString());
}
}

@Nullable
private SplitBriefInfo getSplitBriefInfoForActivity(Activity activity) {
String splitName = getSplitNameForActivityName(activity);
if (!SPLIT_NAME_BASE.equals(splitName)) {
onSplitActivityDestroyed(splitName, activity);
SplitLog.i(TAG, "Activity %s of split %s is destroyed.", activity.getClass().getName(), splitName);
SplitBriefInfo briefInfo = splitBriefInfoCache.get(splitName);
if (briefInfo == null) {
SplitInfoManager infoManager = SplitInfoManagerService.getInstance();
if (infoManager != null) {
SplitInfo splitInfo = infoManager.getSplitInfo(activity, splitName);
if (splitInfo != null) {
briefInfo = new SplitBriefInfo(splitInfo.getSplitName(), splitInfo.getSplitVersion(), splitInfo.isBuiltIn());
splitBriefInfoCache.put(splitName, briefInfo);
}
}
}
return briefInfo;
}
return null;
}

private String getSplitNameForActivityName(Activity activity) {
Expand All @@ -105,37 +129,37 @@ private String getSplitNameForActivityName(Activity activity) {
/**
* Called when split Activity calls {@link Activity#onCreate super.onCreate()}.
*/
public abstract void onSplitActivityCreated(@NonNull String splitName, @NonNull Activity activity, @Nullable Bundle savedInstanceState);
public abstract void onSplitActivityCreated(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity, @Nullable Bundle savedInstanceState);

/**
* Called when split Activity calls {@link Activity#onStart super.onStart()}.
*/
public abstract void onSplitActivityStarted(@NonNull String splitName, @NonNull Activity activity);
public abstract void onSplitActivityStarted(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity);

/**
* Called when split Activity calls {@link Activity#onResume super.onResume()}.
*/
public abstract void onSplitActivityResumed(@NonNull String splitName, @NonNull Activity activity);
public abstract void onSplitActivityResumed(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity);

/**
* Called when split Activity calls {@link Activity#onPause super.onPause()}.
*/
public abstract void onSplitActivityPaused(@NonNull String splitName, @NonNull Activity activity);
public abstract void onSplitActivityPaused(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity);

/**
* Called when split Activity calls {@link Activity#onStop super.onStop()}.
*/
public abstract void onSplitActivityStopped(@NonNull String splitName, @NonNull Activity activity);
public abstract void onSplitActivityStopped(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity);

/**
* Called when split Activity calls
* {@link Activity#onSaveInstanceState super.onSaveInstanceState()}.
*/
public abstract void onSplitActivitySaveInstanceState(@NonNull String splitName, @NonNull Activity activity, @NonNull Bundle outState);
public abstract void onSplitActivitySaveInstanceState(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity, @NonNull Bundle outState);

/**
* Called when split Activity calls {@link Activity#onDestroy super.onDestroy()}.
*/
public abstract void onSplitActivityDestroyed(@NonNull String splitName, @NonNull Activity activity);
public abstract void onSplitActivityDestroyed(@NonNull SplitBriefInfo briefInfo, @NonNull Activity activity);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;

@Keep
Expand All @@ -38,12 +39,26 @@ public class SplitBriefInfo {
public final boolean builtIn;

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public SplitBriefInfo(String splitName, String version, boolean builtIn) {
public SplitBriefInfo(@NonNull String splitName, @NonNull String version, boolean builtIn) {
this.splitName = splitName;
this.version = version;
this.builtIn = builtIn;
}

@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof SplitBriefInfo)) {
return false;
}
SplitBriefInfo briefInfo = (SplitBriefInfo) obj;
if (splitName.equals(briefInfo.splitName)
&& version.equals(briefInfo.version)
&& (builtIn == briefInfo.builtIn)) {
return true;
}
return super.equals(obj);
}

@NonNull
@Override
public String toString() {
Expand Down

0 comments on commit 576033e

Please sign in to comment.