GoogleV3UploadSignInActivity.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package com.epson.iprint.storage.gdrivev3;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import androidx.appcompat.app.AppCompatActivity;
  7. import com.epson.iprint.storage.Network;
  8. import com.epson.iprint.storage.OneButtonDialogFragment;
  9. import com.epson.iprint.storage.gdrivev3.IprintGoogleSignIn;
  10. import com.epson.iprint.storage.gdrivev3.PlayServiceDialogManager;
  11. import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
  12. import epson.print.R;
  13. import java.util.Iterator;
  14. import java.util.LinkedList;
  15. public class GoogleV3UploadSignInActivity extends AppCompatActivity implements ActivityWrapper, PlayServiceDialogManager.SingInCancelNotifier, OneButtonDialogFragment.DialogCallback, IprintGoogleSignIn.SignInListener {
  16. private static final String DIALOG_TAG_OFFLINE_ERROR = "offline_error";
  17. private static final String DIALOG_TAG_SIGN_IN_FAILED = "sign-in_failed";
  18. private static final String PARAM_KEY_CHECK_SERVICE_ONLY = "check-service_only";
  19. private static final String PARAM_KEY_FOR_DISCONNECT = "for-disconnect";
  20. private static final int REQUEST_CODE_CHECK_PLAY_SERVICE = 11;
  21. private static final int REQUEST_CODE_SIGN_IN = 10;
  22. private static final int REQUEST_CODE_SIGN_IN_ADD_SCOPE = 12;
  23. private boolean mActivityForeground;
  24. private boolean mCheckServiceOnly;
  25. private LinkedList<Runnable> mForegroundRunnableList;
  26. private IprintGoogleSignIn mIprintGoogleSignIn;
  27. private Network mMisc;
  28. private PlayServiceDialogManager mPlayServiceDialogManager;
  29. private IprintGoogleSignIn.StartActivityResultCallback mSignInStartActivityCallback;
  30. private boolean mStartForDisconnect;
  31. private boolean mWaitSingInProcess;
  32. @NonNull
  33. public Activity getActivity() {
  34. return this;
  35. }
  36. public int getPlayServiceRequestCode() {
  37. return 11;
  38. }
  39. public int getSingInAddScopeRequestCode() {
  40. return 12;
  41. }
  42. @NonNull
  43. public static Intent getDisconnectIntent(@NonNull Context context) {
  44. Intent intent = new Intent(context, GoogleV3UploadSignInActivity.class);
  45. intent.putExtra(PARAM_KEY_FOR_DISCONNECT, true);
  46. return intent;
  47. }
  48. @NonNull
  49. public static Intent getPlayServiceCheckIntent(@NonNull Context context) {
  50. Intent intent = new Intent(context, GoogleV3UploadSignInActivity.class);
  51. intent.putExtra(PARAM_KEY_CHECK_SERVICE_ONLY, true);
  52. return intent;
  53. }
  54. protected void onCreate(Bundle bundle) {
  55. super.onCreate(bundle);
  56. this.mPlayServiceDialogManager = new PlayServiceDialogManager();
  57. this.mMisc = new Network();
  58. this.mIprintGoogleSignIn = new IprintGoogleSignIn();
  59. this.mWaitSingInProcess = false;
  60. this.mActivityForeground = false;
  61. this.mForegroundRunnableList = new LinkedList<>();
  62. Intent intent = getIntent();
  63. this.mStartForDisconnect = intent.getBooleanExtra(PARAM_KEY_FOR_DISCONNECT, false);
  64. this.mCheckServiceOnly = intent.getBooleanExtra(PARAM_KEY_CHECK_SERVICE_ONLY, false);
  65. }
  66. /* access modifiers changed from: private */
  67. public void showErrorDialog(final int i, final String str) {
  68. if (!this.mActivityForeground) {
  69. this.mForegroundRunnableList.addLast(new Runnable() {
  70. public void run() {
  71. GoogleV3UploadSignInActivity.this.showErrorDialog(i, str);
  72. }
  73. });
  74. } else {
  75. OneButtonDialogFragment.newInstance(i, str).show(getSupportFragmentManager(), str);
  76. }
  77. }
  78. protected void onPostResume() {
  79. super.onPostResume();
  80. this.mMisc.selectSimpleAp(this, false);
  81. this.mActivityForeground = true;
  82. processForegroundList();
  83. if (!this.mMisc.isOnline(this)) {
  84. showErrorDialog(R.string.network_error_mes, DIALOG_TAG_OFFLINE_ERROR);
  85. } else if (!this.mPlayServiceDialogManager.checkPlayService(this, this)) {
  86. if (this.mCheckServiceOnly) {
  87. finishWithResult(true);
  88. } else if (!this.mWaitSingInProcess) {
  89. this.mWaitSingInProcess = true;
  90. if (this.mStartForDisconnect) {
  91. this.mIprintGoogleSignIn.disconnectAccount(this, this);
  92. } else {
  93. this.mIprintGoogleSignIn.startSignIn(this, this, IprintGoogleSignIn.OperationType.UPLOAD);
  94. }
  95. }
  96. }
  97. }
  98. private void processForegroundList() {
  99. Iterator it = this.mForegroundRunnableList.iterator();
  100. while (it.hasNext()) {
  101. it.remove();
  102. ((Runnable) it.next()).run();
  103. }
  104. }
  105. protected void onPause() {
  106. super.onPause();
  107. this.mPlayServiceDialogManager.onActivityPaused();
  108. this.mActivityForeground = false;
  109. }
  110. public void requestSignIn(@NonNull Intent intent, @NonNull IprintGoogleSignIn.StartActivityResultCallback startActivityResultCallback) {
  111. this.mSignInStartActivityCallback = startActivityResultCallback;
  112. startActivityForResult(intent, 10);
  113. }
  114. public void playServiceInstallCancel() {
  115. if (this.mCheckServiceOnly) {
  116. finishWithResult(false);
  117. } else {
  118. showErrorDialog(R.string.authenticate_error_mes, DIALOG_TAG_SIGN_IN_FAILED);
  119. }
  120. }
  121. public void buttonPressed(@Nullable String str) {
  122. if (str != null) {
  123. char c = 65535;
  124. int hashCode = str.hashCode();
  125. if (hashCode != -683930452) {
  126. if (hashCode == 366991495 && str.equals(DIALOG_TAG_SIGN_IN_FAILED)) {
  127. c = 0;
  128. }
  129. } else if (str.equals(DIALOG_TAG_OFFLINE_ERROR)) {
  130. c = 1;
  131. }
  132. switch (c) {
  133. case 0:
  134. finishWithResult(false);
  135. return;
  136. case 1:
  137. startActivity(new Intent("android.settings.WIRELESS_SETTINGS"));
  138. finishWithResult(false);
  139. return;
  140. default:
  141. return;
  142. }
  143. }
  144. }
  145. protected void onActivityResult(int i, int i2, Intent intent) {
  146. switch (i) {
  147. case 10:
  148. IprintGoogleSignIn.StartActivityResultCallback startActivityResultCallback = this.mSignInStartActivityCallback;
  149. if (startActivityResultCallback != null) {
  150. startActivityResultCallback.onActivityResult(i2, intent);
  151. this.mSignInStartActivityCallback = null;
  152. return;
  153. }
  154. return;
  155. case 11:
  156. return;
  157. case 12:
  158. if (i2 == -1) {
  159. finishWithResult(true);
  160. return;
  161. } else {
  162. showErrorDialog(R.string.authenticate_error_mes, DIALOG_TAG_SIGN_IN_FAILED);
  163. return;
  164. }
  165. default:
  166. return;
  167. }
  168. }
  169. public void onSignInComplete(boolean z, GoogleSignInAccount googleSignInAccount) {
  170. if (z) {
  171. finishWithResult(true);
  172. } else {
  173. showErrorDialog(R.string.authenticate_error_mes, DIALOG_TAG_SIGN_IN_FAILED);
  174. }
  175. }
  176. public void onDisconnectCompleted() {
  177. finishWithResult(true);
  178. }
  179. private void finishWithResult(boolean z) {
  180. GoogleV3UploadClient.setSingInValue(z);
  181. setResult(z ? -1 : 0);
  182. finish();
  183. }
  184. }