|
27 | 27 | import android.support.v4.content.LocalBroadcastManager;
|
28 | 28 | import android.text.TextUtils;
|
29 | 29 |
|
| 30 | +import com.qihoo360.mobilesafe.api.Tasks; |
30 | 31 | import com.qihoo360.replugin.RePlugin;
|
31 | 32 | import com.qihoo360.replugin.RePluginConstants;
|
32 | 33 | import com.qihoo360.replugin.RePluginEventCallbacks;
|
| 34 | +import com.qihoo360.replugin.RePluginInternal; |
33 | 35 | import com.qihoo360.replugin.base.IPC;
|
34 | 36 | import com.qihoo360.replugin.base.LocalBroadcastHelper;
|
35 | 37 | import com.qihoo360.replugin.component.ComponentList;
|
|
42 | 44 | import com.qihoo360.replugin.helper.LogRelease;
|
43 | 45 | import com.qihoo360.replugin.model.PluginInfo;
|
44 | 46 | import com.qihoo360.replugin.packages.IPluginManagerServer;
|
| 47 | +import com.qihoo360.replugin.packages.PluginInfoUpdater; |
45 | 48 | import com.qihoo360.replugin.packages.PluginManagerServer;
|
46 | 49 |
|
47 | 50 | import java.io.File;
|
@@ -329,13 +332,29 @@ public PluginInfo pluginDownloaded(String path) throws RemoteException {
|
329 | 332 |
|
330 | 333 | if (pi != null) {
|
331 | 334 | // 通常到这里,表示“安装已成功”,这时不管处于什么状态,都应该通知外界更新插件内存表
|
332 |
| - syncPluginInfo2All(pi); |
| 335 | + syncInstalledPluginInfo2All(pi); |
| 336 | + |
333 | 337 | }
|
334 | 338 |
|
335 | 339 | return pi;
|
336 | 340 | }
|
337 | 341 |
|
338 |
| - private void syncPluginInfo2All(PluginInfo pi) { |
| 342 | + @Override |
| 343 | + public boolean pluginUninstalled(PluginInfo info) throws RemoteException { |
| 344 | + if (LOG) { |
| 345 | + LogDebug.d(PLUGIN_TAG, "pluginUninstalled: pn=" + info.getName()); |
| 346 | + } |
| 347 | + final boolean result = mManager.getService().uninstall(info); |
| 348 | + |
| 349 | + // 卸载完成 |
| 350 | + if (result) { |
| 351 | + syncUninstalledPluginInfo2All(info); |
| 352 | + } |
| 353 | + |
| 354 | + return result; |
| 355 | + } |
| 356 | + |
| 357 | + private void syncInstalledPluginInfo2All(PluginInfo pi) { |
339 | 358 | // PS:若更新了“正在运行”的插件(属于“下次重启进程后更新”),则由于install返回的是“新的PluginInfo”,为防止出现“错误更新”,需要使用原来的
|
340 | 359 | //
|
341 | 360 | // 举例,有一个正在运行的插件A(其Info为PluginInfoOld)升级到新版(其Info为PluginInfoNew),则:
|
@@ -363,7 +382,30 @@ private void syncPluginInfo2All(PluginInfo pi) {
|
363 | 382 | IPC.sendLocalBroadcast2AllSync(mContext, intent);
|
364 | 383 |
|
365 | 384 | if (LOG) {
|
366 |
| - LogDebug.d(TAG, "syncPluginInfo2All: Sync complete! syncPi=" + needToSyncPi); |
| 385 | + LogDebug.d(TAG, "syncInstalledPluginInfo2All: Sync complete! syncPi=" + needToSyncPi); |
| 386 | + } |
| 387 | + } |
| 388 | + |
| 389 | + |
| 390 | + private void syncUninstalledPluginInfo2All(PluginInfo pi) { |
| 391 | + |
| 392 | + // 在常驻进程内更新插件内存表 |
| 393 | + mPluginMgr.pluginUninstalled(pi); |
| 394 | + |
| 395 | + // 给各进程发送广播,同步更新 |
| 396 | + final Intent intent = new Intent(PluginInfoUpdater.ACTION_UNINSTALL_PLUGIN); |
| 397 | + intent.putExtra("obj", pi); |
| 398 | + // 注意:若在attachBaseContext中调用此方法,则由于此时getApplicationContext为空,导致发送广播时会出现空指针异常。 |
| 399 | + // 则应该Post一下,待getApplicationContext有值后再发送广播。 |
| 400 | + if (RePluginInternal.getAppContext().getApplicationContext() != null) { |
| 401 | + IPC.sendLocalBroadcast2AllSync(RePluginInternal.getAppContext(), intent); |
| 402 | + } else { |
| 403 | + Tasks.post2UI(new Runnable() { |
| 404 | + @Override |
| 405 | + public void run() { |
| 406 | + IPC.sendLocalBroadcast2All(RePluginInternal.getAppContext(), intent); |
| 407 | + } |
| 408 | + }); |
367 | 409 | }
|
368 | 410 | }
|
369 | 411 |
|
|
0 commit comments