@Test public void testFindMasterProvider_throwException() throws Exception { when(sharedProviderFinder.findMasterProvider( anyListOf(ProviderInfo.class))).thenCallRealMethod(); try { sharedProviderFinder.findMasterProvider(null); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class); return; } fail("Should throw IllegalStateException"); }
public String findMasterProvider(List<ProviderInfo> providerInfos) { if (providerInfos == null || providerInfos.size() < 1) { throw new IllegalStateException( "There should be at least one Provider registered for this to work."); } ProviderInfo providerInfo; String authority; boolean isMaster; String masterAuthority = null; for (int i = 0, size = providerInfos.size(); i < size; i++) { providerInfo = providerInfos.get(i); authority = providerInfo.authority; if (TextUtils.isEmpty(authority)) continue; isMaster = isProviderMaster(getContentUri(authority), contentResolver); Log.d("SharedProviders", "Auth " + authority + " isMaster: " + isMaster); if (isMaster && TextUtils.isEmpty(masterAuthority)) { masterAuthority = authority; } else if (isMaster && !TextUtils.isEmpty(masterAuthority)) { Log.d("SharedProviders", "Un-Delegate Auth: " + authority); delegateMaster(authority, false); } } if (!TextUtils.isEmpty(masterAuthority)) { return masterAuthority; } masterAuthority = providerInfos.get(0).authority; if (TextUtils.isEmpty(masterAuthority)) { throw new IllegalStateException("There are no valid providers to delegate. " + "Are you sure you have your permissions and authorityMatcher set correctly"); } return delegateMaster(masterAuthority, true); }
SharedProviderFinder implements Types { public String findMasterProvider(List<ProviderInfo> providerInfos) { if (providerInfos == null || providerInfos.size() < 1) { throw new IllegalStateException( "There should be at least one Provider registered for this to work."); } ProviderInfo providerInfo; String authority; boolean isMaster; String masterAuthority = null; for (int i = 0, size = providerInfos.size(); i < size; i++) { providerInfo = providerInfos.get(i); authority = providerInfo.authority; if (TextUtils.isEmpty(authority)) continue; isMaster = isProviderMaster(getContentUri(authority), contentResolver); Log.d("SharedProviders", "Auth " + authority + " isMaster: " + isMaster); if (isMaster && TextUtils.isEmpty(masterAuthority)) { masterAuthority = authority; } else if (isMaster && !TextUtils.isEmpty(masterAuthority)) { Log.d("SharedProviders", "Un-Delegate Auth: " + authority); delegateMaster(authority, false); } } if (!TextUtils.isEmpty(masterAuthority)) { return masterAuthority; } masterAuthority = providerInfos.get(0).authority; if (TextUtils.isEmpty(masterAuthority)) { throw new IllegalStateException("There are no valid providers to delegate. " + "Are you sure you have your permissions and authorityMatcher set correctly"); } return delegateMaster(masterAuthority, true); } }
SharedProviderFinder implements Types { public String findMasterProvider(List<ProviderInfo> providerInfos) { if (providerInfos == null || providerInfos.size() < 1) { throw new IllegalStateException( "There should be at least one Provider registered for this to work."); } ProviderInfo providerInfo; String authority; boolean isMaster; String masterAuthority = null; for (int i = 0, size = providerInfos.size(); i < size; i++) { providerInfo = providerInfos.get(i); authority = providerInfo.authority; if (TextUtils.isEmpty(authority)) continue; isMaster = isProviderMaster(getContentUri(authority), contentResolver); Log.d("SharedProviders", "Auth " + authority + " isMaster: " + isMaster); if (isMaster && TextUtils.isEmpty(masterAuthority)) { masterAuthority = authority; } else if (isMaster && !TextUtils.isEmpty(masterAuthority)) { Log.d("SharedProviders", "Un-Delegate Auth: " + authority); delegateMaster(authority, false); } } if (!TextUtils.isEmpty(masterAuthority)) { return masterAuthority; } masterAuthority = providerInfos.get(0).authority; if (TextUtils.isEmpty(masterAuthority)) { throw new IllegalStateException("There are no valid providers to delegate. " + "Are you sure you have your permissions and authorityMatcher set correctly"); } return delegateMaster(masterAuthority, true); } protected  SharedProviderFinder(Context context, Pattern authorityMatcherPattern,
      String sharedPermission, ContentResolver contentResolver); }
SharedProviderFinder implements Types { public String findMasterProvider(List<ProviderInfo> providerInfos) { if (providerInfos == null || providerInfos.size() < 1) { throw new IllegalStateException( "There should be at least one Provider registered for this to work."); } ProviderInfo providerInfo; String authority; boolean isMaster; String masterAuthority = null; for (int i = 0, size = providerInfos.size(); i < size; i++) { providerInfo = providerInfos.get(i); authority = providerInfo.authority; if (TextUtils.isEmpty(authority)) continue; isMaster = isProviderMaster(getContentUri(authority), contentResolver); Log.d("SharedProviders", "Auth " + authority + " isMaster: " + isMaster); if (isMaster && TextUtils.isEmpty(masterAuthority)) { masterAuthority = authority; } else if (isMaster && !TextUtils.isEmpty(masterAuthority)) { Log.d("SharedProviders", "Un-Delegate Auth: " + authority); delegateMaster(authority, false); } } if (!TextUtils.isEmpty(masterAuthority)) { return masterAuthority; } masterAuthority = providerInfos.get(0).authority; if (TextUtils.isEmpty(masterAuthority)) { throw new IllegalStateException("There are no valid providers to delegate. " + "Are you sure you have your permissions and authorityMatcher set correctly"); } return delegateMaster(masterAuthority, true); } protected  SharedProviderFinder(Context context, Pattern authorityMatcherPattern,
      String sharedPermission, ContentResolver contentResolver); static SharedProviderFinder get(Context context); List<ProviderInfo> findProviders(); String findMasterProvider(List<ProviderInfo> providerInfos); String findMasterProvider(); }
SharedProviderFinder implements Types { public String findMasterProvider(List<ProviderInfo> providerInfos) { if (providerInfos == null || providerInfos.size() < 1) { throw new IllegalStateException( "There should be at least one Provider registered for this to work."); } ProviderInfo providerInfo; String authority; boolean isMaster; String masterAuthority = null; for (int i = 0, size = providerInfos.size(); i < size; i++) { providerInfo = providerInfos.get(i); authority = providerInfo.authority; if (TextUtils.isEmpty(authority)) continue; isMaster = isProviderMaster(getContentUri(authority), contentResolver); Log.d("SharedProviders", "Auth " + authority + " isMaster: " + isMaster); if (isMaster && TextUtils.isEmpty(masterAuthority)) { masterAuthority = authority; } else if (isMaster && !TextUtils.isEmpty(masterAuthority)) { Log.d("SharedProviders", "Un-Delegate Auth: " + authority); delegateMaster(authority, false); } } if (!TextUtils.isEmpty(masterAuthority)) { return masterAuthority; } masterAuthority = providerInfos.get(0).authority; if (TextUtils.isEmpty(masterAuthority)) { throw new IllegalStateException("There are no valid providers to delegate. " + "Are you sure you have your permissions and authorityMatcher set correctly"); } return delegateMaster(masterAuthority, true); } protected  SharedProviderFinder(Context context, Pattern authorityMatcherPattern,
      String sharedPermission, ContentResolver contentResolver); static SharedProviderFinder get(Context context); List<ProviderInfo> findProviders(); String findMasterProvider(List<ProviderInfo> providerInfos); String findMasterProvider();  }