IprintLicenseInfo.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package epson.common;
  2. import android.content.Context;
  3. import android.support.annotation.NonNull;
  4. import com.epson.mobilephone.common.license.DefaultLicenseInfo;
  5. import epson.print.C2135R;
  6. import java.util.Locale;
  7. public class IprintLicenseInfo extends DefaultLicenseInfo {
  8. private static final int LICENSE_VERSION_CODE = 70006;
  9. private static final int PRIVACY_STATEMENT_VERSION_CODE = 60600;
  10. public int getLicenseAgreement(@NonNull Context context) {
  11. IprintAppRecord iprintAppRecord = new IprintAppRecord();
  12. if (!iprintAppRecord.getLicenseAgreementValue(context)) {
  13. return -1;
  14. }
  15. int licenseAgreeVersionCode = iprintAppRecord.getLicenseAgreeVersionCode(context);
  16. return licenseAgreeVersionCode < LICENSE_VERSION_CODE ? licenseAgreeVersionCode < PRIVACY_STATEMENT_VERSION_CODE ? 0 : 1 : licenseAgreeVersionCode < PRIVACY_STATEMENT_VERSION_CODE ? 2 : 3;
  17. }
  18. public void setLicenceAgreement(@NonNull Context context) {
  19. new IprintAppRecord().setLicenseAgreement(context, Math.max(LICENSE_VERSION_CODE, PRIVACY_STATEMENT_VERSION_CODE), true);
  20. }
  21. public String getDocumentString(@NonNull Context context, int i) {
  22. switch (i) {
  23. case 1:
  24. return getLicenseText(context);
  25. case 2:
  26. String language = Locale.getDefault().getLanguage();
  27. if (language == null || !language.equalsIgnoreCase(Locale.JAPAN.getLanguage())) {
  28. return Utils.getAssetsFileContents(context, "iPrint_PRIVACY_STATEMENT20180322.txt");
  29. }
  30. return Utils.getAssetsFileContents(context, "iPrint_privacy_statement_jp20180122.txt");
  31. case 3:
  32. return Utils.getAssetsFileContents(context, "oss_license.txt");
  33. default:
  34. return super.getDocumentString(context, i);
  35. }
  36. }
  37. private String getLicenseText(@NonNull Context context) {
  38. return Utils.getAssetsFileContents(context, "License.txt");
  39. }
  40. public String getApplicationName(@NonNull Context context) {
  41. return context.getString(R.string.app_name);
  42. }
  43. public static boolean isAgreedCurrentVersion(@NonNull Context context) {
  44. return new IprintLicenseInfo().getLicenseAgreement(context) == 3;
  45. }
  46. public static void beforeLicenseCheck(@NonNull Context context) {
  47. if (!new IprintAppRecord().getLicenseAgreementValue(context)) {
  48. ExternalFileUtils.getInstance(context).clearRemotePrintersInfo();
  49. ExternalFileUtils.getInstance(context).clearIpPrintersInfo();
  50. }
  51. }
  52. }