|
@@ -1,6 +1,27 @@
|
|
|
+/**
|
|
|
+ * ownCloud Android client application
|
|
|
+ *
|
|
|
+ * @author masensio
|
|
|
+ * Copyright (C) 2016 ownCloud Inc.
|
|
|
+ *
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License version 2,
|
|
|
+ * as published by the Free Software Foundation.
|
|
|
+ *
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
package com.owncloud.android.ui.activity;
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
+import android.os.AsyncTask;
|
|
|
import android.os.Bundle;
|
|
|
import android.preference.PreferenceManager;
|
|
|
import android.support.v7.app.ActionBar;
|
|
@@ -9,6 +30,7 @@ import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
@@ -19,6 +41,8 @@ public class ManageSpaceActivity extends AppCompatActivity {
|
|
|
|
|
|
private static final String TAG = ManageSpaceActivity.class.getSimpleName();
|
|
|
|
|
|
+ private static final String LIB_FOLDER = "lib";
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
@@ -35,97 +59,119 @@ public class ManageSpaceActivity extends AppCompatActivity {
|
|
|
clearDataButton.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- clearData();
|
|
|
+ ClearDataAsynTask clearDataTask = new ClearDataAsynTask();
|
|
|
+ clearDataTask.execute();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ super.onOptionsItemSelected(item);
|
|
|
+ switch (item.getItemId()) {
|
|
|
+ case android.R.id.home:
|
|
|
+ finish();
|
|
|
+ return true;
|
|
|
+ default:
|
|
|
+ Log_OC.w(TAG, "Unknown menu item triggered");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * Save passcode from Share preferences
|
|
|
- * Clear the rest of data
|
|
|
+ * AsyncTask for Clear Data, saving the passcode
|
|
|
*/
|
|
|
- private void clearData() {
|
|
|
- // Save passcode from Share preferences
|
|
|
- SharedPreferences appPrefs = PreferenceManager
|
|
|
- .getDefaultSharedPreferences(getApplicationContext());
|
|
|
-
|
|
|
- boolean passCodeEnable = appPrefs.getBoolean("set_pincode", false);
|
|
|
-
|
|
|
- String passCodeDigits[] = new String[4];
|
|
|
- if (passCodeEnable) {
|
|
|
- passCodeDigits[0] = appPrefs.getString("PrefPinCode1", null);
|
|
|
- passCodeDigits[1] = appPrefs.getString("PrefPinCode2", null);
|
|
|
- passCodeDigits[2] = appPrefs.getString("PrefPinCode3", null);
|
|
|
- passCodeDigits[3] = appPrefs.getString("PrefPinCode4", null);
|
|
|
- }
|
|
|
+ private class ClearDataAsynTask extends AsyncTask<Void, Void, Boolean>{
|
|
|
|
|
|
- // Clear data
|
|
|
- clearApplicationData();
|
|
|
+ @Override
|
|
|
+ protected Boolean doInBackground(Void... params) {
|
|
|
|
|
|
+ boolean result = true;
|
|
|
|
|
|
- // Clear SharedPreferences
|
|
|
- SharedPreferences.Editor appPrefsEditor = PreferenceManager
|
|
|
- .getDefaultSharedPreferences(getApplicationContext()).edit();
|
|
|
- appPrefsEditor.clear();
|
|
|
- appPrefsEditor.commit();
|
|
|
+ // Save passcode from Share preferences
|
|
|
+ SharedPreferences appPrefs = PreferenceManager
|
|
|
+ .getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
|
|
- // Recover passcode
|
|
|
- if (passCodeEnable) {
|
|
|
- appPrefsEditor.putString("PrefPinCode1", passCodeDigits[0]);
|
|
|
- appPrefsEditor.putString("PrefPinCode2", passCodeDigits[1]);
|
|
|
- appPrefsEditor.putString("PrefPinCode3", passCodeDigits[2]);
|
|
|
- appPrefsEditor.putString("PrefPinCode4", passCodeDigits[3]);
|
|
|
- }
|
|
|
+ boolean passCodeEnable = appPrefs.getBoolean(PassCodeActivity.PREFERENCE_SET_PASSCODE, false);
|
|
|
|
|
|
- appPrefsEditor.putBoolean("set_pincode", passCodeEnable);
|
|
|
- appPrefsEditor.commit();
|
|
|
+ String passCodeDigits[] = new String[4];
|
|
|
+ if (passCodeEnable) {
|
|
|
+ passCodeDigits[0] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D1, null);
|
|
|
+ passCodeDigits[1] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D2, null);
|
|
|
+ passCodeDigits[2] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D3, null);
|
|
|
+ passCodeDigits[3] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D4, null);
|
|
|
+ }
|
|
|
|
|
|
+ // Clear data
|
|
|
+ result = clearApplicationData();
|
|
|
|
|
|
- finish();
|
|
|
- System.exit(0);
|
|
|
|
|
|
- }
|
|
|
+ // Clear SharedPreferences
|
|
|
+ SharedPreferences.Editor appPrefsEditor = PreferenceManager
|
|
|
+ .getDefaultSharedPreferences(getApplicationContext()).edit();
|
|
|
+ appPrefsEditor.clear();
|
|
|
+ result = result && appPrefsEditor.commit();
|
|
|
|
|
|
- public void clearApplicationData() {
|
|
|
- File cache = getCacheDir();
|
|
|
- File appDir = new File(cache.getParent());
|
|
|
- if (appDir.exists()) {
|
|
|
- String[] children = appDir.list();
|
|
|
- for (String s : children) {
|
|
|
- if (!s.equals("lib")) {
|
|
|
- File fileToDelete = new File(appDir, s);
|
|
|
- deleteDir(fileToDelete);
|
|
|
- Log_OC.d(TAG, "Clear Application Data, File: " + fileToDelete.getName()+ " DELETED *******");
|
|
|
- }
|
|
|
+ // Recover passcode
|
|
|
+ if (passCodeEnable) {
|
|
|
+ appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D1, passCodeDigits[0]);
|
|
|
+ appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D2, passCodeDigits[1]);
|
|
|
+ appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D3, passCodeDigits[2]);
|
|
|
+ appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D4, passCodeDigits[3]);
|
|
|
}
|
|
|
+
|
|
|
+ appPrefsEditor.putBoolean(PassCodeActivity.PREFERENCE_SET_PASSCODE, passCodeEnable);
|
|
|
+ result = result && appPrefsEditor.commit();
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPostExecute(Boolean result) {
|
|
|
+ super.onPostExecute(result);
|
|
|
+ if (!result) {
|
|
|
+ Toast.makeText(getApplicationContext(),
|
|
|
+ getString(R.string.manage_space_clear_data),
|
|
|
+ Toast.LENGTH_LONG).show();
|
|
|
+ } else {
|
|
|
+ finish();
|
|
|
+ System.exit(0);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- public boolean deleteDir(File dir) {
|
|
|
- if (dir != null && dir.isDirectory()) {
|
|
|
- String[] children = dir.list();
|
|
|
- for (int i = 0; i < children.length; i++) {
|
|
|
- boolean success = deleteDir(new File(dir, children[i]));
|
|
|
- if (!success) {
|
|
|
- return false;
|
|
|
+ public boolean clearApplicationData() {
|
|
|
+ boolean clearResult = true;
|
|
|
+ File appDir = new File(getCacheDir().getParent());
|
|
|
+ if (appDir.exists()) {
|
|
|
+ String[] children = appDir.list();
|
|
|
+ for (String s : children) {
|
|
|
+ if (!LIB_FOLDER.equals(s)) {
|
|
|
+ File fileToDelete = new File(appDir, s);
|
|
|
+ clearResult = clearResult && deleteDir(fileToDelete);
|
|
|
+ Log_OC.d(TAG, "Clear Application Data, File: " + fileToDelete.getName()+ " DELETED *******");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ return clearResult;
|
|
|
}
|
|
|
|
|
|
- return dir.delete();
|
|
|
- }
|
|
|
+ public boolean deleteDir(File dir) {
|
|
|
+ if (dir != null && dir.isDirectory()) {
|
|
|
+ String[] children = dir.list();
|
|
|
+ for (int i = 0; i < children.length; i++) {
|
|
|
+ boolean success = deleteDir(new File(dir, children[i]));
|
|
|
+ if (!success) {
|
|
|
+ Log_OC.d(TAG, "File NOT deleted " + children[i]);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ Log_OC.d(TAG, "File deleted " + children[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
- super.onOptionsItemSelected(item);
|
|
|
- switch (item.getItemId()) {
|
|
|
- case android.R.id.home:
|
|
|
- finish();
|
|
|
- break;
|
|
|
- default:
|
|
|
- Log_OC.w(TAG, "Unknown menu item triggered");
|
|
|
- return false;
|
|
|
+ return dir.delete();
|
|
|
}
|
|
|
- return true;
|
|
|
}
|
|
|
}
|