|
24 | 24 | import com.surcumference.fingerprint.util.Config; |
25 | 25 | import com.surcumference.fingerprint.util.FileUtils; |
26 | 26 | import com.surcumference.fingerprint.util.Task; |
27 | | -import com.surcumference.fingerprint.util.ZipUtils; |
28 | 27 | import com.surcumference.fingerprint.util.log.L; |
29 | 28 | import com.surcumference.fingerprint.view.DownloadView; |
30 | | -import com.surcumference.fingerprint.view.MagiskInstPluginTargetSelectionView; |
31 | 29 | import com.surcumference.fingerprint.view.MessageView; |
32 | | -import com.surcumference.fingerprint.view.ShellExecuteView; |
33 | 30 | import com.surcumference.fingerprint.view.UpdateInfoView; |
34 | 31 |
|
35 | | -import net.lingala.zip4j.exception.ZipException; |
36 | 32 |
|
37 | 33 | import java.io.File; |
38 | 34 | import java.util.HashMap; |
39 | | -import java.util.Iterator; |
40 | 35 | import java.util.Locale; |
41 | 36 | import java.util.Map; |
42 | 37 | import java.util.concurrent.Callable; |
43 | 38 |
|
44 | | -import eu.chainfire.libsuperuser.Shell; |
45 | | - |
46 | 39 | /** |
47 | 40 | * Created by Jason on 2017/9/10. |
48 | 41 | */ |
@@ -124,86 +117,9 @@ public void onHasUpdate(UpdateInfo updateInfo) { |
124 | 117 | } |
125 | 118 |
|
126 | 119 | private static void handleMagiskUpdate(Context context, UpdateInfo updateInfo, DialogInterface updateInfoViewDialogInterface) { |
127 | | - Task.onBackground(() -> { |
128 | | - if (!Shell.SU.available()) { |
129 | | - if (!Shell.SU.available()) { |
130 | | - Task.onMain(() -> new MessageView(context).text(Lang.getString(R.id.update_no_root)).showInDialog()); |
131 | | - return; |
132 | | - } |
133 | | - } |
134 | | - Task.onMain(() -> { |
135 | | - MagiskInstPluginTargetSelectionView instPluginTargetSelectionView = new MagiskInstPluginTargetSelectionView(context); |
136 | | - instPluginTargetSelectionView.showInDialog(); |
137 | | - instPluginTargetSelectionView.withOnPositiveButtonClickListener((dialog, which) -> { |
138 | | - Map<PluginTarget, Boolean> instPluginTargetSelectionMap = instPluginTargetSelectionView.getSelection(); |
139 | | - L.d("instPluginTargetSelectionMap", instPluginTargetSelectionMap); |
140 | | - if (!instPluginTargetSelectionMap.values().contains(true)) { |
141 | | - Toaster.showShort(Lang.getString(R.id.update_at_least_select_one)); |
142 | | - return; |
143 | | - } |
144 | | - dialog.dismiss(); |
145 | | - String fileName = context.getPackageName() + ".zip"; |
146 | | - File cacheDir = context.getCacheDir(); |
147 | | - File targetFile = new File(cacheDir, fileName); |
148 | | - File unzipDir = new File(cacheDir, BuildConfig.APPLICATION_ID); |
149 | | - Runnable cleanTask = () -> { |
150 | | - FileUtils.delete(targetFile); |
151 | | - FileUtils.delete(unzipDir); |
152 | | - }; |
153 | | - cleanTask.run(); |
154 | | - String mirrorUrl = String.format(Locale.getDefault(), Constant.UPDATE_URL_MIRROR_FILE, updateInfo.version, updateInfo.name); |
155 | | - new DownloadView(context) |
156 | | - .download(new String[]{mirrorUrl, updateInfo.url}, targetFile, updateInfo.size, () -> { |
157 | | - updateInfoViewDialogInterface.dismiss(); |
158 | | - ShellExecuteView shellExecuteView = new ShellExecuteView(context); |
159 | | - shellExecuteView.showInDialog(); |
160 | | - Task.onBackground(() -> { |
161 | | - try { |
162 | | - unzipDir.mkdirs(); |
163 | | - try { |
164 | | - ZipUtils.unzip(targetFile, unzipDir.getAbsolutePath(), ""); |
165 | | - } catch (ZipException e) { |
166 | | - L.e(e); |
167 | | - Task.onMain(() -> new MessageView(context).text(Lang.getString(R.id.update_file_corrupted)).showInDialog()); |
168 | | - return; |
169 | | - } |
170 | | - |
171 | | - File[] moduleZipFiles = unzipDir.listFiles(); |
172 | | - Map<PluginTarget, File> moduleFilePluginTargetMap = matchMagiskModuleFileListToPluginTarget(moduleZipFiles); |
173 | | - L.d("moduleFilePluginTargetMap", moduleFilePluginTargetMap); |
174 | | - if (moduleFilePluginTargetMap.size() <= 0) { |
175 | | - Task.onMain(() -> new MessageView(context).text(Lang.getString(R.id.update_file_missing)).showInDialog()); |
176 | | - return; |
177 | | - } |
178 | | - Iterator<Map.Entry<PluginTarget, Boolean>> it = instPluginTargetSelectionMap.entrySet().iterator(); |
179 | | - while (it.hasNext()) { |
180 | | - Map.Entry<PluginTarget, Boolean> entry = it.next(); |
181 | | - PluginTarget pluginTarget = entry.getKey(); |
182 | | - boolean selected = (boolean)entry.getValue(); |
183 | | - if (!selected) { |
184 | | - continue; |
185 | | - } |
186 | | - File moduleFile = moduleFilePluginTargetMap.get(pluginTarget); |
187 | | - if (moduleFile == null) { |
188 | | - continue; |
189 | | - } |
190 | | - String command = String.format("magisk --install-module \"%s\"", moduleFile.getAbsolutePath()); |
191 | | - int installModuleResult = shellExecuteView.executeCommand(command); |
192 | | - if (installModuleResult != 0) { |
193 | | - Task.onMain(()-> shellExecuteView.appendCommandLineOutput(Lang.getString(R.id.update_installation_failed) + installModuleResult + "\n请尝试前往更新页面手动获取更新")); |
194 | | - return; |
195 | | - } |
196 | | - } |
197 | | - Task.onMain(()-> shellExecuteView.appendCommandLineOutput(Lang.getString(R.id.update_success_note))); |
198 | | - } finally { |
199 | | - cleanTask.run(); |
200 | | - } |
201 | | - }); |
202 | | - }).showInDialog(); |
203 | | - |
204 | | - }); |
205 | | - }); |
206 | | - }); |
| 120 | + com.surcumference.fingerprint.util.UrlUtils.openUrl(context, updateInfo.pageUrl); |
| 121 | + Task.onMain(1000, () -> Toaster.showLong(Lang.getString(R.id.toast_update_available))); |
| 122 | + updateInfoViewDialogInterface.dismiss(); |
207 | 123 | } |
208 | 124 |
|
209 | 125 | private static Map<PluginTarget, File> matchMagiskModuleFileListToPluginTarget(@Nullable File[] moduleZipFiles) { |
|
0 commit comments