FileSyncAdapter.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author Bartek Przybylski
  5. * @author David A. Velasco
  6. * Copyright (C) 2011 Bartek Przybylski
  7. * Copyright (C) 2015 ownCloud Inc.
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. package com.owncloud.android.syncadapter;
  23. import android.accounts.Account;
  24. import android.accounts.AccountsException;
  25. import android.app.NotificationManager;
  26. import android.app.PendingIntent;
  27. import android.content.AbstractThreadedSyncAdapter;
  28. import android.content.ContentProviderClient;
  29. import android.content.ContentResolver;
  30. import android.content.Context;
  31. import android.content.Intent;
  32. import android.content.SyncResult;
  33. import android.os.Bundle;
  34. import android.support.annotation.PluralsRes;
  35. import android.support.v4.app.NotificationCompat;
  36. import com.owncloud.android.R;
  37. import com.owncloud.android.authentication.AuthenticatorActivity;
  38. import com.owncloud.android.datamodel.FileDataStorageManager;
  39. import com.owncloud.android.datamodel.OCFile;
  40. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  41. import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
  42. import com.owncloud.android.lib.common.utils.Log_OC;
  43. import com.owncloud.android.operations.RefreshFolderOperation;
  44. import com.owncloud.android.operations.UpdateOCVersionOperation;
  45. import com.owncloud.android.ui.activity.ErrorsWhileCopyingHandlerActivity;
  46. import com.owncloud.android.ui.notifications.NotificationUtils;
  47. import com.owncloud.android.utils.DataHolderUtil;
  48. import com.owncloud.android.utils.ThemeUtils;
  49. import org.apache.jackrabbit.webdav.DavException;
  50. import java.io.IOException;
  51. import java.util.ArrayList;
  52. import java.util.HashMap;
  53. import java.util.List;
  54. import java.util.Map;
  55. /**
  56. * Implementation of {@link AbstractThreadedSyncAdapter} responsible for synchronizing
  57. * ownCloud files.
  58. *
  59. * Performs a full synchronization of the account received in {@link #onPerformSync(Account, Bundle,
  60. * String, ContentProviderClient, SyncResult)}.
  61. */
  62. public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
  63. private final static String TAG = FileSyncAdapter.class.getSimpleName();
  64. /** Maximum number of failed folder synchronizations that are supported before finishing
  65. * the synchronization operation */
  66. private static final int MAX_FAILED_RESULTS = 3;
  67. public static final String EVENT_FULL_SYNC_START = FileSyncAdapter.class.getName() +
  68. ".EVENT_FULL_SYNC_START";
  69. public static final String EVENT_FULL_SYNC_END = FileSyncAdapter.class.getName() +
  70. ".EVENT_FULL_SYNC_END";
  71. public static final String EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED =
  72. FileSyncAdapter.class.getName() + ".EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED";
  73. public static final String EXTRA_ACCOUNT_NAME = FileSyncAdapter.class.getName() +
  74. ".EXTRA_ACCOUNT_NAME";
  75. public static final String EXTRA_FOLDER_PATH = FileSyncAdapter.class.getName() +
  76. ".EXTRA_FOLDER_PATH";
  77. public static final String EXTRA_RESULT = FileSyncAdapter.class.getName() + ".EXTRA_RESULT";
  78. /** Time stamp for the current synchronization process, used to distinguish fresh data */
  79. private long mCurrentSyncTime;
  80. /** Flag made 'true' when a request to cancel the synchronization is received */
  81. private boolean mCancellation;
  82. /** Counter for failed operations in the synchronization process */
  83. private int mFailedResultsCounter;
  84. /** Result of the last failed operation */
  85. private RemoteOperationResult mLastFailedResult;
  86. /** Counter of conflicts found between local and remote files */
  87. private int mConflictsFound;
  88. /** Counter of failed operations in synchronization of kept-in-sync files */
  89. private int mFailsInFavouritesFound;
  90. /** Map of remote and local paths to files that where locally stored in a location out
  91. * of the ownCloud folder and couldn't be copied automatically into it */
  92. private Map<String, String> mForgottenLocalFiles;
  93. /** {@link SyncResult} instance to return to the system when the synchronization finish */
  94. private SyncResult mSyncResult;
  95. /** 'True' means that the server supports the share API */
  96. private boolean mIsShareSupported;
  97. /**
  98. * Creates a {@link FileSyncAdapter}
  99. *
  100. * {@inheritDoc}
  101. */
  102. public FileSyncAdapter(Context context, boolean autoInitialize) {
  103. super(context, autoInitialize);
  104. }
  105. /**
  106. * Creates a {@link FileSyncAdapter}
  107. *
  108. * {@inheritDoc}
  109. */
  110. public FileSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) {
  111. super(context, autoInitialize, allowParallelSyncs);
  112. }
  113. /**
  114. * {@inheritDoc}
  115. */
  116. @Override
  117. public synchronized void onPerformSync(Account account, Bundle extras,
  118. String authority, ContentProviderClient providerClient,
  119. SyncResult syncResult) {
  120. mCancellation = false;
  121. /* When 'true' the process was requested by the user through the user interface;
  122. when 'false', it was requested automatically by the system */
  123. boolean mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
  124. mFailedResultsCounter = 0;
  125. mLastFailedResult = null;
  126. mConflictsFound = 0;
  127. mFailsInFavouritesFound = 0;
  128. mForgottenLocalFiles = new HashMap<String, String>();
  129. mSyncResult = syncResult;
  130. mSyncResult.fullSyncRequested = false;
  131. mSyncResult.delayUntil = (System.currentTimeMillis()/1000) + 3*60*60; // avoid too many automatic synchronizations
  132. this.setAccount(account);
  133. this.setContentProviderClient(providerClient);
  134. this.setStorageManager(new FileDataStorageManager(account, providerClient));
  135. try {
  136. this.initClientForCurrentAccount();
  137. } catch (IOException | AccountsException e) {
  138. /// the account is unknown for the Synchronization Manager, unreachable this context,
  139. // or can not be authenticated; don't try this again
  140. mSyncResult.tooManyRetries = true;
  141. notifyFailedSynchronization();
  142. return;
  143. }
  144. Log_OC.d(TAG, "Synchronization of ownCloud account " + account.name + " starting");
  145. sendLocalBroadcast(EVENT_FULL_SYNC_START, null, null); // message to signal the start
  146. // of the synchronization to the UI
  147. try {
  148. updateOCVersion();
  149. mCurrentSyncTime = System.currentTimeMillis();
  150. if (!mCancellation) {
  151. synchronizeFolder(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
  152. } else {
  153. Log_OC.d(TAG, "Leaving synchronization before synchronizing the root folder " +
  154. "because cancellation request");
  155. }
  156. } finally {
  157. // it's important making this although very unexpected errors occur;
  158. // that's the reason for the finally
  159. if (mFailedResultsCounter > 0 && mIsManualSync) {
  160. /// don't let the system synchronization manager retries MANUAL synchronizations
  161. // (be careful: "MANUAL" currently includes the synchronization requested when
  162. // a new account is created and when the user changes the current account)
  163. mSyncResult.tooManyRetries = true;
  164. /// notify the user about the failure of MANUAL synchronization
  165. notifyFailedSynchronization();
  166. }
  167. if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
  168. notifyFailsInFavourites();
  169. }
  170. if (mForgottenLocalFiles.size() > 0) {
  171. notifyForgottenLocalFiles();
  172. }
  173. sendLocalBroadcast(EVENT_FULL_SYNC_END, null, mLastFailedResult); // message to signal
  174. // the end to the UI
  175. }
  176. }
  177. /**
  178. * Called by system SyncManager when a synchronization is required to be cancelled.
  179. *
  180. * Sets the mCancellation flag to 'true'. THe synchronization will be stopped later,
  181. * before a new folder is fetched. Data of the last folder synchronized will be still
  182. * locally saved.
  183. *
  184. * See {@link #onPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult)}
  185. * and {@link #synchronizeFolder(OCFile)}.
  186. */
  187. @Override
  188. public void onSyncCanceled() {
  189. Log_OC.d(TAG, "Synchronization of " + getAccount().name + " has been requested to cancel");
  190. mCancellation = true;
  191. super.onSyncCanceled();
  192. }
  193. /**
  194. * Updates the locally stored version value of the ownCloud server
  195. */
  196. private void updateOCVersion() {
  197. UpdateOCVersionOperation update = new UpdateOCVersionOperation(getAccount(), getContext());
  198. RemoteOperationResult result = update.execute(getClient());
  199. if (!result.isSuccess()) {
  200. mLastFailedResult = result;
  201. } else {
  202. mIsShareSupported = update.getOCVersion().isSharedSupported();
  203. }
  204. }
  205. /**
  206. * Synchronizes the list of files contained in a folder identified with its remote path.
  207. *
  208. * Fetches the list and properties of the files contained in the given folder, including their
  209. * properties, and updates the local database with them.
  210. *
  211. * Enters in the child folders to synchronize their contents also, following a recursive
  212. * depth first strategy.
  213. *
  214. * @param folder Folder to synchronize.
  215. */
  216. private void synchronizeFolder(OCFile folder) {
  217. if (mFailedResultsCounter > MAX_FAILED_RESULTS || isFinisher(mLastFailedResult)) {
  218. return;
  219. }
  220. // folder synchronization
  221. RefreshFolderOperation synchFolderOp = new RefreshFolderOperation( folder,
  222. mCurrentSyncTime,
  223. true,
  224. mIsShareSupported,
  225. false,
  226. getStorageManager(),
  227. getAccount(),
  228. getContext()
  229. );
  230. RemoteOperationResult result = synchFolderOp.execute(getClient());
  231. // synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess
  232. sendLocalBroadcast(EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED, folder.getRemotePath(), result);
  233. // check the result of synchronizing the folder
  234. if (result.isSuccess() || result.getCode() == ResultCode.SYNC_CONFLICT) {
  235. if (result.getCode() == ResultCode.SYNC_CONFLICT) {
  236. mConflictsFound += synchFolderOp.getConflictsFound();
  237. mFailsInFavouritesFound += synchFolderOp.getFailsInKeptInSyncFound();
  238. }
  239. if (synchFolderOp.getForgottenLocalFiles().size() > 0) {
  240. mForgottenLocalFiles.putAll(synchFolderOp.getForgottenLocalFiles());
  241. }
  242. if (result.isSuccess()) {
  243. // synchronize children folders
  244. List<OCFile> children = synchFolderOp.getChildren();
  245. // beware of the 'hidden' recursion here!
  246. syncChildren(children);
  247. }
  248. } else if (result.getCode() != ResultCode.FILE_NOT_FOUND) {
  249. // in failures, the statistics for the global result are updated
  250. if (RemoteOperationResult.ResultCode.UNAUTHORIZED.equals(result.getCode())) {
  251. mSyncResult.stats.numAuthExceptions++;
  252. } else if (result.getException() instanceof DavException) {
  253. mSyncResult.stats.numParseExceptions++;
  254. } else if (result.getException() instanceof IOException) {
  255. mSyncResult.stats.numIoExceptions++;
  256. }
  257. mFailedResultsCounter++;
  258. mLastFailedResult = result;
  259. } // else, ResultCode.FILE_NOT_FOUND is ignored, remote folder was
  260. // removed from other thread or other client during the synchronization,
  261. // before this thread fetched its contents
  262. }
  263. /**
  264. * Checks if a failed result should terminate the synchronization process immediately,
  265. * according to OUR OWN POLICY
  266. *
  267. * @param failedResult Remote operation result to check.
  268. * @return 'True' if the result should immediately finish the
  269. * synchronization
  270. */
  271. private boolean isFinisher(RemoteOperationResult failedResult) {
  272. if (failedResult != null) {
  273. RemoteOperationResult.ResultCode code = failedResult.getCode();
  274. return (code.equals(RemoteOperationResult.ResultCode.SSL_ERROR) ||
  275. code.equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) ||
  276. code.equals(RemoteOperationResult.ResultCode.BAD_OC_VERSION) ||
  277. code.equals(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED));
  278. }
  279. return false;
  280. }
  281. /**
  282. * Triggers the synchronization of any folder contained in the list of received files.
  283. *
  284. * No consideration of etag here because it MUST walk down anyway, in case that kept-in-sync files
  285. * have local changes.
  286. *
  287. * @param files Files to recursively synchronize.
  288. */
  289. private void syncChildren(List<OCFile> files) {
  290. int i;
  291. OCFile newFile;
  292. for (i=0; i < files.size() && !mCancellation; i++) {
  293. newFile = files.get(i);
  294. if (newFile.isFolder()) {
  295. synchronizeFolder(newFile);
  296. }
  297. }
  298. if (mCancellation && i <files.size()) {
  299. Log_OC.d(TAG,
  300. "Leaving synchronization before synchronizing " + files.get(i).getRemotePath() +
  301. " due to cancellation request");
  302. }
  303. }
  304. /**
  305. * Sends a message to any application component interested in the progress of the
  306. * synchronization.
  307. *
  308. * @param event Event in the process of synchronization to be notified.
  309. * @param dirRemotePath Remote path of the folder target of the event occurred.
  310. * @param result Result of an individual {@ SynchronizeFolderOperation},
  311. * if completed; may be null.
  312. */
  313. private void sendLocalBroadcast(String event, String dirRemotePath,
  314. RemoteOperationResult result) {
  315. Log_OC.d(TAG, "Send broadcast " + event);
  316. Intent intent = new Intent(event);
  317. intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, getAccount().name);
  318. if (dirRemotePath != null) {
  319. intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath);
  320. }
  321. if (result != null) {
  322. DataHolderUtil dataHolderUtil = DataHolderUtil.getInstance();
  323. String dataHolderItemId = dataHolderUtil.nextItemId();
  324. dataHolderUtil.save(dataHolderUtil.nextItemId(), result);
  325. intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId);
  326. }
  327. intent.setPackage(getContext().getPackageName());
  328. getContext().sendStickyBroadcast(intent);
  329. //LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
  330. }
  331. /**
  332. * Notifies the user about a failed synchronization through the status notification bar
  333. */
  334. private void notifyFailedSynchronization() {
  335. NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
  336. boolean needsToUpdateCredentials = (
  337. mLastFailedResult != null &&
  338. ResultCode.UNAUTHORIZED.equals(mLastFailedResult.getCode())
  339. );
  340. if (needsToUpdateCredentials) {
  341. // let the user update credentials with one click
  342. Intent updateAccountCredentials = new Intent(getContext(), AuthenticatorActivity.class);
  343. updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
  344. updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
  345. AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
  346. updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  347. updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
  348. updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
  349. notificationBuilder
  350. .setTicker(i18n(R.string.sync_fail_ticker_unauthorized))
  351. .setContentTitle(i18n(R.string.sync_fail_ticker_unauthorized))
  352. .setContentIntent(PendingIntent.getActivity(
  353. getContext(), (int)System.currentTimeMillis(), updateAccountCredentials,
  354. PendingIntent.FLAG_ONE_SHOT
  355. ))
  356. .setContentText(i18n(R.string.sync_fail_content_unauthorized, getAccount().name));
  357. } else {
  358. notificationBuilder
  359. .setTicker(i18n(R.string.sync_fail_ticker))
  360. .setContentTitle(i18n(R.string.sync_fail_ticker))
  361. .setContentText(i18n(R.string.sync_fail_content, getAccount().name));
  362. }
  363. showNotification(R.string.sync_fail_ticker, notificationBuilder);
  364. }
  365. /**
  366. * Notifies the user about conflicts and strange fails when trying to synchronize the contents
  367. * of kept-in-sync files.
  368. *
  369. * By now, we won't consider a failed synchronization.
  370. */
  371. private void notifyFailsInFavourites() {
  372. if (mFailedResultsCounter > 0) {
  373. NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
  374. notificationBuilder.setTicker(i18n(R.string.sync_fail_in_favourites_ticker));
  375. // TODO put something smart in the contentIntent below
  376. notificationBuilder
  377. .setContentIntent(PendingIntent.getActivity(
  378. getContext(), (int) System.currentTimeMillis(), new Intent(), 0
  379. ))
  380. .setContentTitle(i18n(R.string.sync_fail_in_favourites_ticker))
  381. .setContentText(getQuantityString(
  382. R.plurals.sync_fail_in_favourites_content,
  383. mFailedResultsCounter,
  384. mFailedResultsCounter + mConflictsFound, mConflictsFound
  385. )
  386. );
  387. showNotification(R.string.sync_fail_in_favourites_ticker, notificationBuilder);
  388. } else {
  389. NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
  390. notificationBuilder.setTicker(i18n(R.string.sync_conflicts_in_favourites_ticker));
  391. // TODO put something smart in the contentIntent below
  392. notificationBuilder
  393. .setContentIntent(PendingIntent.getActivity(
  394. getContext(), (int) System.currentTimeMillis(), new Intent(), 0
  395. ))
  396. .setContentTitle(i18n(R.string.sync_conflicts_in_favourites_ticker))
  397. .setContentText(i18n(R.string.sync_conflicts_in_favourites_ticker, mConflictsFound));
  398. showNotification(R.string.sync_conflicts_in_favourites_ticker, notificationBuilder);
  399. }
  400. }
  401. /**
  402. * Notifies the user about local copies of files out of the ownCloud local directory that
  403. * were 'forgotten' because copying them inside the ownCloud local directory was not possible.
  404. *
  405. * We don't want links to files out of the ownCloud local directory (foreign files) anymore.
  406. * It's easy to have synchronization problems if a local file is linked to more than one
  407. * remote file.
  408. *
  409. * We won't consider a synchronization as failed when foreign files can not be copied to
  410. * the ownCloud local directory.
  411. */
  412. private void notifyForgottenLocalFiles() {
  413. NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
  414. notificationBuilder.setTicker(i18n(R.string.sync_foreign_files_forgotten_ticker));
  415. /// includes a pending intent in the notification showing a more detailed explanation
  416. Intent explanationIntent = new Intent(getContext(), ErrorsWhileCopyingHandlerActivity.class);
  417. explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_ACCOUNT, getAccount());
  418. ArrayList<String> remotePaths = new ArrayList<String>();
  419. ArrayList<String> localPaths = new ArrayList<String>();
  420. remotePaths.addAll(mForgottenLocalFiles.keySet());
  421. localPaths.addAll(mForgottenLocalFiles.values());
  422. explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_LOCAL_PATHS, localPaths);
  423. explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_REMOTE_PATHS, remotePaths);
  424. explanationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  425. notificationBuilder
  426. .setContentIntent(PendingIntent.getActivity(
  427. getContext(), (int) System.currentTimeMillis(), explanationIntent, 0
  428. ))
  429. .setContentTitle(i18n(R.string.sync_foreign_files_forgotten_ticker))
  430. .setContentText(getQuantityString(
  431. R.plurals.sync_foreign_files_forgotten_content,
  432. mForgottenLocalFiles.size(),
  433. mForgottenLocalFiles.size(),
  434. i18n(R.string.app_name))
  435. );
  436. showNotification(R.string.sync_foreign_files_forgotten_ticker, notificationBuilder);
  437. }
  438. /**
  439. * Creates a notification builder with some commonly used settings
  440. *
  441. * @return notification builder
  442. */
  443. private NotificationCompat.Builder createNotificationBuilder() {
  444. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext());
  445. notificationBuilder.setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
  446. notificationBuilder.setColor(ThemeUtils.primaryColor());
  447. return notificationBuilder;
  448. }
  449. /**
  450. * Builds and shows the notification
  451. *
  452. * @param id
  453. * @param builder
  454. */
  455. private void showNotification(int id, NotificationCompat.Builder builder) {
  456. NotificationManager notificationManager = ((NotificationManager) getContext().
  457. getSystemService(Context.NOTIFICATION_SERVICE));
  458. if ((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)) {
  459. builder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_FILE_SYNC);
  460. }
  461. notificationManager.notify(id, builder.build());
  462. }
  463. /**
  464. * Shorthand translation
  465. *
  466. * @param key
  467. * @param args
  468. * @return
  469. */
  470. private String i18n(int key, Object... args) {
  471. return getContext().getString(key, args);
  472. }
  473. /**
  474. * Shorthand plurals translation.
  475. *
  476. * @param id The desired plurals identifier.
  477. * @param quantity The number used to get the correct string for the current language's plural rules.
  478. * @param formatArgs The format arguments that will be used for substitution.
  479. * @return formatted, plurals respecting string
  480. */
  481. private String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs) {
  482. return getContext().getResources().getQuantityString(id, quantity, formatArgs);
  483. }
  484. }