From 6f99593081ca5bf6ae71396954ff50b83c07ff6f Mon Sep 17 00:00:00 2001 From: oasisfeng Date: Tue, 1 Mar 2022 11:57:50 +0800 Subject: [PATCH] FIX: Minor crash. --- .../island/provisioning/IslandProvisioning.java | 8 ++++---- .../com/oasisfeng/island/SystemServiceBridge.java | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/engine/src/main/java/com/oasisfeng/island/provisioning/IslandProvisioning.java b/engine/src/main/java/com/oasisfeng/island/provisioning/IslandProvisioning.java index 454958d32..f98a8a0ce 100644 --- a/engine/src/main/java/com/oasisfeng/island/provisioning/IslandProvisioning.java +++ b/engine/src/main/java/com/oasisfeng/island/provisioning/IslandProvisioning.java @@ -268,7 +268,7 @@ static void setLauncherActivitiesEnabledSetting(final Context context, final Str } public static void startDeviceAndProfileOwnerSharedPostProvisioning(final Context context, final DevicePolicies policies) { - final boolean owner = Users.isParentProfile(); + final boolean isParent = Users.isParentProfile(); if (SDK_INT >= O) { final Set ids = Collections.singleton(AFFILIATION_ID); final Set current_ids = policies.invoke(DevicePolicyManager::getAffiliationIds); @@ -278,13 +278,13 @@ public static void startDeviceAndProfileOwnerSharedPostProvisioning(final Contex policies.clearUserRestrictionsIfNeeded(UserManager.DISALLOW_BLUETOOTH_SHARING); // Ref: UserRestrictionsUtils.DEFAULT_ENABLED_FOR_MANAGED_PROFILES } - if (owner) policies.clearUserRestrictionsIfNeeded(UserManager.DISALLOW_SHARE_LOCATION); // May be restricted on some devices (e.g. LG V20) + if (isParent) policies.clearUserRestrictionsIfNeeded(UserManager.DISALLOW_SHARE_LOCATION); // May be restricted on some devices (e.g. LG V20) try { if (SDK_INT >= N_MR1 && ! policies.isBackupServiceEnabled()) policies.setBackupServiceEnabled(true); // Ref: DevicePolicyManagerService.toggleBackupServiceActive() - } catch (final SecurityException e) { - if (SDK_INT != N_MR1 || ! owner && ! "There should only be one user, managed by Device Owner".equals(e.getMessage())) + } catch (final SecurityException e) { // isBackupServiceEnabled()/setBackupServiceEnabled() require device owner before Android Q. + if (SDK_INT >= Q || ! isParent && ! "There should only be one user, managed by Device Owner".equals(e.getMessage())) Analytics.$().report(e); } catch (final IllegalStateException e) { Analytics.$().report(e); diff --git a/open/src/main/java/com/oasisfeng/island/SystemServiceBridge.java b/open/src/main/java/com/oasisfeng/island/SystemServiceBridge.java index f34b6ab85..129c828d8 100644 --- a/open/src/main/java/com/oasisfeng/island/SystemServiceBridge.java +++ b/open/src/main/java/com/oasisfeng/island/SystemServiceBridge.java @@ -10,6 +10,7 @@ import androidx.annotation.Nullable; +import com.oasisfeng.island.analytics.Analytics; import com.oasisfeng.island.api.DelegatedAppOpsManager; import com.oasisfeng.island.api.DelegatedDevicePolicyManager; import com.oasisfeng.island.api.PermissionForwardingRestrictionsManager; @@ -34,24 +35,24 @@ public class SystemServiceBridge extends Service { case Context.RESTRICTIONS_SERVICE: try { return PermissionForwardingRestrictionsManager.buildBinderProxy(this, user); - } catch (final ReflectiveOperationException e) { - Log.e(TAG, "Error preparing delegated RestrictionsManager", e); + } catch (final ReflectiveOperationException | ExceptionInInitializerError e) { + Analytics.$().logAndReport(TAG, "Error preparing delegated RestrictionsManager", e); } catch (final PermissionForwardingRestrictionsManager.IncompatibilityException e) { - Log.e(TAG, "Incompatible ROM"); + Analytics.$().logAndReport(TAG, "Incompatible ROM", e); } break; case Context.DEVICE_POLICY_SERVICE: try { return DelegatedDevicePolicyManager.buildBinderProxy(this); - } catch (final ReflectiveOperationException e) { - Log.e(TAG, "Error preparing delegated DevicePolicyManager", e); + } catch (final ReflectiveOperationException | ExceptionInInitializerError e) { + Analytics.$().logAndReport(TAG, "Error preparing delegated DevicePolicyManager", e); break; } case Context.APP_OPS_SERVICE: try { return DelegatedAppOpsManager.buildBinderProxy(this); - } catch (final ReflectiveOperationException e) { - Log.e(TAG, "Error preparing delegated AppOpsManager", e); + } catch (final ReflectiveOperationException | ExceptionInInitializerError e) { + Analytics.$().logAndReport(TAG, "Error preparing delegated AppOpsManager", e); break; }