Skip to content

Commit a275470

Browse files
Moved kernel updater internal files into data folder
Signed-off-by: sunilpaulmathew <sunil.kde@gmail.com>
1 parent 810ab67 commit a275470

File tree

2 files changed

+76
-71
lines changed

2 files changed

+76
-71
lines changed

app/src/main/java/com/smartpack/kernelmanager/fragments/tools/SmartPackFragment.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ protected void postInit() {
156156
@SuppressLint("StringFormatInvalid")
157157
private void SmartPackInit(List<RecyclerViewItem> items) {
158158
TitleView smartpack = new TitleView();
159-
smartpack.setText(!KernelUpdater.getKernelName().equals("Unavailable") ? KernelUpdater.getKernelName() :
159+
smartpack.setText(!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable") ? KernelUpdater.getKernelName(requireActivity()) :
160160
getString(R.string.kernel_information));
161161

162162
items.add(smartpack);
@@ -170,8 +170,8 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
170170
GenericInputView updateChannel = new GenericInputView();
171171
updateChannel.setMenuIcon(ViewUtils.getWhiteColoredIcon(R.drawable.ic_dots, requireActivity()));
172172
updateChannel.setTitle(getString(R.string.update_channel));
173-
updateChannel.setValue((!KernelUpdater.getKernelName().equals("Unavailable"))
174-
? KernelUpdater.getUpdateChannel() : getString(R.string.update_channel_summary));
173+
updateChannel.setValue((!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable"))
174+
? KernelUpdater.getUpdateChannel(requireActivity()) : getString(R.string.update_channel_summary));
175175
updateChannel.setOnGenericValueListener((genericSelectView, value) -> {
176176
if (mPermissionDenied) {
177177
Utils.snackbar(getRootView(), getString(R.string.permission_denied_write_storage));
@@ -182,7 +182,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
182182
return;
183183
}
184184
if (value.isEmpty()) {
185-
KernelUpdater.clearUpdateInfo();
185+
KernelUpdater.clearUpdateInfo(requireActivity());
186186
Utils.snackbar(getRootView(), getString(R.string.update_channel_empty));
187187
reload();
188188
return;
@@ -194,7 +194,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
194194
reload();
195195

196196
});
197-
if (!KernelUpdater.getKernelName().equals("Unavailable")) {
197+
if (!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable")) {
198198
updateChannel.setOnMenuListener((itemslist1, popupMenu) -> {
199199
Menu menu = popupMenu.getMenu();
200200
menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.remove));
@@ -207,7 +207,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
207207
.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
208208
})
209209
.setPositiveButton(getString(R.string.yes), (dialogInterface, i) -> {
210-
KernelUpdater.clearUpdateInfo();
210+
KernelUpdater.clearUpdateInfo(requireActivity());
211211
reload();
212212
})
213213
.show();
@@ -235,7 +235,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
235235

236236
items.add(updateChannel);
237237

238-
if (KernelUpdater.getLatestVersion().equals("Unavailable")) {
238+
if (KernelUpdater.getLatestVersion(requireActivity()).equals("Unavailable")) {
239239
DescriptionView info = new DescriptionView();
240240
info.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_info, requireContext()));
241241
info.setMenuIcon(ViewUtils.getWhiteColoredIcon(R.drawable.ic_dots, requireActivity()));
@@ -259,26 +259,26 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
259259
items.add(info);
260260
}
261261

262-
if (!KernelUpdater.getLatestVersion().equals("Unavailable")) {
262+
if (!KernelUpdater.getLatestVersion(requireActivity()).equals("Unavailable")) {
263263
DescriptionView latest = new DescriptionView();
264264
latest.setTitle(getString(R.string.kernel_latest));
265-
latest.setSummary(KernelUpdater.getLatestVersion());
265+
latest.setSummary(KernelUpdater.getLatestVersion(requireActivity()));
266266

267267
items.add(latest);
268268
}
269269

270-
if (!KernelUpdater.getChangeLog().equals("Unavailable")) {
270+
if (!KernelUpdater.getChangeLog(requireActivity()).equals("Unavailable")) {
271271
DescriptionView changelogs = new DescriptionView();
272272
changelogs.setTitle(getString(R.string.change_logs));
273273
changelogs.setSummary(getString(R.string.change_logs_summary));
274274
changelogs.setOnItemClickListener(item -> {
275-
if (KernelUpdater.getChangeLog().contains("https://") ||
276-
KernelUpdater.getChangeLog().contains("http://")) {
277-
Utils.launchUrl(getRootView(), KernelUpdater.getChangeLog(), getActivity());
275+
if (KernelUpdater.getChangeLog(requireActivity()).contains("https://") ||
276+
KernelUpdater.getChangeLog(requireActivity()).contains("http://")) {
277+
Utils.launchUrl(getRootView(), KernelUpdater.getChangeLog(requireActivity()), getActivity());
278278
} else {
279279
new Dialog(requireActivity())
280-
.setTitle(KernelUpdater.getKernelName() + " " + KernelUpdater.getLatestVersion())
281-
.setMessage(KernelUpdater.getChangeLog())
280+
.setTitle(KernelUpdater.getKernelName(requireActivity()) + " " + KernelUpdater.getLatestVersion(requireActivity()))
281+
.setMessage(KernelUpdater.getChangeLog(requireActivity()))
282282
.setPositiveButton(getString(R.string.cancel), (dialog1, id1) -> {
283283
})
284284
.show();
@@ -288,14 +288,14 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
288288
items.add(changelogs);
289289
}
290290

291-
if (!KernelUpdater.getSupport().equals("Unavailable")) {
291+
if (!KernelUpdater.getSupport(requireActivity()).equals("Unavailable")) {
292292
DescriptionView support = new DescriptionView();
293293
support.setTitle(getString(R.string.support));
294294
support.setSummary(getString(R.string.support_summary));
295295
support.setOnItemClickListener(item -> {
296-
if (KernelUpdater.getSupport().contains("https://") ||
297-
KernelUpdater.getSupport().contains("http://")) {
298-
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(), getActivity());
296+
if (KernelUpdater.getSupport(requireActivity()).contains("https://") ||
297+
KernelUpdater.getSupport(requireActivity()).contains("http://")) {
298+
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(requireActivity()), getActivity());
299299
} else {
300300
Utils.snackbar(getRootView(), getString(R.string.unknown_link));
301301
}
@@ -304,7 +304,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
304304
items.add(support);
305305
}
306306

307-
if (!KernelUpdater.getUrl().equals("Unavailable")) {
307+
if (!KernelUpdater.getUrl(requireActivity()).equals("Unavailable")) {
308308
DescriptionView download = new DescriptionView();
309309
download.setTitle(getString(R.string.download));
310310
download.setSummary(getString(R.string.get_it_summary));
@@ -319,15 +319,15 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
319319
items.add(download);
320320
}
321321

322-
if (!KernelUpdater.getLatestVersion().equals("Unavailable")) {
322+
if (!KernelUpdater.getLatestVersion(requireActivity()).equals("Unavailable")) {
323323
DescriptionView donations = new DescriptionView();
324324
donations.setTitle(getString(R.string.donations));
325325
donations.setSummary(getString(R.string.donations_summary));
326326
donations.setOnItemClickListener(item -> {
327-
if (KernelUpdater.getDonationLink().contains("https://") ||
328-
KernelUpdater.getDonationLink().contains("http://")) {
329-
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(), getActivity());
330-
Utils.launchUrl(getRootView(), KernelUpdater.getDonationLink(), getActivity());
327+
if (KernelUpdater.getDonationLink(requireActivity()).contains("https://") ||
328+
KernelUpdater.getDonationLink(requireActivity()).contains("http://")) {
329+
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(requireActivity()), getActivity());
330+
Utils.launchUrl(getRootView(), KernelUpdater.getDonationLink(requireActivity()), getActivity());
331331
} else {
332332
Utils.snackbar(getRootView(), getString(R.string.unknown_link));
333333
}
@@ -337,15 +337,15 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
337337
items.add(donations);
338338
}
339339

340-
if (!KernelUpdater.getKernelName().equals("Unavailable") && Utils.isDownloadBinaries()) {
340+
if (!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable") && Utils.isDownloadBinaries()) {
341341
SwitchView update_check = new SwitchView();
342342
update_check.setSummary(getString(R.string.check_update));
343343
update_check.setChecked(Prefs.getBoolean("update_check", false, getActivity()));
344344
update_check.addOnSwitchListener((switchview, isChecked) -> {
345345
Prefs.saveBoolean("update_check", isChecked, getActivity());
346346
if (Prefs.getBoolean("update_check", true, getActivity())) {
347-
Utils.snackbar(getRootView(), getString(R.string.update_check_message, !KernelUpdater.getKernelName().
348-
equals("Unavailable") ? KernelUpdater.getKernelName() : "this"));
347+
Utils.snackbar(getRootView(), getString(R.string.update_check_message, !KernelUpdater.getKernelName(requireActivity()).
348+
equals("Unavailable") ? KernelUpdater.getKernelName(requireActivity()) : "this"));
349349
}
350350
});
351351

@@ -554,24 +554,24 @@ private void downloadKernel() {
554554
@Override
555555
protected void onPreExecute() {
556556
super.onPreExecute();
557-
showProgressMessage(getString(R.string.downloading_update, KernelUpdater.getKernelName() +
558-
"-" + KernelUpdater.getLatestVersion()) + "...");
557+
showProgressMessage(getString(R.string.downloading_update, KernelUpdater.getKernelName(requireActivity()) +
558+
"-" + KernelUpdater.getLatestVersion(requireActivity())) + "...");
559559
}
560560
@Override
561561
protected Void doInBackground(Void... voids) {
562562
Utils.prepareInternalDataStorage();
563-
Utils.downloadFile(Utils.getInternalDataStorage() + "/Kernel.zip", KernelUpdater.getUrl(), getActivity());
563+
Utils.downloadFile(Utils.getInternalDataStorage() + "/Kernel.zip", KernelUpdater.getUrl(requireActivity()), getActivity());
564564
return null;
565565
}
566566
@Override
567567
protected void onPostExecute(Void aVoid) {
568568
super.onPostExecute(aVoid);
569569
hideProgressMessage();
570-
if (KernelUpdater.getChecksum().equals("Unavailable") || !KernelUpdater.getChecksum().equals("Unavailable") &&
571-
Utils.getChecksum(Utils.getInternalDataStorage() + "/Kernel.zip").contains(KernelUpdater.getChecksum())) {
570+
if (KernelUpdater.getChecksum(requireActivity()).equals("Unavailable") || !KernelUpdater.getChecksum(requireActivity()).equals("Unavailable") &&
571+
Utils.getChecksum(Utils.getInternalDataStorage() + "/Kernel.zip").contains(KernelUpdater.getChecksum(requireActivity()))) {
572572
new Dialog(requireActivity())
573573
.setMessage(getString(R.string.download_completed,
574-
KernelUpdater.getKernelName() + "-" + KernelUpdater.getLatestVersion()))
574+
KernelUpdater.getKernelName(requireActivity()) + "-" + KernelUpdater.getLatestVersion(requireActivity())))
575575
.setCancelable(false)
576576
.setNegativeButton(getString(R.string.cancel), (dialog, id) -> {
577577
})
@@ -672,8 +672,8 @@ public void onStart(){
672672

673673
// Initialize kernel update check - Once in a day
674674
if (Utils.isNetworkAvailable(requireActivity()) && Prefs.getBoolean("update_check", true, getActivity())
675-
&& !KernelUpdater.getUpdateChannel().equals("Unavailable") && Utils.isDownloadBinaries() &&
676-
KernelUpdater.lastModified() + 89280000L < System.currentTimeMillis()) {
675+
&& !KernelUpdater.getUpdateChannel(requireActivity()).equals("Unavailable") && Utils.isDownloadBinaries() &&
676+
KernelUpdater.lastModified(requireActivity()) + 89280000L < System.currentTimeMillis()) {
677677
KernelUpdater.updateInfo(Utils.readFile(Utils.getInternalDataStorage() + "/updatechannel"), getActivity());
678678
}
679679
}

app/src/main/java/com/smartpack/kernelmanager/utils/tools/KernelUpdater.java

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,41 @@
3939

4040
public class KernelUpdater {
4141

42-
private static final String UPDATE_CHANNEL = Utils.getInternalDataStorage() + "/updatechannel";
43-
private static final String UPDATE_INFO = Utils.getInternalDataStorage() + "/updateinfo";
44-
45-
private static void updateChannel(String value) {
46-
Utils.create(value, UPDATE_CHANNEL);
42+
private static void updateChannel(String value, Context context) {
43+
Utils.create(value, updateChannelInfo(context));
4744
}
4845

4946
public static void updateInfo(String value, Context context) {
5047
Utils.prepareInternalDataStorage();
51-
Utils.downloadFile(UPDATE_INFO, value, context);
48+
Utils.downloadFile(updateInfo(context), value, context);
5249
}
5350

54-
public static void clearUpdateInfo() {
55-
Utils.delete(UPDATE_CHANNEL);
56-
Utils.delete(UPDATE_INFO);
51+
public static void clearUpdateInfo(Context context) {
52+
Utils.delete(updateChannelInfo(context));
53+
Utils.delete(updateInfo(context));
5754
}
5855

59-
private static String getKernelInfo() {
56+
private static String getKernelInfo(Context context) {
6057
try {
61-
JSONObject obj = new JSONObject(Utils.readFile(UPDATE_INFO));
58+
JSONObject obj = new JSONObject(Utils.readFile(updateInfo(context)));
6259
return (obj.getString("kernel"));
6360
} catch (JSONException e) {
6461
return "Unavailable";
6562
}
6663
}
6764

68-
private static String getSupportInfo() {
65+
private static String getSupportInfo(Context context) {
6966
try {
70-
JSONObject obj = new JSONObject(Utils.readFile(UPDATE_INFO));
67+
JSONObject obj = new JSONObject(Utils.readFile(updateInfo(context)));
7168
return (obj.getString("support"));
7269
} catch (JSONException e) {
7370
return "Unavailable";
7471
}
7572
}
7673

77-
public static String getUpdateChannel() {
78-
if (Utils.existFile(UPDATE_CHANNEL)) {
79-
return Utils.readFile(UPDATE_CHANNEL);
74+
public static String getUpdateChannel(Context context) {
75+
if (Utils.existFile(updateChannelInfo(context))) {
76+
return Utils.readFile(updateChannelInfo(context));
8077
} else {
8178
return "Unavailable";
8279
}
@@ -95,9 +92,9 @@ protected void onPreExecute() {
9592
}
9693
@Override
9794
protected Void doInBackground(Void... voids) {
98-
clearUpdateInfo();
95+
clearUpdateInfo(context);
9996
updateInfo(value, context);
100-
updateChannel(value);
97+
updateChannel(value, context);
10198
Utils.sleep(1);
10299
return null;
103100
}
@@ -108,78 +105,86 @@ protected void onPostExecute(Void aVoid) {
108105
mProgressDialog.dismiss();
109106
} catch (IllegalArgumentException ignored) {
110107
}
111-
if (getKernelName().equals("Unavailable")) {
108+
if (getKernelName(context).equals("Unavailable")) {
112109
Utils.toast(R.string.update_channel_invalid, context);
113110
}
114111
}
115112
}.execute();
116113
}
117114

118-
public static String getKernelName() {
115+
public static String getKernelName(Context context) {
119116
try {
120-
JSONObject obj = new JSONObject(getKernelInfo());
117+
JSONObject obj = new JSONObject(getKernelInfo(context));
121118
return (obj.getString("name"));
122119
} catch (JSONException e) {
123120
return "Unavailable";
124121
}
125122
}
126123

127-
public static String getLatestVersion() {
124+
public static String getLatestVersion(Context context) {
128125
try {
129-
JSONObject obj = new JSONObject(getKernelInfo());
126+
JSONObject obj = new JSONObject(getKernelInfo(context));
130127
return (obj.getString("version"));
131128
} catch (JSONException e) {
132129
return "Unavailable";
133130
}
134131
}
135132

136-
public static String getUrl() {
133+
public static String getUrl(Context context) {
137134
try {
138-
JSONObject obj = new JSONObject(getKernelInfo());
135+
JSONObject obj = new JSONObject(getKernelInfo(context));
139136
return (obj.getString("link"));
140137
} catch (JSONException e) {
141138
return "Unavailable";
142139
}
143140
}
144141

145-
public static String getChecksum() {
142+
public static String getChecksum(Context context) {
146143
try {
147-
JSONObject obj = new JSONObject(getKernelInfo());
144+
JSONObject obj = new JSONObject(getKernelInfo(context));
148145
return (obj.getString("sha1"));
149146
} catch (JSONException e) {
150147
return "Unavailable";
151148
}
152149
}
153150

154-
public static String getChangeLog() {
151+
public static String getChangeLog(Context context) {
155152
try {
156-
JSONObject obj = new JSONObject(getKernelInfo());
153+
JSONObject obj = new JSONObject(getKernelInfo(context));
157154
return (obj.getString("changelog_url"));
158155
} catch (JSONException e) {
159156
return "Unavailable";
160157
}
161158
}
162159

163-
public static String getSupport() {
160+
public static String getSupport(Context context) {
164161
try {
165-
JSONObject obj = new JSONObject(getSupportInfo());
162+
JSONObject obj = new JSONObject(getSupportInfo(context));
166163
return (obj.getString("link"));
167164
} catch (JSONException e) {
168165
return "Unavailable";
169166
}
170167
}
171168

172-
public static String getDonationLink() {
169+
public static String getDonationLink(Context context) {
173170
try {
174-
JSONObject obj = new JSONObject(getSupportInfo());
171+
JSONObject obj = new JSONObject(getSupportInfo(context));
175172
return (obj.getString("donation"));
176173
} catch (JSONException e) {
177174
return "Unavailable";
178175
}
179176
}
180177

181-
public static long lastModified() {
182-
return new File(UPDATE_INFO).lastModified();
178+
private static String updateInfo(Context context) {
179+
return context.getFilesDir().getPath() + "/release";
180+
}
181+
182+
private static String updateChannelInfo(Context context) {
183+
return context.getFilesDir().getPath() + "/updatechannel";
184+
}
185+
186+
public static long lastModified(Context context) {
187+
return new File(updateInfo(context)).lastModified();
183188
}
184189

185190
}

0 commit comments

Comments
 (0)