Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21106209 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

Merge branch '197-upgrade-initialise' into 'v1-oreo'

eDrive: Initialise folders on each new update

See merge request !121
parents 6124ec05 4de69dcf
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -91,10 +91,10 @@
        <service android:name=".services.SynchronizationService" />

        <receiver
            android:name=".receivers.PackageEventReceiver"
            android:name=".receivers.BootCompletedReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <receiver
+46 −0
Original line number Diff line number Diff line
@@ -13,34 +13,34 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import foundation.e.drive.database.DbHelper;
import foundation.e.drive.services.InitializerService;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;

/**
 * @author Vincent Bourgmayer
 */
public class PackageEventReceiver extends BroadcastReceiver {
public class BootCompletedReceiver extends BroadcastReceiver {
    public static final String TAG = BootCompletedReceiver.class.getSimpleName();
    public static final String DATE_SYSTEM_PROPERTY = "ro.build.date";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("PackageEventReceiver", "onReceive(...)" );
        //If package updated
        if(intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED)) {
        final String action = intent.getAction();
        Log.i(TAG, "onReceive(...)");
        SharedPreferences pref = context.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
            if (!CommonUtils.getProp(DATE_SYSTEM_PROPERTY).equals(pref.getString(DATE_SYSTEM_PROPERTY, ""))) {
                pref.edit().putString(DATE_SYSTEM_PROPERTY, CommonUtils.getProp(DATE_SYSTEM_PROPERTY)).apply();
                //reinitialized the app each time
                pref.edit().putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false).apply();
                context.startService(new Intent(context, InitializerService.class));

                DbHelper dbHelper = new DbHelper(context);
                dbHelper.getWritableDatabase().close(); //Force upgrade of db.

            /*if (!pref.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false)) {
                context.startService(new Intent(context, InitializerService.class));
            } else if(CommonUtils.getAccount( pref.getString(AccountManager.KEY_ACCOUNT_NAME,""),
                        pref.getString(AccountManager.KEY_ACCOUNT_TYPE, ""),
                        AccountManager.get(context) ) != null){
                    JobUtils.scheduleScannerJob(context, 120000);
            }*/
            }
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -90,7 +90,6 @@ public class InitializerService extends Service {
                }
            }
        }
        CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(this));
        return super.onStartCommand(intent, flags, startId);
    }

@@ -101,6 +100,7 @@ public class InitializerService extends Service {
            return;
        }
        
        CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(this));
        final List<String> syncCategories = new ArrayList<>();

        syncCategories.addAll(Arrays.asList(MEDIA_SYNCABLE_CATEGORIES));
+21 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ package foundation.e.drive.utils;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
@@ -37,6 +38,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.files.FileUtils;

import java.io.File;
import java.lang.reflect.Method;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Locale;
@@ -480,4 +482,23 @@ public abstract class CommonUtils {

        workManager.enqueueUniquePeriodicWork(AccountUserInfoWorker.UNIQUE_WORK_NAME, ExistingPeriodicWorkPolicy.REPLACE, periodicUserInfoScanRequest);
    }

    /**
     * Function for get build props through reflection
     *
     * @param prop key that you want to get value for
     * @return value of the prop, returns empty if not found
     */
    @SuppressLint("PrivateApi")
    public static String getProp(String prop) {
        String value = "";
        try {
            Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class);
            value = (String) get.invoke(c, prop);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }
}