mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Use restriction manager for app config
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
9a79ecac08
commit
8a48da3a32
6 changed files with 117 additions and 7 deletions
|
@ -126,6 +126,10 @@
|
|||
android:usesCleartextTraffic="true"
|
||||
tools:ignore="UnusedAttribute"
|
||||
tools:replace="android:allowBackup">
|
||||
|
||||
<meta-data android:name="android.content.APP_RESTRICTIONS"
|
||||
android:resource="@xml/app_config" />
|
||||
|
||||
<activity
|
||||
android:name="com.nextcloud.ui.composeActivity.ComposeActivity"
|
||||
android:exported="false" />
|
||||
|
|
|
@ -21,13 +21,14 @@ import android.app.ActivityManager;
|
|||
import android.app.Application;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -55,6 +56,7 @@ import com.nextcloud.client.onboarding.OnboardingService;
|
|||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.nextcloud.client.preferences.DarkMode;
|
||||
import com.nextcloud.utils.extensions.ContextExtensionsKt;
|
||||
import com.nmc.android.ui.LauncherActivity;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.authentication.PassCodeManager;
|
||||
|
@ -63,6 +65,7 @@ import com.owncloud.android.datamodel.ArbitraryDataProviderImpl;
|
|||
import com.owncloud.android.datamodel.MediaFolder;
|
||||
import com.owncloud.android.datamodel.MediaFolderType;
|
||||
import com.owncloud.android.datamodel.MediaProvider;
|
||||
import com.owncloud.android.datamodel.ReceiverFlag;
|
||||
import com.owncloud.android.datamodel.SyncedFolder;
|
||||
import com.owncloud.android.datamodel.SyncedFolderProvider;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
|
@ -75,6 +78,7 @@ import com.owncloud.android.lib.resources.status.NextcloudVersion;
|
|||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.ui.activity.SyncedFoldersActivity;
|
||||
import com.owncloud.android.ui.notifications.NotificationUtils;
|
||||
import com.owncloud.android.utils.appConfig.AppConfigManager;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.FilesSyncHelper;
|
||||
import com.owncloud.android.utils.PermissionUtil;
|
||||
|
@ -191,6 +195,8 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
|||
@SuppressWarnings("unused")
|
||||
private boolean mBound;
|
||||
|
||||
private AppConfigManager appConfigManager;
|
||||
|
||||
private static AppComponent appComponent;
|
||||
|
||||
/**
|
||||
|
@ -281,6 +287,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
|||
return appComponent;
|
||||
}
|
||||
|
||||
|
||||
@SuppressFBWarnings("ST")
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -291,6 +298,11 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
|||
setAppTheme(preferences.getDarkThemeMode());
|
||||
super.onCreate();
|
||||
|
||||
appConfigManager = new AppConfigManager(this);
|
||||
|
||||
// Listen app config changes
|
||||
ContextExtensionsKt.registerBroadcastReceiver(this, restrictionsReceiver, restrictionsFilter, ReceiverFlag.NotExported);
|
||||
|
||||
ProcessLifecycleOwner.get().getLifecycle().addObserver(lifecycleEventObserver);
|
||||
|
||||
insertConscrypt();
|
||||
|
@ -314,12 +326,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
|||
|
||||
OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
|
||||
|
||||
try {
|
||||
OwnCloudClientManagerFactory.setProxyHost(getResources().getString(R.string.proxy_host));
|
||||
OwnCloudClientManagerFactory.setProxyPort(getResources().getInteger(R.integer.proxy_port));
|
||||
} catch (Resources.NotFoundException e) {
|
||||
// no proxy set
|
||||
}
|
||||
appConfigManager.readProxyConfig();
|
||||
|
||||
// initialise thumbnails cache on background thread
|
||||
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
|
||||
|
@ -358,15 +365,27 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
|||
registerGlobalPassCodeProtection();
|
||||
}
|
||||
|
||||
|
||||
private final LifecycleEventObserver lifecycleEventObserver = ((lifecycleOwner, event) -> {
|
||||
if (event == Lifecycle.Event.ON_START) {
|
||||
Log_OC.d(TAG, "APP IN FOREGROUND");
|
||||
} else if (event == Lifecycle.Event.ON_STOP) {
|
||||
passCodeManager.setCanAskPin(true);
|
||||
Log_OC.d(TAG, "APP IN BACKGROUND");
|
||||
} else if (event == Lifecycle.Event.ON_RESUME) {
|
||||
appConfigManager.readProxyConfig();
|
||||
Log_OC.d(TAG, "APP ON RESUME");
|
||||
}
|
||||
});
|
||||
|
||||
private final IntentFilter restrictionsFilter = new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
|
||||
|
||||
private final BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() {
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
appConfigManager.readProxyConfig();
|
||||
}
|
||||
};
|
||||
|
||||
private void registerGlobalPassCodeProtection() {
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.owncloud.android.utils.appConfig
|
||||
|
||||
/**
|
||||
* These keys are connected to app_config.xml
|
||||
*/
|
||||
enum class AppConfigKeys(val key: String) {
|
||||
ProxyHost("proxy_host"),
|
||||
ProxyPort("proxy_port"),
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.owncloud.android.utils.appConfig
|
||||
|
||||
import android.content.Context
|
||||
import android.content.RestrictionsManager
|
||||
import android.content.res.Resources
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
|
||||
class AppConfigManager(context: Context) {
|
||||
|
||||
private val restrictionsManager =
|
||||
context.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
|
||||
|
||||
private val tag = "AppConfigManager"
|
||||
|
||||
fun readProxyConfig() {
|
||||
val appRestrictions = restrictionsManager.applicationRestrictions
|
||||
|
||||
if (!appRestrictions.containsKey(AppConfigKeys.ProxyHost.key) || !appRestrictions.containsKey(AppConfigKeys.ProxyPort.key)) {
|
||||
// TODO Send feedback to customer
|
||||
}
|
||||
|
||||
val host = appRestrictions.getString(AppConfigKeys.ProxyHost.key)
|
||||
val port = appRestrictions.getInt(AppConfigKeys.ProxyPort.key)
|
||||
|
||||
try {
|
||||
OwnCloudClientManagerFactory.setProxyHost(host)
|
||||
OwnCloudClientManagerFactory.setProxyPort(port)
|
||||
} catch (e: Resources.NotFoundException) {
|
||||
// TODO Send feedback to customer
|
||||
Log_OC.d(tag,"Proxy config cannot able to set due to: $e")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,12 @@
|
|||
|
||||
<string name="ecosystem_apps_display_assistant">Assistant</string>
|
||||
|
||||
<string name="app_config_proxy_host_title">Host</string>
|
||||
<string name="app_config_proxy_host_description">Select a proxy host configuration</string>
|
||||
|
||||
<string name="app_config_proxy_port_title">Port</string>
|
||||
<string name="app_config_proxy_port_description">Select a proxy port configuration</string>
|
||||
|
||||
<string name="assistant_screen_task_types_error_state_message">Unable to fetch task types, please check your internet connection.</string>
|
||||
<string name="assistant_screen_task_list_error_state_message">Unable to fetch task list, please check your internet connection.</string>
|
||||
|
||||
|
|
24
app/src/main/res/xml/app_config.xml
Normal file
24
app/src/main/res/xml/app_config.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Nextcloud - Android Client
|
||||
~
|
||||
~ SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
|
||||
~ SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
-->
|
||||
|
||||
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<restriction
|
||||
android:key="proxy_host"
|
||||
android:restrictionType="string"
|
||||
android:defaultValue=""
|
||||
android:title="@string/app_config_proxy_host_title"
|
||||
android:description="@string/app_config_proxy_host_description" />
|
||||
|
||||
<restriction
|
||||
android:key="proxy_port"
|
||||
android:restrictionType="integer"
|
||||
android:defaultValue="0"
|
||||
android:title="@string/app_config_proxy_port_title"
|
||||
android:description="@string/app_config_proxy_port_description" />
|
||||
|
||||
</restrictions>
|
Loading…
Reference in a new issue