Skip to content

Commit

Permalink
Fix cache directory issue in CrashReport
Browse files Browse the repository at this point in the history
Summary: FacebookSDK.getCacheDir() may cause lock in some cases and we use FacebookSDK.getApplicationContext().getCacheDir() instead

Reviewed By: dreamolight

Differential Revision: D17144611

fbshipit-source-id: 85542716fe94e034dc7021bc671ef493ecf9d8dd
  • Loading branch information
KylinChang authored and facebook-github-bot committed Aug 31, 2019
1 parent 1290de9 commit 856665c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Expand Up @@ -229,7 +229,7 @@ public static void sendReports(String key, JSONArray reports, GraphRequest.Callb
/**
* Get the instrument directory for report if the directory exists. If the directory doesn't
* exist, will attempt to create the directory. Note that, the instrument directory is under
* cache directory defined in {@link com.facebook.FacebookSdk#getCacheDir()} method.
* cache directory of the Application.
*
* Note that the function should be called after FacebookSdk is initialized. Otherwise,
* exception FacebookSdkNotInitializedException will be thrown.
Expand All @@ -239,7 +239,7 @@ public static void sendReports(String key, JSONArray reports, GraphRequest.Callb
*/
@Nullable
public static File getInstrumentReportDir() {
final File cacheDir = FacebookSdk.getCacheDir();
final File cacheDir = FacebookSdk.getApplicationContext().getCacheDir();
final File dir = new File(cacheDir, INSTRUMENT_DIR);
if (dir.exists() || dir.mkdirs()) {
return dir;
Expand Down
4 changes: 4 additions & 0 deletions facebook/src/test/java/com/facebook/GraphErrorTest.java
Expand Up @@ -21,6 +21,7 @@
package com.facebook;

import com.facebook.internal.FacebookRequestErrorClassification;
import com.facebook.internal.FetchedAppGateKeepersManager;
import com.facebook.internal.Utility;

import org.json.JSONException;
Expand All @@ -36,6 +37,7 @@

import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.powermock.api.support.membermodification.MemberMatcher.method;
import static org.powermock.api.support.membermodification.MemberModifier.stub;
Expand All @@ -45,6 +47,7 @@
AccessToken.class,
AccessTokenCache.class,
FacebookSdk.class,
FetchedAppGateKeepersManager.class,
GraphRequest.class,
Utility.class,
})
Expand All @@ -56,6 +59,7 @@ public void before() throws Exception {
Whitebox.setInternalState(FacebookSdk.class, "sdkInitialized", true);
Whitebox.setInternalState(FacebookSdk.class, "applicationContext", RuntimeEnvironment.application);
stub(method(AccessTokenCache.class, "save")).toReturn(null);
mockStatic(FetchedAppGateKeepersManager.class);
}

@Test
Expand Down

1 comment on commit 856665c

@slott
Copy link

@slott slott commented on 856665c Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - our Vivino app just exploded with ANR's because of this.

Please sign in to comment.