Skip to content

Commit

Permalink
FIX: Minor crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
oasisfeng committed Mar 1, 2022
1 parent bf581ff commit 6f99593
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> ids = Collections.singleton(AFFILIATION_ID);
final Set<String> current_ids = policies.invoke(DevicePolicyManager::getAffiliationIds);
Expand All @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions open/src/main/java/com/oasisfeng/island/SystemServiceBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 6f99593

Please sign in to comment.