修复了一些bug和漏洞

develop
Luchangcheng 4 years ago
parent 5ac4540195
commit 225ace6901

@ -0,0 +1 @@
gradlew sonarqube -Dsonar.projectKey=MiCodes -Dsonar.host.url=http://localhost:9000 -Dsonar.login=29c76d5ce5f4da5c0398ac577754cc938c679792

@ -40,7 +40,7 @@ public class SqlData {
private static final int INVALID_ID = -99999; private static final int INVALID_ID = -99999;
public static final String[] PROJECTION_DATA = new String[] { protected static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3 DataColumns.DATA3
}; };

@ -134,28 +134,30 @@ public class TaskList extends Node {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
} }
try { if (js != null) {
JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); try {
JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (folder != null){
if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { if (folder != null){
String name = folder.getString(NoteColumns.SNIPPET); if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name); String name = folder.getString(NoteColumns.SNIPPET);
} else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name);
if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER) } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT); if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER) setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
+ GTaskStringUtils.FOLDER_CALL_NOTE); setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
else + GTaskStringUtils.FOLDER_CALL_NOTE);
Log.e(TAG, "invalid system folder"); else
} else { Log.e(TAG, "invalid system folder");
Log.e(TAG, "error type"); } else {
Log.e(TAG, "error type");
}
} }
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
} }
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
} }
} }

@ -62,7 +62,7 @@ public class WorkingNote {
private NoteSettingChangedListener mNoteSettingStatusListener; private NoteSettingChangedListener mNoteSettingStatusListener;
public static final String[] DATA_PROJECTION = new String[] { protected static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID, DataColumns.ID,
DataColumns.CONTENT, DataColumns.CONTENT,
DataColumns.MIME_TYPE, DataColumns.MIME_TYPE,
@ -72,7 +72,7 @@ public class WorkingNote {
DataColumns.DATA4, DataColumns.DATA4,
}; };
public static final String[] NOTE_PROJECTION = new String[] { protected static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID, NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE, NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID,

@ -73,7 +73,7 @@ public class BackupUtils {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
} }
public int exportToText() { public int exportToText() throws IOException {
return mTextExport.exportToText(); return mTextExport.exportToText();
} }
@ -218,7 +218,7 @@ public class BackupUtils {
/** /**
* Note will be exported as text which is user readable * Note will be exported as text which is user readable
*/ */
public int exportToText() { public int exportToText() throws IOException {
if (!externalStorageAvailable()) { if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted"); Log.d(TAG, "Media was not mounted");
return STATE_SD_CARD_UNMOUONTED; return STATE_SD_CARD_UNMOUONTED;
@ -285,26 +285,25 @@ public class BackupUtils {
/** /**
* Get a print stream pointed to the file {@generateExportedTextFile} * Get a print stream pointed to the file {@generateExportedTextFile}
*/ */
private PrintStream getExportToTextPrintStream() { private PrintStream getExportToTextPrintStream() throws IOException {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path, File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
R.string.file_name_txt_format); R.string.file_name_txt_format);
if (file == null) { if (file == null) {
Log.e(TAG, "create file to exported failed"); Log.e(TAG, "create file to exported failed");
return null; return null;
} }
mFileName = file.getName(); mFileName = file.getName();
mFileDirectory = mContext.getString(R.string.file_path); mFileDirectory = mContext.getString(R.string.file_path);
PrintStream ps = null; PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file); try (FileOutputStream fos = new FileOutputStream(file)) {
ps = new PrintStream(fos); ps = new PrintStream(fos);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
ps.close();
return null; return null;
} catch (NullPointerException e) { } catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
ps.close();
return null; return null;
} }
return ps; return ps;
@ -330,7 +329,12 @@ public class BackupUtils {
filedir.mkdir(); filedir.mkdir();
} }
if (!file.exists()) { if (!file.exists()) {
file.createNewFile(); boolean res = file.createNewFile();
if (res == true) {
Log.i("BackupUtils", "Create new file sucessfully");
} else {
Log.i("BackupUtils", "Fail to create new file");
}
} }
return file; return file;
} catch (SecurityException e) { } catch (SecurityException e) {

@ -30,7 +30,7 @@ import net.micode.notes.data.Notes.NoteColumns;
public class FoldersListAdapter extends CursorAdapter { public class FoldersListAdapter extends CursorAdapter {
public static final String [] PROJECTION = { protected static final String [] PROJECTION = {
NoteColumns.ID, NoteColumns.ID,
NoteColumns.SNIPPET NoteColumns.SNIPPET
}; };

@ -150,7 +150,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
/** /**
* Insert an introduction when user firstly use this application * Insert an introduction when user firstly use this application
*/ */
setAppInfoFromRawRes(); try {
setAppInfoFromRawRes();
} catch (IOException e) {
e.printStackTrace();
}
} }
@Override @Override
@ -169,36 +173,24 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
* 便 * 便
* @return: * @return:
*/ */
private void setAppInfoFromRawRes() { private void setAppInfoFromRawRes() throws IOException {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) { if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
InputStream in = null; InputStream in = null;
in = getResources().openRawResource(R.raw.introduction);
try { if (in != null) {
in = getResources().openRawResource(R.raw.introduction); try (InputStreamReader isr = new InputStreamReader(in);
if (in != null) { BufferedReader br = new BufferedReader(isr);) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024]; char [] buf = new char[1024];
int len = 0; int len = 0;
while ((len = br.read(buf)) > 0) { while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len); sb.append(buf, 0, len);
} }
} catch (IOException e) {
isr.close(); e.printStackTrace();
br.close(); } finally {
} else {
Log.e(TAG, "Read introduction file error");
return;
}
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
if(in != null) {
try { try {
in.close(); in.close();
} catch (IOException e) { } catch (IOException e) {
@ -208,8 +200,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
} }
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER, WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE, AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
ResourceParser.RED); ResourceParser.RED);
@ -982,7 +972,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
@Override @Override
protected Integer doInBackground(Void... unused) { protected Integer doInBackground(Void... unused) {
return backup.exportToText(); try {
return backup.exportToText();
} catch (IOException e) {
e.printStackTrace();
}
return -1;
} }
@Override @Override

@ -33,7 +33,7 @@ import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity; import net.micode.notes.ui.NotesListActivity;
public abstract class NoteWidgetProvider extends AppWidgetProvider { public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] { protected static final String [] PROJECTION = new String [] {
NoteColumns.ID, NoteColumns.ID,
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET NoteColumns.SNIPPET

Loading…
Cancel
Save