修复了一些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;
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.DATA3
};

@ -134,28 +134,30 @@ public class TaskList extends Node {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
}
try {
JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (folder != null){
if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
String name = folder.getString(NoteColumns.SNIPPET);
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name);
} else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
+ GTaskStringUtils.FOLDER_CALL_NOTE);
else
Log.e(TAG, "invalid system folder");
} else {
Log.e(TAG, "error type");
if (js != null) {
try {
JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (folder != null){
if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
String name = folder.getString(NoteColumns.SNIPPET);
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name);
} else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
+ GTaskStringUtils.FOLDER_CALL_NOTE);
else
Log.e(TAG, "invalid system folder");
} 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;
public static final String[] DATA_PROJECTION = new String[] {
protected static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
@ -72,7 +72,7 @@ public class WorkingNote {
DataColumns.DATA4,
};
public static final String[] NOTE_PROJECTION = new String[] {
protected static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,

@ -73,7 +73,7 @@ public class BackupUtils {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
public int exportToText() {
public int exportToText() throws IOException {
return mTextExport.exportToText();
}
@ -218,7 +218,7 @@ public class BackupUtils {
/**
* Note will be exported as text which is user readable
*/
public int exportToText() {
public int exportToText() throws IOException {
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted");
return STATE_SD_CARD_UNMOUONTED;
@ -285,26 +285,25 @@ public class BackupUtils {
/**
* 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,
R.string.file_name_txt_format);
if (file == null) {
Log.e(TAG, "create file to exported failed");
return null;
}
mFileName = file.getName();
mFileDirectory = mContext.getString(R.string.file_path);
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file);
try (FileOutputStream fos = new FileOutputStream(file)) {
ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
ps.close();
return null;
} catch (NullPointerException e) {
e.printStackTrace();
ps.close();
return null;
}
return ps;
@ -330,7 +329,12 @@ public class BackupUtils {
filedir.mkdir();
}
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;
} catch (SecurityException e) {

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

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

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

Loading…
Cancel
Save