Skip to content

Commit

Permalink
add new updater
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Apr 16, 2024
1 parent 57f5950 commit 1645c87
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 30 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ android {
appIcon: "@mipmap/ic_launcher",
appIconRound: "@mipmap/ic_launcher_round"
]
signingConfig signingConfigs.release
}
}

Expand Down Expand Up @@ -195,4 +196,7 @@ dependencies {
// Splash screen
implementation("androidx.core:core-splashscreen:1.0.1")

//Updates
implementation 'com.github.Sharkaboi:AppUpdateChecker:v1.0.5'
implementation("com.google.android.play:app-update-ktx:2.1.0")
}
48 changes: 31 additions & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION" />



<application
android:allowBackup="true"
android:icon="${appIcon}"
android:roundIcon="${appIconRound}"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="${appIconRound}"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning,MissingTvBanner"
tools:targetApi="33">
<receiver
android:name="de.felixnuesse.extract.updates.UpdateUserchoiceReceiver"
android:enabled="true"
android:exported="true" />

<activity android:name=".Activities.OnboardingActivity" />
<activity
android:name=".Activities.MainActivity"
Expand Down Expand Up @@ -69,25 +79,22 @@
</intent-filter>
</provider>

<service android:name=".Services.StreamingService"
<service
android:name=".Services.StreamingService"
android:foregroundServiceType="dataSync" />
<service android:name=".Services.ThumbnailsLoadingService"
<service
android:name=".Services.ThumbnailsLoadingService"
android:foregroundServiceType="dataSync" />
<service
android:name=".Services.TriggerService"
android:foregroundServiceType="dataSync"
android:exported="true" />
android:exported="true"
android:foregroundServiceType="dataSync" />
<service
android:name=".Services.RcdService"
android:foregroundServiceType="dataSync" />

<!-- Used to expose tasks to other apps, no other functionality-->
android:foregroundServiceType="dataSync" /> <!-- Used to expose tasks to other apps, no other functionality -->
<service
android:name=".Services.SyncService"
android:exported="true">
</service>

<!-- This is a default service required for any and all Workers. Do not remove.-->
android:exported="true"></service> <!-- This is a default service required for any and all Workers. Do not remove. -->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync" />
Expand All @@ -106,8 +113,8 @@
android:exported="true" />
<receiver
android:name=".BroadcastReceivers.ClearReportBroadcastReciever"
android:exported="false">
</receiver>
android:exported="false"></receiver>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
Expand Down Expand Up @@ -209,9 +216,7 @@
<activity
android:name=".Activities.TriggerActivity"
android:label="@string/title_activity_trigger"
android:theme="@style/AppTheme.NoActionBar" />

<!-- Auto Language Generation -->
android:theme="@style/AppTheme.NoActionBar" /> <!-- Auto Language Generation -->
<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false"
Expand All @@ -221,6 +226,15 @@
android:value="true" />
</service>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths"/>
</provider>

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ca.pkay.rcloneexplorer.Activities;

import static android.provider.Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM;
import static ca.pkay.rcloneexplorer.util.ActivityHelper.tryStartActivityForResult;

import android.Manifest;
Expand All @@ -10,7 +9,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
Expand All @@ -20,7 +18,6 @@
import android.os.storage.StorageVolume;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
Expand All @@ -29,12 +26,10 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
Expand All @@ -49,7 +44,6 @@

import java.io.File;
import java.io.IOException;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -81,11 +75,11 @@
import ca.pkay.rcloneexplorer.RuntimeConfiguration;
import ca.pkay.rcloneexplorer.Services.StreamingService;
import ca.pkay.rcloneexplorer.Services.TriggerService;
import ca.pkay.rcloneexplorer.pkg.PackageUpdate;
import ca.pkay.rcloneexplorer.util.ActivityHelper;
import ca.pkay.rcloneexplorer.util.FLog;
import ca.pkay.rcloneexplorer.util.PermissionManager;
import ca.pkay.rcloneexplorer.util.SharedPreferencesUtil;
import de.felixnuesse.extract.updates.UpdateChecker;
import es.dmoral.toasty.Toasty;
import java9.util.stream.Stream;

Expand Down Expand Up @@ -219,6 +213,8 @@ protected void onCreate(Bundle savedInstanceState) {
updatePermissionFragmentVisibility();
TriggerService triggerService = new TriggerService(context);
triggerService.queueTrigger();

(new UpdateChecker(this)).schedule();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package de.felixnuesse.extract.notifications

import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import ca.pkay.rcloneexplorer.R
import ca.pkay.rcloneexplorer.util.PermissionManager
import de.felixnuesse.extract.extensions.tag
import de.felixnuesse.extract.updates.UpdateUserchoiceReceiver
import de.felixnuesse.extract.updates.UpdateUserchoiceReceiver.Companion.ACTION_DOWNLOAD
import de.felixnuesse.extract.updates.UpdateUserchoiceReceiver.Companion.ACTION_IGNORE
import de.felixnuesse.extract.updates.UpdateUserchoiceReceiver.Companion.IGNORE_VERSION_EXTRA


class AppUpdateNotification(private var mContext: Context) {

companion object {
var NOTIFICATION_CHANNEL_ID = "NOTIFICATION_CHANNEL_ID"
var NOTIFICATION_ID = 63598
}

@SuppressLint("MissingPermission") // Handled by PermissionManager
fun showNotification(version: String) {
createNotificationChannel()
val builder = NotificationCompat.Builder(mContext, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.appicon)
.setContentTitle(mContext.getString(R.string.app_update_notification_title))
.setContentText(mContext.getString(R.string.app_update_notification_description, version))
.setPriority(NotificationCompat.PRIORITY_LOW)
.addAction(R.drawable.ic_twotone_cancel_24, mContext.getString(R.string.app_updates_notification_action_ignore), getIgnoreVersionIntent(version))
.addAction(R.drawable.ic_check, mContext.getString(R.string.app_updates_notification_action_apply), getApplyIntent())
.setAutoCancel(true)

val notificationManager = NotificationManagerCompat.from(mContext)

if(PermissionManager(mContext).grantedNotifications()) {
notificationManager.notify(NOTIFICATION_ID, builder.build())
} else {
Log.e(tag(), "We don't have notification permission!")
}
}

private fun getIgnoreVersionIntent(version: String): PendingIntent {
val ignoreIntent = Intent(mContext, UpdateUserchoiceReceiver::class.java)
ignoreIntent.setAction(ACTION_IGNORE)
ignoreIntent.putExtra(IGNORE_VERSION_EXTRA, version)
return PendingIntent.getBroadcast(mContext, 0, ignoreIntent, PendingIntent.FLAG_IMMUTABLE)
}

private fun getApplyIntent(): PendingIntent {
val downloadIntent = Intent(mContext, UpdateUserchoiceReceiver::class.java)
downloadIntent.setAction(ACTION_DOWNLOAD)
return PendingIntent.getBroadcast(mContext, 0, downloadIntent, PendingIntent.FLAG_IMMUTABLE)
}

private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = mContext.getString(R.string.app_update_notification_channel_name)
val descriptionText = mContext.getString(R.string.app_update_notification_channel_description)
val importance = NotificationManager.IMPORTANCE_LOW
val channel = NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance).apply {
description = descriptionText
}

val notificationManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}

fun cancelNotification(){
val notificationManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(NOTIFICATION_ID)
}

}
52 changes: 52 additions & 0 deletions app/src/main/java/de/felixnuesse/extract/updates/UpdateChecker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.felixnuesse.extract.updates

import android.content.Context
import android.os.Build
import androidx.preference.PreferenceManager
import ca.pkay.rcloneexplorer.R
import de.felixnuesse.extract.updates.workmanager.UpdateManager


class UpdateChecker(private var mContext: Context) {


private val preferenceManager = PreferenceManager.getDefaultSharedPreferences(mContext)

private var checkForUpdates = preferenceManager.getBoolean(mContext.getString(R.string.pref_key_app_updates), true)

private var updateManager = UpdateManager(mContext)


init {
if(checkForUpdates) {
checkForUpdates = isUpdateableInstall()
}
}

fun schedule() {
if(!checkForUpdates) {
updateManager.cancelAll()
return
}
updateManager.queueRepeating()
}

private fun isUpdateableInstall(): Boolean {
val storeApps = mutableListOf(
"com.android.vending",
"com.google.android.feedback",
"org.fdroid.basic",
"org.fdroid.fdroid",
"com.aurora.store"
)

val sourcePackage = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
mContext.packageManager.getInstallSourceInfo(mContext.packageName).installingPackageName
} else {
mContext.packageManager.getInstallerPackageName(mContext.packageName)
}

return !storeApps.contains(sourcePackage)
}

}
Loading

0 comments on commit 1645c87

Please sign in to comment.