OneDriveClient.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. package com.epson.iprint.storage.onedrive;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.os.AsyncTask;
  5. import android.support.annotation.NonNull;
  6. import android.support.p000v4.app.NotificationCompat;
  7. import com.box.androidsdk.content.models.BoxRepresentation;
  8. import com.epson.iprint.storage.StorageItem;
  9. import com.epson.iprint.storage.StorageSecureStore;
  10. import com.epson.iprint.storage.StorageServiceClient;
  11. import com.epson.iprint.storage.onedrive.OneDriveAuthenticator;
  12. import com.onedrive.sdk.authentication.IAccountInfo;
  13. import com.onedrive.sdk.concurrency.ChunkedUploadProvider;
  14. import com.onedrive.sdk.concurrency.ICallback;
  15. import com.onedrive.sdk.concurrency.IProgressCallback;
  16. import com.onedrive.sdk.core.ClientException;
  17. import com.onedrive.sdk.core.OneDriveErrorCodes;
  18. import com.onedrive.sdk.extensions.ChunkedUploadSessionDescriptor;
  19. import com.onedrive.sdk.extensions.IItemCollectionPage;
  20. import com.onedrive.sdk.extensions.IItemCollectionRequestBuilder;
  21. import com.onedrive.sdk.extensions.IOneDriveClient;
  22. import com.onedrive.sdk.extensions.Item;
  23. import com.onedrive.sdk.extensions.Shared;
  24. import com.onedrive.sdk.extensions.UploadSession;
  25. import com.onedrive.sdk.options.QueryOption;
  26. import epson.print.R;
  27. import epson.print.CommonDefine;
  28. import epson.server.utils.Define;
  29. import java.io.File;
  30. import java.io.FileInputStream;
  31. import java.io.FileNotFoundException;
  32. import java.io.FileOutputStream;
  33. import java.io.IOException;
  34. import java.io.InputStream;
  35. import java.util.ArrayList;
  36. import java.util.Collections;
  37. import java.util.List;
  38. public class OneDriveClient extends StorageServiceClient {
  39. private static final String[] EXTENSIONS_IPRINT_SPEC = {"doc", "docx", "rtf", "xls", "xlsm", "xlsx", "ppt", "pptx", "pps", "ppsx"};
  40. private static final String[] EXTENSIONS_ONEDRIVE_SPEC = {"doc", "docx", "epub", "eml", "htm", "html", "md", NotificationCompat.CATEGORY_MESSAGE, "odp", "ods", "odt", "pps", "ppsx", "ppt", "pptx", "rtf", "tif", "tiff", "xls", "xlsm", "xlsx"};
  41. private static final String[] MIMETYPE_IPRINT_SPEC = {CommonDefine.DOC_TYPE_1, CommonDefine.DOCX_TYPE_2, CommonDefine.POWERPOINT_TYPE_1, "application/vnd.openxmlformats-officedocument.presentationml.slideshow", CommonDefine.POWERPOINT_TYPE_2, CommonDefine.RTF_TYPE, CommonDefine.EXCEL_TYPE_1, CommonDefine.EXCEL_TYPE_2, "application/vnd.ms-excel.sheet.macroEnabled.12"};
  42. protected static final String TAG = "OneDriveClient";
  43. /* access modifiers changed from: private */
  44. public List<StorageItem> mStorageItemList;
  45. /* access modifiers changed from: private */
  46. public StorageServiceClient.ProcessError mUploadProcessError;
  47. /* access modifiers changed from: private */
  48. public IOneDriveClient oneDriveClient;
  49. public interface OnOneDriveClientListener {
  50. void onNotifyOneDriveClientCollectionPage(List<StorageItem> list);
  51. }
  52. /* access modifiers changed from: protected */
  53. public boolean isNeedSignin() {
  54. return true;
  55. }
  56. public boolean isSupportedUploadType(StorageServiceClient.UploadFileType uploadFileType) {
  57. return false;
  58. }
  59. public OneDriveClient() {
  60. resetUploadProcessError();
  61. }
  62. public StorageServiceClient.ProcessError getUploadProcessError() {
  63. return this.mUploadProcessError;
  64. }
  65. public void resetUploadProcessError() {
  66. this.mUploadProcessError = StorageServiceClient.ProcessError.NONE;
  67. }
  68. public StorageServiceClient.Uploader getUploader(Context context, StorageServiceClient.UploadFileType uploadFileType, String str, String str2) {
  69. return new OneDriveUploader(context, uploadFileType, str, str2);
  70. }
  71. public StorageServiceClient.Downloader getDownloader(Context context, StorageItem storageItem, String str) {
  72. return new OneDriveDownloader(context, storageItem, str);
  73. }
  74. public StorageServiceClient.Enumerator getEnumerator(final Context context) {
  75. return new StorageServiceClient.Enumerator() {
  76. public void enumerate(StorageItem storageItem, StorageServiceClient.EnumerateCompletion enumerateCompletion) {
  77. }
  78. public StorageItem getRootItem() {
  79. return new StorageItem("", "", StorageItem.ItemType.DIRECTORY, (Object) null);
  80. }
  81. public void enumerate(StorageItem storageItem, final StorageServiceClient.EnumerateCompletion enumerateCompletion, final StorageServiceClient.SigninCompletion signinCompletion) {
  82. if (storageItem.path.isEmpty()) {
  83. OneDriveClient.this.getClient((Activity) context, new OneDriveAuthenticator.OnOneDriveAuthenticatorListener() {
  84. public void onNotifyOneDriveClient(IOneDriveClient iOneDriveClient) {
  85. if (iOneDriveClient != null) {
  86. StorageServiceClient.SigninCompletion signinCompletion = signinCompletion;
  87. if (signinCompletion != null) {
  88. signinCompletion.onSigninCompletion();
  89. }
  90. OneDriveClient.this.getRootFolder(iOneDriveClient, enumerateCompletion);
  91. return;
  92. }
  93. enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
  94. }
  95. });
  96. return;
  97. }
  98. String str = ((Item) storageItem.userInfo).f323id;
  99. OneDriveClient oneDriveClient = OneDriveClient.this;
  100. oneDriveClient.getItems(oneDriveClient.oneDriveClient, str, enumerateCompletion);
  101. }
  102. };
  103. }
  104. public boolean isSignedIn(Context context) {
  105. return StorageSecureStore.getSharedSecureStore().fetch(Define.ONEDRIVE_TOKEN) != null;
  106. }
  107. public boolean revokeSignedInData(Activity activity) {
  108. StorageSecureStore.getSharedSecureStore().revoke(Define.ONEDRIVE_TOKEN);
  109. IOneDriveClient iOneDriveClient = this.oneDriveClient;
  110. if (iOneDriveClient == null) {
  111. return false;
  112. }
  113. logOut(iOneDriveClient, new ICallback<Void>() {
  114. public void success(Void voidR) {
  115. IOneDriveClient unused = OneDriveClient.this.oneDriveClient = null;
  116. }
  117. public void failure(ClientException clientException) {
  118. clientException.printStackTrace();
  119. IOneDriveClient unused = OneDriveClient.this.oneDriveClient = null;
  120. }
  121. });
  122. return false;
  123. }
  124. public String getStorageServiceName(Context context) {
  125. return context.getString(R.string.onedrive);
  126. }
  127. /* access modifiers changed from: private */
  128. public void getItems(IOneDriveClient iOneDriveClient, String str, StorageServiceClient.EnumerateCompletion enumerateCompletion) {
  129. this.mStorageItemList = new ArrayList();
  130. getItem(iOneDriveClient, str, getCallbackItemCollectionPage(enumerateCompletion));
  131. }
  132. private ICallback<IItemCollectionPage> getCallbackItemCollectionPage(final StorageServiceClient.EnumerateCompletion enumerateCompletion) {
  133. return getCallbackCollectionPage(new OnOneDriveClientListener() {
  134. public void onNotifyOneDriveClientCollectionPage(List<StorageItem> list) {
  135. if (list != null) {
  136. list = OneDriveClient.this.getPrintableItems(list);
  137. }
  138. enumerateCompletion.onEnumerateComplete(list, list != null ? StorageServiceClient.ProcessError.NONE : StorageServiceClient.ProcessError.ERROR);
  139. }
  140. });
  141. }
  142. private void debug_list(List<StorageItem> list) {
  143. for (StorageItem storageItem : list) {
  144. getItemPhotos((Item) storageItem.userInfo);
  145. }
  146. }
  147. /* access modifiers changed from: private */
  148. public List<StorageItem> getPrintableItems(List<StorageItem> list) {
  149. ArrayList arrayList = new ArrayList();
  150. for (StorageItem next : list) {
  151. if (next.type != StorageItem.ItemType.FILE || isPrintableFileTypes(next) || isConvertPdfExtension((Item) next.userInfo) || isConvertPdfMimeType((Item) next.userInfo)) {
  152. arrayList.add(next);
  153. }
  154. }
  155. return arrayList;
  156. }
  157. /* access modifiers changed from: private */
  158. public ICallback<IItemCollectionPage> getCallbackCollectionPage(final OnOneDriveClientListener onOneDriveClientListener) {
  159. return new ICallback<IItemCollectionPage>() {
  160. public void success(IItemCollectionPage iItemCollectionPage) {
  161. if (iItemCollectionPage != null) {
  162. List currentPage = iItemCollectionPage.getCurrentPage();
  163. if (currentPage != null) {
  164. for (int i = 0; i < currentPage.size(); i++) {
  165. StorageItem access$600 = OneDriveClient.this.getStorageItem((Item) currentPage.get(i));
  166. if (access$600 != null) {
  167. OneDriveClient.this.mStorageItemList.add(access$600);
  168. }
  169. }
  170. if (iItemCollectionPage.getNextPage() != null) {
  171. OneDriveClient oneDriveClient = OneDriveClient.this;
  172. oneDriveClient.getNextPage(iItemCollectionPage, oneDriveClient.getCallbackCollectionPage(onOneDriveClientListener));
  173. return;
  174. }
  175. result(OneDriveClient.this.mStorageItemList);
  176. return;
  177. }
  178. result((List<StorageItem>) null);
  179. return;
  180. }
  181. result((List<StorageItem>) null);
  182. }
  183. public void failure(ClientException clientException) {
  184. clientException.printStackTrace();
  185. result((List<StorageItem>) null);
  186. }
  187. private void result(List<StorageItem> list) {
  188. OnOneDriveClientListener onOneDriveClientListener = onOneDriveClientListener;
  189. if (onOneDriveClientListener != null) {
  190. onOneDriveClientListener.onNotifyOneDriveClientCollectionPage(list);
  191. }
  192. }
  193. };
  194. }
  195. /* access modifiers changed from: private */
  196. public StorageItem getStorageItem(Item item) {
  197. StorageItem storageItem = new StorageItem();
  198. storageItem.name = item.name;
  199. storageItem.path = File.separator + item.name;
  200. storageItem.userInfo = item;
  201. if (item.folder != null) {
  202. storageItem.type = StorageItem.ItemType.DIRECTORY;
  203. } else if (item.file != null) {
  204. storageItem.type = StorageItem.ItemType.FILE;
  205. } else if (item.image != null) {
  206. storageItem.type = StorageItem.ItemType.FILE;
  207. } else if (item.photo == null) {
  208. return null;
  209. } else {
  210. storageItem.type = StorageItem.ItemType.FILE;
  211. }
  212. return storageItem;
  213. }
  214. private void getRoot(IOneDriveClient iOneDriveClient, ICallback<Item> iCallback) {
  215. iOneDriveClient.getDrive().getRoot().buildRequest().get(iCallback);
  216. }
  217. private void getItem(IOneDriveClient iOneDriveClient, String str, ICallback<IItemCollectionPage> iCallback) {
  218. iOneDriveClient.getDrive().getItems(str).getChildren().buildRequest().get(iCallback);
  219. }
  220. /* access modifiers changed from: private */
  221. public void getNextPage(IItemCollectionPage iItemCollectionPage, ICallback<IItemCollectionPage> iCallback) {
  222. ((IItemCollectionRequestBuilder) iItemCollectionPage.getNextPage()).buildRequest().get(iCallback);
  223. }
  224. /* access modifiers changed from: private */
  225. public UploadSession getUploadSession(IOneDriveClient iOneDriveClient, String str) {
  226. return iOneDriveClient.getDrive().getRoot().getItemWithPath(str).getCreateSession(new ChunkedUploadSessionDescriptor()).buildRequest().post();
  227. }
  228. /* access modifiers changed from: private */
  229. public void uploadLargeFile(UploadSession uploadSession, InputStream inputStream, int i, IProgressCallback<Item> iProgressCallback) {
  230. ChunkedUploadProvider createUploadProvider;
  231. QueryOption queryOption = new QueryOption("@name.conflictBehavior", "rename");
  232. if (uploadSession != null && (createUploadProvider = uploadSession.createUploadProvider(this.oneDriveClient, inputStream, i, Item.class)) != null) {
  233. try {
  234. createUploadProvider.upload(Collections.singletonList(queryOption), iProgressCallback, 655360, 5);
  235. } catch (IOException e) {
  236. e.printStackTrace();
  237. }
  238. }
  239. }
  240. /* access modifiers changed from: private */
  241. public InputStream getDownloadInputStream(IOneDriveClient iOneDriveClient, String str) {
  242. return iOneDriveClient.getDrive().getItems(str).getContent().buildRequest().get();
  243. }
  244. /* access modifiers changed from: private */
  245. public InputStream getDownloadInputStreamPdf(IOneDriveClient iOneDriveClient, String str) {
  246. return iOneDriveClient.getDrive().getItems(str).getContent().buildRequest(Collections.singletonList(new QueryOption("format", BoxRepresentation.TYPE_PDF))).get();
  247. }
  248. private void logOut(IOneDriveClient iOneDriveClient, ICallback<Void> iCallback) {
  249. iOneDriveClient.getAuthenticator().logout(iCallback);
  250. }
  251. public static void saveToken(IAccountInfo iAccountInfo) {
  252. String accessToken;
  253. if (iAccountInfo != null && (accessToken = iAccountInfo.getAccessToken()) != null && !accessToken.isEmpty()) {
  254. StorageSecureStore.getSharedSecureStore().put(Define.ONEDRIVE_TOKEN, accessToken, StorageSecureStore.EXEC_MODE.OVERWRITE_IF_EXIST);
  255. }
  256. }
  257. public boolean isSessionExpired() {
  258. IOneDriveClient iOneDriveClient = this.oneDriveClient;
  259. if (iOneDriveClient != null) {
  260. return isExpired(iOneDriveClient);
  261. }
  262. return true;
  263. }
  264. /* access modifiers changed from: private */
  265. public boolean isExpired(IOneDriveClient iOneDriveClient) {
  266. return iOneDriveClient.getAuthenticator().getAccountInfo().isExpired();
  267. }
  268. /* access modifiers changed from: private */
  269. public void getClient(Activity activity, OneDriveAuthenticator.OnOneDriveAuthenticatorListener onOneDriveAuthenticatorListener) {
  270. IOneDriveClient iOneDriveClient = this.oneDriveClient;
  271. if (iOneDriveClient == null) {
  272. getOneDriveClient(activity, onOneDriveAuthenticatorListener);
  273. } else if (onOneDriveAuthenticatorListener != null) {
  274. onOneDriveAuthenticatorListener.onNotifyOneDriveClient(iOneDriveClient);
  275. }
  276. }
  277. private void getOneDriveClient(Activity activity, final OneDriveAuthenticator.OnOneDriveAuthenticatorListener onOneDriveAuthenticatorListener) {
  278. OneDriveAuthenticator.getOneDriveClient(activity, new OneDriveAuthenticator.OnOneDriveAuthenticatorListener() {
  279. public void onNotifyOneDriveClient(IOneDriveClient iOneDriveClient) {
  280. IOneDriveClient unused = OneDriveClient.this.oneDriveClient = iOneDriveClient;
  281. OneDriveAuthenticator.OnOneDriveAuthenticatorListener onOneDriveAuthenticatorListener = onOneDriveAuthenticatorListener;
  282. if (onOneDriveAuthenticatorListener != null) {
  283. onOneDriveAuthenticatorListener.onNotifyOneDriveClient(OneDriveClient.this.oneDriveClient);
  284. }
  285. }
  286. });
  287. }
  288. private void getRootFolder(Activity activity, final StorageServiceClient.EnumerateCompletion enumerateCompletion) {
  289. getClient(activity, new OneDriveAuthenticator.OnOneDriveAuthenticatorListener() {
  290. public void onNotifyOneDriveClient(IOneDriveClient iOneDriveClient) {
  291. if (iOneDriveClient != null) {
  292. OneDriveClient.this.getRootFolder(iOneDriveClient, enumerateCompletion);
  293. } else {
  294. enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
  295. }
  296. }
  297. });
  298. }
  299. /* access modifiers changed from: private */
  300. public void getRootFolder(final IOneDriveClient iOneDriveClient, final StorageServiceClient.EnumerateCompletion enumerateCompletion) {
  301. getRoot(iOneDriveClient, new ICallback<Item>() {
  302. public void success(Item item) {
  303. if (item != null) {
  304. OneDriveClient.this.getItems(iOneDriveClient, item.f323id, enumerateCompletion);
  305. } else {
  306. enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
  307. }
  308. }
  309. public void failure(ClientException clientException) {
  310. clientException.printStackTrace();
  311. enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
  312. }
  313. });
  314. }
  315. /* access modifiers changed from: private */
  316. public boolean isConvertPdfExtension(Item item) {
  317. int lastIndexOf;
  318. if (item != null && item.name != null && !item.name.isEmpty() && (lastIndexOf = item.name.lastIndexOf(CommonDefine.DOT)) > 0) {
  319. String substring = item.name.substring(lastIndexOf + 1);
  320. for (String equalsIgnoreCase : EXTENSIONS_IPRINT_SPEC) {
  321. if (substring.equalsIgnoreCase(equalsIgnoreCase)) {
  322. return true;
  323. }
  324. }
  325. }
  326. return false;
  327. }
  328. /* access modifiers changed from: private */
  329. public boolean isConvertPdfMimeType(Item item) {
  330. if (!(item == null || item.file == null || item.file.mimeType == null)) {
  331. for (String equalsIgnoreCase : MIMETYPE_IPRINT_SPEC) {
  332. if (item.file.mimeType.equalsIgnoreCase(equalsIgnoreCase)) {
  333. return true;
  334. }
  335. }
  336. }
  337. return false;
  338. }
  339. /* access modifiers changed from: private */
  340. public String getConvertPdfName(String str) {
  341. if (str == null || str.isEmpty()) {
  342. return "";
  343. }
  344. int lastIndexOf = str.lastIndexOf(CommonDefine.DOT);
  345. if (lastIndexOf > 0) {
  346. return str.substring(0, lastIndexOf) + CommonDefine.FileType_PDF;
  347. }
  348. return str + CommonDefine.FileType_PDF;
  349. }
  350. private String getItemPhotos(Item item) {
  351. String str = "";
  352. if (item == null) {
  353. return str;
  354. }
  355. if (item.name != null) {
  356. str = str + " name: " + item.name;
  357. }
  358. if (item.size != null) {
  359. str = str + " size: " + item.size;
  360. }
  361. if (item.file != null) {
  362. if (item.file.mimeType != null) {
  363. str = str + " mimeType: " + item.file.mimeType;
  364. }
  365. str = str + " -FILE- ";
  366. }
  367. if (item.folder != null) {
  368. str = str + " -FOLDER- ";
  369. }
  370. if (item.image != null) {
  371. str = str + " -IMAGE- ";
  372. }
  373. if (item.photo == null) {
  374. return str;
  375. }
  376. return str + " -PHOTO- ";
  377. }
  378. private String getItemDetails(Item item) {
  379. String str = "";
  380. if (item != null) {
  381. if (item.name != null) {
  382. str = str + " name: " + item.name;
  383. }
  384. if (item.size != null) {
  385. str = str + " size: " + item.size;
  386. }
  387. if (!(item.file == null || item.file.mimeType == null)) {
  388. str = str + " mimeType: " + item.file.mimeType;
  389. }
  390. if (!(item.folder == null || item.folder.childCount == null)) {
  391. str = str + " childCount: " + item.folder.childCount;
  392. }
  393. if (item.image != null) {
  394. if (item.image.width != null) {
  395. str = str + " width: " + item.image.width;
  396. }
  397. if (item.image.height != null) {
  398. str = str + " height: " + item.image.height;
  399. }
  400. }
  401. if (item.audio != null) {
  402. if (item.audio.title != null) {
  403. str = str + " title: " + item.audio.title;
  404. }
  405. if (item.audio.artist != null) {
  406. str = str + " artist: " + item.audio.artist;
  407. }
  408. if (item.audio.bitrate != null) {
  409. str = str + " bitrate: " + item.audio.bitrate;
  410. }
  411. }
  412. if (item.photo != null) {
  413. if (item.photo.cameraMake != null) {
  414. str = str + " cameraMake: " + item.photo.cameraMake;
  415. }
  416. if (item.photo.cameraModel != null) {
  417. str = str + " cameraModel: " + item.photo.cameraModel;
  418. }
  419. if (item.photo.exposureDenominator != null) {
  420. str = str + " exposureDenominator: " + item.photo.exposureDenominator;
  421. }
  422. if (item.photo.exposureNumerator != null) {
  423. str = str + " exposureNumerator: " + item.photo.exposureNumerator;
  424. }
  425. if (item.photo.fNumber != null) {
  426. str = str + " fNumber: " + item.photo.fNumber;
  427. }
  428. if (item.photo.focalLength != null) {
  429. str = str + " focalLength: " + item.photo.focalLength;
  430. }
  431. if (item.photo.iso != null) {
  432. str = str + " iso: " + item.photo.iso;
  433. }
  434. }
  435. if (item.video != null) {
  436. if (item.video.width != null) {
  437. str = str + " width: " + item.video.width;
  438. }
  439. if (item.video.height != null) {
  440. str = str + " height: " + item.video.height;
  441. }
  442. }
  443. if (!(item.createdBy == null || item.createdBy.application == null || item.createdBy.application.displayName == null)) {
  444. str = str + " createdBy-displayName: " + item.createdBy.application.displayName;
  445. }
  446. if (!(item.lastModifiedBy == null || item.lastModifiedBy.application == null || item.lastModifiedBy.application.displayName == null)) {
  447. str = str + " lastModifiedBy-displayName: " + item.lastModifiedBy.application.displayName;
  448. }
  449. if (!(item.parentReference == null || item.parentReference.path == null)) {
  450. str = str + " parentReference-path: " + item.parentReference.path;
  451. }
  452. Shared shared = item.shared;
  453. }
  454. return str;
  455. }
  456. class OneDriveDownloader extends StorageServiceClient.Downloader {
  457. /* access modifiers changed from: private */
  458. public String mItemid;
  459. /* access modifiers changed from: private */
  460. public StorageItem mStorageItem;
  461. private DownloadThread mThread = null;
  462. /* access modifiers changed from: private */
  463. public String mWriteFilename;
  464. public boolean isCancelable() {
  465. return true;
  466. }
  467. OneDriveDownloader(Context context, StorageItem storageItem, String str) {
  468. super();
  469. this.mStorageItem = storageItem;
  470. this.mItemid = ((Item) storageItem.userInfo).f323id;
  471. this.mWriteFilename = str;
  472. }
  473. public void start(StorageServiceClient.DownloadCompletion downloadCompletion) {
  474. this.mThread = new DownloadThread(downloadCompletion);
  475. this.mThread.start();
  476. }
  477. public void cancel() {
  478. DownloadThread downloadThread = this.mThread;
  479. if (downloadThread != null) {
  480. downloadThread.cancel();
  481. }
  482. }
  483. class DownloadThread extends Thread {
  484. private volatile boolean bCanceled;
  485. private boolean bConvertPdf;
  486. private StorageServiceClient.DownloadCompletion downloaded;
  487. private InputStream inputStream;
  488. DownloadThread(StorageServiceClient.DownloadCompletion downloadCompletion) {
  489. this.downloaded = downloadCompletion;
  490. }
  491. public void run() {
  492. this.inputStream = null;
  493. boolean z = false;
  494. this.bCanceled = false;
  495. this.bConvertPdf = OneDriveClient.this.isConvertPdfExtension((Item) OneDriveDownloader.this.mStorageItem.userInfo) || OneDriveClient.this.isConvertPdfMimeType((Item) OneDriveDownloader.this.mStorageItem.userInfo);
  496. if (this.bConvertPdf && !this.bCanceled) {
  497. try {
  498. this.inputStream = OneDriveClient.this.getDownloadInputStreamPdf(OneDriveClient.this.oneDriveClient, OneDriveDownloader.this.mItemid);
  499. } catch (ClientException e) {
  500. e.printStackTrace();
  501. if (e.isError(OneDriveErrorCodes.NotSupported)) {
  502. this.bConvertPdf = this.inputStream != null;
  503. } else {
  504. this.bConvertPdf = this.inputStream != null;
  505. }
  506. }
  507. }
  508. if (!this.bConvertPdf && !this.bCanceled) {
  509. try {
  510. this.inputStream = OneDriveClient.this.getDownloadInputStream(OneDriveClient.this.oneDriveClient, OneDriveDownloader.this.mItemid);
  511. } catch (ClientException e2) {
  512. e2.printStackTrace();
  513. this.inputStream = null;
  514. }
  515. }
  516. String access$1600 = this.bConvertPdf ? OneDriveClient.this.getConvertPdfName(OneDriveDownloader.this.mWriteFilename) : OneDriveDownloader.this.mWriteFilename;
  517. if (this.inputStream != null && !this.bCanceled) {
  518. try {
  519. File file = new File(access$1600);
  520. if (!file.exists()) {
  521. file.getParentFile().mkdirs();
  522. }
  523. FileOutputStream fileOutputStream = new FileOutputStream(file, false);
  524. byte[] bArr = new byte[1048576];
  525. while (true) {
  526. try {
  527. int read = this.inputStream.read(bArr);
  528. if (read != -1 && !this.bCanceled) {
  529. fileOutputStream.write(bArr, 0, read);
  530. }
  531. } catch (IOException e3) {
  532. e3.printStackTrace();
  533. }
  534. }
  535. z = !this.bCanceled;
  536. try {
  537. fileOutputStream.close();
  538. } catch (IOException e4) {
  539. e4.printStackTrace();
  540. }
  541. } catch (IOException e5) {
  542. e5.printStackTrace();
  543. }
  544. }
  545. closeStream();
  546. this.downloaded.onDownloadComplete(OneDriveDownloader.this.mStorageItem, access$1600, z ? StorageServiceClient.ProcessError.NONE : this.bCanceled ? StorageServiceClient.ProcessError.CANCELED : StorageServiceClient.ProcessError.ERROR);
  547. }
  548. private void closeStream() {
  549. try {
  550. if (this.inputStream != null) {
  551. this.inputStream.close();
  552. this.inputStream = null;
  553. }
  554. } catch (IOException e) {
  555. e.printStackTrace();
  556. }
  557. }
  558. public void cancel() {
  559. this.bCanceled = true;
  560. }
  561. }
  562. }
  563. class OneDriveUploader extends StorageServiceClient.Uploader {
  564. private Activity mActivity;
  565. private LocalUploader mLocalUploader;
  566. private String mOrgFilePath;
  567. private String mUploadPath;
  568. public boolean isCancelable() {
  569. return true;
  570. }
  571. OneDriveUploader(Context context, StorageServiceClient.UploadFileType uploadFileType, String str, String str2) {
  572. super();
  573. this.mActivity = (Activity) context;
  574. this.mOrgFilePath = str;
  575. this.mUploadPath = str2;
  576. }
  577. public void start(StorageServiceClient.UploadCompletion uploadCompletion) {
  578. StorageServiceClient.ProcessError unused = OneDriveClient.this.mUploadProcessError = StorageServiceClient.ProcessError.NONE;
  579. OneDriveClient oneDriveClient = OneDriveClient.this;
  580. if (!oneDriveClient.isExpired(oneDriveClient.oneDriveClient)) {
  581. this.mLocalUploader = new LocalUploader(this.mActivity, this.mOrgFilePath, this.mUploadPath, uploadCompletion);
  582. AsyncTask.THREAD_POOL_EXECUTOR.execute(this.mLocalUploader);
  583. return;
  584. }
  585. StorageServiceClient.ProcessError unused2 = OneDriveClient.this.mUploadProcessError = StorageServiceClient.ProcessError.RETRY;
  586. uploadCompletion.onUploadComplete("", "", StorageServiceClient.ProcessError.RETRY);
  587. }
  588. public void cancel() {
  589. super.cancel();
  590. this.mLocalUploader.cancel();
  591. }
  592. }
  593. private class LocalUploader implements Runnable {
  594. /* access modifiers changed from: private */
  595. public volatile boolean bCanceled = false;
  596. private FileInputStream fileInputStream;
  597. private StorageServiceClient.UploadCompletion mNotifier;
  598. private String mOrgFilePath;
  599. private String mUploadFilename;
  600. /* access modifiers changed from: private */
  601. public boolean result = true;
  602. private UploadSession uploadSession;
  603. LocalUploader(Activity activity, String str, String str2, @NonNull StorageServiceClient.UploadCompletion uploadCompletion) {
  604. this.mOrgFilePath = str;
  605. this.mUploadFilename = str2;
  606. this.mNotifier = uploadCompletion;
  607. }
  608. public void run() {
  609. this.bCanceled = false;
  610. this.result = false;
  611. if (!(this.mOrgFilePath == null || this.mUploadFilename == null || this.bCanceled)) {
  612. this.fileInputStream = null;
  613. try {
  614. this.fileInputStream = new FileInputStream(this.mOrgFilePath);
  615. try {
  616. int available = this.fileInputStream.available();
  617. if (available > 0 && !this.bCanceled) {
  618. upload(available);
  619. }
  620. } catch (IOException e) {
  621. e.printStackTrace();
  622. }
  623. } catch (FileNotFoundException e2) {
  624. e2.printStackTrace();
  625. } catch (Throwable th) {
  626. closefile();
  627. throw th;
  628. }
  629. closefile();
  630. }
  631. this.mNotifier.onUploadComplete(this.mOrgFilePath, this.mUploadFilename, this.result ? StorageServiceClient.ProcessError.NONE : this.bCanceled ? StorageServiceClient.ProcessError.CANCELED : StorageServiceClient.ProcessError.ERROR);
  632. }
  633. private void upload(int i) {
  634. this.uploadSession = null;
  635. try {
  636. this.uploadSession = OneDriveClient.this.getUploadSession(OneDriveClient.this.oneDriveClient, "/Epson iPrint/" + this.mUploadFilename);
  637. } catch (ClientException e) {
  638. e.printStackTrace();
  639. }
  640. UploadSession uploadSession2 = this.uploadSession;
  641. if (uploadSession2 != null) {
  642. OneDriveClient.this.uploadLargeFile(uploadSession2, this.fileInputStream, i, new IProgressCallback<Item>() {
  643. public void success(Item item) {
  644. boolean unused = LocalUploader.this.result = true;
  645. }
  646. public void failure(ClientException clientException) {
  647. clientException.printStackTrace();
  648. }
  649. public void progress(long j, long j2) {
  650. if (LocalUploader.this.bCanceled) {
  651. LocalUploader.this.uploadcancel();
  652. }
  653. }
  654. });
  655. }
  656. }
  657. /* access modifiers changed from: private */
  658. public void uploadcancel() {
  659. closefile();
  660. }
  661. private void closefile() {
  662. try {
  663. if (this.fileInputStream != null) {
  664. this.fileInputStream.close();
  665. }
  666. } catch (IOException e) {
  667. e.printStackTrace();
  668. }
  669. }
  670. public void cancel() {
  671. this.bCanceled = true;
  672. }
  673. }
  674. }