22
33import android .app .Activity ;
44import android .app .AlertDialog ;
5+ import android .app .ProgressDialog ;
56import android .content .ActivityNotFoundException ;
67import android .content .ComponentName ;
78import android .content .Context ;
1819import android .preference .PreferenceManager ;
1920import android .provider .Settings ;
2021import android .text .TextUtils ;
22+ import android .util .Log ;
2123import android .view .KeyEvent ;
2224import android .view .View ;
2325import android .view .Window ;
2628
2729import com .android .launcher3 .LauncherFiles ;
2830import com .google .android .apps .nexuslauncher .NexusLauncherActivity ;
31+ import com .lody .virtual .client .core .InstallStrategy ;
2932import com .lody .virtual .client .core .VirtualCore ;
3033import com .lody .virtual .helper .utils .DeviceUtil ;
34+ import com .lody .virtual .helper .utils .FileUtils ;
35+ import com .lody .virtual .helper .utils .MD5Utils ;
36+ import com .lody .virtual .helper .utils .VLog ;
3137
3238import java .io .File ;
39+ import java .io .FileOutputStream ;
40+ import java .io .InputStream ;
41+ import java .io .OutputStream ;
3342import java .lang .reflect .Method ;
3443
35- import io .virtualapp .XApp ;
3644import io .virtualapp .R ;
45+ import io .virtualapp .abs .ui .VUiKit ;
3746import io .virtualapp .settings .SettingsActivity ;
3847import io .virtualapp .update .VAVersionService ;
3948
49+ import static io .virtualapp .XApp .XPOSED_INSTALLER_PACKAGE ;
50+
4051/**
4152 * @author weishu
4253 * @date 18/2/9.
@@ -49,6 +60,7 @@ public class NewHomeActivity extends NexusLauncherActivity {
4960
5061 private Handler mUiHandler ;
5162 private boolean mDirectlyBack = false ;
63+ private boolean checkXposedInstaller = true ;
5264
5365 public static void goHome (Context context ) {
5466 Intent intent = new Intent (context , NewHomeActivity .class );
@@ -68,9 +80,73 @@ public void onCreate(Bundle savedInstanceState) {
6880 mDirectlyBack = sharedPreferences .getBoolean (SettingsActivity .DIRECTLY_BACK_KEY , false );
6981 }
7082
83+ private void installXposed () {
84+ boolean isXposedInstalled = false ;
85+ try {
86+ isXposedInstalled = VirtualCore .get ().isAppInstalled (XPOSED_INSTALLER_PACKAGE );
87+ File oldXposedInstallerApk = getFileStreamPath ("XposedInstaller_1_31.apk" );
88+ if (oldXposedInstallerApk .exists ()) {
89+ VirtualCore .get ().uninstallPackage (XPOSED_INSTALLER_PACKAGE );
90+ oldXposedInstallerApk .delete ();
91+ isXposedInstalled = false ;
92+ Log .d (TAG , "remove xposed installer success!" );
93+ }
94+ } catch (Throwable e ) {
95+ VLog .d (TAG , "remove xposed install failed." , e );
96+ }
97+
98+ if (!isXposedInstalled ) {
99+ ProgressDialog dialog = new ProgressDialog (this );
100+ dialog .setCancelable (false );
101+ dialog .setMessage (getResources ().getString (R .string .prepare_xposed_installer ));
102+ dialog .show ();
103+
104+ VUiKit .defer ().when (() -> {
105+ File xposedInstallerApk = getFileStreamPath ("XposedInstaller_5_8.apk" );
106+ if (!xposedInstallerApk .exists ()) {
107+ InputStream input = null ;
108+ OutputStream output = null ;
109+ try {
110+ input = getApplicationContext ().getAssets ().open ("XposedInstaller_3.1.5.apk_" );
111+ output = new FileOutputStream (xposedInstallerApk );
112+ byte [] buffer = new byte [1024 ];
113+ int length ;
114+ while ((length = input .read (buffer )) > 0 ) {
115+ output .write (buffer , 0 , length );
116+ }
117+ } catch (Throwable e ) {
118+ VLog .e (TAG , "copy file error" , e );
119+ } finally {
120+ FileUtils .closeQuietly (input );
121+ FileUtils .closeQuietly (output );
122+ }
123+ }
124+
125+ if (xposedInstallerApk .isFile () && !DeviceUtil .isMeizuBelowN ()) {
126+ try {
127+ if ("8537fb219128ead3436cc19ff35cfb2e" .equals (MD5Utils .getFileMD5String (xposedInstallerApk ))) {
128+ VirtualCore .get ().installPackage (xposedInstallerApk .getPath (), InstallStrategy .TERMINATE_IF_EXIST );
129+ } else {
130+ VLog .w (TAG , "unknown Xposed installer, ignore!" );
131+ }
132+ } catch (Throwable ignored ) {
133+ }
134+ }
135+ }).then ((v ) -> {
136+ dialog .dismiss ();
137+ }).fail ((err ) -> {
138+ dialog .dismiss ();
139+ });
140+ }
141+ }
142+
71143 @ Override
72144 protected void onResume () {
73145 super .onResume ();
146+ if (checkXposedInstaller ) {
147+ checkXposedInstaller = false ;
148+ installXposed ();
149+ }
74150 // check for update
75151 new Handler ().postDelayed (() ->
76152 VAVersionService .checkUpdate (getApplicationContext (), false ), 1000 );
@@ -146,7 +222,7 @@ private void alertForMeizu() {
146222 if (!DeviceUtil .isMeizuBelowN ()) {
147223 return ;
148224 }
149- boolean isXposedInstalled = VirtualCore .get ().isAppInstalled (XApp . XPOSED_INSTALLER_PACKAGE );
225+ boolean isXposedInstalled = VirtualCore .get ().isAppInstalled (XPOSED_INSTALLER_PACKAGE );
150226 if (isXposedInstalled ) {
151227 return ;
152228 }
0 commit comments