Skip to content

Commit

Permalink
Moved kernel updater internal files into data folder
Browse files Browse the repository at this point in the history
Signed-off-by: sunilpaulmathew <sunil.kde@gmail.com>
  • Loading branch information
sunilpaulmathew committed Nov 15, 2020
1 parent 810ab67 commit a275470
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected void postInit() {
@SuppressLint("StringFormatInvalid")
private void SmartPackInit(List<RecyclerViewItem> items) {
TitleView smartpack = new TitleView();
smartpack.setText(!KernelUpdater.getKernelName().equals("Unavailable") ? KernelUpdater.getKernelName() :
smartpack.setText(!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable") ? KernelUpdater.getKernelName(requireActivity()) :
getString(R.string.kernel_information));

items.add(smartpack);
Expand All @@ -170,8 +170,8 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
GenericInputView updateChannel = new GenericInputView();
updateChannel.setMenuIcon(ViewUtils.getWhiteColoredIcon(R.drawable.ic_dots, requireActivity()));
updateChannel.setTitle(getString(R.string.update_channel));
updateChannel.setValue((!KernelUpdater.getKernelName().equals("Unavailable"))
? KernelUpdater.getUpdateChannel() : getString(R.string.update_channel_summary));
updateChannel.setValue((!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable"))
? KernelUpdater.getUpdateChannel(requireActivity()) : getString(R.string.update_channel_summary));
updateChannel.setOnGenericValueListener((genericSelectView, value) -> {
if (mPermissionDenied) {
Utils.snackbar(getRootView(), getString(R.string.permission_denied_write_storage));
Expand All @@ -182,7 +182,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
return;
}
if (value.isEmpty()) {
KernelUpdater.clearUpdateInfo();
KernelUpdater.clearUpdateInfo(requireActivity());
Utils.snackbar(getRootView(), getString(R.string.update_channel_empty));
reload();
return;
Expand All @@ -194,7 +194,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
reload();

});
if (!KernelUpdater.getKernelName().equals("Unavailable")) {
if (!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable")) {
updateChannel.setOnMenuListener((itemslist1, popupMenu) -> {
Menu menu = popupMenu.getMenu();
menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.remove));
Expand All @@ -207,7 +207,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
})
.setPositiveButton(getString(R.string.yes), (dialogInterface, i) -> {
KernelUpdater.clearUpdateInfo();
KernelUpdater.clearUpdateInfo(requireActivity());
reload();
})
.show();
Expand Down Expand Up @@ -235,7 +235,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {

items.add(updateChannel);

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

if (!KernelUpdater.getLatestVersion().equals("Unavailable")) {
if (!KernelUpdater.getLatestVersion(requireActivity()).equals("Unavailable")) {
DescriptionView latest = new DescriptionView();
latest.setTitle(getString(R.string.kernel_latest));
latest.setSummary(KernelUpdater.getLatestVersion());
latest.setSummary(KernelUpdater.getLatestVersion(requireActivity()));

items.add(latest);
}

if (!KernelUpdater.getChangeLog().equals("Unavailable")) {
if (!KernelUpdater.getChangeLog(requireActivity()).equals("Unavailable")) {
DescriptionView changelogs = new DescriptionView();
changelogs.setTitle(getString(R.string.change_logs));
changelogs.setSummary(getString(R.string.change_logs_summary));
changelogs.setOnItemClickListener(item -> {
if (KernelUpdater.getChangeLog().contains("https://") ||
KernelUpdater.getChangeLog().contains("http://")) {
Utils.launchUrl(getRootView(), KernelUpdater.getChangeLog(), getActivity());
if (KernelUpdater.getChangeLog(requireActivity()).contains("https://") ||
KernelUpdater.getChangeLog(requireActivity()).contains("http://")) {
Utils.launchUrl(getRootView(), KernelUpdater.getChangeLog(requireActivity()), getActivity());
} else {
new Dialog(requireActivity())
.setTitle(KernelUpdater.getKernelName() + " " + KernelUpdater.getLatestVersion())
.setMessage(KernelUpdater.getChangeLog())
.setTitle(KernelUpdater.getKernelName(requireActivity()) + " " + KernelUpdater.getLatestVersion(requireActivity()))
.setMessage(KernelUpdater.getChangeLog(requireActivity()))
.setPositiveButton(getString(R.string.cancel), (dialog1, id1) -> {
})
.show();
Expand All @@ -288,14 +288,14 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
items.add(changelogs);
}

if (!KernelUpdater.getSupport().equals("Unavailable")) {
if (!KernelUpdater.getSupport(requireActivity()).equals("Unavailable")) {
DescriptionView support = new DescriptionView();
support.setTitle(getString(R.string.support));
support.setSummary(getString(R.string.support_summary));
support.setOnItemClickListener(item -> {
if (KernelUpdater.getSupport().contains("https://") ||
KernelUpdater.getSupport().contains("http://")) {
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(), getActivity());
if (KernelUpdater.getSupport(requireActivity()).contains("https://") ||
KernelUpdater.getSupport(requireActivity()).contains("http://")) {
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(requireActivity()), getActivity());
} else {
Utils.snackbar(getRootView(), getString(R.string.unknown_link));
}
Expand All @@ -304,7 +304,7 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
items.add(support);
}

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

if (!KernelUpdater.getLatestVersion().equals("Unavailable")) {
if (!KernelUpdater.getLatestVersion(requireActivity()).equals("Unavailable")) {
DescriptionView donations = new DescriptionView();
donations.setTitle(getString(R.string.donations));
donations.setSummary(getString(R.string.donations_summary));
donations.setOnItemClickListener(item -> {
if (KernelUpdater.getDonationLink().contains("https://") ||
KernelUpdater.getDonationLink().contains("http://")) {
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(), getActivity());
Utils.launchUrl(getRootView(), KernelUpdater.getDonationLink(), getActivity());
if (KernelUpdater.getDonationLink(requireActivity()).contains("https://") ||
KernelUpdater.getDonationLink(requireActivity()).contains("http://")) {
Utils.launchUrl(getRootView(), KernelUpdater.getSupport(requireActivity()), getActivity());
Utils.launchUrl(getRootView(), KernelUpdater.getDonationLink(requireActivity()), getActivity());
} else {
Utils.snackbar(getRootView(), getString(R.string.unknown_link));
}
Expand All @@ -337,15 +337,15 @@ private void SmartPackInit(List<RecyclerViewItem> items) {
items.add(donations);
}

if (!KernelUpdater.getKernelName().equals("Unavailable") && Utils.isDownloadBinaries()) {
if (!KernelUpdater.getKernelName(requireActivity()).equals("Unavailable") && Utils.isDownloadBinaries()) {
SwitchView update_check = new SwitchView();
update_check.setSummary(getString(R.string.check_update));
update_check.setChecked(Prefs.getBoolean("update_check", false, getActivity()));
update_check.addOnSwitchListener((switchview, isChecked) -> {
Prefs.saveBoolean("update_check", isChecked, getActivity());
if (Prefs.getBoolean("update_check", true, getActivity())) {
Utils.snackbar(getRootView(), getString(R.string.update_check_message, !KernelUpdater.getKernelName().
equals("Unavailable") ? KernelUpdater.getKernelName() : "this"));
Utils.snackbar(getRootView(), getString(R.string.update_check_message, !KernelUpdater.getKernelName(requireActivity()).
equals("Unavailable") ? KernelUpdater.getKernelName(requireActivity()) : "this"));
}
});

Expand Down Expand Up @@ -554,24 +554,24 @@ private void downloadKernel() {
@Override
protected void onPreExecute() {
super.onPreExecute();
showProgressMessage(getString(R.string.downloading_update, KernelUpdater.getKernelName() +
"-" + KernelUpdater.getLatestVersion()) + "...");
showProgressMessage(getString(R.string.downloading_update, KernelUpdater.getKernelName(requireActivity()) +
"-" + KernelUpdater.getLatestVersion(requireActivity())) + "...");
}
@Override
protected Void doInBackground(Void... voids) {
Utils.prepareInternalDataStorage();
Utils.downloadFile(Utils.getInternalDataStorage() + "/Kernel.zip", KernelUpdater.getUrl(), getActivity());
Utils.downloadFile(Utils.getInternalDataStorage() + "/Kernel.zip", KernelUpdater.getUrl(requireActivity()), getActivity());
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
hideProgressMessage();
if (KernelUpdater.getChecksum().equals("Unavailable") || !KernelUpdater.getChecksum().equals("Unavailable") &&
Utils.getChecksum(Utils.getInternalDataStorage() + "/Kernel.zip").contains(KernelUpdater.getChecksum())) {
if (KernelUpdater.getChecksum(requireActivity()).equals("Unavailable") || !KernelUpdater.getChecksum(requireActivity()).equals("Unavailable") &&
Utils.getChecksum(Utils.getInternalDataStorage() + "/Kernel.zip").contains(KernelUpdater.getChecksum(requireActivity()))) {
new Dialog(requireActivity())
.setMessage(getString(R.string.download_completed,
KernelUpdater.getKernelName() + "-" + KernelUpdater.getLatestVersion()))
KernelUpdater.getKernelName(requireActivity()) + "-" + KernelUpdater.getLatestVersion(requireActivity())))
.setCancelable(false)
.setNegativeButton(getString(R.string.cancel), (dialog, id) -> {
})
Expand Down Expand Up @@ -672,8 +672,8 @@ public void onStart(){

// Initialize kernel update check - Once in a day
if (Utils.isNetworkAvailable(requireActivity()) && Prefs.getBoolean("update_check", true, getActivity())
&& !KernelUpdater.getUpdateChannel().equals("Unavailable") && Utils.isDownloadBinaries() &&
KernelUpdater.lastModified() + 89280000L < System.currentTimeMillis()) {
&& !KernelUpdater.getUpdateChannel(requireActivity()).equals("Unavailable") && Utils.isDownloadBinaries() &&
KernelUpdater.lastModified(requireActivity()) + 89280000L < System.currentTimeMillis()) {
KernelUpdater.updateInfo(Utils.readFile(Utils.getInternalDataStorage() + "/updatechannel"), getActivity());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,41 @@

public class KernelUpdater {

private static final String UPDATE_CHANNEL = Utils.getInternalDataStorage() + "/updatechannel";
private static final String UPDATE_INFO = Utils.getInternalDataStorage() + "/updateinfo";

private static void updateChannel(String value) {
Utils.create(value, UPDATE_CHANNEL);
private static void updateChannel(String value, Context context) {
Utils.create(value, updateChannelInfo(context));
}

public static void updateInfo(String value, Context context) {
Utils.prepareInternalDataStorage();
Utils.downloadFile(UPDATE_INFO, value, context);
Utils.downloadFile(updateInfo(context), value, context);
}

public static void clearUpdateInfo() {
Utils.delete(UPDATE_CHANNEL);
Utils.delete(UPDATE_INFO);
public static void clearUpdateInfo(Context context) {
Utils.delete(updateChannelInfo(context));
Utils.delete(updateInfo(context));
}

private static String getKernelInfo() {
private static String getKernelInfo(Context context) {
try {
JSONObject obj = new JSONObject(Utils.readFile(UPDATE_INFO));
JSONObject obj = new JSONObject(Utils.readFile(updateInfo(context)));
return (obj.getString("kernel"));
} catch (JSONException e) {
return "Unavailable";
}
}

private static String getSupportInfo() {
private static String getSupportInfo(Context context) {
try {
JSONObject obj = new JSONObject(Utils.readFile(UPDATE_INFO));
JSONObject obj = new JSONObject(Utils.readFile(updateInfo(context)));
return (obj.getString("support"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static String getUpdateChannel() {
if (Utils.existFile(UPDATE_CHANNEL)) {
return Utils.readFile(UPDATE_CHANNEL);
public static String getUpdateChannel(Context context) {
if (Utils.existFile(updateChannelInfo(context))) {
return Utils.readFile(updateChannelInfo(context));
} else {
return "Unavailable";
}
Expand All @@ -95,9 +92,9 @@ protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... voids) {
clearUpdateInfo();
clearUpdateInfo(context);
updateInfo(value, context);
updateChannel(value);
updateChannel(value, context);
Utils.sleep(1);
return null;
}
Expand All @@ -108,78 +105,86 @@ protected void onPostExecute(Void aVoid) {
mProgressDialog.dismiss();
} catch (IllegalArgumentException ignored) {
}
if (getKernelName().equals("Unavailable")) {
if (getKernelName(context).equals("Unavailable")) {
Utils.toast(R.string.update_channel_invalid, context);
}
}
}.execute();
}

public static String getKernelName() {
public static String getKernelName(Context context) {
try {
JSONObject obj = new JSONObject(getKernelInfo());
JSONObject obj = new JSONObject(getKernelInfo(context));
return (obj.getString("name"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static String getLatestVersion() {
public static String getLatestVersion(Context context) {
try {
JSONObject obj = new JSONObject(getKernelInfo());
JSONObject obj = new JSONObject(getKernelInfo(context));
return (obj.getString("version"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static String getUrl() {
public static String getUrl(Context context) {
try {
JSONObject obj = new JSONObject(getKernelInfo());
JSONObject obj = new JSONObject(getKernelInfo(context));
return (obj.getString("link"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static String getChecksum() {
public static String getChecksum(Context context) {
try {
JSONObject obj = new JSONObject(getKernelInfo());
JSONObject obj = new JSONObject(getKernelInfo(context));
return (obj.getString("sha1"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static String getChangeLog() {
public static String getChangeLog(Context context) {
try {
JSONObject obj = new JSONObject(getKernelInfo());
JSONObject obj = new JSONObject(getKernelInfo(context));
return (obj.getString("changelog_url"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static String getSupport() {
public static String getSupport(Context context) {
try {
JSONObject obj = new JSONObject(getSupportInfo());
JSONObject obj = new JSONObject(getSupportInfo(context));
return (obj.getString("link"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static String getDonationLink() {
public static String getDonationLink(Context context) {
try {
JSONObject obj = new JSONObject(getSupportInfo());
JSONObject obj = new JSONObject(getSupportInfo(context));
return (obj.getString("donation"));
} catch (JSONException e) {
return "Unavailable";
}
}

public static long lastModified() {
return new File(UPDATE_INFO).lastModified();
private static String updateInfo(Context context) {
return context.getFilesDir().getPath() + "/release";
}

private static String updateChannelInfo(Context context) {
return context.getFilesDir().getPath() + "/updatechannel";
}

public static long lastModified(Context context) {
return new File(updateInfo(context)).lastModified();
}

}

0 comments on commit a275470

Please sign in to comment.