Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 326be275 authored by Benjamin Franz's avatar Benjamin Franz Committed by Android (Google) Code Review
Browse files

Merge "Profile Owner API to clear application data"

parents 2456be8d a77e3578
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -6283,6 +6283,7 @@ package android.app.admin {
    method public void addPersistentPreferredActivity(android.content.ComponentName, android.content.IntentFilter, android.content.ComponentName);
    method public void addUserRestriction(android.content.ComponentName, java.lang.String);
    method public boolean bindDeviceAdminServiceAsUser(android.content.ComponentName, android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle);
    method public boolean clearApplicationUserData(android.content.ComponentName, java.lang.String, android.app.admin.DevicePolicyManager.OnClearApplicationUserDataListener, android.os.Handler);
    method public void clearCrossProfileIntentFilters(android.content.ComponentName);
    method public deprecated void clearDeviceOwnerApp(java.lang.String);
    method public void clearPackagePersistentPreferredActivities(android.content.ComponentName, java.lang.String);
@@ -6536,6 +6537,10 @@ package android.app.admin {
    field public static final int WIPE_RESET_PROTECTION_DATA = 2; // 0x2
  }
  public static abstract interface DevicePolicyManager.OnClearApplicationUserDataListener {
    method public abstract void onApplicationUserDataCleared(java.lang.String, boolean);
  }
  public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
    method public java.lang.String getHostname();
    method public java.util.List<java.net.InetAddress> getInetAddresses();
+5 −0
Original line number Diff line number Diff line
@@ -6499,6 +6499,7 @@ package android.app.admin {
    method public void addPersistentPreferredActivity(android.content.ComponentName, android.content.IntentFilter, android.content.ComponentName);
    method public void addUserRestriction(android.content.ComponentName, java.lang.String);
    method public boolean bindDeviceAdminServiceAsUser(android.content.ComponentName, android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle);
    method public boolean clearApplicationUserData(android.content.ComponentName, java.lang.String, android.app.admin.DevicePolicyManager.OnClearApplicationUserDataListener, android.os.Handler);
    method public void clearCrossProfileIntentFilters(android.content.ComponentName);
    method public deprecated void clearDeviceOwnerApp(java.lang.String);
    method public void clearPackagePersistentPreferredActivities(android.content.ComponentName, java.lang.String);
@@ -6785,6 +6786,10 @@ package android.app.admin {
    field public static final int WIPE_RESET_PROTECTION_DATA = 2; // 0x2
  }
  public static abstract interface DevicePolicyManager.OnClearApplicationUserDataListener {
    method public abstract void onApplicationUserDataCleared(java.lang.String, boolean);
  }
  public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
    method public java.lang.String getHostname();
    method public java.util.List<java.net.InetAddress> getInetAddresses();
+5 −0
Original line number Diff line number Diff line
@@ -6304,6 +6304,7 @@ package android.app.admin {
    method public void addPersistentPreferredActivity(android.content.ComponentName, android.content.IntentFilter, android.content.ComponentName);
    method public void addUserRestriction(android.content.ComponentName, java.lang.String);
    method public boolean bindDeviceAdminServiceAsUser(android.content.ComponentName, android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle);
    method public boolean clearApplicationUserData(android.content.ComponentName, java.lang.String, android.app.admin.DevicePolicyManager.OnClearApplicationUserDataListener, android.os.Handler);
    method public void clearCrossProfileIntentFilters(android.content.ComponentName);
    method public deprecated void clearDeviceOwnerApp(java.lang.String);
    method public void clearPackagePersistentPreferredActivities(android.content.ComponentName, java.lang.String);
@@ -6567,6 +6568,10 @@ package android.app.admin {
    field public static final int WIPE_RESET_PROTECTION_DATA = 2; // 0x2
  }
  public static abstract interface DevicePolicyManager.OnClearApplicationUserDataListener {
    method public abstract void onApplicationUserDataCleared(java.lang.String, boolean);
  }
  public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
    method public java.lang.String getHostname();
    method public java.util.List<java.net.InetAddress> getInetAddresses();
+2 −1
Original line number Diff line number Diff line
@@ -2698,7 +2698,8 @@ public class ActivityManager {
     * the user choosing to clear the app's data from within the device settings UI.  It
     * erases all dynamic data associated with the app -- its private data and data in its
     * private area on external storage -- but does not remove the installed application
     * itself, nor any OBB files.
     * itself, nor any OBB files. It also revokes all runtime permissions that the app has acquired,
     * clears all notifications and removes all Uri grants related to this application.
     *
     * @return {@code true} if the application successfully requested that the application's
     *     data be erased; {@code false} otherwise.
+49 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice;
@@ -47,6 +48,7 @@ import android.graphics.Bitmap;
import android.net.ProxyInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.os.PersistableBundle;
import android.os.Process;
@@ -8109,4 +8111,51 @@ public class DevicePolicyManager {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Called by the device owner or profile owner to clear application user data of a given
     * package. The behaviour of this is equivalent to the target application calling
     * {@link android.app.ActivityManager#clearApplicationUserData()}.
     *
     * <p><strong>Note:</strong> an application can store data outside of its application data, e.g.
     * external storage or user dictionary. This data will not be wiped by calling this API.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param packageName The name of the package which will have its user data wiped.
     * @param listener A callback object that will inform the caller when the clearing is done.
     * @param handler The handler indicating the thread on which the listener should be invoked.
     * @throws SecurityException if the caller is not the device owner/profile owner.
     * @return whether the clearing succeeded.
     */
    public boolean clearApplicationUserData(@NonNull ComponentName admin,
            @NonNull String packageName, @NonNull OnClearApplicationUserDataListener listener,
            @NonNull Handler handler) {
        throwIfParentInstance("clearAppData");
        try {
            return mService.clearApplicationUserData(admin, packageName,
                    new IPackageDataObserver.Stub() {
                        public void onRemoveCompleted(String pkg, boolean succeeded) {
                            handler.post(() ->
                                    listener.onApplicationUserDataCleared(pkg, succeeded));
                        }
                    });
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Callback used in {@link #clearApplicationUserData}
     * to indicate that the clearing of an application's user data is done.
     */
    public interface OnClearApplicationUserDataListener {
        /**
         * Method invoked when clearing the application user data has completed.
         *
         * @param packageName The name of the package which had its user data cleared.
         * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator
         *                  apps and protected system packages.
         */
        void onApplicationUserDataCleared(String packageName, boolean succeeded);
    }
}
Loading