GoogleV3UploadSignInActivity.java 7.7 KB

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