summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vitor Carvalho <vtrmc@google.com> 2025-02-03 17:11:12 +0000
committer Vitor Carvalho <vtrmc@google.com> 2025-02-03 17:11:51 +0000
commitc09ab40eba93ada916af37e87ef1be2096db5804 (patch)
tree9eac6402161c0ff751dde53240d3e6eb13be71aa
parentfe5ebfec7f6e083c0084591391bd35940798c63f (diff)
Check if the supervision service is null before calling it in SupervisionManager.
Test: n/a Bug: 394066725 Flag: android.app.supervision.flags.deprecate_dpm_supervision_apis Change-Id: If8ec00ae2836f8ff1c8f8dc0b31e30ac45c57278
-rw-r--r--core/java/android/app/supervision/SupervisionManager.java36
1 files changed, 22 insertions, 14 deletions
diff --git a/core/java/android/app/supervision/SupervisionManager.java b/core/java/android/app/supervision/SupervisionManager.java
index a4efd77fce75..d30705536045 100644
--- a/core/java/android/app/supervision/SupervisionManager.java
+++ b/core/java/android/app/supervision/SupervisionManager.java
@@ -33,7 +33,7 @@ import android.os.RemoteException;
@SystemService(Context.SUPERVISION_SERVICE)
public class SupervisionManager {
private final Context mContext;
- private final ISupervisionManager mService;
+ @Nullable private final ISupervisionManager mService;
/**
* Activity action: ask the human user to enable supervision for this user. Only the app that
@@ -66,7 +66,7 @@ public class SupervisionManager {
/** @hide */
@UnsupportedAppUsage
- public SupervisionManager(Context context, ISupervisionManager service) {
+ public SupervisionManager(Context context, @Nullable ISupervisionManager service) {
mContext = context;
mService = service;
}
@@ -93,11 +93,14 @@ public class SupervisionManager {
value = android.Manifest.permission.INTERACT_ACROSS_USERS,
conditional = true)
public boolean isSupervisionEnabledForUser(@UserIdInt int userId) {
- try {
- return mService.isSupervisionEnabledForUser(userId);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
+ if (mService != null) {
+ try {
+ return mService.isSupervisionEnabledForUser(userId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
}
+ return false;
}
/**
@@ -122,10 +125,12 @@ public class SupervisionManager {
value = android.Manifest.permission.INTERACT_ACROSS_USERS,
conditional = true)
public void setSupervisionEnabledForUser(@UserIdInt int userId, boolean enabled) {
- try {
- mService.setSupervisionEnabledForUser(userId, enabled);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
+ if (mService != null) {
+ try {
+ mService.setSupervisionEnabledForUser(userId, enabled);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
}
}
@@ -138,10 +143,13 @@ public class SupervisionManager {
@UserHandleAware
@Nullable
public String getActiveSupervisionAppPackage() {
- try {
- return mService.getActiveSupervisionAppPackage(mContext.getUserId());
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
+ if (mService != null) {
+ try {
+ return mService.getActiveSupervisionAppPackage(mContext.getUserId());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
}
+ return null;
}
}