diff --git a/app/src/main/java/dev/ukanth/ufirewall/Api.java b/app/src/main/java/dev/ukanth/ufirewall/Api.java index cdba365a..9763a5b8 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/Api.java +++ b/app/src/main/java/dev/ukanth/ufirewall/Api.java @@ -2748,14 +2748,6 @@ public static boolean loadSharedPreferencesFromFile(Context ctx, StringBuilder b return res; } - /** - * Probe log target - * @param ctx - */ - public static void probeLogTarget(final Context ctx) { - - } - @SuppressLint("InlinedApi") public static void showInstalledAppDetails(Context context, String packageName) { final String SCHEME = "package"; @@ -2989,19 +2981,6 @@ public static void applyDefaultChainsv6(Context ctx, RootCommand callback) { } } - /** - * Delete all firewall rules. For diagnostic purposes only. - * - * @param ctx application context - * @param callback callback for completion - */ - public static void flushOtherRules(Context ctx, RootCommand callback) { - List cmds = new ArrayList(); - cmds.add("-F firewall"); - cmds.add("-X firewall"); - apply46(ctx, cmds, callback); - } - // Clipboard public static void copyToClipboard(Context context, String val) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); @@ -3159,13 +3138,13 @@ public static void setDefaultPermission(ApplicationInfo applicationInfo) { static class RuleDataSet { - List wifiList; - List dataList; - List lanList; - List roamList; - List vpnList; - List tetherList; - List torList; + final List wifiList; + final List dataList; + final List lanList; + final List roamList; + final List vpnList; + final List tetherList; + final List torList; RuleDataSet(List uidsWifi, List uids3g, List uidsRoam, List uidsVPN, List uidsTether, diff --git a/app/src/main/java/dev/ukanth/ufirewall/InterfaceDetails.java b/app/src/main/java/dev/ukanth/ufirewall/InterfaceDetails.java index 411b4027..fd590135 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/InterfaceDetails.java +++ b/app/src/main/java/dev/ukanth/ufirewall/InterfaceDetails.java @@ -32,8 +32,9 @@ public class InterfaceDetails { public boolean isBluetoothTethered = false; public boolean tetherBluetoothStatusKnown = false; - public boolean isUsbTethered = false; - public boolean tetherUsbStatusKnown = false; + final public boolean isUsbTethered = false; + + final public boolean tetherUsbStatusKnown = false; public String lanMaskV4 = ""; public String lanMaskV6 = ""; diff --git a/app/src/main/java/dev/ukanth/ufirewall/InterfaceTracker.java b/app/src/main/java/dev/ukanth/ufirewall/InterfaceTracker.java index 18477a08..32b2d5fe 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/InterfaceTracker.java +++ b/app/src/main/java/dev/ukanth/ufirewall/InterfaceTracker.java @@ -24,10 +24,8 @@ import static dev.ukanth.ufirewall.util.G.ctx; -import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothProfile; import android.content.Context; -import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiManager; diff --git a/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java b/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java index 292bf2bd..8cd4a52d 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java +++ b/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java @@ -159,7 +159,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte private static final int DEFAULT_COLUMN = 2; private int selectedColumns = DEFAULT_COLUMN; private static final int DEFAULT_VIEW_LIMIT = 4; - private View view; public boolean isDirty() { return dirty; @@ -272,14 +271,6 @@ private void updateSelectedColumns() { selectedColumns = G.enableTor() ? selectedColumns + 1 : selectedColumns; } - private void registerLogService() { - if (G.enableLogService()) { - Log.i(G.TAG, "Starting Log Service"); - final Intent logIntent = new Intent(getBaseContext(), LogService.class); - startService(logIntent); - } - } - private void registerUIRefresh() { IntentFilter filter = new IntentFilter("dev.ukanth.ufirewall.ui.CHECKREFRESH"); uiRefreshReceiver = new BroadcastReceiver() { @@ -831,27 +822,6 @@ private void reloadProfileList(boolean reset) { } } - public void deviceCheck() { - if (Build.VERSION.SDK_INT >= 21) { - if ((G.isDoKey(getApplicationContext()) || isDonate())) { - KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); - if (keyguardManager.isKeyguardSecure()) { - Intent createConfirmDeviceCredentialIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, null); - if (createConfirmDeviceCredentialIntent != null) { - try { - startActivityForResult(createConfirmDeviceCredentialIntent, LOCK_VERIFICATION); - } catch (ActivityNotFoundException e) { - } - } - } else { - Toast.makeText(this, getText(R.string.android_version), Toast.LENGTH_SHORT).show(); - } - } else { - Api.donateDialog(MainActivity.this, true); - } - } - } - @Override protected void onPause() { super.onPause(); @@ -898,8 +868,6 @@ private void checkPreferences() { */ private void refreshHeader() { final String mode = G.pPrefs.getString(Api.PREF_MODE, Api.MODE_WHITELIST); - //final TextView labelmode = (TextView) this.findViewById(R.id.label_mode); - final Resources res = getResources(); if (mode.equals(Api.MODE_WHITELIST)) { if (mainMenu != null) { @@ -1251,7 +1219,7 @@ private void copyOldExportedData() { String targetDir = ctx.getExternalFilesDir(null) + "/"; String command = "cp -R " + existingDir + " " + targetDir; Log.i(TAG, "Invoking migration script " + command); - com.topjohnwu.superuser.Shell.Result result = com.topjohnwu.superuser.Shell.cmd(command).exec(); + com.topjohnwu.superuser.Shell.cmd(command).exec(); G.hasCopyOldExports(true); } } @@ -2434,7 +2402,7 @@ protected void onProgressUpdate(Integer... progress) { } private class RunApply extends AsyncTask { - boolean enabled = Api.isEnabled(getApplicationContext()); + final boolean enabled = Api.isEnabled(getApplicationContext()); private final WeakReference activityReference; @@ -2524,7 +2492,7 @@ protected void onPostExecute(Boolean aVoid) { private class RootCheck extends AsyncTask { MaterialDialog suDialog = null; boolean unsupportedSU = false; - boolean[] suGranted = {false}; + final boolean[] suGranted = {false}; private Context context = null; //private boolean suAvailable = false; @@ -2594,19 +2562,4 @@ public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) } } } - - @RequiresApi(28) - private static class OnUnhandledKeyEventListenerWrapper implements View.OnUnhandledKeyEventListener { - private final ViewCompat.OnUnhandledKeyEventListenerCompat mCompatListener; - - OnUnhandledKeyEventListenerWrapper(ViewCompat.OnUnhandledKeyEventListenerCompat listener) { - this.mCompatListener = listener; - } - - public boolean onUnhandledKeyEvent(View v, KeyEvent event) { - return this.mCompatListener.onUnhandledKeyEvent(v, event); - } - } - } - diff --git a/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java b/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java index f7e7e170..8b01ef8e 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java +++ b/app/src/main/java/dev/ukanth/ufirewall/preferences/ExpPreferenceFragment.java @@ -25,7 +25,6 @@ import dev.ukanth.ufirewall.Api; import dev.ukanth.ufirewall.R; -import dev.ukanth.ufirewall.service.RootCommand; import dev.ukanth.ufirewall.util.G; public class ExpPreferenceFragment extends PreferenceFragment implements diff --git a/app/src/main/java/dev/ukanth/ufirewall/profiles/ProfileHelper.java b/app/src/main/java/dev/ukanth/ufirewall/profiles/ProfileHelper.java index f731dae7..56699ba6 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/profiles/ProfileHelper.java +++ b/app/src/main/java/dev/ukanth/ufirewall/profiles/ProfileHelper.java @@ -65,21 +65,6 @@ public static ProfileData getProfileByIdentifier(String identifier) { .querySingle(); } - public static void updateProfileName(String identifier,String newName) { - ProfileData profileData = SQLite.select() - .from(ProfileData.class).where(ProfileData_Table.name.eq(identifier)) - .querySingle(); - profileData.setName(newName); - profileData.save(); - } - - public static boolean deleteProfile(String identifier) { - ProfileData data = getProfileByIdentifier(identifier); - if (data != null) { - data.delete(); - } - return true; - } public static boolean deleteProfileByName(String profileName) { ProfileData data = getProfileByName(profileName); if (data != null) { diff --git a/app/src/main/java/dev/ukanth/ufirewall/util/FileDialog.java b/app/src/main/java/dev/ukanth/ufirewall/util/FileDialog.java index 8fcf8230..48f73a84 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/util/FileDialog.java +++ b/app/src/main/java/dev/ukanth/ufirewall/util/FileDialog.java @@ -5,7 +5,6 @@ import android.os.Environment; import com.afollestad.materialdialogs.MaterialDialog; -import com.topjohnwu.superuser.Shell; import java.io.File; import java.io.FilenameFilter; diff --git a/app/src/main/java/dev/ukanth/ufirewall/util/G.java b/app/src/main/java/dev/ukanth/ufirewall/util/G.java index 7cf974f5..ae861ac2 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/util/G.java +++ b/app/src/main/java/dev/ukanth/ufirewall/util/G.java @@ -50,19 +50,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; import dev.ukanth.ufirewall.Api; import dev.ukanth.ufirewall.BuildConfig; import dev.ukanth.ufirewall.InterfaceTracker; -import dev.ukanth.ufirewall.MainActivity; import dev.ukanth.ufirewall.log.Log; import dev.ukanth.ufirewall.log.LogPreference; import dev.ukanth.ufirewall.log.LogPreferenceDB; -import dev.ukanth.ufirewall.log.LogPreference_Table; import dev.ukanth.ufirewall.preferences.DefaultConnectionPref; import dev.ukanth.ufirewall.preferences.DefaultConnectionPrefDB; @@ -72,8 +66,6 @@ public class G extends Application implements Application.ActivityLifecycleCallb private static boolean enabledPrivateLink = false; - private static boolean isActivityVisible; - static { //TODO: Remove this line before release //com.topjohnwu.superuser.Shell.enableVerboseLogging = BuildConfig.DEBUG; @@ -114,22 +106,16 @@ public static Context getContext() { private static final String ENABLE_CONFIRM = "enableConfirm"; private static final String ENABLE_MULTI_PROFILE = "enableMultiProfile"; private static final String SHOW_UID = "showUid"; - private static final String NOTIFY_INSTALL = "notifyAppInstall"; private static final String DISABLE_ICONS = "disableIcons"; private static final String IPTABLES_PATH = "ipt_path"; private static final String PROTECTION_OPTION = "passSetting"; private static final String BUSYBOX_PATH = "bb_path"; - private static final String TOAST_POS = "toast_pos"; private static final String LANGUAGE = "locale"; //private static final String LOG_DMESG = "logDmesg"; private static final String SORT_BY = "sort"; private static final String LAST_STORED_PROFILE = "storedProfile"; private static final String STARTUP_DELAY = "addDelayStart"; private static final String SYSTEM_APP_COLOR = "sysColor"; - - private static final String PRIMARY_COLOR = "primaryColor"; - private static final String PRIMARY_DARK_COLOR = "primaryColor"; - private static final String ACTIVE_RULES = "activeRules"; private static final String ADD_DELAY = "addDelay"; @@ -142,11 +128,9 @@ public static Context getContext() { private static final String DNS_PROXY = "dns_value"; private static final String MULTI_USER = "multiUser"; private static final String MULTI_USER_ID = "multiUserId"; - private static final String IS_MIGRATED = "isMigrated"; private static final String SHOW_FILTER = "showFilter"; private static final String PATTERN_MAX_TRY = "patternMax"; private static final String PATTERN_STEALTH = "stealthMode"; - private static final String ISKINGDETECT = "kingDetect"; private static final String PWD_ENCRYPT = "pwdEncrypt"; private static final String PROFILE_PWD = "profilePwd"; private static final String FINGERPRINT_ENABLED = "fingerprintEnabled"; @@ -158,7 +142,6 @@ public static Context getContext() { private static final String SHOW_ALL_APPS = "showAllApps"; private static final String THEME = "theme"; - private static final String FASTER_RULES = "fasterApplyRules"; private static boolean privateDns = false; //private static final String QUICK_RULES = "quickApply"; @@ -187,52 +170,21 @@ public static Context getContext() { private static final String INITPATH = "initPath"; private static final String AFWALL_PROFILE = "AFWallProfile"; - //private static final String SHOW_LOG_TOAST = "showLogToasts"; - public static String[] profiles = {"AFWallPrefs", AFWALL_PROFILE + 1, AFWALL_PROFILE + 2, AFWALL_PROFILE + 3}; - public static String[] default_profiles = {"AFWallProfile1", "AFWallProfile2", "AFWallProfile3"}; + public static final String[] profiles = {"AFWallPrefs", AFWALL_PROFILE + 1, AFWALL_PROFILE + 2, AFWALL_PROFILE + 3}; + public static final String[] default_profiles = {"AFWallProfile1", "AFWallProfile2", "AFWallProfile3"}; public static Context ctx; public static SharedPreferences gPrefs; public static SharedPreferences pPrefs; public static SharedPreferences sPrefs; - public static Set storedPid() { - return gPrefs.getStringSet("storedPid", null); - } - - public static void storedPid(Set store) { - gPrefs.edit().putStringSet("storedPid", store).commit(); - } - public static boolean supportDual() { return gPrefs.getBoolean(DUAL_APPS, false); } - public static boolean supportDual(boolean val) { - gPrefs.edit().putBoolean(DUAL_APPS, val).commit(); - return val; - } - - - public static boolean isFaster() { - return gPrefs.getBoolean(FASTER_RULES, false); - } - - public static boolean isFaster(boolean val) { - gPrefs.edit().putBoolean(FASTER_RULES, val).commit(); - return val; - } - - public static boolean isRun() { return gPrefs.getBoolean(RUN_NOTIFICATION, true); } - public static boolean isRun(boolean val) { - gPrefs.edit().putBoolean(RUN_NOTIFICATION, val).commit(); - return val; - } - - public static boolean hasCopyOld() { return gPrefs.getBoolean(COPIED_OLD_EXPORTS, false); } @@ -247,12 +199,6 @@ public static boolean showAllApps() { return gPrefs.getBoolean(SHOW_ALL_APPS, false); } - public static boolean showAllApps(boolean val) { - gPrefs.edit().putBoolean(SHOW_ALL_APPS, val).commit(); - return val; - } - - /* public static boolean showQuickButton() { return gPrefs.getBoolean(QUICK_RULES, false); }*/ @@ -475,12 +421,6 @@ public static boolean showHost() { return gPrefs.getBoolean(SHOW_HOST, false); } - public static boolean showHost(boolean val) { - gPrefs.edit().putBoolean(SHOW_HOST, val).commit(); - return val; - } - - public static boolean enableDeviceCheck() { return gPrefs.getBoolean(ENABLE_DEVICE_CHECK, false); } @@ -507,30 +447,10 @@ public static boolean showUid() { return gPrefs.getBoolean(SHOW_UID, false); } - public static boolean showUid(boolean val) { - gPrefs.edit().putBoolean(SHOW_UID, val).commit(); - return val; - } - public static boolean showFilter() { return gPrefs.getBoolean(SHOW_FILTER, false); } - public static boolean showFilter(boolean val) { - gPrefs.edit().putBoolean(SHOW_FILTER, val).commit(); - return val; - } - - - public static boolean kingDetected() { - return gPrefs.getBoolean(ISKINGDETECT, false); - } - - public static boolean kingDetected(boolean val) { - gPrefs.edit().putBoolean(ISKINGDETECT, val).commit(); - return val; - } - public static boolean disableIcons() { return gPrefs.getBoolean(DISABLE_ICONS, false); } @@ -539,11 +459,6 @@ public static String ip_path() { return gPrefs.getString(IPTABLES_PATH, "system"); } - public static String ip_path(String val) { - gPrefs.edit().putString(IPTABLES_PATH, val).commit(); - return val; - } - public static String dns_proxy() { return gPrefs.getString(DNS_PROXY, "auto"); } @@ -552,24 +467,10 @@ public static String bb_path() { return gPrefs.getString(BUSYBOX_PATH, "builtin"); } - public static String bb_path(String val) { - gPrefs.edit().putString(BUSYBOX_PATH, val).commit(); - return val; - } - - public static String toast_pos() { - return gPrefs.getString(TOAST_POS, "bottom"); - } - public static String locale() { return PreferenceManager.getDefaultSharedPreferences(ctx).getString(LANGUAGE, "en"); } - public static String locale(String val) { - gPrefs.edit().putString(LANGUAGE, val).commit(); - return val; - } - /*public static String logDmsg() { return gPrefs.getString(LOG_DMESG, "OS"); } @@ -698,16 +599,6 @@ public static int appVersion(int val) { return val; } - public static boolean isMigrated() { - return gPrefs.getBoolean(IS_MIGRATED, false); - } - - public static boolean isMigrated(boolean val) { - gPrefs.edit().putBoolean(IS_MIGRATED, val).commit(); - return val; - } - - public static int ruleTextSize() { return gPrefs.getInt("ruleTextSize", 32); } @@ -844,18 +735,6 @@ public static String protectionLevel() { gPrefs.edit().putString(BLOCKED_NOTIFICATION, listString).commit(); }*/ - - public static void storeBlockedApps(List list) { - // store to DB - for (Integer uid : list) { - LogPreference preference = new LogPreference(); - preference.setUid(uid); - preference.setTimestamp(System.currentTimeMillis()); - preference.setDisable(true); - FlowManager.getDatabase(LogPreferenceDB.class).beginTransactionAsync(databaseWrapper -> preference.save(databaseWrapper)).build().execute(); - } - } - public static void storeDefaultConnection(List list1, List list2, int modeType) { // store to DB @@ -888,19 +767,6 @@ public static List readDefaultConnection(int modeType) { return listSelected; } - public static List readBlockedApps() { - List list = SQLite.select() - .from(LogPreference.class) - .queryList(); - List listSelected = new ArrayList<>(); - for (LogPreference pref : list) { - if (pref.isDisable()) { - listSelected.add(pref.getUid()); - } - } - return listSelected; - } - /* public static List getBlockedNotifyApps() { String blockedApps = gPrefs.getString(BLOCKED_NOTIFICATION, null); List data = new ArrayList(); @@ -942,9 +808,6 @@ public static boolean isXposedEnabled() { return false; } - - - @Override public void onCreate() { instance = this; @@ -988,30 +851,12 @@ public static void reloadProfile() { Api.applications = null; } - public static boolean setProfile(boolean newEnableMultiProfile, String profileName) { + public static void setProfile(boolean newEnableMultiProfile, String profileName) { enableMultiProfile(newEnableMultiProfile); storedProfile(profileName); reloadProfile(); - return true; - } - - public static void addAdditionalProfile(String profile) { - String previousProfiles = gPrefs.getString(ADDITIONAL_PROFILES, ""); - StringBuilder builder = new StringBuilder(); - if (profile != null && profile.length() > 0) { - profile = profile.trim(); - if (previousProfiles.length() == 0) { - builder.append(profile); - } else { - builder.append(previousProfiles); - builder.append(","); - builder.append(profile); - } - gPrefs.edit().putString(ADDITIONAL_PROFILES, builder.toString()).commit(); - } } - public static boolean clearSharedPreferences(Context ctx, String preferenceName) { File dir = new File(ctx.getFilesDir().getParent() + "/shared_prefs/"); String[] children = dir.list(); @@ -1073,17 +918,6 @@ public static void updateLogNotification(int uid, boolean isChecked) { gPrefs.edit().putString(BLOCKED_NOTIFICATION, "").commit(); }*/ - public static boolean isNotificationMigrated() { - return gPrefs.getBoolean("NewDBNotification", false); - } - - public static boolean canShow(int uid) { - LogPreference logPreference = SQLite.select() - .from(LogPreference.class) - .where(LogPreference_Table.uid.eq(uid)).querySingle(); - return (logPreference == null) || !logPreference.isDisable(); - } - public static boolean isActivityVisible() { return activityVisible; } @@ -1098,35 +932,24 @@ public static void activityPaused() { private static boolean activityVisible; - @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { - } @Override public void onActivityStarted(Activity activity) { - } @Override public void onActivityResumed(Activity activity) { - if (activity instanceof MainActivity) { - isActivityVisible = true; - } } @Override public void onActivityPaused(Activity activity) { - } @Override public void onActivityStopped(Activity activity) { - if (activity instanceof MainActivity) { - isActivityVisible = false; - } - } @Override @@ -1136,34 +959,6 @@ public void onActivitySaveInstanceState(Activity activity, Bundle outState) { @Override public void onActivityDestroyed(Activity activity) { } - - private static Pattern VALID_IPV4_PATTERN = null; - private static Pattern VALID_IPV6_PATTERN = null; - private static final String ipv4Pattern = "(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])"; - private static final String ipv6Pattern = "^(((?=(?>.*?::)(?!.*::)))(::)?([0-9A-F]{1,4}::?){0,5}" - + "|([0-9A-F]{1,4}:){6})(\\2([0-9A-F]{1,4}(::?|$)){0,2}|((25[0-5]" - + "|(2[0-4]|1\\d|[1-9])?\\d)(\\.|$)){4}|[0-9A-F]{1,4}:[0-9A-F]{1," - + "4})(? { - - private final Context ctx; - boolean[] result = {false}; - - private LoadTask(Context context) { - this.ctx = context; - } - - @Override - protected Boolean doInBackground(Void... voids) { - File sdCard = Environment.getExternalStorageDirectory(); - File dir = new File(sdCard.getAbsolutePath() + "/afwall/"); - dir.mkdirs(); - File shared_prefs = new File(getDataDir(ctx, "com.googlecode.droidwall.free") + File.separator + "shared_prefs" + File.separator + "DroidWallPrefs.xml"); - File file = new File(dir, "DroidWallPrefs.xml"); - RootTools.copyFile(shared_prefs.getPath(), dir.getPath(), true, false); - final Editor prefEdit = ctx.getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE).edit(); - // write the logic to read the copied xml - String wifi = null, g = null; - try { - String xmlStr = readTextFile(new FileInputStream(file)); - Document doc = XMLfromString(xmlStr); - NodeList nodes = doc.getElementsByTagName("string"); - - for (int i = 0; i < nodes.getLength(); i++) { - Element e = (Element) nodes.item(i); - if (e.getAttribute("name").equals("AllowedUidsWifi")) { - wifi = getElementValue(e); - Log.d("AllowedUidsWifi", wifi); - } else if (e.getAttribute("name").equals("AllowedUids3G")) { - g = getElementValue(e); - Log.d("AllowedUids3G", g); - } - } - - } catch (FileNotFoundException e) { - } - - if (wifi != null) { - prefEdit.putString(Api.PREF_WIFI_PKG, getPackageListFromUID(ctx, wifi)); - prefEdit.putString(Api.PREF_WIFI_PKG_UIDS, wifi); - } - if (g != null) { - prefEdit.putString(Api.PREF_3G_PKG, getPackageListFromUID(ctx, g)); - prefEdit.putString(Api.PREF_3G_PKG_UIDS, g); - } - prefEdit.commit(); - result[0] = true; - return result[0]; - } - - @Override - protected void onPostExecute(Boolean result) { - // result holds what you return from doInBackground - } - } - - public static boolean loadSharedPreferencesFromDroidWall(Context ctx) { - try { - LoadTask task = new LoadTask(ctx); - task.execute(); - return task.result[0]; - } catch (Exception e) { - } - return false; - } - - private static String getElementValue(Node elem) { - Node kid; - if (elem != null) { - if (elem.hasChildNodes()) { - for (kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling()) { - if (kid.getNodeType() == Node.TEXT_NODE) { - return kid.getNodeValue(); - } - } - } - } - return ""; - } - - private static String readTextFile(InputStream inputStream) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - final byte[] buf = new byte[4096]; - int len; - try { - while ((len = inputStream.read(buf)) != -1) { - outputStream.write(buf, 0, len); - } - outputStream.close(); - inputStream.close(); - } catch (IOException e) { - - } - return outputStream.toString(); - } - - private static Document XMLfromString(String v) { - Document doc = null; - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - try { - DocumentBuilder db = dbf.newDocumentBuilder(); - InputSource is = new InputSource(); - is.setCharacterStream(new StringReader(v)); - doc = db.parse(is); - } catch (ParserConfigurationException e) { - } catch (SAXException e) { - } catch (IOException e) { - } - return doc; - - } - - private static String getPackageListFromUID(Context ctx, final String uids) { - final PackageManager pm = ctx.getPackageManager(); - final StringBuilder pkg = new StringBuilder(); - final StringTokenizer tok = new StringTokenizer(uids, "|"); - while (tok.hasMoreTokens()) { - final int uid = Integer.parseInt(tok.nextToken()); - String[] pack = pm.getPackagesForUid(uid); - if (pack != null && pack.length == 1) { - pkg.append(pack[0]).append("|"); - } - if (uid == 1000) { - pkg.append("android|"); - } - } - return pkg.toString(); - }*/ -}