Search in sources :

Example 6 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class PushUtils method migratePushKeys.

private static void migratePushKeys() {
    Context context = MainApp.getAppContext();
    AppPreferences preferences = AppPreferencesImpl.fromContext(context);
    if (!preferences.isKeysMigrationEnabled()) {
        String oldKeyPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
        File oldPrivateKeyFile = new File(oldKeyPath, "push_key.priv");
        File oldPublicKeyFile = new File(oldKeyPath, "push_key.pub");
        String keyPath = context.getDir("nc-keypair", Context.MODE_PRIVATE).getAbsolutePath();
        File privateKeyFile = new File(keyPath, "push_key.priv");
        File publicKeyFile = new File(keyPath, "push_key.pub");
        if ((privateKeyFile.exists() && publicKeyFile.exists()) || (!oldPrivateKeyFile.exists() && !oldPublicKeyFile.exists())) {
            preferences.setKeysMigrationEnabled(true);
        } else {
            if (oldPrivateKeyFile.exists()) {
                FileStorageUtils.moveFile(oldPrivateKeyFile, privateKeyFile);
            }
            if (oldPublicKeyFile.exists()) {
                FileStorageUtils.moveFile(oldPublicKeyFile, publicKeyFile);
            }
            if (privateKeyFile.exists() && publicKeyFile.exists()) {
                preferences.setKeysMigrationEnabled(true);
            }
        }
    }
}
Also used : Context(android.content.Context) AppPreferences(com.nextcloud.client.preferences.AppPreferences) File(java.io.File)

Example 7 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class MainApp method updateToAutoUpload.

private static void updateToAutoUpload() {
    Context context = getAppContext();
    AppPreferences preferences = AppPreferencesImpl.fromContext(context);
    if (preferences.instantPictureUploadEnabled() || preferences.instantVideoUploadEnabled()) {
        preferences.removeLegacyPreferences();
        // show info pop-up
        try {
            new AlertDialog.Builder(context, R.style.Theme_ownCloud_Dialog).setTitle(R.string.drawer_synced_folders).setMessage(R.string.synced_folders_new_info).setPositiveButton(R.string.drawer_open, (dialog, which) -> {
                // show Auto Upload
                Intent folderSyncIntent = new Intent(context, SyncedFoldersActivity.class);
                dialog.dismiss();
                context.startActivity(folderSyncIntent);
            }).setNegativeButton(R.string.drawer_close, (dialog, which) -> dialog.dismiss()).setIcon(R.drawable.nav_synced_folders).show();
        } catch (WindowManager.BadTokenException e) {
            Log_OC.i(TAG, "Error showing Auto Upload Update dialog, so skipping it: " + e.getMessage());
        }
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(android.content.Context) RequiresApi(androidx.annotation.RequiresApi) MultiDexApplication(androidx.multidex.MultiDexApplication) User(com.nextcloud.client.account.User) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) Arrays(java.util.Arrays) SSLContext(javax.net.ssl.SSLContext) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NotificationUtils(com.owncloud.android.ui.notifications.NotificationUtils) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) Security(java.security.Security) UserAccountManager(com.nextcloud.client.account.UserAccountManager) Clock(com.nextcloud.client.core.Clock) DarkMode(com.nextcloud.client.preferences.DarkMode) ContentResolver(android.content.ContentResolver) SecurityUtils(com.owncloud.android.utils.SecurityUtils) Locale(java.util.Locale) Map(java.util.Map) NotificationChannel(android.app.NotificationChannel) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) ReceiversHelper(com.owncloud.android.utils.ReceiversHelper) DisplayUtils(com.owncloud.android.utils.DisplayUtils) DispatchingAndroidInjector(dagger.android.DispatchingAndroidInjector) Method(java.lang.reflect.Method) MediaFolder(com.owncloud.android.datamodel.MediaFolder) HasAndroidInjector(dagger.android.HasAndroidInjector) NotificationManager(android.app.NotificationManager) PREFERENCE_CONTACTS_AUTOMATIC_BACKUP(com.owncloud.android.ui.activity.ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP) Logger(com.nextcloud.client.logger.Logger) AndroidInjector(dagger.android.AndroidInjector) AppPreferences(com.nextcloud.client.preferences.AppPreferences) FilesSyncHelper(com.owncloud.android.utils.FilesSyncHelper) Conscrypt(org.conscrypt.Conscrypt) Log_OC(com.owncloud.android.lib.common.utils.Log_OC) DataStorageProvider(com.owncloud.android.datastorage.DataStorageProvider) List(java.util.List) StringRes(androidx.annotation.StringRes) Application(android.app.Application) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Pair(androidx.core.util.Pair) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) SecurityKeyManagerConfig(de.cotech.hw.SecurityKeyManagerConfig) StoragePoint(com.owncloud.android.datastorage.StoragePoint) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ActivityManager(android.app.ActivityManager) Context(android.content.Context) AppInfo(com.nextcloud.client.appinfo.AppInfo) PermissionUtil(com.owncloud.android.utils.PermissionUtil) AlertDialog(androidx.appcompat.app.AlertDialog) AppPreferencesImpl(com.nextcloud.client.preferences.AppPreferencesImpl) Environment(android.os.Environment) ConnectivityService(com.nextcloud.client.network.ConnectivityService) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent) HashMap(java.util.HashMap) OwnCloudClientManagerFactory(com.owncloud.android.lib.common.OwnCloudClientManagerFactory) OnboardingService(com.nextcloud.client.onboarding.OnboardingService) PackageInfo(android.content.pm.PackageInfo) MediaFolderType(com.owncloud.android.datamodel.MediaFolderType) ArrayList(java.util.ArrayList) SSLEngine(javax.net.ssl.SSLEngine) Inject(javax.inject.Inject) SecurityKeyManager(de.cotech.hw.SecurityKeyManager) SuppressLint(android.annotation.SuppressLint) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) LegacyLoggerAdapter(com.nextcloud.client.logger.LegacyLoggerAdapter) EventBus(org.greenrobot.eventbus.EventBus) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager) PowerManagementService(com.nextcloud.client.device.PowerManagementService) Build(android.os.Build) MediaProvider(com.owncloud.android.datamodel.MediaProvider) ExceptionHandler(com.nextcloud.client.errorhandling.ExceptionHandler) PassCodeManager(com.owncloud.android.authentication.PassCodeManager) SyncedFoldersActivity(com.owncloud.android.ui.activity.SyncedFoldersActivity) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) TextUtils(android.text.TextUtils) MigrationsManager(com.nextcloud.client.migrations.MigrationsManager) BackgroundJobManager(com.nextcloud.client.jobs.BackgroundJobManager) StrictMode(android.os.StrictMode) ActivityInjector(com.nextcloud.client.di.ActivityInjector) Activity(android.app.Activity) DaggerAppComponent(com.nextcloud.client.di.DaggerAppComponent) SyncedFoldersActivity(com.owncloud.android.ui.activity.SyncedFoldersActivity) AppPreferences(com.nextcloud.client.preferences.AppPreferences) Intent(android.content.Intent) WindowManager(android.view.WindowManager)

Example 8 with AppPreferences

use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.

the class MainApp method cleanOldEntries.

private static void cleanOldEntries(Clock clock) {
    // previous versions of application created broken entries in the SyncedFolderProvider
    // database, and this cleans all that and leaves 1 (newest) entry per synced folder
    Context context = getAppContext();
    AppPreferences preferences = AppPreferencesImpl.fromContext(context);
    if (!preferences.isLegacyClean()) {
        SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver(), preferences, clock);
        List<SyncedFolder> syncedFolderList = syncedFolderProvider.getSyncedFolders();
        Map<Pair<String, String>, Long> syncedFolders = new HashMap<>();
        ArrayList<Long> ids = new ArrayList<>();
        for (SyncedFolder syncedFolder : syncedFolderList) {
            Pair<String, String> checkPair = new Pair<>(syncedFolder.getAccount(), syncedFolder.getLocalPath());
            if (syncedFolders.containsKey(checkPair)) {
                if (syncedFolder.getId() > syncedFolders.get(checkPair)) {
                    syncedFolders.put(checkPair, syncedFolder.getId());
                }
            } else {
                syncedFolders.put(checkPair, syncedFolder.getId());
            }
        }
        ids.addAll(syncedFolders.values());
        if (ids.size() > 0) {
            int deletedCount = syncedFolderProvider.deleteSyncedFoldersNotInList(ids);
            if (deletedCount > 0) {
                preferences.setLegacyClean(true);
            }
        } else {
            preferences.setLegacyClean(true);
        }
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(android.content.Context) HashMap(java.util.HashMap) AppPreferences(com.nextcloud.client.preferences.AppPreferences) ArrayList(java.util.ArrayList) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) StoragePoint(com.owncloud.android.datastorage.StoragePoint) SuppressLint(android.annotation.SuppressLint) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) Pair(androidx.core.util.Pair)

Aggregations

AppPreferences (com.nextcloud.client.preferences.AppPreferences)8 Context (android.content.Context)6 SyncedFolderProvider (com.owncloud.android.datamodel.SyncedFolderProvider)4 SSLContext (javax.net.ssl.SSLContext)4 SuppressLint (android.annotation.SuppressLint)3 SyncedFolder (com.owncloud.android.datamodel.SyncedFolder)3 ArrayList (java.util.ArrayList)3 ContentResolver (android.content.ContentResolver)2 Bundle (android.os.Bundle)2 Pair (androidx.core.util.Pair)2 StoragePoint (com.owncloud.android.datastorage.StoragePoint)2 HashMap (java.util.HashMap)2 Account (android.accounts.Account)1 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 Application (android.app.Application)1 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1