convert LocalRepoManager to a proper singleton
This gives us lazy initialization that happens the first time an instance is needed. And Peter asked to have this more this way :)
This commit is contained in:
		
							parent
							
								
									ab165a4d7b
								
							
						
					
					
						commit
						b7aad893a3
					
				| @ -23,22 +23,12 @@ import android.app.Activity; | ||||
| import android.app.Application; | ||||
| import android.bluetooth.BluetoothAdapter; | ||||
| import android.bluetooth.BluetoothManager; | ||||
| import android.content.ComponentName; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.ServiceConnection; | ||||
| import android.content.SharedPreferences; | ||||
| import android.content.pm.ApplicationInfo; | ||||
| import android.content.pm.PackageManager; | ||||
| import android.content.*; | ||||
| import android.content.pm.*; | ||||
| import android.content.pm.PackageManager.NameNotFoundException; | ||||
| import android.content.pm.ResolveInfo; | ||||
| import android.net.Uri; | ||||
| import android.net.wifi.WifiManager; | ||||
| import android.os.Build; | ||||
| import android.os.IBinder; | ||||
| import android.os.Message; | ||||
| import android.os.Messenger; | ||||
| import android.os.RemoteException; | ||||
| import android.os.*; | ||||
| import android.preference.PreferenceManager; | ||||
| import android.util.Log; | ||||
| import android.widget.Toast; | ||||
| @ -55,24 +45,16 @@ import org.fdroid.fdroid.compat.PRNGFixes; | ||||
| import org.fdroid.fdroid.data.AppProvider; | ||||
| import org.fdroid.fdroid.data.InstalledAppCacheUpdater; | ||||
| import org.fdroid.fdroid.data.Repo; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoManager; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoService; | ||||
| import org.fdroid.fdroid.net.WifiStateChangeService; | ||||
| import org.thoughtcrime.ssl.pinning.PinningTrustManager; | ||||
| import org.thoughtcrime.ssl.pinning.SystemKeyStore; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.security.KeyManagementException; | ||||
| import java.security.KeyStore; | ||||
| import java.security.KeyStoreException; | ||||
| import java.security.NoSuchAlgorithmException; | ||||
| import java.security.*; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| import javax.net.ssl.HttpsURLConnection; | ||||
| import javax.net.ssl.SSLContext; | ||||
| import javax.net.ssl.TrustManager; | ||||
| import javax.net.ssl.TrustManagerFactory; | ||||
| import javax.net.ssl.X509TrustManager; | ||||
| import javax.net.ssl.*; | ||||
| 
 | ||||
| public class FDroidApp extends Application { | ||||
| 
 | ||||
| @ -82,7 +64,6 @@ public class FDroidApp extends Application { | ||||
|     public static String ssid = ""; | ||||
|     public static String bssid = ""; | ||||
|     public static Repo repo = new Repo(); | ||||
|     public static LocalRepoManager localRepo = null; | ||||
|     public static Set<String> selectedApps = null; // init in SelectLocalAppsFragment | ||||
| 
 | ||||
|     private static Messenger localRepoServiceMessenger = null; | ||||
| @ -125,8 +106,6 @@ public class FDroidApp extends Application { | ||||
|         // Apply the Google PRNG fixes to properly seed SecureRandom | ||||
|         PRNGFixes.apply(); | ||||
| 
 | ||||
|         localRepo = new LocalRepoManager(getApplicationContext()); | ||||
| 
 | ||||
|         // Check that the installed app cache hasn't gotten out of sync somehow. | ||||
|         // e.g. if we crashed/ran out of battery half way through responding | ||||
|         // to a package installed intent. It doesn't really matter where | ||||
|  | ||||
| @ -63,7 +63,15 @@ public class LocalRepoManager { | ||||
|     public final File repoDir; | ||||
|     public final File iconsDir; | ||||
| 
 | ||||
|     public LocalRepoManager(Context c) { | ||||
|     private static LocalRepoManager localRepoManager; | ||||
| 
 | ||||
|     public static LocalRepoManager get(Context context) { | ||||
|         if(localRepoManager == null) | ||||
|             localRepoManager = new LocalRepoManager(context); | ||||
|         return localRepoManager; | ||||
|     } | ||||
| 
 | ||||
|     private LocalRepoManager(Context c) { | ||||
|         context = c; | ||||
|         pm = c.getPackageManager(); | ||||
|         assetManager = c.getAssets(); | ||||
|  | ||||
| @ -14,6 +14,7 @@ import org.fdroid.fdroid.FDroidApp; | ||||
| import org.fdroid.fdroid.Preferences; | ||||
| import org.fdroid.fdroid.Utils; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoKeyStore; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoManager; | ||||
| 
 | ||||
| import java.security.cert.Certificate; | ||||
| import java.util.Locale; | ||||
| @ -66,8 +67,9 @@ public class WifiStateChangeService extends Service { | ||||
|                         scheme, FDroidApp.ipAddressString, FDroidApp.port); | ||||
|                 Certificate localCert = LocalRepoKeyStore.get(getApplication()).getCertificate(); | ||||
|                 FDroidApp.repo.fingerprint = Utils.calcFingerprint(localCert); | ||||
|                 FDroidApp.localRepo.setUriString(FDroidApp.repo.address); | ||||
|                 FDroidApp.localRepo.writeIndexPage( | ||||
|                 LocalRepoManager lrm = LocalRepoManager.get(WifiStateChangeService.this); | ||||
|                 lrm.setUriString(FDroidApp.repo.address); | ||||
|                 lrm.writeIndexPage( | ||||
|                         Utils.getSharingUri(WifiStateChangeService.this, FDroidApp.repo).toString()); | ||||
|             } catch (InterruptedException e) { | ||||
|                 e.printStackTrace(); | ||||
|  | ||||
| @ -23,6 +23,7 @@ import android.widget.*; | ||||
| 
 | ||||
| import org.fdroid.fdroid.*; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoKeyStore; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoManager; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoService; | ||||
| import org.fdroid.fdroid.net.WifiStateChangeService; | ||||
| import org.spongycastle.operator.OperatorCreationException; | ||||
| @ -73,7 +74,7 @@ public class LocalRepoActivity extends Activity { | ||||
|         LocalBroadcastManager.getInstance(this).registerReceiver(onLocalRepoChange, | ||||
|                 new IntentFilter(LocalRepoService.STATE)); | ||||
|         // if no local repo exists, create one with only FDroid in it | ||||
|         if (!FDroidApp.localRepo.xmlIndex.exists()) | ||||
|         if (!LocalRepoManager.get(this).xmlIndex.exists()) | ||||
|             new UpdateAsyncTask(this, new String[] { | ||||
|                     getPackageName(), | ||||
|             }).execute(); | ||||
| @ -321,26 +322,27 @@ public class LocalRepoActivity extends Activity { | ||||
|         @Override | ||||
|         protected Void doInBackground(Void... params) { | ||||
|             try { | ||||
|                 final LocalRepoManager lrm = LocalRepoManager.get(LocalRepoActivity.this); | ||||
|                 publishProgress(getString(R.string.deleting_repo)); | ||||
|                 FDroidApp.localRepo.deleteRepo(); | ||||
|                 lrm.deleteRepo(); | ||||
|                 for (String app : selectedApps) { | ||||
|                     publishProgress(String.format(getString(R.string.adding_apks_format), app)); | ||||
|                     FDroidApp.localRepo.addApp(getApplicationContext(), app); | ||||
|                     lrm.addApp(getApplicationContext(), app); | ||||
|                 } | ||||
|                 FDroidApp.localRepo.writeIndexPage(sharingUri.toString()); | ||||
|                 lrm.writeIndexPage(sharingUri.toString()); | ||||
|                 publishProgress(getString(R.string.writing_index_xml)); | ||||
|                 FDroidApp.localRepo.writeIndexXML(); | ||||
|                 lrm.writeIndexXML(); | ||||
|                 publishProgress(getString(R.string.writing_index_jar)); | ||||
|                 FDroidApp.localRepo.writeIndexJar(); | ||||
|                 lrm.writeIndexJar(); | ||||
|                 publishProgress(getString(R.string.linking_apks)); | ||||
|                 FDroidApp.localRepo.copyApksToRepo(); | ||||
|                 lrm.copyApksToRepo(); | ||||
|                 publishProgress(getString(R.string.copying_icons)); | ||||
|                 // run the icon copy without progress, its not a blocker | ||||
|                 new AsyncTask<Void, Void, Void>() { | ||||
| 
 | ||||
|                     @Override | ||||
|                     protected Void doInBackground(Void... params) { | ||||
|                         FDroidApp.localRepo.copyIconsToRepo(); | ||||
|                         lrm.copyIconsToRepo(); | ||||
|                         return null; | ||||
|                     } | ||||
|                 }.execute(); | ||||
|  | ||||
| @ -26,7 +26,6 @@ import android.graphics.drawable.Drawable; | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.text.TextUtils; | ||||
| import android.util.Log; | ||||
| import android.view.ActionMode; | ||||
| import android.view.View; | ||||
| import android.widget.*; | ||||
| @ -37,6 +36,7 @@ import org.fdroid.fdroid.FDroidApp; | ||||
| import org.fdroid.fdroid.R; | ||||
| import org.fdroid.fdroid.data.InstalledAppProvider; | ||||
| import org.fdroid.fdroid.data.InstalledAppProvider.DataColumns; | ||||
| import org.fdroid.fdroid.localrepo.LocalRepoManager; | ||||
| import org.fdroid.fdroid.views.SelectLocalAppsActivity; | ||||
| 
 | ||||
| import java.util.HashSet; | ||||
| @ -113,7 +113,7 @@ public class SelectLocalAppsFragment extends ListFragment | ||||
|         // build list of existing apps from what is on the file system | ||||
|         if (FDroidApp.selectedApps == null) { | ||||
|             FDroidApp.selectedApps = new HashSet<String>(); | ||||
|             for (String filename : FDroidApp.localRepo.repoDir.list()) { | ||||
|             for (String filename : LocalRepoManager.get(selectLocalAppsActivity).repoDir.list()) { | ||||
|                 if (filename.matches(".*\\.apk")) { | ||||
|                     String packageName = filename.substring(0, filename.indexOf("_")); | ||||
|                     FDroidApp.selectedApps.add(packageName); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Hans-Christoph Steiner
						Hans-Christoph Steiner