@Override public List<String> getPrivacyLists() throws RemoteException { Log.d(TAG, "BEGIN getPrivacyLists."); List<String> res = new ArrayList<String>(); try { PrivacyList[] registeredPrivacyLists = mPrivacyListManager.getPrivacyLists(); Log.d(TAG, "> registeredPrivacyLists size: " + registeredPrivacyLists.length); if (registeredPrivacyLists.length > 0) { for (int i = 0; i < registeredPrivacyLists.length; i++) { res.add(registeredPrivacyLists[i].toString()); Log.d(TAG, "> " + res.get(i) + " added."); } } } catch (XMPPException e) { Log.e(TAG, e.getMessage()); } Log.d(TAG, "END getPrivacyLists."); return res; }
private void initializePrivacyLists() { try { PrivacyList[] lists = privacyManager.getPrivacyLists(); for (PrivacyList list: lists) { SparkPrivacyList sparkList = new SparkPrivacyList(list); sparkList.addSparkPrivacyListener(_presenceHandler); _privacyLists.add(sparkList); } } catch (XMPPException e) { Log.error("Could not load PrivacyLists"); e.printStackTrace(); } if(hasDefaultList()) { setListAsActive(getDefaultList().getListName()); } }
@Override public String getActivePrivacyList() throws RemoteException { try { PrivacyList activePrivacyList = mPrivacyListManager.getActiveList(); return activePrivacyList.toString(); } catch (XMPPException e) { Log.e(TAG, e.getMessage()); } return null; }
@Override public List<String> getBlockedGroupsByList(String listName) throws RemoteException { List<String> blockedGroups = new ArrayList<String>(); try { PrivacyList pL = mPrivacyListManager.getPrivacyList(listName); for (PrivacyItem pI : pL.getItems()) { if (pI.getType().equals(PrivacyItem.Type.group) && !pI.isAllow()) blockedGroups.add(pI.getValue()); } } catch (XMPPException e) { Log.e(TAG, e.getMessage()); } return blockedGroups; }
@Override public List<String> getBlockedUsersByList(String listName) throws RemoteException { List<String> blockedUsers = new ArrayList<String>(); try { PrivacyList pL = mPrivacyListManager.getPrivacyList(listName); for (PrivacyItem pI : pL.getItems()) { if (pI.getType().equals(PrivacyItem.Type.jid) && !pI.isAllow()) blockedUsers.add(pI.getValue()); } } catch (XMPPException e) { Log.e(TAG, e.getMessage()); } return blockedUsers; }
@Override public String getDefaultPrivacyList() throws RemoteException { try { PrivacyList defaultPrivacyList = mPrivacyListManager.getDefaultList(); return defaultPrivacyList.toString(); } catch (XMPPException e) { Log.e(TAG, e.getMessage()); } return null; }
/** * Action associated with the items, it MUST be filled and will allow or deny * the communication by default */ public SparkPrivacyList(PrivacyList list) { _listName = list.toString(); _myPrivacyList = list; _isActive = _myPrivacyList.isActiveList(); _isDefault = _myPrivacyList.isDefaultList(); loadItems(); }
/** * Check when a client set more than one list. */ public void testCreateTwoLists() { try { String listName1 = "1testCreateTwoLists"; String listName2 = "2testCreateTwoLists"; String groupName = "testCreateTwoListsGroup"; PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0)); PrivacyClient client = new PrivacyClient(privacyManager); privacyManager.addListener(client); // Add a list ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>(); PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.name(), true, 1); item.setValue(getConnection(0).getUser()); items.add(item); privacyManager.createPrivacyList(listName1, items); Thread.sleep(500); // Add the another list ArrayList<PrivacyItem> itemsList2 = new ArrayList<PrivacyItem>(); item = new PrivacyItem(PrivacyItem.Type.group.name(), false, 2); item.setValue(groupName); item.setFilterMessage(true); itemsList2.add(item); privacyManager.createPrivacyList(listName2, itemsList2); Thread.sleep(500); // Assert the list composition. PrivacyList[] privacyLists = privacyManager.getPrivacyLists(); PrivacyList receivedList1 = null; PrivacyList receivedList2 = null; for (PrivacyList privacyList : privacyLists) { if (listName1.equals(privacyList.toString())) { receivedList1 = privacyList; } if (listName2.equals(privacyList.toString())) { receivedList2 = privacyList; } } PrivacyItem receivedItem; // Assert on the list 1 assertNotNull(receivedList1); assertEquals(1, receivedList1.getItems().size()); receivedItem = receivedList1.getItems().get(0); assertEquals(1, receivedItem.getOrder()); assertEquals(PrivacyItem.Type.jid, receivedItem.getType()); assertEquals(true, receivedItem.isAllow()); assertEquals(getConnection(0).getUser(), receivedItem.getValue()); // Assert on the list 2 assertNotNull(receivedList2); assertEquals(1, receivedList2.getItems().size()); receivedItem = receivedList2.getItems().get(0); assertEquals(2, receivedItem.getOrder()); assertEquals(PrivacyItem.Type.group, receivedItem.getType()); assertEquals(groupName, receivedItem.getValue()); assertEquals(false, receivedItem.isAllow()); assertEquals(groupName, receivedItem.getValue()); assertEquals(false, receivedItem.isFilterEverything()); assertEquals(true, receivedItem.isFilterMessage()); assertEquals(false, receivedItem.isFilterPresence_in()); assertEquals(false, receivedItem.isFilterPresence_out()); privacyManager.deletePrivacyList(listName1); privacyManager.deletePrivacyList(listName2); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }