Exemplo n.º 1
0
  public static void setVendorCompat(Context context, VendorCompat compat) {
    cachedCompat = compat;

    // Application-wide configuration
    Context appContext = context.getApplicationContext();

    // PlayHaven specific configuration for this Application
    SharedPreferences pref = appContext.getSharedPreferences(SHARED_PREF_NAME, SHARED_PREF_MODE);
    SharedPreferences.Editor editor = pref.edit();

    // Set the property
    editor.putString(Config.PluginIdentifer.toString(), compat.getVendorId());
    editor.putString(Config.PluginType.toString(), compat.getClass().getCanonicalName());

    // And commit it
    editor.commit();

    i("PlayHaven plugin identifier set: %s", compat.getVendorId());
    debugConfig(context);
  }
Exemplo n.º 2
0
  /**
   * Provide default configuration for PlayHaven
   *
   * @param context of the application
   * @return a SharedPreferences Editor for further configuration
   * @throws PlayHavenException if a problem occurs
   */
  private static SharedPreferences.Editor defaultConfiguration(Context context)
      throws PlayHavenException {
    // Application-wide configuration
    Context appContext = context.getApplicationContext();

    // PlayHaven specific configuration for this Application
    SharedPreferences pref = appContext.getSharedPreferences(SHARED_PREF_NAME, SHARED_PREF_MODE);
    SharedPreferences.Editor editor = pref.edit();

    VendorCompat compat = getVendorCompat(context);

    // Setup PlayHaven values
    int apiServerResId =
        compat.getResourceId(context, ResourceType.string, "playhaven_public_api_server");
    editor.putString(Config.APIServer.toString(), context.getResources().getString(apiServerResId));
    editor.putString(Config.SDKVersion.toString(), Version.PROJECT_VERSION);

    // Setup Publisher values
    String pkgName = context.getPackageName();
    PackageInfo packageInfo = null;
    try {
      packageInfo = context.getPackageManager().getPackageInfo(pkgName, 0);
    } catch (PackageManager.NameNotFoundException e) {
      throw new PlayHavenException("Unable to obtain package inforamtion", e);
    }
    // AndroidManifest.xml | <manifest package />
    editor.putString(Config.AppPkg.toString(), packageInfo.packageName);
    // AndroidManifest.xml | <manifest android:versionName />
    editor.putString(Config.AppVersion.toString(), packageInfo.versionName);

    // Setup Device values
    editor.putString(Config.OSName.toString(), Build.VERSION.RELEASE);
    editor.putInt(Config.OSVersion.toString(), Build.VERSION.SDK_INT);
    editor.putString(Config.DeviceId.toString(), new DeviceId(context).toString());
    editor.putString(Config.DeviceModel.toString(), Build.MODEL);

    // And commit it
    editor.commit();

    return editor;
  }