bug 773943 - fix null pointer exception from accessing getExternalFilesDir r=snorp

This commit is contained in:
Arkady Blyakher 2012-07-19 17:36:48 -04:00
Родитель 39c0df43d5
Коммит 08535479ad
2 изменённых файлов: 20 добавлений и 10 удалений

Просмотреть файл

@ -2374,19 +2374,20 @@ abstract public class GeckoApp
((GeckoApplication) getApplication()).removeApplicationLifecycleCallbacks(this);
}
// Get/Create a temporary direcory
// Get a temporary directory, may return null
public static File getTempDirectory() {
File dir = mAppContext.getExternalFilesDir("temp");
dir.mkdirs();
return dir;
}
// Delete any files in our temporary directory
public static void deleteTempFiles() {
File[] files = getTempDirectory().listFiles();
File dir = getTempDirectory();
if (dir == null)
return;
File[] files = dir.listFiles();
if (files == null)
return;
for (File file : files) {
file.delete();
}

Просмотреть файл

@ -1042,8 +1042,13 @@ public class GeckoAppShell
Intent intent = new Intent(Intent.ACTION_SEND);
boolean isDataURI = aSrc.startsWith("data:");
OutputStream os = null;
File dir = GeckoApp.getTempDirectory();
if (dir == null) {
showImageShareFailureToast();
return;
}
GeckoApp.deleteTempFiles();
try {
@ -1089,11 +1094,7 @@ public class GeckoAppShell
intent.putExtra(Intent.EXTRA_TEXT, aSrc);
intent.setType("text/plain");
} else {
// Don't fail silently, tell the user that we weren't able to share the image
Toast toast = Toast.makeText(GeckoApp.mAppContext,
GeckoApp.mAppContext.getResources().getString(R.string.share_image_failed),
Toast.LENGTH_SHORT);
toast.show();
showImageShareFailureToast();
return;
}
} finally {
@ -1103,6 +1104,14 @@ public class GeckoAppShell
GeckoApp.mAppContext.getResources().getString(R.string.share_title)));
}
// Don't fail silently, tell the user that we weren't able to share the image
private static final void showImageShareFailureToast() {
Toast toast = Toast.makeText(GeckoApp.mAppContext,
GeckoApp.mAppContext.getResources().getString(R.string.share_image_failed),
Toast.LENGTH_SHORT);
toast.show();
}
static boolean openUriExternal(String aUriSpec, String aMimeType, String aPackageName,
String aClassName, String aAction, String aTitle) {
Intent intent = getIntentForActionString(aAction);