diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..df6f477c --- /dev/null +++ b/build.gradle @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2005-2017 Qihoo 360 Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + ext.kotlin_version = '1.1.3' + repositories { + jcenter() + mavenCentral() + maven { + url "file:///Users/knero/Documents/local_maven/" + } + } + dependencies { + classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' + classpath 'com.qihoo360.replugin:replugin-host-gradle:2.2.1' + classpath 'com.qihoo360.replugin:replugin-plugin-gradle:2.2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + jcenter() + mavenCentral() + maven { + url "file:///Users/knero/Documents/local_maven/" + } + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..13372aef Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..ada24495 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,22 @@ +# +# Copyright (C) 2005-2017 Qihoo 360 Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. +# + +#Fri Mar 03 10:15:50 CST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..9d82f789 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100755 index 00000000..8a0b282a --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/Loader.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/Loader.java index 622d4a3e..8184531b 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/Loader.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/Loader.java @@ -313,6 +313,9 @@ final boolean loadDex(ClassLoader parent, int load) { // 线上环境保持不变 parent = getClass().getClassLoader().getParent(); // TODO: 这里直接用父类加载器 } + + Log.d("LZC", " ======:" + parent); + String soDir = mPackageInfo.applicationInfo.nativeLibraryDir; mClassLoader = RePlugin.getConfig().getCallbacks().createPluginClassLoader(mPluginObj.mInfo, mPath, out, soDir, parent); Log.i("dex", "load " + mPath + " = " + mClassLoader); diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginContext.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginContext.java index dd7fee28..8e3354de 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginContext.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginContext.java @@ -26,6 +26,7 @@ import android.content.res.Resources; import android.os.Bundle; import android.util.AttributeSet; +import android.util.Log; import android.view.ContextThemeWrapper; import android.view.InflateException; import android.view.LayoutInflater; @@ -105,6 +106,7 @@ public ClassLoader getClassLoader() { @Override public Resources getResources() { + Log.d("LZC", "animation---:getResource()" ); if (mNewResources != null) { return mNewResources; } diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginProviderStub.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginProviderStub.java index 4abc6b4f..52ceeab4 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginProviderStub.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginProviderStub.java @@ -24,12 +24,16 @@ import android.os.IBinder.DeathRecipient; import android.os.RemoteException; import android.text.TextUtils; +import android.util.Log; +import com.qihoo360.i.IPluginManager; import com.qihoo360.loader2.sp.IPref; import com.qihoo360.loader2.sp.PrefImpl; import com.qihoo360.replugin.base.IPC; import com.qihoo360.replugin.component.process.ProcessPitProviderBase; import com.qihoo360.replugin.component.process.ProcessPitProviderPersist; +import com.qihoo360.replugin.component.process.ProcessPitProviderUI; +import com.qihoo360.replugin.helper.HostConfigHelper; import com.qihoo360.replugin.helper.LogDebug; import com.qihoo360.replugin.utils.CloseableUtils; @@ -50,7 +54,7 @@ public class PluginProviderStub { private static final String URL_PARAM_KEY_LOADED = "loaded"; private static final String PROJECTION_MAIN[] = { - "main" + "main" }; private static final String SELECTION_MAIN_BINDER = "main_binder"; @@ -90,6 +94,7 @@ public static final Cursor stubMain(Uri uri, String[] projection, String selecti /** * 在目标插件进程中运行 + * * @param uri * @param values * @return @@ -159,10 +164,16 @@ static final IBinder proxyFetchHostPref(Context context) { * @return */ private static final IBinder proxyFetchHostBinder(Context context, String selection) { - // Cursor cursor = null; + Uri uri; + if (HostConfigHelper.PERSISTENT_ENABLE) { + uri = ProcessPitProviderPersist.URI; + } else { + uri = ProcessPitProviderUI.buildUri(IPluginManager.PROCESS_UI); + } + Log.d("LZC", "uri:" + uri + " currentProcess:" + IPC.getCurrentProcessName()); try { - Uri uri = ProcessPitProviderPersist.URI; + cursor = context.getContentResolver().query(uri, PROJECTION_MAIN, selection, null, null); if (cursor == null) { if (LOG) { diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/process/ProcessPitProviderUI.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/process/ProcessPitProviderUI.java index 18be6bc1..96ff44f7 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/process/ProcessPitProviderUI.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/process/ProcessPitProviderUI.java @@ -16,9 +16,22 @@ package com.qihoo360.replugin.component.process; +import android.database.Cursor; +import android.net.Uri; + +import com.qihoo360.loader2.PluginProviderStub; +import com.qihoo360.replugin.helper.HostConfigHelper; + /** * @author RePlugin Team */ public class ProcessPitProviderUI extends ProcessPitProviderBase { + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { + if (HostConfigHelper.PERSISTENT_ENABLE) { + return super.query(uri, projection, selection, selectionArgs, sortOrder); + } + return PluginProviderStub.stubMain(uri, projection, selection, selectionArgs, sortOrder); + } } diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/service/ServiceDispatcher.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/service/ServiceDispatcher.java index 46e9cc7f..9413240c 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/service/ServiceDispatcher.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/component/service/ServiceDispatcher.java @@ -68,6 +68,7 @@ private static class InnerConnection extends IServiceConnection.Stub { mDispatcher = new WeakReference(sd); } + @Override public void connected(ComponentName name, IBinder service) throws RemoteException { ServiceDispatcher sd = mDispatcher.get(); if (sd != null) { diff --git a/replugin-sample/host/app/build.gradle b/replugin-sample/host/app/build.gradle index a2acf0d9..2933c517 100644 --- a/replugin-sample/host/app/build.gradle +++ b/replugin-sample/host/app/build.gradle @@ -22,7 +22,7 @@ android { defaultConfig { applicationId "com.qihoo360.replugin.sample.host" minSdkVersion 9 - targetSdkVersion 22 + targetSdkVersion 20 versionCode 1 versionName "1.0" } @@ -37,7 +37,7 @@ android { apply plugin: 'replugin-host-gradle' repluginHostConfig { useAppCompat = true - +// persistentEnable = false // 可以在这里自定义常驻进程的名字 // persistentName = ":XXXXService" } @@ -45,5 +45,6 @@ repluginHostConfig { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.qihoo360.replugin:replugin-host-lib:2.2.2' + compile project(':replugin-host-library:replugin-host-lib') + compile 'com.qihoo360.accounts:qihoo-account-plugin:1.0.3' } diff --git a/replugin-sample/host/app/src/main/AndroidManifest.xml b/replugin-sample/host/app/src/main/AndroidManifest.xml index be049a1e..92a6a562 100644 --- a/replugin-sample/host/app/src/main/AndroidManifest.xml +++ b/replugin-sample/host/app/src/main/AndroidManifest.xml @@ -43,6 +43,8 @@ + \ No newline at end of file diff --git a/replugin-sample/host/app/src/main/assets/account.jar b/replugin-sample/host/app/src/main/assets/account.jar new file mode 100644 index 00000000..35a40318 Binary files /dev/null and b/replugin-sample/host/app/src/main/assets/account.jar differ diff --git a/replugin-sample/host/app/src/main/assets/config.properties b/replugin-sample/host/app/src/main/assets/config.properties new file mode 100644 index 00000000..b7376c20 --- /dev/null +++ b/replugin-sample/host/app/src/main/assets/config.properties @@ -0,0 +1,25 @@ +src=mpc_qucsdk +app_secret=z53ea84md +server=xcx.passport.360.cn +## 第三方登录的相关配置,如果不配置,不显示登录的入口 +#wx_app_id=wx5f93ae865c6715f4 +#qq_app_id=1105336340 +#sina_app_id=3883559376 +#sina_redirect_url=https://i.360.cn/ +## 登录入口的相关配置 +## 是否有邮箱注册 +#reg_email=false +## 邮箱注册是否需要激活 +#reg_eamil_active=true +## 输入框是否展示上次登录帐号 +#show_last_account=true +## 是否支持海外手机号 +#suport_oversea=true +## 第三方第一次登录,是否要补全手机号,其中0为不跳过(用户可以选择跳过),1为跳过,2为强制补全 +#oauth_login_set_info=0 +## 登录返回的头像大小, A/S/M/B/Q(分别代表20x20/48x48/64x64/100x100/150x150) +#head_icon_size=Q +## 登录、注册返回的字段, 按接口指定配置 +#fields=qid,username,nickname,loginemail,head_pic,mobile +## 第三方登录返回字段, 如果不填,使用fields +#oauth_fields=qid,username,nickname,loginemail,head_pic,mobile \ No newline at end of file diff --git a/replugin-sample/host/app/src/main/assets/plugins/demo1.jar b/replugin-sample/host/app/src/main/assets/plugins/demo1.jar index 088e0e49..a410ff91 100644 Binary files a/replugin-sample/host/app/src/main/assets/plugins/demo1.jar and b/replugin-sample/host/app/src/main/assets/plugins/demo1.jar differ diff --git a/replugin-sample/host/app/src/main/assets/style.json b/replugin-sample/host/app/src/main/assets/style.json new file mode 100644 index 00000000..aec50d0a --- /dev/null +++ b/replugin-sample/host/app/src/main/assets/style.json @@ -0,0 +1,47 @@ +[ + { + "id": "qihoo_accounts_green", + "type": "color", + "value": "#FF0000" + }, + { + "id": "qihoo_accounts_dialog_account_color", + "type": "color", + "value": "#FF0000" + }, + { + "id": "qihoo_accounts_btn_main_selector", + "type": "selector", + "value": "#FF0000" + }, + { + "id": "qihoo_accounts_checkbox_selector", + "type": "tint_drawable", + "value": "#FF0000" + }, + { + "id": "qihoo_accounts_country_touch_value_bg", + "type": "tint_drawable", + "value": "#FF0000" + }, + { + "id": "qihoo_accounts_dialog_background", + "type": "tint_drawable", + "value": "#FF0000" + }, + { + "id": "qihoo_accounts_dialog_logining", + "type": "tint_drawable", + "value": "#FF0000" + }, + { + "id": "qrcode_scan_line", + "type": "tint_drawable", + "value": "#FF0000" + }, + { + "id": "qihoo_accounts_webview_dskin", + "type": "string", + "value": "#FF0000_#FF0000_#FF0000_#FF0000" + } +] \ No newline at end of file diff --git a/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/MainActivity.java b/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/MainActivity.java index 3fc18d1c..b053e480 100644 --- a/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/MainActivity.java +++ b/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/MainActivity.java @@ -27,6 +27,7 @@ import android.view.View; import android.widget.Toast; +import com.qihoo360.accounts.plugin.QihooAccountsPlugin; import com.qihoo360.replugin.RePlugin; import com.qihoo360.replugin.model.PluginInfo; import com.qihoo360.replugin.utils.FileUtils; @@ -99,8 +100,26 @@ public void run() { } }); + findViewById(R.id.start_process).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + QihooAccountsPlugin.toLogin(MainActivity.this); +// Intent intent = RePlugin.createIntent("sdk.quc.test", "com.example.demo.UCActivity"); +// RePlugin.startActivity(MainActivity.this, intent); +// Intent intent = new Intent(MainActivity.this, OtherProcessActivity.class); +// startActivity(intent); + } + }); // 刻意使用Thread的ClassLoader来测试效果 testThreadClassLoader(); + + try { + Class clazz = getClass().getClassLoader() + .loadClass("com.example.demo.MainActivity"); + Activity activity = (Activity) clazz.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } } private void testThreadClassLoader() { diff --git a/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/OtherProcessActivity.java b/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/OtherProcessActivity.java new file mode 100644 index 00000000..5cdbcb0c --- /dev/null +++ b/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/OtherProcessActivity.java @@ -0,0 +1,169 @@ +package com.qihoo360.replugin.sample.host; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.view.View; +import android.widget.Toast; + +import com.qihoo360.replugin.RePlugin; +import com.qihoo360.replugin.model.PluginInfo; +import com.qihoo360.replugin.utils.FileUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; + +/** + * @author knero + * @date 11/14/17 created. + */ + +public class OtherProcessActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + findViewById(R.id.btn_start_demo1).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // 刻意以“包名”来打开 + RePlugin.startActivity(OtherProcessActivity.this, RePlugin.createIntent("com.qihoo360.replugin.sample.demo1", "com.qihoo360.replugin.sample.demo1.OtherProcessActivity")); + } + }); + + findViewById(R.id.btn_start_plugin_for_result).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // 刻意以“Alias(别名)”来打开 + Intent intent = new Intent(); + intent.setComponent(new ComponentName("demo1", "com.qihoo360.replugin.sample.demo1.activity.for_result.ForResultActivity")); + RePlugin.startActivityForResult(OtherProcessActivity.this, intent, REQUEST_CODE_DEMO1, null); + } + }); + + findViewById(R.id.btn_load_fragment_from_demo1).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + startActivity(new Intent(OtherProcessActivity.this, PluginFragmentActivity.class)); + } + }); + + findViewById(R.id.btn_start_demo3).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // 若没有安装,则直接提示“错误” + // TODO 将来把回调串联上 + if (RePlugin.isPluginInstalled("demo3")) { + RePlugin.startActivity(OtherProcessActivity.this, RePlugin.createIntent("demo3", "com.qihoo360.replugin.sample.demo3.OtherProcessActivity")); + } else { + Toast.makeText(OtherProcessActivity.this, "You must install demo3 first!", Toast.LENGTH_SHORT).show(); + } + } + }); + + findViewById(R.id.btn_install_apk_from_assets).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + final ProgressDialog pd = ProgressDialog.show(OtherProcessActivity.this, "Installing...", "Please wait...", true, true); + // FIXME: 仅用于安装流程演示 2017/7/24 + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { + @Override + public void run() { + simulateInstallExternalPlugin(); + pd.dismiss(); + } + }, 1000); + } + }); + + // 刻意使用Thread的ClassLoader来测试效果 + testThreadClassLoader(); + } + + private void testThreadClassLoader() { + // 在2.1.7及以前版本,如果直接调用此方法,则拿到的ClassLoader可能是PathClassLoader或者为空。有极个别Java库会用到此方法 + // 这里务必确保:cl == getClassLoader(),才符合预期 + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl != getClassLoader()) { + throw new RuntimeException("Thread.current.classLoader != getClassLoader(). cl=" + cl + "; getC=" + getClassLoader()); + } + } + + private static final int REQUEST_CODE_DEMO1 = 0x011; + private static final int RESULT_CODE_DEMO1 = 0x012; + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == REQUEST_CODE_DEMO1 && resultCode == RESULT_CODE_DEMO1) { + Toast.makeText(this, data.getStringExtra("data"), Toast.LENGTH_SHORT).show(); + } + } + + /** + * 模拟安装或升级(覆盖安装)外置插件 + * 注意:为方便演示,外置插件临时放置到Host的assets/external目录下,具体说明见README

+ */ + private void simulateInstallExternalPlugin() { + String demo3Apk= "demo3.apk"; + String demo3apkPath = "external" + File.separator + demo3Apk; + + // 文件是否已经存在?直接删除重来 + String pluginFilePath = getFilesDir().getAbsolutePath() + File.separator + demo3Apk; + File pluginFile = new File(pluginFilePath); + if (pluginFile.exists()) { + FileUtils.deleteQuietly(pluginFile); + } + + // 开始复制 + copyAssetsFileToAppFiles(demo3apkPath, demo3Apk); + PluginInfo info = null; + if (pluginFile.exists()) { + info = RePlugin.install(pluginFilePath); + } + + if (info != null) { + RePlugin.startActivity(OtherProcessActivity.this, RePlugin.createIntent(info.getName(), "com.qihoo360.replugin.sample.demo3.OtherProcessActivity")); + } else { + Toast.makeText(OtherProcessActivity.this, "install external plugin failed", Toast.LENGTH_SHORT).show(); + } + } + + /** + * 从assets目录中复制某文件内容 + * @param assetFileName assets目录下的Apk源文件路径 + * @param newFileName 复制到/data/data/package_name/files/目录下文件名 + */ + private void copyAssetsFileToAppFiles(String assetFileName, String newFileName) { + InputStream is = null; + FileOutputStream fos = null; + int buffsize = 1024; + + try { + is = this.getAssets().open(assetFileName); + fos = this.openFileOutput(newFileName, Context.MODE_PRIVATE); + int byteCount = 0; + byte[] buffer = new byte[buffsize]; + while((byteCount = is.read(buffer)) != -1) { + fos.write(buffer, 0, byteCount); + } + fos.flush(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + is.close(); + fos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/SampleApplication.java b/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/SampleApplication.java index fc31be08..6052e4fb 100644 --- a/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/SampleApplication.java +++ b/replugin-sample/host/app/src/main/java/com/qihoo360/replugin/sample/host/SampleApplication.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.util.Log; +import com.qihoo360.accounts.plugin.QihooAccountsPlugin; import com.qihoo360.replugin.RePlugin; import com.qihoo360.replugin.RePluginApplication; import com.qihoo360.replugin.RePluginCallbacks; @@ -37,6 +38,13 @@ protected void attachBaseContext(Context base) { // FIXME 允许接收rpRunPlugin等Gradle Task,发布时请务必关掉,以免出现问题 RePlugin.enableDebugger(base, BuildConfig.DEBUG); + QihooAccountsPlugin.App.attachBaseContext(this); + } + + @Override + public void onCreate() { + super.onCreate(); + QihooAccountsPlugin.App.onCreate(); } // ---------- diff --git a/replugin-sample/host/app/src/main/res/layout/activity_main.xml b/replugin-sample/host/app/src/main/res/layout/activity_main.xml index 9338a5aa..0db2bf42 100644 --- a/replugin-sample/host/app/src/main/res/layout/activity_main.xml +++ b/replugin-sample/host/app/src/main/res/layout/activity_main.xml @@ -55,4 +55,11 @@ android:layout_height="50dp" android:layout_gravity="center" android:text="@string/installPluginFromAssets" /> + +