public boolean isAllowNetworkRequest(AbstractServerProxy proxy) { if (!NetworkStatusManager.getInstance().isConnected()) { String errorMessage = ResourceManager.getInstance() .getCurrentBundle() .getString(IStringCommon.RES_NO_CELL_COVERAGE, IStringCommon.FAMILY_COMMON); proxy.setErrorMsg(errorMessage); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } return false; } return true; }
protected void syncStops() { boolean isSyncEnabled = MigrationExecutor.getInstance().isSyncEnabled(); boolean isnetworkAvailable = NetworkStatusManager.getInstance().isConnected(); if (isSyncEnabled && isnetworkAvailable) { final IUserProfileProvider userProfileProvider = (IUserProfileProvider) get(ICommonConstants.KEY_O_USER_PROFILE_PROVIDER); IJob syncJob = new IJob() { public void execute(int handlerID) { // don't do sync before migration succ. if (MigrationExecutor.getInstance().isInProgress()) { MigrationExecutor.getInstance().setListener(AbstractCommonNetworkModel.this); return; } else { boolean isMigrationSucc = DaoManager.getInstance().getAddressDao().isMigrationSucc(); // don't do normal sync before migration succ. if (isMigrationSucc) { SyncStopsExecutor.getInstance() .syncStop(AbstractCommonNetworkModel.this, userProfileProvider); IServerProxyListener listener = new IServerProxyListener() { @Override public void updateTransactionStatus( AbstractServerProxy proxy, byte progress) {} @Override public void transactionFinished(AbstractServerProxy proxy, String jobId) { String action = proxy.getRequestAction(); if (proxy instanceof IToolsProxy && IServerProxyConstants.ACT_SYNC_PREFERENCE.equals(action)) { SyncResExecutor.getInstance().handlePreferenceResp((IToolsProxy) proxy); } } @Override public void transactionError(AbstractServerProxy proxy) {} @Override public void networkError( AbstractServerProxy proxy, byte statusCode, String jobId) {} @Override public boolean isAllowNetworkRequest(AbstractServerProxy proxy) { return AbstractCommonNetworkModel.this.isAllowNetworkRequest(proxy); } }; SyncResExecutor.getInstance() .syncPreference(null, IToolsProxy.SYNC_TYPE_DOWNLOAD, listener, null, -1); } else { MigrationExecutor.getInstance().doMigration(AbstractCommonNetworkModel.this); } } } public void cancel() {} public boolean isCancelled() { return false; } public boolean isRunning() { return true; } }; ThreadPool pool = ThreadManager.getPool(ThreadManager.TYPE_APP_ACTION); pool.addJob(syncJob); } }