/** * Initialize SDK This function will be called once in the application, it is tried to be called * as early as possible; This is the place to register broadcast listeners. */ public static synchronized void sdkInitialize(Context context) { if (sdkInitialized == true) { return; } // Make sure we've loaded default settings if we haven't already. Settings.loadDefaultsFromMetadataIfNeeded(context); // Load app settings from network so that dialog configs are available Utility.loadAppSettingsAsync(context, Settings.getApplicationId()); BoltsMeasurementEventListener.getInstance(context.getApplicationContext()); sdkInitialized = true; }
static void publishInstallAsync( final Context context, final String applicationId, final Request.Callback callback) { // grab the application context ahead of time, since we will return to the caller immediately. final Context applicationContext = context.getApplicationContext(); Settings.getExecutor() .execute( new Runnable() { @Override public void run() { final Response response = Settings.publishInstallAndWaitForResponse( applicationContext, applicationId, false); if (callback != null) { // invoke the callback on the main thread. Handler handler = new Handler(Looper.getMainLooper()); handler.post( new Runnable() { @Override public void run() { callback.onCompleted(response); } }); } } }); }
public void deinit(Appendable out, boolean force) throws Exception { Settings settings = new Settings(platform.getConfigFile()); if (!force) { Justif justify = new Justif(80, 40); StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); try { String list = listFiles(platform.getGlobal()); if (list != null) { f.format("In global default environment:%n"); f.format(list); } list = listFiles(platform.getLocal()); if (list != null) { f.format("In local default environment:%n"); f.format(list); } if (settings.containsKey(JPM_CACHE_GLOBAL)) { list = listFiles(IO.getFile(settings.get(JPM_CACHE_GLOBAL))); if (list != null) { f.format("In global configured environment:%n"); f.format(list); } } if (settings.containsKey(JPM_CACHE_LOCAL)) { list = listFiles(IO.getFile(settings.get(JPM_CACHE_LOCAL))); if (list != null) { f.format("In local configured environment:%n"); f.format(list); } } list = listSupportFiles(); if (list != null) { f.format("jpm support files:%n"); f.format(list); } f.format("%n%n"); f.format( "All files listed above will be deleted if deinit is run with the force flag set" + " (\"jpm deinit -f\" or \"jpm deinit --force\"%n%n"); f.flush(); justify.wrap(sb); out.append(sb.toString()); } finally { f.close(); } } else { // i.e. if(force) int count = 0; File[] caches = {platform.getGlobal(), platform.getLocal(), null, null}; if (settings.containsKey(JPM_CACHE_LOCAL)) { caches[2] = IO.getFile(settings.get(JPM_CACHE_LOCAL)); } if (settings.containsKey(JPM_CACHE_GLOBAL)) { caches[3] = IO.getFile(settings.get(JPM_CACHE_GLOBAL)); } ArrayList<File> toDelete = new ArrayList<File>(); for (File cache : caches) { if (cache == null || !cache.exists()) { continue; } listFiles(cache, toDelete); if (toDelete.size() > count) { count = toDelete.size(); if (!cache.canWrite()) { reporter.error(PERMISSION_ERROR + " (" + cache + ")"); return; } toDelete.add(cache); } } listSupportFiles(toDelete); for (File f : toDelete) { if (f.exists() && !f.canWrite()) { reporter.error(PERMISSION_ERROR + " (" + f + ")"); } } if (reporter.getErrors().size() > 0) { return; } for (File f : toDelete) { if (f.exists()) { IO.deleteWithException(f); } } } }
/** * Certain logging behaviors are available for debugging beyond those that should be enabled in * production. * * <p>Checks if a particular extended logging behavior is enabled. * * @param behavior The LoggingBehavior to check * @return whether behavior is enabled */ public static final boolean isLoggingBehaviorEnabled(LoggingBehavior behavior) { synchronized (loggingBehaviors) { return Settings.isDebugEnabled() && loggingBehaviors.contains(behavior); } }