Skip to content

Commit

Permalink
init RestrictionsManager only for branded plus clients
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed May 3, 2024
1 parent 5927623 commit 1c19499
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
24 changes: 19 additions & 5 deletions app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -299,9 +300,6 @@ public void onCreate() {
setAppTheme(preferences.getDarkThemeMode());
super.onCreate();

RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
appConfigManager = new AppConfigManager(this, restrictionsManager.getApplicationRestrictions());

// Listen app config changes
ContextExtensionsKt.registerBroadcastReceiver(this, restrictionsReceiver, restrictionsFilter, ReceiverFlag.NotExported);

Expand All @@ -328,7 +326,13 @@ public void onCreate() {

OwnCloudClientManagerFactory.setUserAgent(getUserAgent());

appConfigManager.setProxyConfig(isClientBrandedPlus());
if (isClientBrandedPlus()) {
RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
appConfigManager = new AppConfigManager(this, restrictionsManager.getApplicationRestrictions());
appConfigManager.setProxyConfig(isClientBrandedPlus());
} else {
setProxyForNonBrandedPlusClients();
}

// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
Expand Down Expand Up @@ -367,19 +371,28 @@ public void onCreate() {
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) {
if (appConfigManager == null) return;
appConfigManager.setProxyConfig(isClientBrandedPlus());
Log_OC.d(TAG, "APP ON RESUME");
}
});

private void setProxyForNonBrandedPlusClients() {
try {
OwnCloudClientManagerFactory.setProxyHost(getResources().getString(R.string.proxy_host));
OwnCloudClientManagerFactory.setProxyPort(getResources().getInteger(R.integer.proxy_port));
} catch (Resources.NotFoundException e) {
Log_OC.d(TAG, "Error caught at setProxyForNonBrandedPlusClients: " + e);
}
}

public static boolean isClientBrandedPlus() {
return (getAppContext().getResources().getBoolean(R.bool.is_branded_plus_client));
}
Expand All @@ -388,6 +401,7 @@ public static boolean isClientBrandedPlus() {

private final BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
if (appConfigManager == null) return;
appConfigManager.setProxyConfig(isClientBrandedPlus());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import com.owncloud.android.lib.common.OwnCloudCredentials;
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.UserInfo;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.network.CertificateCombinedException;
Expand Down Expand Up @@ -321,10 +322,13 @@ protected void onCreate(Bundle savedInstanceState) {
}

boolean webViewLoginMethod;
String webloginUrl = null;

RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
AppConfigManager appConfigManager = new AppConfigManager(this, restrictionsManager.getApplicationRestrictions());
String webloginUrl = appConfigManager.getBaseUrl(MainApp.isClientBrandedPlus());
if (MainApp.isClientBrandedPlus()) {
RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
AppConfigManager appConfigManager = new AppConfigManager(this, restrictionsManager.getApplicationRestrictions());
webloginUrl = appConfigManager.getBaseUrl(MainApp.isClientBrandedPlus());
}

if (webloginUrl != null) {
webViewLoginMethod = true;
Expand Down Expand Up @@ -1383,7 +1387,7 @@ protected boolean createAccount(RemoteOperationResult<UserInfo> authResult) {
// can be anything: email, name, name with whitespaces
String loginName = webViewUser;

String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, loginName);
String accountName = AccountUtils.buildAccountName(uri, loginName);
Account newAccount = new Account(accountName, accountType);
if (accountManager.exists(newAccount)) {
// fail - not a new account, but an existing one; disallow
Expand Down Expand Up @@ -1488,7 +1492,7 @@ private void startQRScanner() {
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == PermissionUtil.PERMISSIONS_CAMERA) {// If request is cancelled, result arrays are empty.
if (requestCode == PERMISSIONS_CAMERA) {// If request is cancelled, result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
startQRScanner();
Expand Down

0 comments on commit 1c19499

Please sign in to comment.